688 行
29 KiB
PHP
可执行文件
688 行
29 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Common\Business;
|
||
|
||
|
||
use Common\Model\RetailCashierModel;
|
||
use Common\Model\RetailPlusVipModel;
|
||
use Common\Model\RetailRechargeOrderModel;
|
||
use Common\Model\RetailVipChangeModel;
|
||
use Common\Model\RetailVipModel;
|
||
use LittleGift\Business\Vip;
|
||
use think\Exception;
|
||
|
||
use Common\Model\RetailSmallProgramUserModel;
|
||
|
||
use Retail\Business\PlusVip;
|
||
|
||
//[1.9.17]
|
||
|
||
/**
|
||
* 会员编辑类
|
||
* Class VipEdit
|
||
* [
|
||
* 会员编辑信息 editInfo
|
||
* 修改会员支付密码 editVipPassword
|
||
* 会员编辑的字段 getEditInfo
|
||
* 等级为plus会员的处理 vipPlus
|
||
* 会员编辑信息验证 editInfoVerify
|
||
* Plus会员挂失冻结恢复操作 plusOperate
|
||
* ]
|
||
* @package Common\Business
|
||
*/
|
||
class VipEdit
|
||
{
|
||
/**
|
||
* 会员编辑信息
|
||
* @param $param
|
||
* [
|
||
* platform_type 商户平台类型 1默认系统 2微礼平台
|
||
* operator_type 1后台端 2收银端 3助手端
|
||
* user_type 3商户 4门店 5导购 6收银
|
||
* operator_id 操作人id
|
||
* merchant_id
|
||
* store_id
|
||
* cashier_id
|
||
* cashier_vip_edit 收银员的编辑权限
|
||
* cashier_vip_code 收银员的权限码
|
||
* modify_vip_code 收银员输入的权限码
|
||
* modify_plus_mem 收银员是否有将普通会员编辑成为plus会员的权限
|
||
* vip_edit_info json字符串=>[
|
||
* vip_id 会员id
|
||
* vip_type 修改后的角色 1常规会员 2plus会员
|
||
* vip_name 会员名称
|
||
* grade_id 常规会员的等级
|
||
* balance 会员余额
|
||
* integral 积分
|
||
* mobile_phone 手机号
|
||
* operate_days_type //plus会员 0不操作 1增加时长 2减少时长
|
||
* operate_days //plus会员时长
|
||
* ]
|
||
* ]
|
||
* @return mixed
|
||
*/
|
||
public function editInfo($param)
|
||
{
|
||
$verifyResult = $this->editInfoVerify($param); //验证参数
|
||
if ($verifyResult['status'] != 1) {
|
||
return $verifyResult;
|
||
}
|
||
$editResult = $this->getEditInfo($param);
|
||
if ($editResult['status'] != 1) {
|
||
return $editResult;
|
||
}
|
||
$platform_type = $param['platform_type'] ? $param['platform_type'] : 1;
|
||
$edit_info = $editResult['data']['edit_info']; //编辑的信息
|
||
$recharge_order_arr = $editResult['data']['recharge_order_arr']; //充值订单信息
|
||
$change_arr = $editResult['data']['change_arr']; //变更记录
|
||
$original_phone = $editResult['data']['original_phone']; //会员原来的手机号
|
||
if ($platform_type == 2 && !empty($edit_info) && !empty($original_phone)) {
|
||
//第三方平台编辑
|
||
$old_vip = $editResult['data']['vip_info'];
|
||
$third_edit_info = $edit_info;
|
||
$third_edit_info['name'] = $param['vip_edit_info']['vip_name'];
|
||
$third_edit_info['storeid'] = $param['vip_edit_info']['storeId']?$param['vip_edit_info']['storeId']:$old_vip['storeid'];
|
||
$VipClass = new Vip();
|
||
$result = $VipClass->vipModify([
|
||
'merchant_id' => $param['merchant_id'],
|
||
'phone' => $original_phone,
|
||
'vip_info' => json_encode($third_edit_info)
|
||
]);
|
||
if ($result['status'] == 0) {
|
||
return $result;
|
||
}
|
||
}
|
||
try {
|
||
M()->startTrans();
|
||
if (!empty($edit_info)) {
|
||
$VipModel = new RetailVipModel();
|
||
$vip_edit_state = $VipModel->updateOrder([
|
||
'id' => $param['vip_edit_info']['vip_id']
|
||
], $edit_info);
|
||
|
||
$plugVip = new PlusVip();
|
||
|
||
if (isset($edit_info['storeid'])) {
|
||
//plus会员修改门店
|
||
$save = [
|
||
'storeid' => $edit_info['storeid']
|
||
];
|
||
$where = [
|
||
'vip_id' => $param['vip_edit_info']['vip_id']
|
||
];
|
||
$plugVip->plugVipStoreSave($where, $save);
|
||
|
||
//小程序会员修改门店
|
||
$saveOne = [
|
||
'store_id' => $edit_info['storeid']
|
||
];
|
||
$whereOne = [
|
||
'vid' => $param['vip_edit_info']['vip_id']
|
||
];
|
||
$plugVip->xcxVipStoreSave($whereOne, $saveOne);
|
||
}
|
||
|
||
if (!$vip_edit_state) {
|
||
return callBack(statusCode()['error'], '暂无修改');
|
||
}
|
||
}
|
||
$time = $_SERVER['REQUEST_TIME'];
|
||
//充值订单
|
||
if (!empty($recharge_order_arr)) {
|
||
$recharge_order_arr['vid'] = $param['vip_edit_info']['vip_id'];
|
||
$recharge_order_arr['status'] = 1;
|
||
$recharge_order_arr['store_id'] = $param['store_id'] ? $param['store_id'] : 0;
|
||
$recharge_order_arr['add_time'] = $time;
|
||
$recharge_order_arr['merchant_id'] = $param['merchant_id'];
|
||
$RechargeModel = new RetailRechargeOrderModel();
|
||
$order_id = $RechargeModel->add($recharge_order_arr);
|
||
if (empty($order_id)) {
|
||
M()->rollback();
|
||
return callBack(statusCode()['error'], '充值订单保存失败');
|
||
}
|
||
}
|
||
//变更记录
|
||
if (!empty($change_arr)) {
|
||
$change_arr['operator_id'] = $param['operator_id'];
|
||
$change_arr['merchant_id'] = $param['merchant_id'];
|
||
$change_arr['store_id'] = $param['store_id'] ? $param['store_id'] : 0;
|
||
$change_arr['add_time'] = $time;
|
||
$change_arr['vip_id'] = $param['vip_edit_info']['vip_id'];
|
||
$VipChangeModel = new RetailVipChangeModel();
|
||
$record_id = $VipChangeModel->addOrder($change_arr);
|
||
if (empty($record_id)) {
|
||
M()->rollback();
|
||
return callBack(statusCode()['error'], '变更记录保存失败');
|
||
}
|
||
}
|
||
M()->commit();
|
||
return callBack(statusCode()['success'], '操作成功');
|
||
} catch (\Exception $e) {
|
||
return callBack(statusCode()['error'], '修改失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 修改会员支付密码
|
||
* @param $param
|
||
* $param['operator_type'] 1后台端 2收银端 3助手端
|
||
* $param['user_type'] 3商户 4门店 5导购 6收银
|
||
* $param['operator_id'] 操作人id
|
||
* $param['merchant_id'] 商户ID
|
||
* $param['store_id'] 操作的 门店ID
|
||
* $param['vip_id'] 会员的ID
|
||
* $param['password'] 新密码
|
||
* @return mixed
|
||
*/
|
||
public function editVipPassword($param)
|
||
{
|
||
if (!$param['vip_id'] || !$param['password']) {
|
||
return callBack(statusCode()['error'], '缺少参数');
|
||
} else {
|
||
$VipModel = new RetailVipModel();
|
||
$map = [
|
||
'id' => $param['vip_id'],
|
||
'merchantid' => $param['merchant_id'],
|
||
];
|
||
$vip = $VipModel->getFind($map, 'addtime');
|
||
if (empty($vip)) {
|
||
return callBack(statusCode()['error'], '会员不存在');
|
||
}
|
||
$password = createPassword($param['password'], $vip['addtime']);
|
||
try {
|
||
M()->startTrans();
|
||
$save = $VipModel->updateOrder($map, ['password' => $password]);
|
||
if ($save) {
|
||
$record = array(
|
||
'operator' => 1,
|
||
'operator_id' => $param['operator_id'],
|
||
'merchant_id' => $param['merchant_id'],
|
||
'add_time' => time(),
|
||
'vip_id' => $param['vip_id'],
|
||
'password_state' => 1,
|
||
);
|
||
$VipChangeModel = new RetailVipChangeModel();
|
||
$addRecord = $VipChangeModel->addOrder($record);
|
||
if (!$addRecord) {
|
||
M()->rollback();
|
||
return callBack(statusCode()['error'], '修改失败');
|
||
}
|
||
M()->commit();
|
||
return callBack(statusCode()['success'], '修改成功');
|
||
} else {
|
||
M()->rollback();
|
||
return callBack(statusCode()['error'], '修改失败');
|
||
}
|
||
} catch (Exception $e) {
|
||
return callBack(statusCode()['error'], '修改失败');
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 会员编辑的字段
|
||
* @param $param
|
||
* [
|
||
* operator_type 1后台端 2收银端 3助手端
|
||
* operator_id 操作人id
|
||
* user_type 3商户 4门店 5导购 6收银
|
||
* merchant_id
|
||
* store_id
|
||
* cashier_id
|
||
* cashier_vip_edit 收银员的编辑权限
|
||
* cashier_vip_code 收银员的权限码
|
||
* modify_vip_code 收银员输入的权限码
|
||
* modify_plus_mem 收银员将普通会员编辑成为plus会员的权限
|
||
* vip_edit_info =>[
|
||
* vip_id 会员id
|
||
* vip_type 角色 1常规会员 2plus会员
|
||
* vip_name 会员名称
|
||
* grade_id 常规会员的等级
|
||
* balance 会员余额
|
||
* integral 积分
|
||
* mobile_phone 手机号
|
||
* operate_days_type //plus会员 0不操作 1增加时长 2减少时长
|
||
* operate_days //plus会员时长
|
||
* ]
|
||
* ]
|
||
* @return mixed
|
||
* [
|
||
* edit_info 编辑的信息
|
||
* recharge_order_arr 充值订单
|
||
* change_arr 变更记录
|
||
* $original_phone 原来会员的手机号
|
||
* ]
|
||
*/
|
||
public function getEditInfo($param)
|
||
{
|
||
$vip_edit_info = $param['vip_edit_info']; //会员编辑的信息
|
||
$VipClass = new VipInfo();
|
||
$vipResult = $VipClass->basisIdGetVipInfo([
|
||
'merchant_id' => $param['merchant_id'],
|
||
'vip_id' => $vip_edit_info['vip_id'],
|
||
'status' => ['neq', 2]
|
||
]);
|
||
if ($vipResult['status'] != 1) {
|
||
return callBack(statusCode()['error'], '未找到该会员,刷新重试');
|
||
}
|
||
$vip_info = $vipResult['data']; //会员信息
|
||
$original_phone = $vip_info['mobile_phone']; //会员原来的手机号
|
||
switch ($param['user_type']) {
|
||
case 3:
|
||
//商户
|
||
$recharge_order_arr['user_type'] = 1;
|
||
$recharge_name = '商户';
|
||
$change_arr['operator'] = 1;
|
||
break;
|
||
case 4:
|
||
//门店
|
||
$recharge_order_arr['user_type'] = 2;
|
||
$recharge_name = '店长';
|
||
$change_arr['operator'] = 2;
|
||
break;
|
||
case 6:
|
||
//收银员
|
||
$recharge_order_arr['user_type'] = 3;
|
||
$recharge_name = '收银员';
|
||
$change_arr['operator'] = 3;
|
||
break;
|
||
}
|
||
switch ($param['operator_type']) {
|
||
case 1:
|
||
//后台
|
||
if ($param['user_type'] == 3) {
|
||
$recharge_order_arr['scene_type'] = 2;
|
||
} else if ($param['user_type'] == 4) {
|
||
$recharge_order_arr['scene_type'] = 3;
|
||
}
|
||
break;
|
||
case 2:
|
||
//收银
|
||
$recharge_order_arr['scene_type'] = 1;
|
||
break;
|
||
case 3:
|
||
//助手
|
||
$recharge_order_arr['scene_type'] = 6;
|
||
break;
|
||
}
|
||
//会员角色
|
||
switch ($vip_info['plus_type']) {
|
||
case 2:
|
||
//plus会员
|
||
if (in_array($vip_edit_info['operate_days_type'], ['1', '2'])) {
|
||
//修改时长
|
||
$plusResult = $this->vipPlus([
|
||
'vip_info' => $vip_info,
|
||
'store_id' => $param['store_id'],
|
||
'expire_time' => $vip_edit_info['operate_days'],
|
||
'operate_days_type' => $vip_edit_info['operate_days_type']
|
||
]);
|
||
if ($plusResult['status'] != 1) {
|
||
return $plusResult;
|
||
}
|
||
$change_arr['before_plus_end_time'] = $plusResult['data']['before_plus_end_time'];
|
||
$change_arr['after_plus_end_time'] = $plusResult['data']['after_plus_end_time'];
|
||
}
|
||
break;
|
||
case 3:
|
||
//常规会员
|
||
$vip_grade = $VipClass->singleVipGrade([
|
||
'grade_integral' => $vip_info['grade_integral'],
|
||
'merchant_id' => $param['merchant_id'],
|
||
]);
|
||
switch ($vip_edit_info['vip_type']) {
|
||
case 1:
|
||
//常规会员
|
||
if ($vip_grade['id'] != $vip_edit_info['grade_id']) {
|
||
$grade_info = $VipClass->singleVipGrade([
|
||
'grade_id' => $vip_edit_info['grade_id'],
|
||
'merchant_id' => $param['merchant_id'],
|
||
]);
|
||
if (empty($grade_info)) {
|
||
if ($vip_edit_info['grade_id'] == 0) {
|
||
$data['grade_integral'] = 0;
|
||
} else {
|
||
return callBack(statusCode()['error'], '会员等级有误');
|
||
}
|
||
} else {
|
||
$data['grade_integral'] = $grade_info['min_integral'];
|
||
}
|
||
$change_arr['before_grade'] = $vip_grade['grade_name'] ? $vip_grade['grade_name'] : '无等级';
|
||
$change_arr['after_grade'] = $grade_info['grade_name'] ? $grade_info['grade_name'] : '无等级';
|
||
}
|
||
break;
|
||
case 2:
|
||
//升级为plus会员
|
||
if ($param['modify_plus_mem'] != 2 && $param['user_type'] == 6) {
|
||
return callBack(statusCode()['error'], '暂无权限');
|
||
}
|
||
$plusResult = $this->vipPlus([
|
||
'vip_info' => $vip_info,
|
||
'store_id' => $param['store_id'],
|
||
'expire_time' => $vip_edit_info['operate_days']
|
||
]);
|
||
if ($plusResult['status'] != 1) {
|
||
return $plusResult;
|
||
}
|
||
$plus_id = $plusResult['data']['plus_id'];
|
||
if ($vip_info['plus_id'] != $plus_id) {
|
||
$data['plus_id'] = $plus_id;
|
||
}
|
||
$data['plus_type'] = 2;
|
||
$data['plus_state'] = 1;
|
||
$change_arr['before_grade'] = $vip_grade['grade_name'] ? $vip_grade['grade_name'] : '无等级';
|
||
$change_arr['after_grade'] = 'PlUS会员';
|
||
break;
|
||
}
|
||
break;
|
||
}
|
||
//手机号
|
||
if ($vip_info['mobile_phone'] != $vip_edit_info['mobile_phone']) {
|
||
if (!empty($vip_edit_info['mobile_phone'])) {
|
||
$other_vip = $VipClass->singleVipInfo([
|
||
'where' => [
|
||
'id' => ['neq', $vip_edit_info['vip_id']],
|
||
'mobile_phone' => $vip_edit_info['mobile_phone'],
|
||
'merchantid' => $param['merchant_id'],
|
||
'status' => ['neq', 2]
|
||
]
|
||
]);
|
||
if (!empty($other_vip)) {
|
||
return callBack(statusCode()['error'], '该手机号已被占用');
|
||
}
|
||
$data['mobile_phone'] = $vip_edit_info['mobile_phone'];
|
||
$data['cardnum'] = $vip_edit_info['mobile_phone'];
|
||
$change_arr['before_phone'] = $vip_info['mobile_phone'];
|
||
$change_arr['after_phone'] = $vip_edit_info['mobile_phone'];
|
||
} else {
|
||
if (!empty($vip_info['mobile_phone'])) {
|
||
return callBack(statusCode()['error'], '不能将原有手机号删除');
|
||
}
|
||
}
|
||
}
|
||
//余额
|
||
if ($vip_info['balance'] != $vip_edit_info['balance']) {
|
||
$data['balance'] = $vip_edit_info['balance'];
|
||
$change_arr['before_balance'] = $vip_info['balance'];
|
||
$change_arr['after_balance'] = $vip_edit_info['balance'];
|
||
if ($vip_edit_info['balance'] < $vip_info['balance']) {
|
||
//扣除
|
||
$money = round($vip_info['balance'] - $vip_edit_info['balance'], 2);
|
||
$recharge_order_arr['type'] = 4;
|
||
$recharge_order_arr['money'] = $money;
|
||
$recharge_order_arr['remark'] = $recharge_name . '修改余额扣除' . $money . '元';
|
||
} else {
|
||
//增加
|
||
$money = round($vip_edit_info['balance'] - $vip_info['balance'], 2);
|
||
$recharge_order_arr['type'] = 3;
|
||
$recharge_order_arr['money'] = 0;
|
||
$recharge_order_arr['remark'] = $recharge_name . '修改余额增加' . $money . '元';
|
||
}
|
||
$recharge_order_arr['all_money'] = $money;
|
||
} else {
|
||
unset($recharge_order_arr);
|
||
}
|
||
//积分
|
||
if ($vip_info['integral'] != $vip_edit_info['integral']) {
|
||
$data['integral'] = $vip_edit_info['integral'];
|
||
$change_arr['before_integral'] = $vip_info['integral'];
|
||
$change_arr['after_integral'] = $vip_edit_info['integral'];
|
||
}
|
||
if ($vip_info['name'] != $vip_edit_info['vip_name']) {
|
||
$data['name'] = $vip_edit_info['vip_name'];
|
||
}
|
||
if (count($change_arr) <= 1) {
|
||
unset($change_arr);
|
||
}
|
||
if ($vip_info['storeid'] != $vip_edit_info['storeId']) {
|
||
//存在门店id字段,并且不为空
|
||
$data['storeid'] = $vip_edit_info['storeId'];
|
||
}
|
||
if (!empty($data) || !empty($recharge_order_arr) || !empty($change_arr)) {
|
||
return callBack(statusCode()['success'], '成功', [
|
||
'edit_info' => $data,
|
||
'recharge_order_arr' => $recharge_order_arr ? $recharge_order_arr : [],
|
||
'change_arr' => $change_arr ? $change_arr : [],
|
||
'original_phone' => $original_phone,
|
||
'vip_info'=>$vip_info
|
||
]);
|
||
} else {
|
||
return callBack(statusCode()['error'], '暂无修改');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 等级为plus会员的处理
|
||
* @param $param
|
||
* [
|
||
* vip_info 会员信息
|
||
* store_id 门店id
|
||
* expire_time 天数
|
||
* operate_days_type //plus会员 0不操作 1增加时长 2减少时长
|
||
* ]
|
||
* @return mixed
|
||
* [
|
||
* plus_id
|
||
* before_plus_end_time 会员时长(变更前)
|
||
* after_plus_end_time 会员时长(变更后)
|
||
* ]
|
||
*/
|
||
public function vipPlus($param)
|
||
{
|
||
$time = $_SERVER['REQUEST_TIME'];
|
||
$operate_days_type = $param['operate_days_type'] ? $param['operate_days_type'] : 1;
|
||
$vip_info = $param['vip_info'];
|
||
$expire_time = $param['expire_time'];
|
||
$add_time = $expire_time ? ($expire_time * 86400) : 31536000; //到期变动的时间戳
|
||
$PlusVipModel = new RetailPlusVipModel();
|
||
try {
|
||
$plus_info = $PlusVipModel->getOrderFind(['vip_id' => $vip_info['id']], '*', 'id desc');
|
||
if (!empty($plus_info)) {
|
||
//编辑
|
||
$data['state'] = 1;
|
||
if ($plus_info['state'] == 2 || $plus_info['end_time'] < $time) {
|
||
//过期
|
||
$data['start_time'] = $time;
|
||
$data['end_time'] = $time + $add_time;
|
||
} else {
|
||
//续期或者缩期
|
||
switch ($operate_days_type) {
|
||
case 1:
|
||
$data['end_time'] = $plus_info['end_time'] + $add_time;
|
||
break;
|
||
case 2:
|
||
$data['end_time'] = $plus_info['end_time'] - $add_time;
|
||
break;
|
||
}
|
||
}
|
||
$plus_state = $PlusVipModel->updateOrder([
|
||
'id' => $plus_info['id']
|
||
], $data);
|
||
if (!$plus_state) {
|
||
return callBack(statusCode()['error'], 'plus信息暂无修改');
|
||
}
|
||
$plus_id = $plus_info['id'];
|
||
} else {
|
||
//新增
|
||
$data = [
|
||
'vip_id' => $vip_info['id'],
|
||
'merchantid' => $vip_info['merchantid'],
|
||
'storeid' => $param['store_id'] ? $param['store_id'] : $vip_info['storeid'],
|
||
'addtime' => $time,
|
||
'start_time' => $time,
|
||
'end_time' => ($time + $add_time),
|
||
'state' => 1,
|
||
];
|
||
$plus_id = $PlusVipModel->addOrder($data);
|
||
}
|
||
if ($plus_id) {
|
||
$xcx_info = M('retail_xcxvip')->where(array('merchantid' => $vip_info['merchantid'], 'vid' => $vip_info['id']))->find();
|
||
if (!empty($xcx_info)) {
|
||
M('retail_xcxvip')->where(array('id' => $xcx_info['id']))->save(array('plus_vip_id' => $plus_id, 'type' => 2));
|
||
$PlusVipModel->updateOrder([
|
||
'id' => $plus_id
|
||
], [
|
||
'xcx_vip_id' => $xcx_info['id']
|
||
]);
|
||
}
|
||
return callBack(statusCode()['success'], '操作成功', [
|
||
'plus_id' => $plus_id,
|
||
'before_plus_end_time' => $plus_info['end_time'],
|
||
'after_plus_end_time' => $data['end_time']
|
||
]);
|
||
} else {
|
||
return callBack(statusCode()['error'], 'plus信息暂无修改');
|
||
}
|
||
} catch (\Exception $e) {
|
||
return callBack(statusCode()['error'], 'plus信息暂无修改');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 会员编辑信息验证
|
||
* @param $param
|
||
* [
|
||
* operator_type 1后台端 2收银端 3助手端
|
||
* user_type 3商户 4门店 5导购 6收银
|
||
* merchant_id
|
||
* store_id
|
||
* cashier_id
|
||
* modify_vip_code 收银员输入的权限码
|
||
* vip_edit_info json字符串=>[
|
||
* vip_id 会员id
|
||
* vip_type 角色 1常规会员 2plus会员
|
||
* vip_name 会员名称
|
||
* grade_id 常规会员的等级
|
||
* balance 会员余额
|
||
* integral 积分
|
||
* mobile_phone 手机号
|
||
* operate_days_type //plus会员 0不操作 1增加时长 2减少时长
|
||
* operate_days //plus会员时长
|
||
* ]
|
||
* ]
|
||
* @return mixed
|
||
* [
|
||
* cashier_vip_edit 收银员的编辑权限
|
||
* cashier_vip_code 收银员的权限码
|
||
* modify_plus_mem 收银员是否有将普通会员编辑成为plus会员的权限
|
||
* ]
|
||
*/
|
||
public function editInfoVerify(&$param)
|
||
{
|
||
//验证身份
|
||
$VerifyClass = new VerifyParam();
|
||
$verifyResult = $VerifyClass->identityVerify($param);
|
||
if ($verifyResult['status'] != 1) {
|
||
return $verifyResult;
|
||
}
|
||
$vip_edit_info = json_decode($param['vip_edit_info'], true);
|
||
//参数验证
|
||
if ($param['user_type'] == 6 || $param['user_type'] == 4) {
|
||
//门店权限
|
||
$AuthClass = new StoreAuthority();
|
||
$auth_name = $AuthClass->checkSingleAuth([
|
||
'store_id' => $param['store_id'],
|
||
'field' => 'store_edit_vip_info'
|
||
]);
|
||
if ($auth_name == 2) {
|
||
return callBack(statusCode()['error'], '门店暂无编辑权限');
|
||
}
|
||
if ($param['user_type'] == 6) {
|
||
//收银端权限
|
||
$CashierModel = new RetailCashierModel();
|
||
$cashier_info = $CashierModel->getFind([
|
||
'id' => $param['cashier_id'],
|
||
'status' => 1
|
||
], 'modifymem,modifymemcode,modify_plus_mem');
|
||
if (empty($cashier_info)) {
|
||
return callBack(statusCode()['error'], '暂无权限');
|
||
}
|
||
$param['cashier_vip_edit'] = $cashier_info['modifymem'];
|
||
$param['cashier_vip_code'] = $cashier_info['modifymemcode'];
|
||
$param['modify_plus_mem'] = $cashier_info['modify_plus_mem'];
|
||
if ($param['cashier_vip_edit'] != 2) {
|
||
return callBack(statusCode()['error'], '收银员暂无编辑权限');
|
||
}
|
||
if ($param['cashier_vip_code'] != trim($param['modify_vip_code']) || empty($param['modify_vip_code'])) {
|
||
return callBack(statusCode()['error'], '权限码错误');
|
||
}
|
||
}
|
||
}
|
||
if (empty($vip_edit_info['vip_id'])) {
|
||
return callBack(statusCode()['error'], '请选择会员');
|
||
}
|
||
if (!empty($vip_edit_info['vip_type']) && !in_array($vip_edit_info['vip_type'], ['1', '2'])) {
|
||
return callBack(statusCode()['error'], '请选择会员的角色');
|
||
}
|
||
if ($vip_edit_info['vip_type'] == 1 && !isset($vip_edit_info['grade_id'])) {
|
||
return callBack(statusCode()['error'], '请选择会员等级');
|
||
}
|
||
$reg1 = '/^[0-9]+(.[0-9]{1,2})?$/';
|
||
$reg2 = '/^\+?[0-9][0-9]*$/';
|
||
$reg3 = '/^1[3456789]\d{9}$/';
|
||
if (!empty($vip_edit_info['balance']) && !preg_match($reg1, $vip_edit_info['balance'])) {
|
||
return callBack(statusCode()['error'], '请输入正确的余额');
|
||
}
|
||
if (!empty($vip_edit_info['integral']) && !preg_match($reg2, $vip_edit_info['integral'])) {
|
||
return callBack(statusCode()['error'], '请输入正确的积分');
|
||
}
|
||
if (!empty($vip_edit_info['vip_name']) && mb_strlen($vip_edit_info['vip_name'], 'UTF8') > 30) {
|
||
return callBack(statusCode()['error'], '姓名不能超过30个字符');
|
||
}
|
||
if (!empty($vip_edit_info['mobile_phone']) && !preg_match($reg3, $vip_edit_info['mobile_phone'])) {
|
||
return callBack(statusCode()['error'], '请输入正确手机号');
|
||
}
|
||
if (($vip_edit_info['vip_type'] == 2 || in_array($vip_edit_info['operate_days_type'], ['1', '2'])) && empty($vip_edit_info['operate_days'])) {
|
||
return callBack(statusCode()['error'], '请输入时长');
|
||
}
|
||
$vip_edit_info['balance'] = $vip_edit_info['balance'] ? $vip_edit_info['balance'] : 0;
|
||
$vip_edit_info['integral'] = $vip_edit_info['integral'] ? $vip_edit_info['integral'] : 0;
|
||
$param['vip_edit_info'] = $vip_edit_info;
|
||
return callBack(statusCode()['success'], '验证成功');
|
||
}
|
||
|
||
|
||
/**
|
||
* 会员挂失\冻结\恢复操作
|
||
* @param param [
|
||
* merchant_id
|
||
* vip_id
|
||
* plus_type 2plus会员 3常规会员
|
||
* status 1恢复 3冻结 4挂失
|
||
* scene 类型 3商户 4门店
|
||
* ]
|
||
* @return array
|
||
*/
|
||
public function operateVipStatus($param)
|
||
{
|
||
if (!$param['merchant_id'] || !$param['vip_id']) {
|
||
return ['status' => 0, 'msg' => '登录超时,请重新登录'];
|
||
}
|
||
if (!$param['status'] || !in_array($param['status'], [1, 3, 4]) || !$param['scene']) {
|
||
return ['status' => 0, 'msg' => '缺少必要参数'];
|
||
}
|
||
$VipModel = new RetailVipModel();
|
||
$desc = $param['plus_type'] == 2 ? 'PLUS' : '常规';
|
||
switch ($param['status']) {
|
||
case 4:
|
||
$desc .= '会员挂失';
|
||
break;
|
||
case 3:
|
||
$desc .= '会员冻结';
|
||
break;
|
||
case 1:
|
||
$desc .= '会员恢复';
|
||
break;
|
||
}
|
||
$result = $VipModel->updateOrder(['id' => $param['vip_id'], 'merchantid' => $param['merchant_id']], ['status' => $param['status']]);
|
||
if ($result) {
|
||
$source = 0; //请求来源: 0pc系统 1小助手
|
||
$type = $param['scene']; //平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($param); //请求参数 json数据
|
||
action_log($source, $type, $request_data, $desc);
|
||
}
|
||
return ['status' => 1, 'msg' => '操作成功'];
|
||
}
|
||
} |