ajaxReturn($res); } } /** * 用户领取的优惠券 */ public function myCoupon() { $store_id = self::$store_id; //门店id $uid = self::$uid; //用户id $type = I('post.type');//查看的优惠券类型 1:正常可用的卷 2:已使用的卷 3:过期的卷 $CouponLogsModel = D('RetailCouponLogs'); $CouponModel = D('RetailCoupon'); $where['l.' . $CouponLogsModel::STORE_ID] = $store_id; $where['l.' . $CouponLogsModel::UID] = $uid; //默认查询未使用并且在有效期内的优惠券 if ($type == 1) { //正常可使用的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 1;//未使用的优惠券 $where['c.' . $CouponModel::END_TIME] = array('gt', time());//结束时间大于当前时间 } else if ($type == 2) { //已使用的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 2;//已使用的优惠券 } else if ($type == 3) { //过期的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 1;//未使用的优惠券 $where['c.' . $CouponModel::END_TIME] = array('lt', time());//结束时间小于当前时间 } $field = array( 'c.' . $CouponModel::COUPON_NAME, 'c.' . $CouponModel::BEGIN_TIME, 'c.' . $CouponModel::END_TIME, 'c.' . $CouponModel::NEED_MONEY, 'c.' . $CouponModel::REDUCTION_MONEY, 'l.' . $CouponLogsModel::USE_TIME, ); $coupon = $CouponLogsModel->getCoupon($where, $field); foreach ($coupon as $key => &$val) { $val[$CouponModel::BEGIN_TIME] = date('Y-m-d', $val[$CouponModel::BEGIN_TIME]); $val[$CouponModel::END_TIME] = date('Y-m-d', $val[$CouponModel::END_TIME]); $val[$CouponLogsModel::USE_TIME] = date('Y-m-d H:i:s', $val[$CouponLogsModel::USE_TIME]); } if (!empty($coupon)) { $res['status'] = 1; $res['msg'] = '查询成功'; $res['data'] = $coupon; } else { $res['status'] = 0; $res['msg'] = '暂无查询到相关优惠券'; } $this->ajaxReturn($res); } /** * 商家券 2020-08-15 */ public function getCanUseCoupon() { $money = I('post.money'); if (empty($money)) { $res['status'] = 0; $res['msg'] = '缺少参数'; $this->ajaxReturn($res); } $store_id = self::$store_id; $merchant_id = self::$merchant_id; $uid = self::$uid; $CouponLogsModel = D('RetailCouponLogs');//门店优惠券领取记录 $CouponModel = D('RetailCoupon');//门店优惠券 $time = time(); $s_coupon_id_redis = []; //门店优惠券 $m_coupon_id_redis = []; //商户优惠券 $h_coupon_id_redis = []; //门店商家券 if (C('IS_SET_REDIS')) { $ApiRedis = new \Addons\Api\RedisController(); $coupon_redis_key = 'retail_coupon_store_id_' . $store_id . '_uid_*'; $coupon_redis = $ApiRedis::$redis->mget($ApiRedis::$redis->keys($coupon_redis_key)); if ($coupon_redis) { foreach ($coupon_redis as $coupon_key => $coupon_val) { $coupon_info = json_decode($coupon_val, true); switch ($coupon_info['coupon_type']) { case 1: //门店优惠券 $s_coupon_id_redis[] = $coupon_info['coupon_id']; break; case 2: //商户优惠券 $m_coupon_id_redis[] = $coupon_info['coupon_id']; break; case 3: //商家券 $h_coupon_id_redis[] = $coupon_info['coupon_id']; break; } } } } $sMap = array( 'l.' . $CouponLogsModel::STORE_ID => $store_id, 'l.' . $CouponLogsModel::UID => $uid, 'l.' . $CouponLogsModel::STATUS => 1, //未使用的优惠券 'c.' . $CouponModel::BEGIN_TIME => array('lt', $time), //开始时间小于当前时间 'c.' . $CouponModel::END_TIME => array('gt', $time), //结束时间大于当前时间 'c.' . $CouponModel::NEED_MONEY => array('elt', $money), //结束时间大于当前时间 ); if (!empty($s_coupon_id_redis)) { $sMap['l.id'] = array('not in', $s_coupon_id_redis); } $sFields = array( 'l.' . $CouponLogsModel::ID, 'c.' . $CouponModel::COUPON_NAME, 'c.' . $CouponModel::BEGIN_TIME, 'c.' . $CouponModel::END_TIME, 'c.' . $CouponModel::NEED_MONEY . ' as need_money', 'c.' . $CouponModel::REDUCTION_MONEY . ' as reduce_money', ); //默认查询未使用并且在有效期内的优惠券 //正常可使用的优惠券 $sCoupon = $CouponLogsModel->getCoupon($sMap, $sFields, "c.end_time", ""); if (!empty($sCoupon)) { foreach ($sCoupon as $key => &$value) { $value['coupon_choice_type'] = 1; //门店优惠券 $value['begin_time'] = date('Y.m.d', $value[$CouponModel::BEGIN_TIME]); $value['end_time'] = date('Y.m.d', $value[$CouponModel::END_TIME]); } } else { $sCoupon = array(); } $vipInfo = $this->getVipInfo(); if (!empty($vipInfo)) { $VipMCouponModel = D('RetailVipMCoupon'); $map = array( 'v.' . $VipMCouponModel::IS_USE => 1, 'v.' . $VipMCouponModel::VID => $vipInfo['vid'], 'v.' . $VipMCouponModel::NEED_MONEY => array('elt', floatval($money)), 'v.' . $VipMCouponModel::START_TIME => array("LT", $time), 'v.' . $VipMCouponModel::END_TIME => array("GT", $time), 'v.' . $VipMCouponModel::MERCHANT_ID => $merchant_id, ); if (!empty($m_coupon_id_redis)) { $map['v.id'] = array('not in', $m_coupon_id_redis); } $mCoupon = $VipMCouponModel->getSelectUseCoupon($map, self::$store_id); if (!$mCoupon) { $mCoupon = array(); } } else { $mCoupon = array(); } $Plug = new Plug(); $result = $Plug->PlugPermissions([ 'merchant_id' => $merchant_id, 'identification_arr' => [ 'shopcoupon' ] ]); //商户插件权限 if (!empty($result['data']['plug']['shopcoupon'])) { $scene_type = I('post.scene_type') ? I('post.scene_type') : 1; //1普通下单场景 2预售下单场景 $is_integral_cash = I('post.is_integral_cash'); //是否开启积分低现 $shopping_ids = json_decode(I('post.shopping_ids'), true);//购物车id $goods_id = I('post.goods_id'); //预售订单的商品id if ($scene_type != 2) { $VipInfoClass = new VipInfo(); $vip_info = $VipInfoClass->getVipInfo([ 'merchant_id' => self::$merchant_id, 'user' => self::$user ]); } $ShopCouponClass = new ShopCoupon(); $result = $ShopCouponClass->xcxGetUserPayShopCoupon([ 'merchant_id' => self::$merchant_id, 'store_id' => self::$store_id, 'shopping_ids' => $shopping_ids, 'goods_id' => $goods_id, 'xcx_id' => self::$uid, 'vip_info' => $vip_info ? $vip_info : [], 'is_integral_cash' => $is_integral_cash, 'h_coupon_id_redis' => $h_coupon_id_redis, 'order_money' => $money, 'scene_type' => $scene_type ]); $shop_coupon = $result['data']['shop_coupon']; if (!empty($shop_coupon)) { $sCoupon = array_merge($sCoupon, $shop_coupon); } } $res['status'] = 1; $res['msg'] = '查询成功'; $res['sCoupon'] = $sCoupon; $res['mCoupon'] = $mCoupon; $this->ajaxReturn($res); } /** * 会员优惠券 2020-12-23 */ public function getCanUseCoupon_v1() { $type = I('post.type'); //1优惠券 2会员优惠券 3商家券 $money = I('post.money'); $scene_type = I('post.scene_type') ? I('post.scene_type') : 1; //1普通下单场景 2预售下单场景 $is_integral_cash = I('post.is_integral_cash'); //是否开启积分低现 $shopping_ids = json_decode(I('post.shopping_ids'), true);//购物车id $goods_id = I('post.goods_id'); //预售订单的商品id $sku_id = I('post.sku_id'); //预售订单的商品规格id $goods_class_id = I('post.goods_class_id'); //预售订单的商品的分类id if (empty($money)) { $res['status'] = 0; $res['msg'] = '缺少订单金额'; $this->ajaxReturn($res); } $store_id = self::$store_id; $merchant_id = self::$merchant_id; $uid = self::$uid; $CouponLogsModel = D('RetailCouponLogs');//门店优惠券领取记录 $CouponModel = D('RetailCoupon');//门店优惠券 $time = time(); $s_coupon_id_redis = []; //门店优惠券 $m_coupon_id_redis = []; //商户优惠券 $h_coupon_id_redis = []; //门店商家券 if (C('IS_SET_REDIS')) { $ApiRedis = new \Addons\Api\RedisController(); $coupon_redis_key = 'retail_coupon_store_id_' . $store_id . '_uid_*'; $coupon_redis = $ApiRedis::$redis->mget($ApiRedis::$redis->keys($coupon_redis_key)); if ($coupon_redis) { foreach ($coupon_redis as $coupon_key => $coupon_val) { $coupon_info = json_decode($coupon_val, true); switch ($coupon_info['coupon_type']) { case 1: //门店优惠券 $s_coupon_id_redis[] = $coupon_info['coupon_id']; break; case 2: //商户优惠券 $m_coupon_id_redis[] = $coupon_info['coupon_id']; break; case 3: //商家券 $h_coupon_id_redis[] = $coupon_info['coupon_id']; break; } } } } switch ($type) { case 1: $sMap = array( 'l.' . $CouponLogsModel::STORE_ID => $store_id, 'l.' . $CouponLogsModel::UID => $uid, 'l.' . $CouponLogsModel::STATUS => 1, //未使用的优惠券 'c.' . $CouponModel::BEGIN_TIME => array('lt', $time), //开始时间小于当前时间 'c.' . $CouponModel::END_TIME => array('gt', $time), //结束时间大于当前时间 'c.' . $CouponModel::NEED_MONEY => array('elt', $money), //结束时间大于当前时间 ); if (!empty($s_coupon_id_redis)) { $sMap['l.id'] = array('not in', $s_coupon_id_redis); } $sFields = array( 'l.' . $CouponLogsModel::ID, 'c.' . $CouponModel::COUPON_NAME, 'c.' . $CouponModel::BEGIN_TIME, 'c.' . $CouponModel::END_TIME, 'c.' . $CouponModel::NEED_MONEY . ' as need_money', 'c.' . $CouponModel::REDUCTION_MONEY . ' as reduce_money', ); //默认查询未使用并且在有效期内的优惠券 //正常可使用的优惠券 $couponList = $CouponLogsModel->getCoupon($sMap, $sFields, "c.end_time", ""); if (!empty($couponList)) { foreach ($couponList as $key => &$value) { $value['coupon_choice_type'] = 1; //门店优惠券 $value['begin_time'] = date('Y.m.d', $value[$CouponModel::BEGIN_TIME]); $value['end_time'] = date('Y.m.d', $value[$CouponModel::END_TIME]); } } else { $couponList = []; } break; case 2: //会员卡普通优惠券 $VipInfoClass = new VipInfo(); $vip_info = $VipInfoClass->getVipInfo([ 'merchant_id' => self::$merchant_id, 'user' => self::$user ]); if (!empty($vip_info)) { $CouponUseClass = new CouponUse(); $result = $CouponUseClass->getUsableCouponList([ 'merchant_id' => self::$merchant_id, 'store_id' => self::$store_id, 'xcx_id' => self::$uid, 'm_coupon_id_redis' => $m_coupon_id_redis, 'scene_type' => $scene_type, 'shopping_ids' => $shopping_ids, 'goods_id' => $goods_id ? $goods_id : 0, 'sku_id' => $sku_id ? $sku_id : 0, 'goods_class_id' => $goods_class_id ? $goods_class_id : 0, 'vip_info' => $vip_info ? $vip_info : [], 'is_integral_cash' => $is_integral_cash, 'order_money' => $money ]); if ($result['status'] == 1) { $couponList = $result['data']; } } break; case 3: //会员卡普通优惠券 $VipInfoClass = new VipInfo(); $vip_info = $VipInfoClass->getVipInfo([ 'merchant_id' => self::$merchant_id, 'user' => self::$user ]); $Plug = new Plug(); $result = $Plug->PlugPermissions([ 'merchant_id' => $merchant_id, 'identification_arr' => [ 'shopcoupon' ] ]); //商户插件权限 if (!empty($result['data']['plug']['shopcoupon'])) { $ShopCouponClass = new ShopCoupon(); $result = $ShopCouponClass->xcxGetUserPayShopCoupon([ 'merchant_id' => self::$merchant_id, 'store_id' => self::$store_id, 'shopping_ids' => $shopping_ids, 'goods_id' => $goods_id, 'sku_id' => $sku_id ? $sku_id : 0, 'xcx_id' => self::$uid, 'vip_info' => $vip_info ? $vip_info : [], 'is_integral_cash' => $is_integral_cash, 'h_coupon_id_redis' => $h_coupon_id_redis, 'order_money' => $money, 'scene_type' => $scene_type ]); $shop_coupon = $result['data']['shop_coupon']; if (!empty($shop_coupon)) { $couponList = $shop_coupon; } } break; } $res['status'] = 1; $res['message'] = '查询成功'; $res['data'] = $couponList?$couponList:[]; $this->ajaxReturn($res); } /** * 2020-8-20 领券中心 */ public function coupons() { $uid = self::$uid;//小程序用户ID $store_id = self::$store_id;//门店id $merchant_id = self::$merchant_id;//商户id $coupon_type = I('post.coupon_type') ? I('post.coupon_type') : 1; //1门店优惠券 3商家券 $page = I('post.page') ? I('post.page') : 1; $limit = 10; switch ($coupon_type) { case 1: //门店优惠券 $CouponLogsModel = new RetailCouponLogsModel(); $user_log_ids = $CouponLogsModel->getFindField([ 'uid' => $uid, 'merchantid' => $merchant_id, 'storeid' => $store_id, ], "coupon_id", true); $CouponModel = new RetailCouponModel(); $where[$CouponModel::STATUS] = 2;//可用卷状态 $where[$CouponModel::END_TIME] = array('gt', time());//过期时间大于当前时间 $where[$CouponModel::STORE_ID] = $store_id; $where[$CouponModel::MERCHANT_ID] = $merchant_id; $where[$CouponModel::QUANTITY] = array('gt', 0); if (!empty($user_log_ids)) { $where['id'] = ['not in', $user_log_ids]; } $coupons = $CouponModel->getSelect($where, '*', 'id asc', $page . ',' . $limit); foreach ($coupons as $key => &$value) { $value['begin_time'] = date('Y-m-d ', $value[$CouponModel::BEGIN_TIME]); $value['end_time'] = date('Y-m-d ', $value[$CouponModel::END_TIME]); $value['collar'] = 0;//用户未领取 } $res['data'] = $coupons; break; case 3: //商家券 $shopCouponClass = new ShopCoupon(); $result = $shopCouponClass->couponList([ 'merchant_id' => $merchant_id, 'xcx_id' => $uid, 'store_id' => $store_id, 'page' => $page, 'limit' => $limit ]); $res['data'] = $result['data']['list']; break; case 4: //代金券 $payCouponClass = new PayCoupon(); $payResult = $payCouponClass->couponList([ 'merchant_id' => $merchant_id, 'store_id' => $store_id, 'uid' => $uid, 'page' => $page, 'limit' => $limit ]); $res['data'] = $payResult['data']['list']; break; } $title = 'http'; if ($_SERVER['HTTPS'] == 'on') { $title .= 's'; } $res['web_url'] = $title . '://' . $_SERVER['HTTP_HOST'] . '/index.php/Vip/CouponAuth/couponAuth'; $res['status'] = 1; $res['msg'] = '查询成功'; $this->ajaxReturn($res); } /** * 优惠券领取 */ public function collar() { if (IS_POST) { $uid = self::$uid;//小程序用户ID $store_id = self::$store_id;//门店id $merchant_id = self::$merchant_id;//商户id $coupon_id = I('post.coupon_id');//优惠券id $CouponLogsModel = D('RetailCouponLogs'); $CouponModel = D('RetailCoupon'); if (empty($uid)) { $res['status'] = -1; $res['msg'] = '用户未登录'; $this->ajaxReturn($res); } $coupon_info = $CouponModel->getFind(array("id" => $coupon_id)); if ($coupon_info['status'] != 2) { $res['status'] = 0; $res['msg'] = '该优惠券已下架'; $this->ajaxReturn($res); } if ($coupon_info['quantity'] <= 0) { $res['status'] = 0; $res['msg'] = '该优惠券已领完'; $this->ajaxReturn($res); } $find = $CouponLogsModel->getFind(array($CouponLogsModel::COUPON_ID => $coupon_id, $CouponLogsModel::UID => $uid)); if (!empty($find)) { $res['status'] = 0; $res['msg'] = '您已领取过了'; $this->ajaxReturn($res); } //用户领取得优惠券入库记录 $data[$CouponLogsModel::UID] = $uid; $data[$CouponLogsModel::STORE_ID] = $store_id; $data[$CouponLogsModel::MERCHANT_ID] = $merchant_id; $data[$CouponLogsModel::COUPON_ID] = $coupon_id; $data[$CouponLogsModel::ADD_TIME] = time(); $collar = $CouponLogsModel->addOrder($data); if ($collar) { //领取成功后,减去优惠券的库存 $quantity = $CouponModel->toSetDec(array($CouponModel::ID => $coupon_id), $CouponModel::QUANTITY, 1); $res['status'] = 1; $res['msg'] = '领取成功'; } else { $res['status'] = 0; $res['msg'] = '领取失败'; } $this->ajaxReturn($res); } } /** * 首页获取部分优惠券 */ public function getSomeCoupon() { $uid = self::$uid;//小程序用户ID $store_id = self::$store_id;//门店id $merchant_id = self::$merchant_id;//商户id $couponType = I('post.couponType') ? I('post.couponType') : null; //(diy)1门店优惠券 2商家券 if ($couponType == 1 || empty($couponType)) { //优惠券只查询有效期内的可用卷 $CouponModel = D('RetailCoupon'); $map = array( $CouponModel::STATUS => 2,//可用卷状态 $CouponModel::STORE_ID => $store_id, $CouponModel::MERCHANT_ID => $merchant_id, $CouponModel::END_TIME => array('gt', time()),//过期时间大于当前时间 $CouponModel::QUANTITY => array('gt', 0) ); if (!empty($uid)) { $map[$CouponModel::ID] = array('exp', "NOT IN (SELECT l.coupon_id FROM ls_retail_coupon_logs AS l WHERE l.uid=" . $uid . ")"); } $fields = array( $CouponModel::ID, $CouponModel::COUPON_NAME, $CouponModel::BEGIN_TIME, $CouponModel::END_TIME, $CouponModel::NEED_MONEY . ' as need_money', $CouponModel::REDUCTION_MONEY . ' as reduce_money', ); $order = $CouponModel::REDUCTION_MONEY . ' asc'; $coupons = $CouponModel->getSelect($map, $fields, $order, '1,3'); foreach ($coupons as &$value) { $value['begin_time'] = date('Y.m.d ', $value[$CouponModel::BEGIN_TIME]); $value['end_time'] = date('Y.m.d ', $value[$CouponModel::END_TIME]); $value['need_money'] = floatval($value['need_money']); $value['reduce_money'] = floatval($value['reduce_money']); $value['use'] = false; } } $data = [ 'merchant_id' => $merchant_id, 'identification_arr' => [ 'shopcoupon', 'wxpaycoupon' ], ]; $PlugClass = new Plug(); $PlugResult = $PlugClass->PlugPermissions($data); //商家券插件权限 if (($couponType == 2 || empty($couponType)) && !empty($PlugResult['data']['plug']['shopcoupon'])) { //商家券权限 $data = [ 'merchant_id' => $merchant_id, 'xcx_id' => $uid, 'store_id' => $store_id, 'couponType' => $couponType, 'page' => 1, 'limit' => 3 ]; $ShopCouponClass = new ShopCoupon(); $shopResult = $ShopCouponClass->couponList($data); if (!empty($shopResult['data']['list'])) { $shop_coupon = $shopResult['data']['list']; } } if (!empty($PlugResult['data']['plug']['wxpaycoupon'])) { //有代金券权限 $data = [ 'merchant_id' => $merchant_id, 'store_id' => $store_id, 'uid' => self::$uid, 'page' => 1, 'limit' => 3 ]; $PayCouponClass = new PayCoupon(); $payResult = $PayCouponClass->couponList($data); if (!empty($payResult['data']['list'])) { $pay_coupon = $payResult['data']['list']; } } $title = 'http'; if ($_SERVER['HTTPS'] == 'on') { $title .= 's'; } $web_url = $title . '://' . $_SERVER['HTTP_HOST'] . '/index.php/Vip/CouponAuth/couponAuth'; if ($couponType == 2) { $res['data'] = $shop_coupon ? $shop_coupon : []; } else { $res['data'] = $coupons ? $coupons : []; } $res['status'] = 1; $res['shop_coupon'] = $shop_coupon ? $shop_coupon : []; $res['pay_coupon'] = $pay_coupon ? $pay_coupon : []; $res['web_url'] = $web_url ? $web_url : ''; $res['msg'] = '查询成功'; $this->ajaxBack($res); } /** * 用户领取的优惠券(分页) 2020-01-03 */ public function myCoupon_v1() { $store_id = self::$store_id; //门店id $uid = self::$uid; //用户id $type = I('post.type') ? I('post.type') : 1;//查看的优惠券类型 1:正常可用的卷 2:已使用的卷 3:过期的卷 $page = I('post.page') ? I('post.page') : 1; $CouponLogsModel = D('RetailCouponLogs'); $CouponModel = D('RetailCoupon'); $where['l.' . $CouponLogsModel::STORE_ID] = $store_id; $where['l.' . $CouponLogsModel::UID] = $uid; //默认查询未使用并且在有效期内的优惠券 if ($type == 1) { //正常可使用的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 1;//未使用的优惠券 $where['c.' . $CouponModel::END_TIME] = array('gt', time());//结束时间大于当前时间 } else if ($type == 2) { //已使用的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 2;//已使用的优惠券 } else if ($type == 3) { //过期的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 1;//未使用的优惠券 $where['c.' . $CouponModel::END_TIME] = array('lt', time());//结束时间小于当前时间 } $field = array( 'c.' . $CouponModel::COUPON_NAME, 'c.' . $CouponModel::BEGIN_TIME, 'c.' . $CouponModel::END_TIME, 'c.' . $CouponModel::NEED_MONEY, 'c.' . $CouponModel::REDUCTION_MONEY, 'l.' . $CouponLogsModel::USE_TIME, ); $limit = 10; $coupon = $CouponLogsModel->getCoupon($where, $field, '', $page . ',' . $limit); foreach ($coupon as $key => &$val) { $val[$CouponModel::BEGIN_TIME] = date('Y - m - d', $val[$CouponModel::BEGIN_TIME]); $val[$CouponModel::END_TIME] = date('Y - m - d', $val[$CouponModel::END_TIME]); $val[$CouponLogsModel::USE_TIME] = date('Y - m - d H:i:s', $val[$CouponLogsModel::USE_TIME]); } $res['limit'] = $limit; if (!empty($coupon)) { $res['status'] = 1; $res['msg'] = '查询成功'; $res['data'] = $coupon; } else { $res['status'] = 1; $res['msg'] = '暂无查询到相关优惠券'; $res['data'] = array(); } $this->ajaxReturn($res); } /** * 用户领取的优惠券(分页) 2020-05-22 */ public function myCoupon_v2() { $merchant_id = self::$merchant_id; //商户ID $uid = self::$uid; //用户id $type = I('post.type') ? I('post.type') : 1;//查看的优惠券类型 1:正常可用的卷 2:已使用的卷 3:过期的卷 $page = I('post.page') ? I('post.page') : 1; $CouponLogsModel = new RetailCouponLogsModel(); $CouponModel = new RetailCouponModel(); $where['l.' . $CouponLogsModel::UID] = $uid; $where['l.' . $CouponLogsModel::MERCHANT_ID] = $merchant_id; //默认查询未使用并且在有效期内的优惠券 if ($type == 1) { //正常可使用的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 1;//未使用的优惠券 $where['c.' . $CouponModel::END_TIME] = array('gt', time());//结束时间大于当前时间 } else if ($type == 2) { //已使用的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 2;//已使用的优惠券 } else if ($type == 3) { //过期的优惠券 $where['l.' . $CouponLogsModel::STATUS] = 1;//未使用的优惠券 $where['c.' . $CouponModel::END_TIME] = array('lt', time());//结束时间小于当前时间 } $field = array( 'c.' . $CouponModel::COUPON_NAME, 'c.' . $CouponModel::BEGIN_TIME, 'c.' . $CouponModel::END_TIME, 'c.' . $CouponModel::NEED_MONEY, 'c.' . $CouponModel::REDUCTION_MONEY, 'l.' . $CouponLogsModel::USE_TIME, 'c.' . $CouponLogsModel::STORE_ID . ' as store_id', ); $limit = 10; $coupon = $CouponLogsModel->getCoupon($where, $field, '', $page . ',' . $limit); $store_array = []; $StoreModel = new RetailStoreModel(); foreach ($coupon as $key => &$val) { $val[$CouponModel::BEGIN_TIME] = date('Y.m.d', $val[$CouponModel::BEGIN_TIME]); $val[$CouponModel::END_TIME] = date('Y.m.d', $val[$CouponModel::END_TIME]); if ($val[$CouponLogsModel::USE_TIME]) $val[$CouponLogsModel::USE_TIME] = date('Y - m - d H:i:s', $val[$CouponLogsModel::USE_TIME]); if ($store_array[$val['store_id']]) { $val['store_name'] = $store_array[$val['store_id']]; } else { $val['store_name'] = $StoreModel->getFindField(array('id' => $val['store_id']), 'storetag'); $store_array[$val['store_id']] = $val['store_name']; } } $res['limit'] = $limit; if (!empty($coupon)) { $res['status'] = 1; $res['msg'] = '查询成功'; $res['data'] = $coupon; } else { $res['status'] = 1; $res['msg'] = '暂无优惠券'; $res['data'] = array(); } $this->ajaxReturn($res); } /* * ***********************************新版普通优惠券2020-12-21************************************** */ //会员普通优惠券领取记录 public function getOrdinaryCouponList() { $data = I('post.'); $data['merchant_id'] = self::$merchant_id; $data['vip_id'] = $data['vid']; $CouponUserClass = new CouponUse(); $result = $CouponUserClass->getVipCouponList($data); $this->ajaxReturn($result); } //普通优惠券详情 public function getCouponInfo() { $data = I('post.'); $data['merchant_id'] = self::$merchant_id; $CouponUserClass = new CouponUse(); $result = $CouponUserClass->couponInfo($data); $this->ajaxReturn($result); } }