文件
mashangyoujiu/Application/Common/Business/CouponList.class.php

883 行
33 KiB
PHP
可执行文件

<?php
namespace Common\Business;
use Common\Model\RetailMCouponGroupModel;
use Common\Model\RetailMCouponModel;
use Common\Model\RetailStoreModel;
use Common\Model\RetailVipIntegralModel;
use Common\Model\RetailVipMCouponModel;
use Common\Model\RetailVipModel;
//[1.7.72]
/**
* 优惠券列表类
* Class CouponList
* [
* 获取指定会员的列表 getAppointVipList
* 获取指定会员的门店与等级列表 getAppointList
* 券包详情 couponPackageInfo
* 券包列表 couponPackageList
* 单张券详情 couponInfo
* 优惠券发放记录 couponGrantRecord
* 发放记录字段转换 grantRecordRotate
* 优惠券列表 couponList
* 优惠券列表字段转换 convertList
* 优惠券列表的查询条件 couponTerm
* 优惠券列表的参数验证 couponListVerify
* ]
* @package Common\Business
*/
class CouponList
{
/**
* 获取指定会员的门店与等级列表
* @param $param
* [
* user_type 3商户 4门店
* merchant_id
* coupon_type 1优惠券 2券包
* id 优惠券或券包id
* ]
* @return mixed
*/
public function getAppointList($param)
{
if (!in_array($param['coupon_type'], ['1', '2'])) {
return callBack(statusCode()['error'], '请输入券类型');
}
if (empty($param['id'])) {
return callBack(statusCode()['error'], "缺少券ID");
}
switch ($param['coupon_type']) {
case 1:
//优惠券
$CouponModel = new RetailMCouponModel();
$info = $CouponModel->getFind([
'id' => $param['id']
], "storeids as store_id_str,coupon_gradeid as grade_id_str,coupon_name");
break;
case 2:
//券包
$PackageCouponModel = new RetailMCouponGroupModel();
$info = $PackageCouponModel->getFind([
'id' => $param['id']
], "storeids as store_id_str,gradeids as grade_id_str,coupon_group_name as coupon_name");
break;
}
if (empty($info)) {
return callBack(statusCode()['error'], '未找到该券');
}
//门店
if ($info['store_id_str'] != '0') {
$StoreClass = new Store();
$storeResult = $StoreClass->storeNameList([
'store_id_gather' => $info['store_id_str']
]);
$store_list = $storeResult['data']['list'];
} else {
$store_list = ['0' => '所有门店'];
}
//获取等级
if ($info['grade_id_str'] == '-1') {
// 指定plus
$grade_list = ['0' => 'plus专属'];
} else if ($info['grade_id_str'] == '0') {
// 所有会员等级
$grade_list = ['0' => '所有等级'];
} else {
$VipIntegralModel = new RetailVipIntegralModel();
$grade_list = $VipIntegralModel->getFindField([
'id' => ['in', $info['grade_id_str']],
'merchantid' => $param['merchant_id']
], 'cardname', true);
}
return callBack(statusCode()['success'], "查询成功", [
'store_list' => $store_list,
'grade_list' => $grade_list,
'coupon_name' => $info['coupon_name']
]);
}
/**
* @param $param
* [
* user_type 3商户 4门店
* merchant_id
* coupon_type 1优惠券 2券包
* id 优惠券或券包id
* search_info 搜索内容
* page
* limit
* ]
* @return mixed
*/
public function getAppointVipList($param)
{
if (!in_array($param['coupon_type'], ['1', '2'])) {
return callBack(statusCode()['error'], '请输入券类型');
}
if (empty($param['id'])) {
return callBack(statusCode()['error'], "缺少券ID");
}
switch ($param['coupon_type']) {
case 1:
//优惠券
$CouponModel = new RetailMCouponModel();
$info = $CouponModel->getFind([
'id' => $param['id']
], "id,coupon_name,storeids as store_id_str,coupon_gradeid as grade_id_str");
break;
case 2:
//券包
$PackageCouponModel = new RetailMCouponGroupModel();
$info = $PackageCouponModel->getFind([
'id' => $param['id']
], "id,coupon_group_name as coupon_name,storeids as store_id_str,gradeids as grade_id_str");
break;
}
if (empty($info)) {
return callBack(statusCode()['error'], '未找到该券');
}
if ($info['grade_id_str'] == '-1') {
$fields = [
'v.id,v.storeid,v.mobile_phone,v.balance,v.name,v.nickname,v.integral,v.card_key,v.grade_integral,v.plus_type,v.plus_state'
];
} else {
$fields = [
'id,storeid,mobile_phone,balance,name,nickname,integral,card_key,grade_integral,plus_type,plus_state'
];
}
$VipInfoClass = new VipInfo();
$vipResult = $VipInfoClass->basisStoreGetVip([
'user_type' => $param['user_type'],
'merchant_id' => $param['merchant_id'],
'store_id_str' => $info['store_id_str'],
'grade_id_str' => $info['grade_id_str'],
'search_info' => $param['search_info'],
'fields' => $fields,
'need_count' => 1,
'page' => $param['page'],
'limit' => $param['limit']
]);
if ($vipResult['status'] != 1) {
return $vipResult;
}
$vip_list = $vipResult['data']['vip_id_arr'];
$count = $vipResult['data']['count'];
if (!empty($vip_list)) {
$StoreModel = new RetailStoreModel();
foreach ($vip_list as $key => &$value) {
$value['store_name'] = $StoreModel->getFindField([
'id' => $value['storeid']
], 'storetag');
$name = $value['name'] ? $value['name'] : '未设置';
$nickname = $value['nickname'] ? $value['nickname'] : '未设置';
$value['user_name'] = $name . '|' . $nickname;
$value['card_key'] = !$value['card_key'] || $value['card_key'] == 0 || $value['card_key'] == '0' ? '暂无' : $value['card_key'];
$value['balance'] = $value['balance'] > 0 ? $value['balance'] : 0;
$value['integral'] = $value['integral'] > 0 ? $value['integral'] : 0;
if ($value['plus_type'] == 2) {
// plus会员
$value['vip_grade_name'] = 'Plus会员';
} else {
$value['vip_grade_name'] = '常规会员';
}
}
}
return callBack(statusCode()['success'], "查询成功", [
'list' => $vip_list,
'count' => $count
]);
}
/**
* 券包详情
* @param $param
* [
* id 券包id
* merchant_id
* ]
* @return mixed
*/
public function couponPackageInfo($param)
{
if (empty($param['id'])) {
return callBack(statusCode()['error'], "缺少券包id");
}
try {
$CouponPackageModel = new RetailMCouponGroupModel();
$CouponModel = new RetailMCouponModel();
$info = $CouponPackageModel->getFind(['id' => $param['id']]);
if (empty($info)) {
return callBack(statusCode()['error'], "未找到该券包");
}
$coupon = [
'coupon_name' => $info['coupon_group_name'],
'coupon_amount' => $info['coupon_group_allnum'],
'coupon_group_money' => $info['coupon_group_money'],
'grant_type' => $info['give_status'],
'choose_store' => $info['storeids'] == '0' ? '0' : '1',
'store_id_arr' => $info['storeids']
];
if ($info['gradeids'] == '0' || $info['gradeids'] == '-1') {
$coupon['choose_grade'] = $info['gradeids'];
} else {
$coupon['choose_grade'] = '1';
$coupon['vip_grade_id'] = $info['gradeids'];
}
$coupon_list = $CouponModel->getSelect([
'type' => 2,
'mcoupon_group_id' => $param['id'],
'status' => ['neq', 3]
], 'id,coupon_name,needmoney,reducemoney,daynum,starttime,endtime,detailmsg,coupontype,appoint_type,appoint_id_str', 'id asc');
if (!empty($coupon_list)) {
$Classify = new GoodsClassify();
$SaleClass = new SaleGoods();
$coupon_list_new = [];
foreach ($coupon_list as $key => $value) {
$coupon_list_new[$key]['id'] = $value['id'];
if ($value['coupontype'] == 1) {
$coupon_list_new[$key]['start_time'] = date('Y-m-d H:i:s', $value['starttime']);
$coupon_list_new[$key]['end_time'] = date('Y-m-d H:i:s', $value['endtime']);
}
$coupon_list_new[$key]['validity_time_type'] = $value['coupontype'];
$coupon_list_new[$key]['consumption_threshold'] = $value['needmoney'];
$coupon_list_new[$key]['discount_amount'] = $value['reducemoney'];
$coupon_list_new[$key]['explain'] = $value['detailmsg'];
$coupon_list_new[$key]['appoint_type'] = $value['appoint_type'];
$coupon_list_new[$key]['day_num'] = $value['daynum'];
$coupon_list_new[$key]['coupon_name'] = $value['coupon_name'];
if ($value['appoint_type'] == 2) {
//指定分类
$coupon_list_new[$key]['class_list'] = $Classify->appointClass([
'merchant_id' => $info['merchantid'],
'store_id' => $info['storeids'],
'class_id_str' => $value['appoint_id_str']
]);
} else if ($value['appoint_type'] == 3) {
//指定商品
$coupon_list_new[$key]['goods_list'] = $SaleClass->appointGoodsList($value['appoint_id_str']);
}
$coupon_list_new[$key]['appoint_id_arr'] = $value['appoint_id_str'];
}
}
$coupon['coupon_list'] = $coupon_list_new ? $coupon_list_new : [];
return callBack(statusCode()['success'], "查询成功", $coupon);
} catch (\Exception $e) {
return callBack(statusCode()['error'], "查询失败");
}
}
/**
* 优惠券发放记录
* @param $param
* [
* user_type 3商户 4门店
* merchant_id
* store_id
* type 1单张优惠券 2券包
* id 券id
* search_info=>[
* search_type 1会员昵称 2会员手机号
* search_text 会员昵称、会员手机号
* usage_status 1,可使用 2,已使用,3,已过期
* ]
* page
* limit
* ]
* @return mixed
*/
public function couponGrantRecord($param)
{
if (empty($param['id'])) {
return callBack(statusCode()['error'], "缺少券id");
}
$time = $_SERVER['REQUEST_TIME'];
$where = [
'r.merchantid' => $param['merchant_id'],
'r.status' => ['in', ['1', '2']]
];
switch ($param['type']) {
case 1:
$where['r.mcouponid'] = $param['id'];
$where['r.type'] = 1;
break;
case 2:
$where['r.mcoupon_group_id'] = $param['id'];
$where['r.type'] = 2;
break;
}
switch ($param['search_info']['usage_status']) {
case 1:
$where['r.isuse'] = 1;
$where[] = [
[
'c.coupontype' => 1,
'c.endtime' => ['gt', $time]
],
[
'c.coupontype' => 2,
'r.addtime + (c.daynum*86400)' => ['gt', $time]
],
[
'c.coupontype' => 3,
'r.addtime+86400' => ['lt', $time],
'r.addtime+86400+(c.daynum*86400)' => ['gt', $time]
],
'_logic' => 'OR'
];
break;
case 2:
$where['r.isuse'] = 2;
break;
case 3:
$where['r.isuse'] = ['neq', 2];
$where[] = [
[
'c.coupontype' => 1,
'c.endtime' => ['elt', $time]
],
[
'c.coupontype' => 2,
'r.addtime + (c.daynum*86400)' => ['lt', $time]
],
[
'c.coupontype' => 3,
'r.addtime+(c.daynum*86400)' => ['lt', $time],
],
'_logic' => 'OR'
];
break;
}
if (!empty($param['search_info']['search_type'])) {
$vip_map = [
'status' => ['neq', 2],
'merchantid' => $param['merchant_id']
];
switch ($param['search_info']['search_type']) {
case 1:
//会员昵称
$vip_map['nickname|name'] = ['like', '%' . $param['search_info']['search_text'] . '%'];
break;
case 2:
//会员手机号
$vip_map['mobile_phone'] = ['like', '%' . $param['search_info']['search_text'] . '%'];
break;
}
try {
$VipModel = new RetailVipModel();
$vip_id = $VipModel->getFindField($vip_map, "id", true);
} catch (\Exception $e) {
$vip_id = [];
}
if (!empty($vip_id)) {
$where['r.vid'] = ['in', $vip_id];
} else {
return callBack(statusCode()['success'], "查询成功", [
'list' => [],
'count' => 0
]);
}
}
$result = $this->grantRecordRotate([
'where' => $where,
'page' => $param['page'],
'limit' => $param['limit']
]);
return $result;
}
/**
* 发放记录字段转换
* @param $param
* [
* where 条件
* page
* limit
* ]
* @return mixed
*/
public function grantRecordRotate($param)
{
$where = $param['where'];
try {
$fields = [
'r.id',
'r.vid',
'r.mcouponid',
'r.isuse',
'r.usetime',
'r.addtime',
'r.storeid',
'r.type',
'c.starttime',
'c.endtime',
'c.needmoney',
'c.reducemoney',
'c.coupon_name',
'c.coupontype',
'c.daynum',
'v.name',
'v.nickname',
'v.mobile_phone',
];
$VipCouponModel = new RetailVipMCouponModel();
$list = $VipCouponModel->getGrantRecord($where, $fields, 'r.usetime desc,r.addtime desc', $param['page'], $param['limit']);
} catch (\Exception $e) {
$list = [];
}
if (!empty($list)) {
$time = $_SERVER['REQUEST_TIME'];
$count = $VipCouponModel->getGrantRecordCount($where);
$StoreModel = new RetailStoreModel();
foreach ($list as $key => &$val) {
$val['index'] = $key + 1;
switch ($val['coupontype']) {
case 1:
$start_time_str = $val['starttime'];
$end_time_str = $val['endtime'];
break;
case 2:
$start_time_str = $val['addtime'];
$end_time_str = $val['addtime'] + ($val['daynum'] * 86400);
break;
case 3:
$start_time_str = $val['addtime'] + 86400;
$end_time_str = ($val['addtime'] + 86400) + ($val['daynum'] * 86400);
break;
}
if ($val['isuse'] == 2) {
//已使用
$val['isuse_name'] = '已使用';
$val['use_time'] = date('Y-m-d H:i:s', $val['usetime']);
$val['use_store'] = $StoreModel->getFindField(['id' => $val['storeid']], "storetag");
} else {
$val['use_time'] = '';
$val['use_store'] = '';
if ($end_time_str > $time) {
$val['isuse_name'] = '未使用';
} else {
$val['isuse_name'] = '已过期';
}
}
$val['vip_name'] = $val['name'] ? $val['name'] : ($val['nickname'] ? $val['nickname'] : '未设置名称');
$val['vip_phone'] = $val['mobile_phone'];
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
$start_time = date('Y-m-d H:i:s', $start_time_str);
$end_time = date('Y-m-d H:i:s', $end_time_str);
$val['canusetime'] = $start_time . '至' . $end_time;
}
}
return callBack(statusCode()['success'], "查询成功", [
'list' => $list,
'count' => $count ? $count : 0
]);
}
/**
* 券包列表
* @param $param
* [
* user_type 3商户 4门店
* merchant_id
* store_id
* search_ino=>[
* coupon_group_name 券包名称
* start_time 创建时间(起)
* end_time 创建时间(止)
* ]
* ]
* @return mixed
*/
public function couponPackageList($param)
{
$search_ino = $param['search_ino'];
$map['merchantid'] = $param['merchant_id'];
// 名称搜索
if (trim($search_ino['coupon_group_name'], '')) {
$map['coupon_group_name'] = array('like', "%" . trim($search_ino['coupon_group_name'], '') . "%");
}
// 创建时间
if (!empty($search_ino['start_time']) && !empty($search_ino['end_time'])) {
$start_time = strtotime($search_ino['start_time']);
$end_time = strtotime($search_ino['end_time']);
$map['addtime'] = array("between", "$start_time,$end_time");
} else if (!empty($search_ino['start_time'])) {
$start_time = strtotime($search_ino['start_time']);
$map['addtime'] = array('gt', $start_time);
} else if (!empty($search_ino['end_time'])) {
$end_time = strtotime($search_ino['end_time']);
$map['addtime'] = array('lt', $end_time);
}
// $map['user_type'] = $param['user_type'];
if ($param['user_type'] == 4) {
$map[] = [
'FIND_IN_SET("' . $param['store_id'] . '",storeids)',
'storeids' => '0',
'_logic' => 'OR',
];
// $map['storeids'] = $param['store_id'];
}
try {
$PackageModel = new RetailMCouponGroupModel();
$packageList = $PackageModel->getSelect($map, '*', $order = 'addtime desc', $param['page'] . ',' . $param['limit']);
if (!empty($packageList)) {
$count = $PackageModel->getCount($map);
$StoreClass = new Store();
$storeList = $StoreClass->getStoreList([
'merchant_id' => $param['merchant_id']
]);
$storeList = array_column($storeList, null, 'id');
foreach ($packageList as &$val) {
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
$val['coupon_group_allnum'] = floatval($val['coupon_group_allnum']);
$val['coupon_group_num'] = floatval($val['coupon_group_num']);
$val['coupon_group_money'] = floatval($val['coupon_group_money']);
if ($val['give_status'] == 1) {
$val['give_name'] = '自主发放';
} else if ($val['give_status'] == 2) {
$val['give_name'] = '充值赠送';
} else {
$val['give_name'] = '未知类型';
}
$store_name = '';
if (!empty($val['storeids'])) {
$store_id_arr = explode(',', $val['storeids']);
foreach ($store_id_arr as $value) {
$store_name .= $storeList[$value]['storetag'] . ',';
}
$store_name = trim($store_name, ',');
} else {
$store_name = '不限制门店';
}
$val['store_name'] = $store_name;
}
}
return callBack(statusCode()['success'], "查询成功", [
'list' => $packageList ? $packageList : [],
'count' => $count ? $count : 0
]);
} catch (\Exception $e) {
return callBack(statusCode()['error'], "查询失败", [
'list' => [],
'count' => 0
]);
}
}
/**
* 单张券详情
* @param $param
* [
* id 优惠券id
* ]
* @return mixed
*/
public function couponInfo($param)
{
$id = $param['id'];
if (empty($id)) {
return callBack(statusCode()['error'], "请选择优惠券");
}
try {
$CouponModel = new RetailMCouponModel();
$SaleGoodsClass = new SaleGoods();
$Classify = new GoodsClassify();
$info = $CouponModel->getFind([
'id' => $id
]);
if (empty($info)) {
return callBack(statusCode()['error'], "未找到该优惠券");
}
$coupon['coupon'] = [
'coupon_name' => $info['coupon_name'],
'coupon_amount' => $info['coupon_allnum'],
'discount_amount' => $info['reducemoney'],
'consumption_threshold' => $info['needmoney'],
'grant_type' => $info['give_status'],
'choose_store' => $info['storeids'] == '0' ? '0' : '1',
'store_id_arr' => $info['storeids'] != '0' ? $info['storeids'] : '',
'validity_time_type' => $info['coupontype'],
'start_time' => $info['starttime'] ? newDate('Y-m-d H:i:s', $info['starttime']) : '',
'end_time' => $info['endtime'] ? newDate('Y-m-d H:i:s', $info['endtime']) : '',
'day_num' => $info['daynum'],
'explain' => $info['detailmsg'],
'appoint_id_arr' => $info['appoint_id_str']
];
if ($info['coupon_gradeid'] == '-1' || $info['coupon_gradeid'] == '0') {
$coupon['coupon']['choose_grade'] = $info['coupon_gradeid'];
} else {
$coupon['coupon']['choose_grade'] = '1';
$coupon['coupon']['vip_grade_id'] = $info['coupon_gradeid'];
}
if ($coupon['coupon']['choose_store'] == 1 && count($coupon['coupon']['store_id_arr']) == 1) {
//指定单门店
$coupon['coupon']['appoint_type'] = $info['appoint_type'];
if ($coupon['coupon']['appoint_type'] == 2 || $coupon['coupon']['appoint_type'] == 3) {
if ($coupon['coupon']['appoint_type'] == 2) {
//指定分类
$coupon['class_list'] = $Classify->appointClass([
'class_id_str' => $info['appoint_id_str'],
'merchant_id' => $info['merchantid'],
'store_id' => $info['storeids']
]);
} else if ($coupon['coupon']['appoint_type'] == 3) {
//指定商品
$coupon['goods_list'] = $SaleGoodsClass->appointGoodsList($info['appoint_id_str']);
}
}
}
return callBack(statusCode()['success'], "查询成功", $coupon);
} catch (\Exception $e) {
return callBack(statusCode()['success'], "查询失败", []);
}
}
/**
* 优惠券列表
* @param $param
* [
* operator_type 1后台 2收银端 3助手端
* user_type 3商户 4门店
* merchant_id
* store_id
* search_info=>[
* coupon_state 1全部 2未开始 3进行中 4已结束
* coupon_name 优惠券名称
* start_time 开始时间
* end_time 结束时间
* appoint_type 1 全部商品 2指定分类 3指定商品
* ]
* page
* limit
* ]
* @return mixed
*/
public function couponList($param)
{
$verifyResult = $this->couponListVerify($param); //参数验证
if ($verifyResult['status'] != 1) {
return $verifyResult;
}
if (!in_array($param['search_info']['coupon_state'], ['1', '2', '3', '4'])) {
return callBack(statusCode()['error'], '查询类型有问题');
}
$where = $this->couponTerm($param); //查询条件
try {
$CouponModel = new RetailMCouponModel();
$list = $CouponModel->getSelect($where, '*', 'id desc', $param['page'] . ',' . $param['limit']);
if (!empty($list)) {
$count = $CouponModel->getCount($where);
$StoreClass = new Store();
$storeList = $StoreClass->getStoreList([
'merchant_id' => $param['merchant_id']
]);
$storeList = array_column($storeList, null, 'id');
$list = $this->convertList([
'storeList' => $storeList ? $storeList : [],
'list' => $list,
]);
}
return callBack(statusCode()['success'], "查询成功", [
'list' => $list ? $list : [],
'count' => $count ? $count : 0,
]);
} catch (\Exception $e) {
return callBack(statusCode()['success'], "查询成功", [
'list' => [],
'count' => 0,
'e' => $e,
]);
}
}
/**
* 优惠券列表字段转换
* @param $param
* [
* user_type 3商户 4门店
* list 需要转换的数组
* storeList 门店列表
* ]
* @return mixed
*/
public function convertList($param)
{
$list = $param['list'];
$storeList = $param['storeList'];
$time = $_SERVER['REQUEST_TIME'];
foreach ($list as &$val) {
$store_name = '';
if (!empty($val['storeids'])) {
$store_id_arr = explode(',', $val['storeids']);
foreach ($store_id_arr as $value) {
$store_name .= $storeList[$value]['storetag'] . ',';
}
$store_name = trim($store_name, ',');
} else {
$store_name = '不限制门店';
}
$val['store_name'] = $store_name;
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
if ($val['status'] == 2) {
$val['state'] = 2;
$val['type_name'] = '已结束';
} else {
switch ($val['coupontype']) {
case 1:
$val['validity_time'] = date('Y-m-d H:i:s', $val['starttime']) . '至' . date('Y-m-d H:i:s', $val['endtime']);
if ($val['starttime'] > $time) {
$val['state'] = 1;
$val['type_name'] = '未开始';
} else if ($val['endtime'] < $time || $val['coupon_num'] <= 0) {
$val['state'] = 2;
$val['type_name'] = '已结束';
} else {
$val['state'] = 1;
$val['type_name'] = '进行中';
}
break;
case 2:
$val['validity_time'] = "会员领取当日起" . $val['daynum'] . '天内有效';
$val['type_name'] = $val['coupon_num'] > 0 ? '进行中' : '已结束';
$val['state'] = $val['coupon_num'] > 0 ? 1 : 2;
break;
case 3:
$val['validity_time'] = "会员领取次日日起" . $val['daynum'] . '天内有效';
$val['type_name'] = $val['coupon_num'] > 0 ? '进行中' : '已结束';
$val['state'] = $val['coupon_num'] > 0 ? 1 : 2;
break;
}
}
switch ($val['give_status']) {
case 1:
$val['give_name'] = '自主发放';
break;
case 2:
$val['give_name'] = '充值赠送';
break;
case 3:
$val['give_name'] = '支付发放';
break;
}
}
return $list;
}
/**
* 优惠券列表验证
* @param $param
* [
* operator_type 1后台 2收银端 3助手端
* user_type 3商户 4门店
* merchant_id
* store_id
* search_info=>[
* coupon_state 1全部 2未开始 3进行中 4已结束
* coupon_name 优惠券名称
* start_time 开始时间
* end_time 结束时间
* appoint_type 1 全部商品 2指定分类 3指定商品
* ]
* ]
* @return mixed
*/
public function couponTerm($param)
{
$search_info = $param['search_info'];
$time = $_SERVER['REQUEST_TIME'];
$where = [
'merchantid' => $param['merchant_id'],
'type' => 1
];
if ($param['user_type'] == 4) {
$where[] = [
'FIND_IN_SET("' . $param['store_id'] . '",storeids)',
'storeids' => '0',
'_logic' => 'OR',
];
}
if (!empty($search_info['coupon_name'])) {
$where['coupon_name'] = ['like', '%' . trim($search_info['coupon_name'], '') . '%'];
}
if(!empty($search_info['start_time'])){
$start_time = strtotime($search_info['start_time']);
}
if(!empty($search_info['end_time'])){
$end_time = strtotime($search_info['end_time']);
}
if (!empty($search_info['start_time']) && !empty($search_info['end_time'])) {
$where['addtime'] = ['between', [$start_time, $end_time]];
} else if (!empty($search_info['start_time'])) {
$where['addtime'] = ['egt', $start_time];
} else if (!empty($search_info['end_time'])) {
$where['addtime'] = ['elt', $end_time];
}
if (!empty($search_info['appoint_type'])) {
$where['appoint_type'] = $search_info['appoint_type'];
}
switch ($search_info['coupon_state']) {
case 1:
$where['status'] = ['in', ['1', '2']]; // 正常、失效的优惠券
break;
case 2:
$where['status'] = 1;
$where['coupontype'] = 1;
$where['starttime'] = array('gt', $time);
$where['coupon_num'] = array('gt', 0);
break;
case 3:
$where['status'] = 1;
$where['coupon_num'] = array('gt', 0);
$where['_string'] = "(coupontype = 1 AND starttime < {$time} AND endtime > {$time}) OR (coupontype = 2) OR (coupontype = 3)";
break;
case 4:
$where['_string'] = "(status != 3 AND ((coupontype = 1 AND endtime < {$time}) OR (coupon_num <= 0))) OR (status = 2)";
break;
}
return $where;
}
/**
* 优惠券列表的参数验证
* @param $param
* [
* operator_type 1后台 2收银端 3助手端
* user_type 3商户 4门店
* merchant_id
* store_id
* search_info=>[
* coupon_state 1全部 2未开始 3进行中 4已结束
* coupon_name 优惠券名称
* start_time 开始时间
* end_time 结束时间
* appoint_type 1 全部商品 2指定分类 3指定商品
* ]
* ]
* @return mixed
*/
public function couponListVerify($param)
{
$VerifyClass = new VerifyParam();
$verifyResult = $VerifyClass->identityVerify($param);
if ($verifyResult['status'] != 1) {
return $verifyResult;
}
if (!in_array($param['search_info']['coupon_state'], ['1', '2', '3', '4'])) {
return callBack(statusCode()['error'], '请选择正确的券状态');
}
return callBack(statusCode()['success'], "验证成功");
}
}