display(); } //获取门店和登记会员(该方法更新会员积分时请删除) public function getStoreListAndVipGrade() { $StoreClass = new Store(); $store_list = $StoreClass->storeListInfo([ 'merchant_id' => $this->merchant_id, 'fields' => [ 'id', 'storetag as store_name' ] ]); $VipInfoClass = new VipInfo(); $vip_grade_list = $VipInfoClass->getGradeList([ 'merchant_id' => $this->merchant_id, 'fields' => [ 'id', 'cardname as grade_name' ] ]); $res['status'] = 1; $res['store_list'] = $store_list ? $store_list : []; $res['vip_grade_list'] = $vip_grade_list ? $vip_grade_list : []; $this->ajaxReturn($res); } /** * 保存充值赠设置 * @param [array] $recharge 充值设置 * @return [array] $res */ public function setRechargeState() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponOperation(); $result = $CouponClass->rechargeSet($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-优惠券充值设置';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //保存支付赠优惠券设置 public function setPaymentState() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponOperation(); $result = $CouponClass->paySet($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-优惠券支付设置';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //指定会员列表的门店与等级列表 public function getAppointList() { $data = I('post.'); $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $CouponListClass = new CouponList(); $result = $CouponListClass->getAppointList($data); $this->ajaxReturn($result); } //获取指定的会员列表 public function getStoreGradeVipInfo() { $data = I('post.'); $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $CouponListClass = new CouponList(); $result = $CouponListClass->getAppointVipList($data); $this->ajaxReturn($result); } //优惠券或券包使失效 public function couponFailure() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponOperation(); $result = $CouponClass->couponInvalid($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 if ($data['coupon_type'] == 1) { $desc = '插件-使失效优惠券';//操作行为描述 } else if ($data['coupon_type'] == 2) { $desc = '插件-使失效券包';//操作行为描述 } action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //批量发放优惠券或券包 public function batchGrantCoupon() { $data = I('post.'); $data['operator_type'] = 1; $data['operator_id'] = session('jurisdiction_user')['id']; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponOperation(); $result = $CouponClass->batchGrantCoupon($data); if (C('IS_SET_REDIS')) { if ($data['batch_type'] == 1) { //优惠券 $redis_key = 'retail_merchant_id_' . $data['merchant_id'] . '_coupon_type_2_coupon_id_' . $data['id']; } else if ($data['batch_type'] == 2) { //券包 $redis_key = 'retail_merchant_id_' . $data['merchant_id'] . '_coupon_package_id_' . $data['id']; } $CacheClass = new CacheHandle(); $CacheClass->eliminateCache($redis_key); $CacheClass->submitAffair(); } if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 if ($data['batch_type'] == 1) { $desc = '插件-发放优惠券';//操作行为描述 } else if ($data['batch_type'] == 2) { $desc = '插件-发放券包';//操作行为描述 } action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //创建券包 public function createCouponGroup() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['type'] = 2; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->createCouponPackage($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-新增券包';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //券包编辑接口 public function editPackage() { $data = I('post.'); $data['operator_type'] = 1; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $data['user_type'] = 4; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->editPackage($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-编辑券包';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //券包发放记录 public function couponGroupRecordList() { $data = I('post.'); $data['user_type'] = 4; $data['type'] = 2; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponList(); $result = $CouponClass->couponGrantRecord($data); $this->ajaxReturn($result); } //券包详情 public function couponGroupDetails() { $data = I('post.'); $data['merchant_id'] = $this->merchant_id; $CouponClass = new CouponList(); $result = $CouponClass->couponPackageInfo($data); $this->ajaxReturn($result); } //券包列表 public function getCouponGroupList() { $data = I('post.'); $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $data['user_type'] = 4; $CouponClass = new CouponList(); $result = $CouponClass->couponPackageList($data); $this->ajaxReturn($result); } //创建优惠券 public function createCoupon() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['type'] = 1; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->createCoupon($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-新增优惠券';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //编辑优惠券 public function editCoupon() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $data['operator_id'] = session('jurisdiction_user')['id']; $CouponClass = new CouponOperation(); $result = $CouponClass->editCoupon($data); if ($result['status'] == 1) { //操作日志记录 $source = 0;//请求来源: 0pc系统 1小助手 $type = 4;//平台:1合伙人端 2代理商端 3商户端 4门店端 $request_data = json_encode($_POST);//请求参数 json数据 $desc = '插件-编辑优惠券';//操作行为描述 action_log($source, $type, $request_data, $desc); } $this->ajaxReturn($result); } //优惠券发放记录couponRecordList public function couponRecordList() { $data = I('post.'); $data['user_type'] = 4; $data['type'] = 1; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponList(); $result = $CouponClass->couponGrantRecord($data); $this->ajaxReturn($result); } //优惠券详情 public function couponInfo() { $data = I('post.'); $CouponClass = new CouponList(); $result = $CouponClass->couponInfo($data); $this->ajaxReturn($result); } //优惠券列表 public function getCouponList() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $CouponClass = new CouponList(); $result = $CouponClass->couponList($data); $this->ajaxReturn($result); } //指定分类查看商品详情 public function basisClassGetGoods() { $data = I('post.'); $data['operator_type'] = 1; $data['user_type'] = 4; $data['merchant_id'] = $this->merchant_id; $data['store_id'] = $this->store_id; $SaleClass = new SaleGoods(); $result = $SaleClass->basisClassIdGetGoods($data); $this->ajaxReturn($result); } //新建优惠券时搜索指定用户(手机号搜索,无需是会员) public function searchVipForCoupon() { $search_info = trim(I('post.search_info')); if (empty($search_info)) { $this->ajaxReturn(['status' => 0, 'message' => '请输入手机号']); return; } $XcxUserModel = new RetailSmallProgramUserModel(); $where = [ 'merchant_id' => $this->merchant_id, 'mobile_phone' => ['like', '%' . $search_info . '%'], ]; $fields = ['id', 'vid', 'nickname', 'mobile_phone']; try { $list = $XcxUserModel->getSelect($where, $fields, 'id desc', '1,20'); } catch (\Exception $e) { $this->ajaxReturn(['status' => 0, 'message' => '搜索失败']); return; } $result_list = []; if (!empty($list)) { foreach ($list as $user) { $nickname = $user['nickname'] ? $user['nickname'] : '未设置昵称'; $result_list[] = [ 'xcxvip_id' => $user['id'], 'vid' => $user['vid'], 'user_name' => $nickname, 'mobile_phone' => $user['mobile_phone'], 'is_member' => (!empty($user['vid']) && $user['vid'] > 0) ? 1 : 0, ]; } } $this->ajaxReturn(['status' => 1, 'message' => '搜索成功', 'data' => ['list' => $result_list]]); } //新建优惠券后发放给指定用户(会员或非会员均可,非会员自动创建会员记录) public function grantCouponToUser() { $coupon_id = trim(I('post.coupon_id')); $xcxvip_id = trim(I('post.xcxvip_id')); if (empty($coupon_id) || empty($xcxvip_id)) { $this->ajaxReturn(['status' => 0, 'message' => '参数不完整']); return; } // 查找登录用户 $XcxUserModel = new RetailSmallProgramUserModel(); $user = $XcxUserModel->getFind([ 'id' => $xcxvip_id, 'merchant_id' => $this->merchant_id, ]); if (empty($user)) { $this->ajaxReturn(['status' => 0, 'message' => '未找到该用户']); return; } $vid = $user['vid']; // 如果没有会员记录,自动创建一条简易会员记录并关联 if (empty($vid) || $vid <= 0) { $VipModel = new RetailVipModel(); $vip_data = [ 'mobile_phone' => $user['mobile_phone'], 'cardnum' => $user['mobile_phone'], 'nickname' => $user['nickname'] ? $user['nickname'] : '', 'merchantid' => $this->merchant_id, 'storeid' => $this->store_id, 'status' => 1, 'addtime' => $_SERVER['REQUEST_TIME'], 'plus_type' => 3, 'source_channel' => 'store_coupon_grant', ]; $vid = $VipModel->add($vip_data); if (!$vid) { $this->ajaxReturn(['status' => 0, 'message' => '创建会员记录失败,无法发放优惠券']); return; } // 将xcxvip与新建vip记录关联 $XcxUserModel->where(['id' => $xcxvip_id])->save(['vid' => $vid]); } // 调用现有批量发放逻辑 $data = [ 'batch_type' => '1', 'grant_type' => '2', 'id' => $coupon_id, 'vip_id_arr' => strval($vid), 'operator_type' => 1, 'operator_id' => session('jurisdiction_user')['id'], 'user_type' => 4, 'merchant_id' => $this->merchant_id, 'store_id' => $this->store_id, 'page' => 1, 'limit' => 1, ]; $CouponClass = new CouponOperation(); $result = $CouponClass->batchGrantCoupon($data); $this->ajaxReturn($result); } }