ajaxReturn($res); } $merchant_id = self::$merchant_id; //商户id; $store_id = self::$store_id; //门店id $cashier_id = self::$cashier_id; //门店id $VipDynamicCodeModel = D('RetailVipDynamicCode'); $VipModel = D('RetailVip'); $temp = (int)substr($code, 0, 2); $field = array( $VipModel::ID, $VipModel::NICK_NAME, $VipModel::NAME, $VipModel::BALANCE, $VipModel::MOBILE_PHONE . ' as cardnum', $VipModel::CARD_KEY, $VipModel::INTEGRAL, $VipModel::GRADE_INTEGRAL, $VipModel::STATUS, $VipModel::PLUS_TYPE, $VipModel::DENSITY_FREE ); if (is_numeric($code) && strlen($code) == 18 && $temp >= 86 && $temp <= 89) { $map = array( $VipDynamicCodeModel::CODE => $code, $VipDynamicCodeModel::STATUS => 0, $VipDynamicCodeModel::STATE => 0, $VipDynamicCodeModel::MERCHANT_ID => $merchant_id ); $old = $VipDynamicCodeModel->getFind($map); if (empty($old) || $old[$VipDynamicCodeModel::FAILURE_TIME] <= time()) { $res['status'] = 0; $res['msg'] = '请会员刷新动态码'; $this->ajaxReturn($res); } else { $save = array( $VipDynamicCodeModel::STATUS => 1, $VipDynamicCodeModel::USE_STORE_ID => $store_id, $VipDynamicCodeModel::USE_CASHIER_ID => $cashier_id ); $VipDynamicCodeModel->updateOrder($map, $save); } $where[$VipModel::ID] = $old[$VipDynamicCodeModel::VID]; $where[$VipModel::STATUS] = array('neq', 2); $vip = $VipModel->getSelect($where, $field); $login_type = 1; $payCode = $code; $vipList = $vip; } else { $map[$VipModel::MERCHANT_ID] = $merchant_id; $map[$VipModel::STATUS] = array('neq', 2); if (is_numeric($code) && strlen($code) == 11) { $map[$VipModel::MOBILE_PHONE . '|' . $VipModel::CARD_KEY] = $code; } else if (is_numeric($code) && strlen($code) == 4) { $map[$VipModel::MOBILE_PHONE] = array('like', '%' . $code); } else if (is_numeric($code)) { $map[$VipModel::CARD_KEY . '|' . $VipModel::CARD_NUM] = $code; } else { $map[$VipModel::CARD_KEY] = $code; } $vipList = $VipModel->getSelect($map, $field); $login_type = 2; } if (!empty($vipList)) { foreach ($vipList as &$value) { $vipData = $this->getVipData($value); $value['login_type'] = $login_type; $value['payCode'] = !empty($payCode) ? $payCode : ($value[$VipModel::CARD_NUM] ? $value[$VipModel::CARD_NUM] : $value[$VipModel::CARD_KEY]); $value['grade_name'] = $vipData['grade']['grade_name']; $week = date("w"); $discount = 1; $WeekDiscount = new WeekDiscountModel(); $DiscountData = $WeekDiscount->getData(); // var_dump($DiscountData) //特殊周的特殊折扣 if($week == $DiscountData['week']){ $discount = $DiscountData['discount']; }else{ $discount = floatval($vipData['grade']['discount']); } // var_dump($week); $value['discount'] = $discount; $value['couponList'] = $vipData['couponList']; //存在赊销插件 if (in_array('Credit', C('MODULE_ALLOW_LIST'))) { $CreditorModel = new CreditorModel(); $CreditData = $CreditorModel->getFind(['vid' => $value['id'], 'status' => 1, 'store_id' => self::$store_id], 'quota,total_arrearage'); if ($CreditData) { $value['creditQuota'] = bcsub($CreditData['quota'], $CreditData['total_arrearage'], 2); $value['isCreditUser'] = 1; } else { $value['isCreditUser'] = 2; } } if (empty($value[$VipModel::NICK_NAME])) { $value['nickname'] = $value[$VipModel::NAME]; } if (empty($value[$VipModel::NAME])) { $value['name'] = $value[$VipModel::NICK_NAME]; } } $StoreModel = D('RetailStore'); $res['density_free_state'] = self::$store[$StoreModel::DENSITY_FREE_STATE]; $res['info'] = $vipList; $res['status'] = 1; $res['msg'] = '查询成功'; } else { $res['status'] = 0; $res['msg'] = '查询失败'; } $this->ajaxReturn($res); } } public function getVipData($vip) { if (empty($vip)) { return false; } $VipModel = D('RetailVip'); $merchant_id = self::$merchant_id; $store_id = self::$store_id; $VipInfo = new VipInfo(); if ($vip[$VipModel::PLUS_TYPE] == 2) { //plus会员享受最优折扣 $grade['discount'] = $VipInfo->getPlusDiscount(['merchant_id' => $merchant_id]); $grade['grade_name'] = 'PLUS会员'; } else { //常规会员用来判断会员等级 $grade = $VipInfo->singleVipGrade([ 'merchant_id' => $merchant_id, 'grade_integral' => $vip['grade_integral'], 'get_default' => true, ]); $grade['discount'] = $grade['id'] ? $grade['discount'] : 1; } $m_coupon_id_redis = []; //正在使用的会员优惠券 $h_coupon_id_redis = []; //正在使用的商家券券 if (C('IS_SET_REDIS')) { $coupon_redis_key = 'retail_coupon_store_id_' . $store_id . '_uid_*'; $CacheClass = new CacheHandle(); $coupon_redis = $CacheClass->getManyCache($coupon_redis_key); if (!empty($coupon_redis)) { foreach ($coupon_redis as $coupon_key => $coupon_val) { $coupon_info = json_decode($coupon_val, true); switch ($coupon_info['coupon_type']) { case 2: //会员优惠券 $m_coupon_id_redis[] = $coupon_info['coupon_id']; break; case 3: //商家券 $h_coupon_id_redis[] = $coupon_info['coupon_id']; break; } } } } $coupons = []; //优惠券列表 $CouponUseClass = new CouponUse(); $couponResult = $CouponUseClass->cashierGetCouponList([ 'merchant_id' => $merchant_id, 'store_id' => $store_id, 'vip_id' => $vip['id'], 'm_coupon_id_redis' => $m_coupon_id_redis ]); if ($couponResult['status'] == 1) { $coupons = $couponResult['data']; //会员普通优惠券 } $PlugClass = new Plug(); $PlugData = $PlugClass->PlugPermissions([ 'merchant_id' => $merchant_id, 'identification_arr' => ['shopcoupon'] ]); //商家券插件权限 if (!empty($PlugData['data']['plug']['shopcoupon'])) { $XxcUserModel = new RetailSmallProgramUserModel(); $xcx_id = $XxcUserModel->getFindField([ 'vid' => $vip['id'] ], 'id'); //查询小程序用户id if (!empty($xcx_id)) { $ShopCouponClass = new ShopCoupon(); $result = $ShopCouponClass->getVipShopCouponList([ 'merchant_id' => $merchant_id, 'store_id' => $store_id, 'xcx_id' => $xcx_id, 'h_coupon_id_redis' => $h_coupon_id_redis ? $h_coupon_id_redis : [] ]); //有效期内的商家券 if ($result['status'] == 1 && !empty($result['data']['list'])) { $coupons = $coupons ? $coupons : []; $coupons = array_merge($coupons, $result['data']['list']); } } } $res['grade'] = $grade; $res['couponList'] = $coupons ? $coupons : array(); return $res; } /* ************************************** 会员统计Start ************************************** */ // 获取会员信息 -- 饼状图 public function getActiveUserBread() { $type = I('post.type'); $store_id = self::$store_id; $merchant_id = self::$merchant_id; $MemberAnalyzeModel = new MemberAnalyzeModel(); $result = $MemberAnalyzeModel->getActiveUserBread($type, $store_id, $merchant_id); $this->ajaxReturn($result); } // 根据月份获取用户数据 public function getActiveUserByMonth() { $timestamp = I('post.timestamp'); // 查询月份 $page = I('post.page') ? I('post.page') : 0; $pageSize = I('post.pageSize') ? I('post.pageSize') : 10; $type = I('post.type'); // 沉睡会员/活跃会员 $merchant_id = self::$merchant_id; $store_id = self::$store_id; $MemberAnalyzeModel = new MemberAnalyzeModel(); $result = $MemberAnalyzeModel->getActiveUserByMonth($timestamp, $type, $page, $pageSize, $store_id, $merchant_id); $this->ajaxReturn($result); } // 会员生日统计 -- 饼状图 public function getBirthUserBread() { $merchant_id = self::$merchant_id; $store_id = self::$store_id; $MemberAnalyzeModel = new MemberAnalyzeModel(); $result = $MemberAnalyzeModel->getBirthUserBread($merchant_id); $this->ajaxReturn($result); } // 获取会员生日信息 public function getActiveUserByBirth() { $type = I('post.type'); $page = I('post.page') ? I('post.page') : 0; $pageSize = I('post.pageSize') ? I('post.pageSize') : 10; $merchant_id = self::$merchant_id; $store_id = self::$store_id; $MemberAnalyzeModel = new MemberAnalyzeModel(); $result = $MemberAnalyzeModel->getActiveUserByBirth($type, $page, $pageSize, $merchant_id); $this->ajaxReturn($result); } }