| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\admin\points;
- use app\common\repositories\store\product\ProductRepository;
- use app\validate\merchant\StoreProductValidate;
- use think\App;
- use crmeb\basic\BaseController;
- use app\validate\merchant\StoreProductAdminValidate as validate;
- use app\common\repositories\store\pionts\PointsProductRepository;
- /**
- * 积分商品
- */
- class Product extends BaseController
- {
- /**
- * @var PointsProductRepository
- */
- protected $repository;
- /**
- * StoreProduct constructor.
- * @param App $app
- * @param PointsProductRepository $repository
- */
- public function __construct(App $app, PointsProductRepository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- }
- /**
- * 列表
- * @Author:Qinii
- * @Date: 2020/5/18
- * @return mixed
- */
- public function lst()
- {
- [$page, $limit] = $this->getPage();
- $where = $this->request->params(['cate_id', 'keyword', 'is_used', 'date', 'store_name']);
- return app('json')->success($this->repository->getAdminList(0, $where, $page, $limit));
- }
- /**
- * 添加
- * @return \think\response\Json
- * @author Qinii
- */
- public function create()
- {
- $data = $this->checkParams();
- $this->repository->create($data, $this->repository::PRODUCT_TYPE_POINTS);
- return app('json')->success('添加成功');
- }
- /**
- * 头部筛选 统计
- * @Author:Qinii
- * @Date: 2020/5/18
- * @return mixed
- */
- public function getStatusFilter()
- {
- return app('json')->success($this->repository->getFilter(null, '商品', 0));
- }
- /**
- * 详情
- * @Author:Qinii
- * @Date: 2020/5/18
- * @param $id
- * @return mixed
- */
- public function detail($id)
- {
- return app('json')->success($this->repository->detail($id));
- }
- /**
- * 编辑
- * @Author:Qinii
- * @Date: 2020/5/11
- * @param $id
- * @param validate $validate
- * @return mixed
- */
- public function update($id)
- {
- $data = $this->checkParams();
- $this->repository->edit($id, $data, $this->request->merId(), $this->repository::PRODUCT_TYPE_POINTS);
- return app('json')->success('编辑成功');
- }
- /**
- * 上 / 下架
- * @Author:Qinii
- * @Date: 2020/5/18
- * @param int $id
- * @return mixed
- */
- public function switchStatus($id)
- {
- if (!$this->repository->merExists(null, $id))
- return app('json')->fail('数据不存在');
- $status = $this->request->param('status', 0) == 1 ? 1 : 0;
- $this->repository->switchShow($id, $status, 'is_used');
- return app('json')->success('修改成功');
- }
- /**
- * 删除
- * @Author:Qinii
- * @Date: 2020/5/18
- * @param $id
- * @return mixed
- */
- public function delete($id)
- {
- if (!$this->repository->merExists($this->request->merId(), $id))
- return app('json')->fail('数据不存在');
- $this->repository->destory($id);
- return app('json')->success('删除成功');
- }
- /**
- * 验证数据
- * @Author:Qinii
- * @Date: 2020/5/11
- * @param validate $validate
- * @return array
- */
- public function checkParams()
- {
- $data = $this->request->params($this->repository::CREATE_PARAMS);
- $data['mer_status'] = 1;
- $data['delivery_way'] = [2];
- $data['delivery_free'] = 1;
- $data['is_used'] = $this->request->param('is_used', 0);
- $data['is_hot'] = $this->request->param('is_hot', 0);
- $data['is_show'] = 1;
- $data['status'] = 1;
- $data['pay_limit'] = 2;
- $data['product_type'] = $this->repository::PRODUCT_TYPE_POINTS;
- app()->make(StoreProductValidate::class)->check($data);
- return $data;
- }
- /**
- * 设置排序
- * @param $id
- * @return \think\response\Json
- * @author Qinii
- * @day 3/17/21
- */
- public function updateSort($id)
- {
- $sort = $this->request->param('sort');
- $this->repository->updateSort($id, null, ['rank' => $sort]);
- return app('json')->success('修改成功');
- }
- /**
- * 批量显示隐藏
- * @return \think\response\Json
- * @author Qinii
- * @day 2022/11/14
- */
- public function batchShow()
- {
- $ids = $this->request->param('ids');
- $status = $this->request->param('status') == 1 ? 1 : 0;
- $this->repository->batchSwitchShow($ids, $status, 'is_used', 0);
- return app('json')->success('修改成功');
- }
- /**
- * 获取商品的规格
- * @param $id
- * @return mixed
- * @author Qinii
- */
- public function isFormatAttr($id)
- {
- $data = $this->request->params([
- ['attrs', []],
- ['items', []],
- ['product_type', 0]
- ]);
- $data = app()->make(ProductRepository::class)->isFormatAttr($data['attrs'], $id);
- return app('json')->success($data);
- }
- /**
- * 预览
- * @return \think\response\Json
- * @author Qinii
- */
- public function preview()
- {
- $data = $this->request->param();
- return app('json')->success($this->repository->preview($data));
- }
- }
|