123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\admin\v1\marketing\promotions;
- use app\controller\admin\AuthController;
- use app\services\activity\promotions\StorePromotionsServices;
- use think\facade\App;
- /**
- * 促销活动
- * Class StorePromotions
- * @package app\controller\admin\v1\marketing\promotions
- */
- class StorePromotions extends AuthController
- {
- /**
- * StorePromotions constructor.
- * @param App $app
- * @param StorePromotionsServices $services
- */
- public function __construct(App $app, StorePromotionsServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index($type)
- {
- $where = $this->request->getMore([
- [['status', 's'], ''],
- ['threshold_type', ''],
- ['n_piece_n_discount', ''],
- [['name', 's'], '']
- ]);
- $where['promotions_type'] = $type;
- $where['type'] = 1;
- $where['store_id'] = 0;
- $where['pid'] = 0;
- $where['is_del'] = 0;
- return $this->success($this->services->systemPage($where));
- }
- /**
- * 详情
- * @param $id
- * @return mixed
- */
- public function getInfo($id)
- {
- $info = $this->services->getInfo($id);
- return $this->success(compact('info'));
- }
- /**
- * 保存折扣促销活动
- * @param $type
- * @param $id
- * @return mixed
- */
- public function saveDiscount($type, $id)
- {
- $data = $this->request->postMore([
- [['promotions_cate', 'd'], 1],//优惠类型
- [['name', 's'], ''],//名称
- [['threshold_type', 'd'], 1],//门槛类型1:满N元2:满N件
- ['threshold', 0],//优惠门槛
- [['discount_type', 'd'], 1],//优惠类型1:满减2:满折
- [['n_piece_n_discount', 'd'], 3],//n件n折类型:1:第二件半件2:买1送1 3:自定义
- ['discount', 0],//优惠
- [['give_integral', 'd'], 0],//赠送积分
- ['give_coupon_id', []],//赠送优惠券ID
- ['give_product_id', []],//赠送商品ID
- ['give_product_unique', []],//赠送商品规格唯一值
- [['is_label', 'd'], 0],
- ['label_id', []],//关联标签
- [['product_partake_type', 'd'], 1],//商品参与类型
- ['product_id', []],//关联商品
- ['brand_id', []],//关联品牌ID
- ['store_label_id', []],//关联商品标签ID
- [['is_limit', 'd'], 0],//是否限量
- [['limit_num', 'd'], 0],//限量个数
- [['is_overlay', 'd'], 0],
- ['overlay', []],//叠加方式方式
- ['section_time', []],//时间
- [['sort', 'd'], 0],//排序
- ['applicable_type', 1],//适用门店类型
- ['applicable_store_id', []],//适用门店IDS
- ]);
- $data['promotions_type'] = $type;
- if ($data['promotions_type'] == 2) {
- $data['threshold_type'] = 2;
- }
- if (!$data['is_label']) {
- $data['label_id'] = [];
- }
- if (!$data['is_overlay']) {
- $data['overlay'] = [];
- }
- unset($data['is_label'], $data['is_overlay']);
- $data['promotions'][] = [
- 'threshold_type' => $data['threshold_type'],
- 'threshold' => $data['threshold'],
- 'discount_type' => $data['discount_type'],
- 'n_piece_n_discount' => $data['n_piece_n_discount'],
- 'discount' => $data['discount'],
- 'give_integral' => $data['give_integral'],
- 'give_coupon_id' => [],
- 'give_product_id' => [],
- 'give_product_unique' => [],
- ];
- if ($data['product_partake_type'] == 2 && !$data['product_id']) {
- return $this->fail('请选择要参与活动的商品');
- }
- if ($data['product_partake_type'] == 4 && !$data['brand_id']) {
- return $this->fail('请选择要参与活动的商品品牌');
- }
- if ($data['product_partake_type'] == 5 && !$data['store_label_id']) {
- return $this->fail('请选择要参与活动的商品标签');
- }
- if ($data['applicable_type'] == 1) {
- $data['applicable_store_id'] = [];
- } elseif ($data['applicable_type'] == 2) {
- if (!$data['applicable_store_id']) {
- return $this->fail('请选择要适用门店');
- }
- }
- $this->services->saveData((int)$id, $data);
- return $this->success('保存成功');
- }
- /**
- * 保存促销活动
- * @param $type
- * @param $id
- * @return mixed
- */
- public function save($type, $id)
- {
- $data = $this->request->postMore([
- [['promotions_cate', 'd'], 1],//优惠类型
- [['threshold_type', 'd'], 1],//门槛类型1:满N元2:满N件
- [['name', 's'], ''],//名称
- [['is_label', 'd'], 0],
- ['label_id', []],//关联标签
- [['product_partake_type', 'd'], 1],//商品参与类型
- ['product_id', []],//关联商品ID
- ['brand_id', []],//关联品牌ID
- ['store_label_id', []],//关联商品标签ID
- [['is_limit', 'd'], 0],//是否限量
- [['limit_num', 'd'], 0],//限量个数
- [['is_overlay', 'd'], 0],
- ['overlay', []],//叠加方式方式
- ['section_time', []],//时间
- [['sort', 'd'], 0],//排序
- ['promotions', []],//阶梯优惠数组
- ['applicable_type', 1],//适用门店类型
- ['applicable_store_id', []],//适用门店IDS
- ]);
- $data['promotions_type'] = $type;
- if (!$data['is_label']) {
- $data['label_id'] = [];
- }
- if (!$data['is_overlay']) {
- $data['overlay'] = [];
- }
- if ($data['product_partake_type'] == 2 && !$data['product_id']) {
- return $this->fail('请选择要参与活动的商品');
- }
- if ($data['product_partake_type'] == 4 && !$data['brand_id']) {
- return $this->fail('请选择要参与活动的商品品牌');
- }
- if ($data['product_partake_type'] == 5 && !$data['store_label_id']) {
- return $this->fail('请选择要参与活动的商品标签');
- }
- if ($data['applicable_type'] == 1) {
- $data['applicable_store_id'] = [];
- } elseif ($data['applicable_type'] == 2) {
- if (!$data['applicable_store_id']) {
- return $this->fail('请选择要适用门店');
- }
- }
- unset($data['is_label'], $data['is_overlay']);
- $this->services->saveData((int)$id, $data);
- return $this->success('保存成功');
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- if (!$id) return $this->fail('缺少参数');
- $this->services->update(['id|pid' => $id], ['is_del' => 1]);
- return $this->success('删除成功!');
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return mixed
- */
- public function setStatus($id, $status)
- {
- $this->services->update($id, ['status' => $status, 'update_time' => time()]);
- return $this->success($status == 0 ? '关闭成功' : '开启成功');
- }
- }
|