文件
mashangyoujiu/Application/Common/Business/VipInfo.class.php

514 行
19 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Common\Business;
use Common\Model\ImageGalleryModel;
use Common\Model\RetailPlusVipModel;
use Common\Model\RetailSmallProgramUserModel;
use Common\Model\RetailVipIntegralModel;
use Common\Model\RetailVipModel;
use Common\Model\StoreConfigModel;
//[1.8.71]
/**
* 小程序会员信息类
* Class VipInfo
* [
* 根据积分的获取对应的会员等级信息 singleVipGrade
* 获取单个会员的信息 singleVipInfo
* 获取所有会员等级 getGradeList
* 根据门店或会员等级获取会员信息 basisStoreGetVip
* 依据会员id查询会员信息 basisIdGetVipInfo
* 根据会员手机号查询会员信息 basisPhoneGetVip
* 小程序获取会员信息 getVipInfo
* 获取会员信息--vip表 getVipGroup
* 获取对应的会员等级名称 getVipGradeName
* ]
* @package Common\Business
*/
class VipInfo
{
/**
* 获取plus会员享受的折扣值
* @param $param
* $param['merchant_id'] 商户ID
* @return int|mixed
*/
public function getPlusDiscount($param)
{
$IntegralModel = new RetailVipIntegralModel();
$map = [
'merchantid' => $param['merchant_id'],
];
$discount = $IntegralModel->getOrderFindField($map, 'discount', 'discount asc');
return $discount ? floatval($discount) : 1;
}
/**
* 根据积分的获取对应的会员等级信息
* @param $param
* [
* merchant_id 商户ID
* grade_integral 等级积分
* grade_id 等级ID
* ]
* @return mixed
*/
public function singleVipGrade($param)
{
try {
$map = [
'merchantid' => $param['merchant_id'],
];
if ($param['grade_id']) {
$map['id'] = $param['grade_id'];
} else {
$map['min_integral'] = ['elt', $param['grade_integral']];
}
$IntegralModel = new RetailVipIntegralModel();
$grade = $IntegralModel->getOrderFind($map, 'id,cardname as grade_name,discount,min_integral,gradeimgurl as grade_img', 'min_integral desc');
if (!$param['get_default']) {
return $grade;
} else {
return $grade ? $grade : ['id' => '', 'grade_name' => '默认会员', 'discount' => '-', 'min_integral' => 0, 'grade_img' => ''];
}
} catch (\Exception $e) {
if (!$param['get_default']) {
return [];
} else {
return ['id' => '', 'grade_name' => '默认会员', 'discount' => '-', 'min_integral' => 0, 'grade_img' => ''];
}
}
}
/**
* 获取某会员的信息
* @param $param
* [
* where 查询条件
* fields 查询字段
* ]
* @return mixed
*/
public function singleVipInfo($param)
{
$param['fields'] = $param['fields'] ? $param['fields'] : '*';
try {
$VipModel = new RetailVipModel();
$info = $VipModel->getFind($param['where'], $param['fields']);
return $info;
} catch (\Exception $e) {
return [];
}
}
/**
* 获取所有会员等级
* @param $param
* [
* merchant_id
* fields
* ]
* @return mixed
*/
public function getGradeList($param)
{
$fields = $param['fields'] ? $param['fields'] : '*';
try {
$VipIntegralModel = new RetailVipIntegralModel();
$list = $VipIntegralModel->getSelect([
'merchantid' => $param['merchant_id']
], $fields, 'discount asc');
return $list;
} catch (\Exception $e) {
return [];
}
}
/**
* 获取会员等级列表
* @param $param
* $param['merchant_id'] 商户ID
* $param['integralRange'] 是否需要等级积分范围
* $param['icon'] 是否需要等级图片
* @return array
*/
public function getVipGradeList($param)
{
if (empty($param)) {
return [];
}
$VipIntegralModel = new RetailVipIntegralModel();
$fields = 'id,cardname as grade_name,discount,min_integral' . ($param['icon'] ? 'gradeimgurl_id' : '');
$list = $VipIntegralModel->getSelect(['merchantid' => $param['merchant_id']], $fields, 'min_integral asc');
if ($param['integralRange'] === true || $param['icon'] === true) {
$ImageGalleryModel = new ImageGalleryModel();
foreach ($list as $key => &$value) {
if ($param['integralRange'] === true) $value['max_integral'] = $list[$key + 1] ? bcsub($list[$key + 1]['min_integral'], 1, 0) : '';
if ($param['icon'] === true) {
$value['image'] = $ImageGalleryModel->getImagePath($value['gradeimgurl_id']);
unset($value['gradeimgurl_id']);
}
}
}
return $list ? $list : [];
}
/**
* 根据优惠券信息获取发放的会员集合
* @param $param
* [
* user_type 3商户 4门店
* merchant_id
* need_count 0不需要总数 1需要
* store_id_str 门店集合string
* grade_id_str 会员等级集合 string -1 字段v前缀
* search_info 搜索内容
* fields 查询的字段
* page
* limit
* ]
* @return mixed
*/
public function basisStoreGetVip($param)
{
$time = $_SERVER['REQUEST_TIME'];
$fields = $param['fields'];
$need_count = $param['need_count'] ? $param['need_count'] : 0;
$vip_id_arr = [];
$VipModel = new RetailVipModel();
if ($param['grade_id_str'] == '-1') {
//Plus
$where = [
'v.merchantid' => $param['merchant_id'],
'v.plus_type' => 2,
'v.status' => 1,
'p.start_time' => ['elt', $time],
'p.end_time' => ['gt', $time],
'p.state' => 1
];
if ($param['user_type'] == 4 || ($param['user_type'] == 3 && $param['store_id_str'] != '0')) {
//指定门店
$where['v.storeid'] = ['in', $param['store_id_str']];
}
if (!empty($param['search_info'])) {
$where['v.mobile_phone|v.card_key'] = ['like', '%' . $param['search_info'] . '%'];
}
try {
$vip_id_arr = $VipModel->getPlusInfo($where, $fields, $order = 'v.grade_integral desc,id desc', $param['page'], $param['limit']);
if ($need_count == 1) {
$count = $VipModel->getPlusCount($where);
}
} catch (\Exception $e) {
return callBack(statusCode()['error'], "会员查询失败", [
'vip_id_arr' => [],
'count' => 0
]);
}
} else if ($param['grade_id_str'] == '0') {
//所有
$where = [
'merchantid' => $param['merchant_id'],
'status' => 1,
];
if ($param['user_type'] == 4 || ($param['user_type'] == 3 && $param['store_id_str'] != '0')) {
//指定门店
$where['storeid'] = ['in', $param['store_id_str']];
}
if (!empty($param['search_info'])) {
$where['mobile_phone|card_key'] = ['like', '%' . $param['search_info'] . '%'];
}
try {
$vip_id_arr = $VipModel->getSelect($where, $fields, 'grade_integral desc,id desc', $param['page'] . ',' . $param['limit']);
if ($need_count == 1) {
$count = $VipModel->getCount($where);
}
} catch (\Exception $e) {
return callBack(statusCode()['error'], "会员查询失败", [
'vip_id_arr' => [],
'count' => 0
]);
}
} else {
//指定等级
$where = [
'merchantid' => $param['merchant_id'],
'status' => 1,
'plus_type' => 3
];
if ($param['user_type'] == 4 || ($param['user_type'] == 3 && $param['store_id_str'] != '0')) {
//指定门店
$where['storeid'] = ['in', $param['store_id_str']];
}
if (!empty($param['search_info'])) {
$where['mobile_phone|card_key'] = ['like', '%' . $param['search_info'] . '%'];
}
try {
$RetailVipIntegralModel = new RetailVipIntegralModel();
$grade_integral_arr = $RetailVipIntegralModel->getFindField([
'id' => ['in', $param['grade_id_str']],
'merchantid' => $param['merchant_id']
], 'min_integral', true);
// 会员
$integral_map = [];
$map = [
'merchantid' => $param['merchant_id'],
];
foreach ($grade_integral_arr as $val) { // 积分获取
$map['min_integral'] = ['gt', $val];
$min_integral = $RetailVipIntegralModel->getOrderFind($map, 'min_integral', 'min_integral asc');
if (!empty($min_integral)) {
$integral_map[] = ['between', [$val, $min_integral['min_integral'] - 1]];// 之上有积分
} else { // 之上无积分
$integral_map[] = ['egt', $val];
}
}
if (!empty($integral_map)) {
$integral_map[] = 'OR';
$where['grade_integral'] = $integral_map;
}
$vip_id_arr = $VipModel->getSelect($where, $fields, 'grade_integral desc,id desc', $param['page'] . ',' . $param['limit']);
if ($need_count == 1) {
$count = $VipModel->getCount($where);
}
} catch (\Exception $e) {
return callBack(statusCode()['error'], "会员查询失败", [
'vip_id_arr' => [],
'count' => 0
]);
}
}
return callBack(statusCode()['success'], "获取成功", [
'vip_id_arr' => $vip_id_arr,
'count' => $count ? $count : 0
]);
}
/**
* 依据会员id查询会员信息
* @param $param
* [
* merchant_id
* vip_id
* status 会员状态;默认1为正常;1:正常会员,2:删除会员 3冻结 4挂失
* ]
* @return mixed
*/
public function basisIdGetVipInfo($param)
{
try {
$VipModel = new RetailVipModel();
$info = $VipModel->getFind([
'merchantid' => $param['merchant_id'],
'id' => $param['vip_id'],
'status' => $param['status']
]);
if (!empty($info)) {
return callBack(statusCode()['success'], "会员查询成功", $info);
} else {
return callBack(statusCode()['error'], "会员查询失败");
}
} catch (\Exception $e) {
return callBack(statusCode()['error'], "会员查询失败");
}
}
/**
* 根据会员手机号查询会员信息
* @param $param
* [
* merchant_id
* mobile_phone 手机号
* ]
* @return mixed
*/
public function basisPhoneGetVip($param)
{
if (empty($param['merchant_id']) || empty($param['mobile_phone'])) {
return callBack(statusCode()['error'], "缺少参数");
}
try {
$VipModel = new RetailVipModel();
$vipInfo = $VipModel->getFind([
'merchantid' => $param['merchant_id'],
'mobile_phone' => $param['mobile_phone'],
'status' => ['neq', 2]
]);
if (empty($vipInfo)) {
return callBack(statusCode()['error'], '未找到该会员');
} else {
return callBack(statusCode()['success'], '查询成功', $vipInfo);
}
} catch (\Exception $e) {
return callBack(statusCode()['error'], '未找到该会员');
}
}
/**
* 小程序获取会员信息
* @param $param
* [
* merchant_id
* user 小程序用户信息
* ]
* @return bool
*/
public function getVipInfo($param)
{
$VipModel = new RetailVipModel();
$VipIntegralModel = new RetailVipIntegralModel();
$SmallProgramUserModel = new RetailSmallProgramUserModel();
$PlusVipModel = new RetailPlusVipModel();
$user = $param['user'];
if ($user['user_type'] == 2 || $user['user_type'] == 3) {
$map = array(
$VipIntegralModel::MERCHANT_ID => $param['merchant_id'],
$VipIntegralModel::DISCOUNT => array('gt', 0)
);
$vMap = array(
$VipModel::ID => $user[$SmallProgramUserModel::VID],
$VipModel::STATUS => 1
);
try {
$vip = $VipModel->getFind($vMap);
//PLUS共计优惠金额
$plus_data = $PlusVipModel->getOrderFind(array('vip_id' => $vip['id']), 'total_less_money,state,end_time');
if (!empty($vip)) {
if ($user['user_type'] == 2) {
//plus会员
$grade = $VipIntegralModel->getOrderFind($map, '*', $VipIntegralModel::DISCOUNT . ' asc');
$vipInfo['grade_name'] = 'PLUS会员';
} else {
//常规会员
$map[$VipIntegralModel::MIN_INTEGRAL] = array('ELT', $vip[$VipModel::GRADE_INTEGRAL]);
$grade = $VipIntegralModel->getOrderFind($map, '*', $VipIntegralModel::MIN_INTEGRAL . ' desc');
$vipInfo['grade_name'] = $grade[$VipIntegralModel::CARD_NAME];
}
$next_grade = $VipIntegralModel->getVipNextGradeInfo($param['merchant_id'], $vip['grade_integral']);
} else {
$user['user_type'] = 1;
$grade = array();
}
} catch (\Exception $e) {
$user['user_type'] = 1;
$grade = array();
}
} else {
$grade = array();
}
$vipInfo = false;
if ($user['user_type'] != 1) {
$vipInfo['user_type'] = $user['user_type'];
$vipInfo['integral'] = $vip[$VipModel::INTEGRAL] ? $vip[$VipModel::INTEGRAL] : 0;
$vipInfo['discount'] = ($grade[$VipIntegralModel::DISCOUNT] > 0 && $grade[$VipIntegralModel::DISCOUNT] < 1) ? $grade[$VipIntegralModel::DISCOUNT] : 1;
$vipInfo['vid'] = $vip[$VipModel::ID] ? $vip[$VipModel::ID] : 0;
$vipInfo['balance'] = $vip[$VipModel::BALANCE] ? $vip[$VipModel::BALANCE] : 0;
$vipInfo['card_num'] = $vip[$VipModel::MOBILE_PHONE] ? $vip[$VipModel::MOBILE_PHONE] : $vip[$VipModel::CARD_KEY];
$vipInfo['nickname'] = $vip[$VipModel::NICK_NAME] ? $vip[$VipModel::NICK_NAME] : $user[$SmallProgramUserModel::NICKNAME];
$vipInfo['avatar'] = $vip[$VipModel::AVATAR] ? $vip[$VipModel::AVATAR] : $user[$SmallProgramUserModel::AVATAR];
$vipInfo['password'] = $vip[$VipModel::PASSWORD];
$vipInfo['add_time'] = $vip[$VipModel::ADD_TIME];
$vipInfo['plus_id'] = $vip[$VipModel::PLUS_ID];
$vipInfo['grade_integral'] = $vip[$VipModel::GRADE_INTEGRAL];
$vipInfo['next_grade_integral'] = empty($next_grade['min_integral']) ? $grade['min_integral'] : $next_grade['min_integral'];
$vipInfo['total_less_money'] = empty($plus_data['total_less_money']) ? 0 : $plus_data['total_less_money'];
$vipInfo['plus_end_time'] = date('Y-m-d', $plus_data['end_time']);
$vipInfo['plus_state'] = $plus_data['state'];
}
return $vipInfo;
}
/**
* 获取会员信息--vip表
* @param $param
* [
* merchant_id
* store_id
* search
* field
* page
* limit
* desc
* ]
* @return array
*/
public function getVipGroup($param)
{
if (!$param['merchant_id'] || !$param['store_id']) {
return ['status' => 0, 'msg' => '必要参数缺失!'];
}
$where = [
'merchantid' => $param['merchant_id'],
// 'storeid' => $param['store_id'],
'status' => 1,
'id' => ['exp', "NOT IN (select ifnull (vid,0) from `ls_retail_creditor` where store_id = " . $param['store_id'] . " and status = 1)"],
];
if ($param['search']) {
$where['nickname|name|mobile_phone'] = ['like', "%{$param['search']}%"];
}
$field = $param['field'] ? $param['field'] : 'id, mobile_phone, nickname, name, headimgurl as avatar';
$page = $param['page'] ? $param['page'] : 1;
$limit = $param['limit'] ? $param['limit'] : 10;
$desc = $param['desc'] ? $param['desc'] : 'id desc';
$RetailVipModel = new RetailVipModel();
$StoreConfigModel = new StoreConfigModel();
$list = $RetailVipModel->getVipXcxUserLink($where, $field, $desc, $page, $limit);
$storeSetQuota = $StoreConfigModel->getFindField(['store_id' => $param['store_id']], 'credit_quota');
if ($list['list']) {
foreach ($list['list'] as &$val) {
$val['quota'] = $storeSetQuota ? $storeSetQuota : '0';
if (empty($val['nickname'])) {
$val['nickname'] = '-';
}
if (empty($val['avatar'])) {
$val['avatar'] = '-';
}
if (empty($val['name'])) {
$val['name'] = '-';
}
$val['displayName'] = $val['nickname'] . '|' . $val['name'];
if (empty($val['mobile_phone'])) {
$val['mobile_phone'] = '-';
}
}
return ['status' => 1, 'msg' => '查询成功!', 'data' => ['list' => $list['list'], 'total' => $list['count']]];
}
return ['status' => 0, 'msg' => '暂无数据!'];
}
/**
* 获取对应的会员等级名称
* @param $param
* $param['merchant_id'] 商户ID
* $param['grade_integral'] 等级积分
* @return mixed|string
*/
public function getVipGradeName($param)
{
$IntegralModel = new RetailVipIntegralModel();
$map = [
'min_integral' => ['elt', $param['grade_integral']],
'merchantid' => $param['merchant_id'],
];
$grade_name = $IntegralModel->getOrderFindField($map, 'cardname', 'min_integral desc');
return $grade_name ? $grade_name : '默认会员';
}
}