123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\controller\admin\v1\marketing\lottery;
- use app\controller\admin\AuthController;
- use app\services\activity\lottery\LuckLotteryServices;
- use think\facade\App;
- /**
- * 抽奖活动
- * Class LuckLottery
- * @package app\controller\admin\v1\marketing\lottery
- */
- class LuckLottery extends AuthController
- {
- /**
- * LuckLottery constructor.
- * @param App $app
- * @param LuckLotteryServices $services
- */
- public function __construct(App $app, LuckLotteryServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 列表
- * @return mixed
- */
- public function index()
- {
- $where = $this->request->postMore([
- ['start_status', '', '', 'start'],
- ['status', ''],
- ['factor', ''],
- ['store_name', '', '', 'keyword'],
- ]);
- return $this->success($this->services->getList($where));
- }
- /**
- * id查询详情
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function detail($id)
- {
- if (!$id) {
- return $this->fail('缺少参数id');
- }
- return $this->success($this->services->getlotteryInfo((int)$id));
- }
- /**
- * 活动类型查询详情
- * @param $factor
- * @return mixed
- */
- public function factorInfo($factor)
- {
- if (!$factor) {
- return app('json')->fail('缺少参数');
- }
- return app('json')->success($this->services->getlotteryFactorInfo((int)$factor));
- }
- /**
- * 添加
- * @return mixed
- */
- public function add()
- {
- $data = $this->request->postMore([
- ['name', ''],
- ['desc', ''],
- ['image', ''],
- ['factor', 1],
- ['factor_num', 1],
- ['attends_user', 1],
- ['user_level', []],
- ['user_label', []],
- ['is_svip', 0],
- ['period', [0, 0]],
- ['lottery_num_term', 1],
- ['lottery_num', 1],
- ['total_lottery_num', 1],
- ['spread_num', 1],
- ['is_all_record', 1],
- ['is_personal_record', 1],
- ['is_content', 1],
- ['content', ''],
- ['status', 1],
- ['prize', []]
- ]);
- if (!$data['name']) {
- return $this->fail('请添加抽奖活动名称');
- }
- if ($data['is_content'] && !$data['content']) {
- return $this->fail('请添加抽奖描述等文案');
- }
- [$start, $end] = $data['period'];
- unset($data['period']);
- $data['start_time'] = $start ? strtotime($start) : 0;
- $data['end_time'] = $end ? strtotime($end) : 0;
- if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
- return $this->fail('活动结束时间必须大于开始时间');
- }
- if (!$data['prize']) {
- return $this->fail('请添加奖品');
- }
- if (in_array($data['factor'], [1, 2]) && !$data['factor_num']) {
- return $this->fail('请填写消耗' . ($data['factor'] == '1' ? '积分' : '余额') . '数量');
- }
- if ($data['factor'] == 1 && $data['lottery_num'] > $data['total_lottery_num']) {
- return $this->fail('积分抽奖时每天抽奖次数不能大于总次数');
- }
- $this->services->add($data);
- return $this->success( '保存成功');
- }
- /**
- * 修改
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit($id)
- {
- $data = $this->request->postMore([
- ['name', ''],
- ['desc', ''],
- ['image', ''],
- ['factor', 1],
- ['factor_num', 1],
- ['attends_user', 1],
- ['user_level', []],
- ['user_label', []],
- ['is_svip', 0],
- ['period', [0, 0]],
- ['lottery_num_term', 1],
- ['lottery_num', 1],
- ['total_lottery_num', 1],
- ['spread_num', 1],
- ['is_all_record', 1],
- ['is_personal_record', 1],
- ['is_content', 1],
- ['content', ''],
- ['status', 1],
- ['prize', []]
- ]);
- if (!$id) {
- return $this->fail('缺少参数id');
- }
- if (!$data['name']) {
- return $this->fail('请添加抽奖活动名称');
- }
- [$start, $end] = $data['period'];
- unset($data['period']);
- $data['start_time'] = $start ? strtotime($start) : 0;
- $data['end_time'] = $end ? strtotime($end) : 0;
- if ($data['start_time'] && $data['end_time'] && $data['end_time'] <= $data['start_time']) {
- return $this->fail('活动结束时间必须大于开始时间');
- }
- if ($data['is_content'] && !$data['content']) {
- return $this->fail('请添加抽奖描述等文案');
- }
- if (!$data['prize']) {
- return $this->fail('请添加奖品');
- }
- if (in_array($data['factor'], [1, 2]) && !$data['factor_num']) {
- return $this->fail('请填写消耗' . ($data['factor'] == '1' ? '积分' : '余额') . '数量');
- }
- if ($data['factor'] == 1 && $data['lottery_num'] > $data['total_lottery_num']) {
- return $this->fail('积分抽奖时每天抽奖次数不能大于总次数');
- }
- $this->services->edit((int)$id, $data);
- return $this->success('保存成功');
- }
- /**
- * 删除
- * @param $id
- * @throws \Exception
- */
- public function delete()
- {
- [$id] = $this->request->getMore([
- ['id', 0],
- ], true);
- if (!$id) return $this->fail('数据不存在');
- $this->services->delLottery((int)$id);
- return $this->success('刪除成功!');
- }
- /**
- * 设置活动状态
- * @return json
- */
- public function setStatus($id = '', $status = '')
- {
- if ($status == '' || $id == '') return $this->fail('缺少参数');
- return $this->success($this->services->setStatus((int)$id, (int)$status) ? '上架成功' : '下架成功');
- }
- }
|