123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\admin\controller;
- use app\admin\logic\GoodLogic;
- use app\admin\validate\GoodValidate;
- use app\BaseController;
- use think\exception\ValidateException;
- use think\facade\Config;
- use think\facade\Validate;
- //商品
- class Good extends BaseController
- {
- //获取商品列表
- public function list()
- {
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 10,
- 'good_code' => '',
- 'good_name' => '',
- 'status' => '',
- 'type' => ''
- ], 'post');
- return GoodLogic::list($param);
- }
- //添加商品
- public function add()
- {
- $param = $this->request->only([
- 'good_cover_img',
- 'good_name',
- 'moq',
- 'step',
- 'good_banner_img',
- 'good_img',
- 'good_param',
- 'unit_id',
- 'type',
- 'price' => 0,
- 'good_remark' => '',
- ], 'post');
- validate(GoodValidate::class)->scene('add')->check($param);
- return GoodLogic::add($param);
- }
- //读取商品详情
- public function read()
- {
- $id = $this->request->post('id/d', 0);
- validate(GoodValidate::class)->scene('read')->check(['id' => $id]);
- return GoodLogic::read($id);
- }
- //编辑商品
- public function edit()
- {
- $param = $this->request->only([
- 'id',
- 'good_cover_img',
- 'good_name',
- 'moq',
- 'step',
- 'price',
- 'good_banner_img',
- 'good_img',
- 'good_param',
- 'unit_id',
- 'good_remark',
- ], 'post');
- validate(GoodValidate::class)->scene('edit')->check($param);
- return GoodLogic::edit($param);
- }
- //商品启禁用
- public function status()
- {
- $param = $this->request->only(['id', 'status',], 'post');
- $val = Validate::rule(Config::get('validate_rules.status'));
- if (!$val->check($param)) throw new ValidateException($val->getError());
- return GoodLogic::status($param);
- }
- //删除商品
- public function delete()
- {
- $id = $this->request->post('id/d', 0);
- return GoodLogic::delete($id);
- }
- }
|