| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <?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\bargain;
- use app\controller\admin\AuthController;
- use app\services\activity\bargain\StoreBargainServices;
- use app\services\activity\bargain\StoreBargainUserHelpServices;
- use app\services\activity\bargain\StoreBargainUserServices;
- use think\facade\App;
- /**
- * 砍价管理
- * Class StoreBargain
- * @package app\controller\admin\v1\marketing
- */
- class StoreBargain extends AuthController
- {
- /**
- * StoreBargain constructor.
- * @param App $app
- * @param StoreBargainServices $services
- */
- public function __construct(App $app, StoreBargainServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = $this->request->getMore([
- ['start_status', ''],
- ['status', ''],
- ['store_name', ''],
- ]);
- $where['is_del'] = 0;
- $list = $this->services->getStoreBargainList($where);
- return $this->success($list);
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save($id)
- {
- $data = $this->request->postMore([
- ['title', ''],
- ['info', ''],
- ['unit_name', ''],
- ['section_time', []],
- ['images', []],
- ['bargain_max_price', 0],
- ['bargain_min_price', 0],
- ['sort', 0],
- ['give_integral', 0],
- ['is_hot', 0],
- ['status', 0],
- ['product_id', 0],
- ['description', ''],
- ['attrs', []],
- ['items', []],
- ['temp_id', 0],
- ['rule', ''],
- ['num', 1],
- ['copy', 0],
- ['bargain_num', 1],
- ['people_num', 1],
- ['is_support_refund', 1],//是否支持退款
- ['delivery_type', []],//物流方式
- ['freight', 1],//运费设置
- ['postage', 0],//邮费
- ['custom_form', ''],//自定义表单
- ['system_form_id', 0],//系统表单ID
- ['product_type', 0],//商品类型
- ['applicable_type', 1],//适用门店类型
- ['applicable_store_id', []],//适用门店IDS
- ]);
- $this->validate($data, \app\validate\admin\marketing\StoreBargainValidate::class, 'save');
- if ($data['section_time']) {
- [$start_time, $end_time] = $data['section_time'];
- if (strtotime($end_time) < time()) {
- return $this->fail('活动结束时间不能小于当前时间');
- }
- }
- $bragain = [];
- if ($id) {
- $bragain = $this->services->get((int)$id);
- if (!$bragain) {
- return $this->fail('数据不存在');
- }
- }
- //限制编辑
- if ($data['copy'] == 0 && $bragain) {
- if ($bragain['stop_time'] < time()) {
- return $this->fail('活动已结束,请重新添加或复制');
- }
- }
- if ($data['copy'] == 1) {
- $id = 0;
- unset($data['copy']);
- }
- $this->services->saveData($id, $data);
- return $this->success('保存成功');
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- $info = $this->services->getInfo($id);
- return $this->success(compact('info'));
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- $this->services->update($id, ['is_del' => 1]);
- $this->services->cacheTag()->clear();
- return $this->success('删除成功!');
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return mixed
- */
- public function set_status($id, $status)
- {
- $this->services->update($id, ['status' => $status]);
- $this->services->cacheTag()->clear();
- return $this->success($status == 0 ? '关闭成功' : '开启成功');
- }
- /**
- * 砍价列表
- * @return mixed
- */
- public function bargainList()
- {
- $where = $this->request->getMore([
- ['status', ''],
- ['data', '', '', 'time'],
- ]);
- /** @var StoreBargainUserServices $bargainUserService */
- $bargainUserService = app()->make(StoreBargainUserServices::class);
- $list = $bargainUserService->bargainUserList($where);
- return $this->success($list);
- }
- /**
- * 砍价信息
- * @param $id
- * @return mixed
- */
- public function bargainListInfo($id)
- {
- /** @var StoreBargainUserHelpServices $bargainUserHelpService */
- $bargainUserHelpService = app()->make(StoreBargainUserHelpServices::class);
- $list = $bargainUserHelpService->getHelpList($id);
- return $this->success(compact('list'));
- }
- /**
- * 砍价统计
- * @param $id
- * @return mixed
- */
- public function bargainStatistics($id)
- {
- $data = $this->services->bargainStatistics((int)$id);
- return app('json')->success($data);
- }
- /**
- * 砍价统计列表
- * @param $id
- * @return mixed
- */
- public function bargainStatisticsList($id)
- {
- $where = $this->request->getMore([
- ['real_name', ''],
- ]);
- $data = $this->services->bargainStatisticsList((int)$id, $where);
- return app('json')->success($data);
- }
- /**
- * 砍价统计订单
- * @param $id
- * @return mixed
- */
- public function bargainStatisticsOrder($id)
- {
- $where = $this->request->getMore([
- ['real_name', ''],
- ['status', '']
- ]);
- return app('json')->success($this->services->bargainStatisticsOrder((int)$id, $where));
- }
- }
|