| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- <?php
- namespace addons\Coupon\api\modules\v1\controllers;
- use addons\Coupon\common\enums\AddonsCouponEnum;
- use addons\Coupon\common\models\AddonsCoupon;
- use addons\Coupon\common\models\AddonsCouponCatRelate;
- use addons\Coupon\common\models\AddonsCouponGoodsRelate;
- use addons\Coupon\common\models\AddonsCouponMemberRelate;
- use addons\Coupon\common\models\AddonsCouponShareLog;
- use addons\Coupon\common\models\AddonsCouponUserRelate;
- use addons\Coupon\common\services\SettingService;
- use addons\Mch\common\models\Mch;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreCoupon;
- use addons\Store\common\models\StoreCouponShareLog;
- use addons\Store\common\models\StoreCouponUserRelate;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\models\StoreGoodsAttr;
- use addons\Store\common\models\StoreGoodsCateRelate;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\helpers\ApiCode;
- use common\helpers\LocationHelper;
- use common\models\goods\GoodsCateRelate;
- use common\models\mall\MallAddons;
- use Yii;
- use api\controllers\OnAuthController;
- use common\helpers\ArrayHelper;
- use common\models\goods\Goods;
- use common\models\user\User;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Coupon\api\modules\v1\controllers
- */
- class CouponController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- private function getCommonWhere($coupon_status)
- {
- $common_where = [
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => StatusEnum::ENABLED]
- ];
- switch ($coupon_status) {
- case 1:
- $common_where[] = ['is_use' => 1];
- break;
- case 2:
- $common_where[] = ['coupon_status' => 2];
- $common_where[] = ['is_use' => 0];
- break;
- case 3:
- $common_where[] = ['coupon_status' => [3, 4]];
- $common_where[] = ['is_giving' => 0];
- $common_where[] = ['is_use' => 0];
- break;
- case 4:
- $common_where[] = ['is_giving' => 1];
- $common_where[] = ['giving_status' => 2];
- break;
- }
- return $common_where;
- }
- public function actionMyCouponSummary()
- {
- $coupon_status = \Yii::$app->request->get('coupon_status', 1);
- $common_where = $this->getCommonWhere($coupon_status);
- $data = [
- 'platform_coupon_nums' => 0,
- 'store_coupon_nums' => 0,
- 'mch_coupon_nums' => 0,
- ];
- $platform_where = $common_where;
- $platform_where[] = ['mch_id' => ''];
- $platform_where[] = ['status' => StatusEnum::ENABLED];
- $platform_counts = AddonsCouponUserRelate::getOne($platform_where, true, [], false, 'count(*) as counts');
- if (!empty($platform_counts)) $data['platform_coupon_nums'] = $platform_counts['counts'];
- $mch_where = $common_where;
- $mch_where[] = ['<>', 'mch_id', ''];
- $mch_counts = AddonsCouponUserRelate::getOne($mch_where, true, [], false, 'count(*) as counts');
- if (!empty($mch_counts)) $data['mch_coupon_nums'] = $mch_counts['counts'];
- if (MallAddons::isInstall($this->mall_id, 'Store')) {
- $store_counts = StoreCouponUserRelate::getOne($common_where, true, [], false, 'count(*) as counts');
- if (!empty($mch_counts)) $data['store_coupon_nums'] = $store_counts['counts'];
- }
- return $this->success('操作成功', $data);
- }
- public function actionMyCouponList()
- {
- $params = \Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['from_type', 'coupon_status'], 'required'],
- [['page', 'limit'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $coupon_status = $params['coupon_status'] ?? 1;
- $from_type = $params['from_type'] ?? 1;
- $common_where = $this->getCommonWhere($coupon_status);
- $page_list = [];
- switch ($from_type) {
- case 1:
- case 3:
- $where = $common_where;
- $where[] = ['status' => StatusEnum::ENABLED];
- $select = 'id,coupon_id,start_time,end_time,is_use,is_giving,giving_status,mch_id,updated_at';
- if ($from_type == 1) {
- $where[] = ['mch_id' => ''];
- } else {
- $where[] = ['<>', 'mch_id', ''];
- }
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $params['select'] = $select;
- $params['with'] = ['coupon' => function ($query) {
- $query->select('id,name,min_price,sub_price,appoint_type,is_giving,type,discount,is_giving_use, coupon_status')
- ->with(['goodsRelate', 'cateRelate']);
- }];
- $page_list = AddonsCouponUserRelate::listPage($params);
- if (!empty($page_list['list'])) {
- $mch_ids = array_column($page_list['list'], 'mch_id');
- $mch_list = [];
- if(MallAddons::isInstall($this->mall_id, 'Mch')) {
- $mch_list = Mch::lists(['where' => [['id' => $mch_ids]], 'index' => 'id']);
- }
- if ($params['coupon_status'] == 4) {
- $user_coupon_ids = array_column($page_list['list'], 'id');
- $share_logs = AddonsCouponShareLog::lists(['where' => [['user_coupon_id' => $user_coupon_ids], ['giving_status' => 2]], 'index' => 'user_coupon_id', 'select' => 'user_coupon_id,receive_user_id']);
- $receive_user_ids = array_column($share_logs, 'receive_user_id');
- $receive_user_list = User::lists(['where' => [['id' => $receive_user_ids]], 'index' => 'id', 'select' => 'id,mobile,nickname']);
- }
- // 通过转增得到的ids
- $giftedIds = AddonsCoupon::getGiftedList($this->mall_id, $page_list['list'], 1);
- foreach ($page_list['list'] as &$item) {
- $item['mch_name'] = '';
- $item['logo_img'] = '';
- $item['store_id'] = '';
- $item['give_name'] = '';
- $item['give_mobile'] = '';
- $item['from_type'] = $from_type;
- $item['coupon']['goods_ids'] = '';
- $item['coupon']['cate_ids'] = '';
- $item['use_time'] = $item['updated_at'];
- if (isset($mch_list[$item['mch_id']])) {
- $item['mch_name'] = $mch_list[$item['mch_id']]['store_name'];
- $item['logo_img'] = $mch_list[$item['mch_id']]['logo_img'];
- }
- $item['coupon']['is_goods_single'] = 0;
- if (count($item['coupon']['goodsRelate']) == 1) $item['coupon']['is_goods_single'] = 1;
- foreach ($item['coupon']['goodsRelate'] as $goodsRelate) {
- $item['coupon']['goods_ids'] .= $goodsRelate['goods_id'] . ',';
- }
- foreach ($item['coupon']['cateRelate'] as $cateRelate) {
- $item['coupon']['cate_ids'] .= $cateRelate['cate_id'] . ',';
- }
- $item['coupon']['goods_ids'] = trim($item['coupon']['goods_ids'], ',');
- $item['coupon']['cate_ids'] = trim($item['coupon']['cate_ids'], ',');
- unset($item['coupon']['goodsRelate']);
- unset($item['coupon']['cateRelate']);
- if ($params['coupon_status'] == 4) {
- if ($item['is_giving']) {
- $item['give_time'] = $item['updated_at'];
- }
- if (isset($share_logs[$item['id']])) {
- $receive_user_id = $share_logs[$item['id']]['receive_user_id'];
- if (isset($receive_user_list) && isset($receive_user_list[$receive_user_id])) {
- $item['give_name'] = $receive_user_list[$receive_user_id]['nickname'];
- $item['give_mobile'] = $receive_user_list[$receive_user_id]['mobile'];
- }
- }
- }
- $item['is_show_use_btn'] = true;
- // 返回是否显示使用按钮
- if (!empty($item['coupon']['is_giving']) && !empty($item['coupon']['is_giving_use']) && !in_array($item['id'], $giftedIds)) {
- $item['is_show_use_btn'] = false;
- }
- }
- }
- break;
- case 2:
- $params['where'] = $common_where;
- $params['order'] = 'id desc';
- $select = 'id,coupon_id,start_time,end_time,is_use,is_giving,giving_status,store_id,from_type,updated_at, coupon_status';
- $params['select'] = $select;
- $page_list = StoreCouponUserRelate::listPage($params);
- if (!empty($page_list['list'])) {
- $platform_coupon_ids = $store_coupon_ids = [];
- foreach ($page_list['list'] as &$item) {
- switch ($item['from_type']) {
- case 1:
- $platform_coupon_ids[] = $item['coupon_id'];
- break;
- case 2:
- $store_coupon_ids[] = $item['coupon_id'];
- break;
- }
- }
- $platform_coupon_list = AddonsCoupon::lists(['where' => [['id' => $platform_coupon_ids]], 'index' => 'id', 'select' => 'id,name,min_price,sub_price,appoint_type,is_giving,type,discount,is_giving_use', 'with' => ['storeGoodsRelate']]);
- $store_coupon_list = StoreCoupon::lists(['where' => [['id' => $store_coupon_ids]], 'with' => ['goodsRelate', 'cateRelate'], 'index' => 'id', 'select' => 'id,name,min_price,sub_price,appoint_type,is_giving,type,discount,exchange_voucher_type']);
- $store_ids = array_column($page_list['list'], 'store_id');
- $store_list = Store::lists(['where' => [['id' => $store_ids]], 'index' => 'id']);
- if ($params['coupon_status'] == 4) {
- $user_coupon_ids = array_column($page_list['list'], 'id');
- $share_logs = StoreCouponShareLog::lists(['where' => [['user_coupon_id' => $user_coupon_ids]], 'index' => 'user_coupon_id', 'select' => 'user_coupon_id,receive_user_id']);
- $receive_user_ids = array_column($share_logs, 'receive_user_id');
- $receive_user_list = User::lists(['where' => [['id' => $receive_user_ids]], 'index' => 'id', 'select' => 'id,mobile,nickname']);
- }
- foreach ($page_list['list'] as &$item) {
- $item['store_name'] = '';
- $item['logo_img'] = '';
- $item['give_name'] = '';
- $item['give_mobile'] = '';
- $item['use_time'] = $item['updated_at'];
- if (isset($store_list[$item['store_id']])) {
- $item['store_name'] = $store_list[$item['store_id']]['store_name'];
- $item['logo_img'] = $store_list[$item['store_id']]['logo_img'];
- }
- if ($params['coupon_status'] == 4) {
- if ($item['is_giving']) {
- $item['give_time'] = $item['updated_at'];
- }
- if (isset($share_logs[$item['id']])) {
- $receive_user_id = $share_logs[$item['id']]['receive_user_id'];
- if (isset($receive_user_list) && isset($receive_user_list[$receive_user_id])) {
- $item['give_name'] = $receive_user_list[$receive_user_id]['nickname'];
- $item['give_mobile'] = $receive_user_list[$receive_user_id]['mobile'];
- }
- }
- }
- $item['is_show_use_btn'] = true;
- $item['coupon'] = [];
- switch ($item['from_type']) {
- case 1:
- if (isset($platform_coupon_list[$item['coupon_id']])) {
- $item['coupon'] = $platform_coupon_list[$item['coupon_id']];
- $item['coupon']['is_goods_single'] = 0;
- if (count($item['coupon']['storeGoodsRelate']) == 1) $item['coupon']['is_goods_single'] = 1;
- foreach ($item['coupon']['storeGoodsRelate'] as $goodsRelate) {
- $item['coupon']['goods_ids'] .= $goodsRelate['goods_id'] . ',';
- }
- $item['coupon']['goods_ids'] = trim($item['coupon']['goods_ids'], ',');
- unset($item['coupon']['storeGoodsRelate']);
- // 存储平台优惠券,用于查询这个优惠券是否允许显示
- $platformCouponUserRelate[] = &$item;
- }
- !isset($item['coupon']['goods_ids']) && $item['coupon']['goods_ids'] = '';
- $item['coupon']['cate_ids'] = '';
- break;
- case 2:
- if (isset($store_coupon_list[$item['coupon_id']])) {
- $item['coupon'] = $store_coupon_list[$item['coupon_id']];
- }
- foreach ($item['coupon']['goodsRelate'] as $goodsRelate) {
- $item['coupon']['goods_ids'] .= $goodsRelate['goods_id'] . ',';
- }
- foreach ($item['coupon']['cateRelate'] as $cateRelate) {
- $item['coupon']['cate_ids'] .= $cateRelate['cate_id'] . ',';
- }
- $item['coupon']['goods_ids'] = trim($item['coupon']['goods_ids'], ',');
- $item['coupon']['cate_ids'] = trim($item['coupon']['cate_ids'], ',');
- unset($item['coupon']['goodsRelate']);
- unset($item['coupon']['cateRelate']);
- break;
- }
- }
- // 通过转增得到的ids
- if (!empty($platformCouponUserRelate)) {
- $giftedIds = AddonsCoupon::getGiftedList($this->mall_id, $platformCouponUserRelate, 2);
- array_walk($platformCouponUserRelate, function (&$item) use ($giftedIds) {
- // 返回是否显示使用按钮
- if (!empty($item['coupon']['is_giving']) && !empty($item['coupon']['is_giving_use']) && !in_array($item['id'], $giftedIds)) {
- $item['is_show_use_btn'] = false;
- }
- });
- }
- }
- break;
- }
- $settingService = new SettingService(['mall_id' => $this->mall_id]);
- $config = $settingService->getSetting();
- $page_list = array_merge($page_list, $config);
- return $this->success('操作成功', $page_list);
- }
- public function actionDetail()
- {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['from_type', 'coupon_id'], 'required'],
- [['store_id', 'user_coupon_id'], 'safe'],
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $select = 'id,name,min_price,sub_price,appoint_type,rule,expire_type,expire_day,effect_days,begin_at ,end_at';
- switch ($params['from_type']) {
- case 1:
- case 3:
- $coupon = AddonsCoupon::getOne([['id' => $params['coupon_id']], 'mall_id' => $this->mall_id], true, false, $select);
- if (!empty($params['user_coupon_id'])) {
- if (!empty($params['store_id'])) {
- $coupon_user_relate = StoreCouponUserRelate::findOne(['id' => $params['user_coupon_id']]);
- } else {
- $coupon_user_relate = AddonsCouponUserRelate::findOne(['id' => $params['user_coupon_id']]);
- }
- }
- break;
- case 2:
- $coupon = StoreCoupon::getOne([['id' => $params['coupon_id']], 'mall_id' => $this->mall_id], true, false, $select);
- if (!empty($params['user_coupon_id'])) $coupon_user_relate = StoreCouponUserRelate::findOne(['id' => $params['user_coupon_id']]);
- break;
- }
- $coupon['start_time'] = $coupon['begin_at'];
- $coupon['end_time'] = $coupon['end_at'];
- if (!empty($coupon_user_relate)) {
- $coupon['start_time'] = $coupon_user_relate['start_time'];
- $coupon['end_time'] = $coupon_user_relate['end_time'];
- }
- return $this->success('操作成功', $coupon);
- }
- public function actionDetailList()
- {
- $params = \Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['from_type', 'coupon_id'], 'required'],
- [['longitude', 'latitude', 'page', 'limit'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $select = 'id,name,min_price,sub_price,appoint_type,rule,type';
- $coupon = [];
- $goods_page_list = [];
- $store_page_list = [];
- $mch_page_list = [];
- $isInstallStore = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE);
- switch ($params['from_type']) {
- case 1:
- case 3:
- $select .= ',mch_id,store_id';
- $with = ['goodsRelate', 'cateRelate'];
- if ($isInstallStore) {
- $with[] = 'storeGoodsRelate';
- }
- $coupon = AddonsCoupon::getOne([['id' => $params['coupon_id']], 'mall_id' => $this->mall_id], true, $with, false, $select);
- switch ($coupon['appoint_type']) {
- case 1:
- $cate_ids = [];
- foreach ($coupon['cateRelate'] as $cateRelate) {
- $cate_ids[] = $cateRelate['cate_id'];
- }
- $goods_cate_relate_list = GoodsCateRelate::lists(['where' => [['cate_id' => $cate_ids]]]);
- $goods_ids = array_column($goods_cate_relate_list, 'goods_id');
- $params['where'][] = ['id' => $goods_ids, 'status' => StatusEnum::ENABLED, 'is_on_sale' => 1];
- $goods_page_list = Goods::listPage($params);
- break;
- case 2:
- $goods_ids = [];
- foreach ($coupon['goodsRelate'] as $goodsRelate) {
- $goods_ids[] = $goodsRelate['goods_id'];
- }
- $params['where'][] = ['id' => $goods_ids, 'status' => StatusEnum::ENABLED, 'is_on_sale' => 1];
- $params['select'] = 'id,goods_name,cover_pic,price,original_price';
- $goods_page_list = Goods::listPage($params);
- break;
- case 4:
- $store_ids = explode(',', $coupon['store_id']);
- $params['where'][] = ['id' => $store_ids];
- $params['select'] = 'id,store_name,logo_img,longitude,latitude,sales_volume,praise';
- $store_page_list = Store::listPage($params);
- if (!empty($store_page_list['list'])) {
- foreach ($store_page_list['list'] as &$value) {
- $distance = (new LocationHelper())->getDistanceByGeo($params['latitude'], $params['longitude'], $value['latitude'], $value['longitude']);
- $value['distance'] = $distance;
- }
- }
- break;
- case 5:
- $mch_id = explode(',', $coupon['mch_id']);
- $params['where'][] = ['id' => $mch_id];
- $params['select'] = 'id,store_name,logo_img,sales_volume,praise';
- $mch_page_list = Mch::listPage($params);
- break;
- case AddonsCouponEnum::APPOINT_TYPE6:
- if (!$isInstallStore) {
- break;
- }
- $params['where'][] = ['id' => array_column($coupon['storeGoodsRelate'] ?? [], 'goods_id'), 'status' => StatusEnum::ENABLED, 'check_status' => 1, 'is_on_sale' => 1];
- $params['select'] = 'id,store_id,goods_name,cover_pic,price,original_price';
- $goods_page_list = StoreGoods::listPage($params);
- if ($coupon['type'] == AddonsCouponEnum::EXCHANGE) {
- foreach ($goods_page_list['list'] as &$value) {
- $value['price'] = 0;
- }
- }
- break;
- }
- break;
- case 2:
- $select .= ',store_id, exchange_voucher_type';
- $coupon = StoreCoupon::getOne([['id' => $params['coupon_id']], 'mall_id' => $this->mall_id], true, ['goodsRelate', 'cateRelate'], false, $select);
- switch ($coupon['appoint_type']) {
- case 1:
- $cate_ids = [];
- foreach ($coupon['cateRelate'] as $cateRelate) {
- $cate_ids[] = $cateRelate['cate_id'];
- }
- $goods_cate_relate_list = StoreGoodsCateRelate::lists(['where' => [['cate_id' => $cate_ids]]]);
- $goods_ids = array_column($goods_cate_relate_list, 'goods_id');
- $params['where'][] = ['id' => $goods_ids, 'status' => StatusEnum::ENABLED, 'check_status' => 1, 'is_on_sale' => 1];
- $params['select'] = 'id,store_id,goods_name,cover_pic,price,original_price';
- $goods_page_list = StoreGoods::listPage($params);
- break;
- case 2:
- $goods_ids = [];
- foreach ($coupon['goodsRelate'] as $goodsRelate) {
- $goods_ids[] = $goodsRelate['goods_id'];
- }
- $params['where'][] = ['id' => $goods_ids, 'status' => StatusEnum::ENABLED, 'check_status' => 1, 'is_on_sale' => 1];
- $params['select'] = 'id,store_id,goods_name,cover_pic,price,original_price';
- $goods_page_list = StoreGoods::listPage($params);
- if ($coupon['type'] == StoreEnum::EXCHANGE) {
- $goods_attr_relates = StoreGoodsAttr::find()->where(['goods_id' => $goods_ids, 'status' => StatusEnum::ENABLED])->select('goods_id, id')->indexBy('goods_id')->asArray()->all();
- foreach ($goods_page_list['list'] as &$value) {
- if ($coupon['exchange_voucher_type'] == StoreEnum::ALL_DEDUCTION) {
- $value['price'] = 0;
- } else {
- $value['price'] = bcsub($value['price'], $coupon['sub_price'], 2);
- if ($value['price'] < 0) {
- $value['price'] = 0;
- }
- }
- $value['attr_id'] = $goods_attr_relates[$value['id']]['id'] ?? 0;
- }
- }
- break;
- case 3:
- $params['where'][] = ['id' => $coupon['store_id']];
- $params['select'] = 'id,store_name,logo_img,longitude,latitude,sales_volume,praise';
- $store_page_list = Store::listPage($params);
- if (!empty($store_page_list['list'])) {
- foreach ($store_page_list['list'] as &$value) {
- $distance = (new LocationHelper())->getDistanceByGeo($params['latitude'], $params['longitude'], $value['latitude'], $value['longitude']);
- $value['distance'] = bcdiv($distance, 1000, 1);
- }
- }
- break;
- }
- break;
- }
- unset($coupon['goodsRelate']);
- unset($coupon['cateRelate']);
- unset($coupon['storeGoodsRelate']);
- return $this->success('操作成功', ['coupon' => $coupon, 'goods_page_list' => $goods_page_list, 'store_page_list' => $store_page_list, 'mch_page_list' => $mch_page_list]);
- }
- public function actionCenter()
- {
- $params = \Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['from_type',], 'required'],
- [['page', 'limit', 'appoint_type'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ['is_public_receive' => StatusEnum::ENABLED],
- ['coupon_status' => AddonsCouponEnum::STATUS_RECEIVING],
- ];
- $params['order'] = 'id desc';
- switch ($params['from_type']) {
- case 1:
- $where[] = ['mch_id' => ''];
- $class = AddonsCoupon::class;
- break;
- case 2:
- $class = StoreCoupon::class;
- break;
- case 3:
- $where[] = ['<>', 'mch_id', ''];
- $class = AddonsCoupon::class;
- break;
- }
- $params['where'] = $where;
- $list = $class::listPage($params, false, true);
- return $this->success('操作成功', $list);
- }
- /**
- * @return mixed|void|null
- */
- public function actionJumpCheck()
- {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['user_coupon_id', 'goods_id', 'from_type'], 'required'],
- [['user_coupon_id', 'goods_id', 'from_type'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['from_type'] = $params['from_type'] == 2 ? 2 : 1;
- if (!AddonsCoupon::jumpCheck($this->getCommonWhere(2), $this->mall_id, $this->user_id, $params)) {
- $this->error(AddonsCoupon::getStaticError());
- return;
- }
- $this->success();
- }
- }
|