recordListTerm($param); $page = $param['page'] ? $param['page'] : 1; $limit = $param['limit'] ? $param['limit'] : 10; $fields = 'c.user_type,c.available_type,c.stock_name,c.stock_type,r.stock_id,r.openid,v.name,v.nickname,v.mobile_phone ,r.add_time,s.storetag,r.verification_available_type,j.name as operator_name,r.wechatpay_use_time,r.verification_store_id'; try { $ShopCouponRecordModel = new ShopCouponRecordModel(); $list = $ShopCouponRecordModel->recordList($fields, $where, $page, $limit); } catch (\Exception $e) { return callBack(statusCode()['success'], "查询成功", ['list' => [], 'count' => 0]); } if ($list) { $count = $ShopCouponRecordModel->recordCount($where); $storeModel = new RetailStoreModel(); foreach ($list as $key => &$val) { $val['index'] = $key + 1; $val['vip_name'] = $val['name'] ? $val['name'] : $val['nickname']; $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); if (!empty($val['verification_store_id'])) { $val['use_storetag'] = $storeModel->getFindField([ 'id' => $val['verification_store_id'] ], 'storetag'); } else { $val['use_storetag'] = ''; } $available_type = explode(',', $val['available_type']); $val['available_type_name'] = ''; if (in_array(1, $available_type)) { $val['available_type_name'] .= '线上'; } if (in_array(2, $available_type)) { $val['available_type_name'] .= '线下'; } if (!empty($val['wechatpay_use_time'])) { $val['wechatpay_use_time'] = date('Y-m-d H:i:s', $val['wechatpay_use_time']); } switch ($val['user_type']) { case 1: $val['user_type_name'] = '普通支付模式'; break; case 2: $val['user_type_name'] = '服务商支付模式'; break; } switch ($val['stock_type']) { case 1: $val['stock_type_name'] = '满减券'; break; case 2: $val['stock_type_name'] = '折扣券'; break; case 3: $val['stock_type_name'] = '换购券'; break; } switch ($val['verification_available_type']) { case 1: $val['verification_available_name'] = '线上'; break; case 2: $val['verification_available_name'] = '线下'; break; } } } return callBack(statusCode()['success'], "查询成功", ['list' => $list, 'count' => $count ? $count : 0]); } /** * 发放记录列表的where条件 * @param $param * [ * merchant_id * page * limit * searchText 会员名称/商家券名称/手机号/发放的商家券ID * wechatpay_use_time 核销日期 * verification_store_id 核销门店 * verification_available_type 核销场景 * use_type 使用状态 * verification_type 核销状态 * ] * @return mixed */ public function recordListTerm($param) { if (!empty($param['searchText'])) { $param['searchText'] = trim($param['searchText']); $where['v.mobile_phone|v.nickname|v.name|c.stock_name|r.stock_id'] = ["like", "%{$param['searchText']}%"]; } if (!empty($param['wechatpay_use_time'])) { $start_time = strtotime($param['wechatpay_use_time'][0] . '00:00:00'); $end_time = strtotime($param['wechatpay_use_time'][1] . '23:59:59'); $where['r.wechatpay_use_time'] = ['between', [$start_time, $end_time]]; } if (!empty($param['use_type'])) { $where['r.used_type'] = $param['use_type']; } if (!empty($param['verification_type'])) { $where['r.verification_type'] = $param['verification_type']; } if (!empty($param['verification_store_id'])) { $where['r.verification_store_id'] = $param['verification_store_id']; } if (!empty($param['verification_available_type'])) { $where['r.verification_available_type'] = $param['verification_available_type']; } $where['r.merchant_id'] = $param['merchant_id']; if(!empty($param['available_type'])){ $where['c.available_type'] = implode(',',$param['available_type']); } return $where; } /** * 商家券详情 * @param $param * [ * merchant_id * id 商家券id * ] * @return mixed */ public function couponInfo($param) { if (empty($param['merchant_id']) || empty($param['id'])) { return callBack(statusCode()['error'], '参数缺失'); } $where = [ 'merchant_id' => $param['merchant_id'], 'id' => $param['id'] ]; $fields = 'stock_name,goods_name,stock_type,coupon_use_rule,stock_send_rule,display_pattern_info,valid_time_type,user_type,store_id_gather,store_type,goods_type,goods_list,available_type,type'; try { $ShopCouponModel = new ShopCouponModel(); $info = $ShopCouponModel->getFind($where, $fields); $info['user_type'] = intval($info['user_type']); $info['type'] = intval($info['type']); $info['available_type'] = array_map('int', explode(',', $info['available_type']));; $info['coupon_use_rule'] = json_decode($info['coupon_use_rule'], true); $info['available_time'][] = $info['coupon_use_rule']['coupon_available_time']['available_begin_time']; $info['available_time'][] = $info['coupon_use_rule']['coupon_available_time']['available_end_time']; $info['stock_send_rule'] = json_decode($info['stock_send_rule'], true); $info['display_pattern_info'] = json_decode($info['display_pattern_info'], true); $info['store_id_gather'] = explode(',', $info['store_id_gather']); if (!empty($info['goods_list'])) { $info['goodsList'] = json_decode($info['goods_list'], true); } return callBack(statusCode()['success'], "查询成功", ['info' => $info]); } catch (\Exception $e) { return callBack(statusCode()['success'], "查询成功", ['info' => []]); } } /** * 商家券列表 * @param $param * [ * merchant_id * stock_name * suspend_status * add_time * ] * @return mixed */ public function couponList($param) { $where = $this->couponListTerm($param); $page = $param['page'] ? $param['page'] : 1; $limit = $param['limit'] ? $param['limit'] : 10; $fields = "id,user_type,type,stock_type,stock_id,stock_name,stock_send_rule,coupon_use_rule,operator_id,suspend_status,available_type,coupon_num,operation_num,store_id_gather,store_type"; try { $shopCouponModel = new ShopCouponModel(); $list = $shopCouponModel->getSelect($where, $fields, 'id desc', $page . ',' . $limit); } catch (\Exception $e) { return callBack(statusCode()['success'], "查询成功", ['list' => [], 'count' => 0]); } if ($list) { $count = $shopCouponModel->getCount($where); $JurisdictionUserModel = new JurisdictionUserModel(); foreach ($list as $key => &$val) { $val['index'] = $key + 1; switch ($val['user_type']) { case 1: $val['user_name'] = '普通支付模式'; break; case 2: $val['user_name'] = '服务商支付模式'; break; } switch ($val['type']) { case 1: $val['type_name'] = '小程序'; break; case 2: $val['type_name'] = '公众号'; break; } switch ($val['stock_type']) { case 1: $val['stock_type_name'] = '满减券'; break; case 2: $val['stock_type_name'] = '折扣券'; break; case 3: $val['stock_type_name'] = '换购券'; break; } switch ($val['suspend_status']) { case 1: $val['suspend_name'] = '正在发放'; break; case 2: $val['suspend_name'] = '暂停发放'; break; } $available_type = explode(',', $val['available_type']); $val['available_name'] = ''; if (in_array(1, $available_type)) { $val['available_name'] .= '线上'; } if (in_array(2, $available_type)) { $val['available_name'] .= '线下'; } $coupon_use_rule = json_decode($val['coupon_use_rule'], true); $stock_send_rule = json_decode($val['stock_send_rule'], true); $val['coupon_available_time'] = $coupon_use_rule['coupon_available_time']['available_begin_time'] . '-' . $coupon_use_rule['coupon_available_time']['available_end_time']; $val['max_amount'] = round($stock_send_rule['max_amount'], 2); $val['operator_name'] = $JurisdictionUserModel->getFindField(['id' => $val['operator_id']], "name"); } } return callBack(statusCode()['success'], "查询成功", ['list' => $list, 'count' => $count ? $count : 0]); } /** * 商家券列表的where条件 * @param $param * [ * merchant_id * stock_name * suspend_status * add_time * ] * @return mixed */ public function couponListTerm($param) { if (!empty($param['stock_name'])) { $param['stock_name'] = trim($param['stock_name']); $where['stock_name|stock_id'] = ["like", "%{$param['stock_name']}%"]; } if (!empty($param['suspend_status'])) { $where['suspend_status'] = $param['suspend_status']; } if (!empty($param['stock_type'])) { $where['stock_type'] = $param['stock_type']; } if (!empty($param['add_time'])) { $start_time = strtotime($param['add_time'][0]); $end_time = strtotime($param['add_time'][1]); $where['create_time'] = ['between', [$start_time, $end_time]]; } $where['merchant_id'] = $param['merchant_id']; $where['status'] = 1; return $where; } /** * 门店列表 * @param $param * @return mixed */ public function getStoreList($param) { $storeClass = new Store(); $list = $storeClass->getStoreList($param); return callBack(statusCode()['success'], "查询成功", ['list' => $list]); } }