123 lines
3.5 KiB
PHP
123 lines
3.5 KiB
PHP
<?php
|
|
|
|
|
|
|
|
namespace app\controller\admin\store;
|
|
|
|
use app\common\repositories\store\product\ProductPresellRepository as repository;
|
|
use app\common\repositories\store\product\SpuRepository;
|
|
use crmeb\basic\BaseController;
|
|
use think\App;
|
|
use app\validate\merchant\StoreProductAdminValidate as validate;
|
|
|
|
class StoreProductPresell extends BaseController
|
|
{
|
|
protected $repository ;
|
|
|
|
/**
|
|
* Product constructor.
|
|
* @param App $app
|
|
* @param repository $repository
|
|
*/
|
|
public function __construct(App $app ,repository $repository)
|
|
{
|
|
parent::__construct($app);
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
/**
|
|
* TODO 列表
|
|
* @return mixed
|
|
* @author Qinii
|
|
* @day 2020-10-12
|
|
*/
|
|
public function lst()
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$where = $this->request->params(['product_status','keyword','status','type','presell_type','mer_id','is_trader','us_status','star','product_presell_id','sys_labels']);
|
|
$data = $this->repository->getAdminList($where,$page,$limit);
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
/**
|
|
* TODO 详情
|
|
* @param $id
|
|
* @return mixed
|
|
* @author Qinii
|
|
* @day 2020-10-12
|
|
*/
|
|
public function detail($id)
|
|
{
|
|
$data = $this->repository->detail(null,$id);
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
/**
|
|
* TODO 获取商品
|
|
* @param $id
|
|
* @return mixed
|
|
* @author Qinii
|
|
* @day 2020-11-02
|
|
*/
|
|
public function get($id)
|
|
{
|
|
$data = $this->repository->get($id);
|
|
if(!$data) return app('json')->fail('数据不存在');
|
|
return app('json')->success($data);
|
|
}
|
|
|
|
/**
|
|
* TODO 编辑商品
|
|
* @param $id
|
|
* @param validate $validate
|
|
* @return mixed
|
|
* @author Qinii
|
|
* @day 2020-11-02
|
|
*/
|
|
public function update($id,validate $validate)
|
|
{
|
|
$data = $this->checkParams($validate);
|
|
if(!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
|
|
return app('json')->fail('数据不存在');
|
|
$this->repository->updateProduct($id,$data);
|
|
return app('json')->success('编辑成功');
|
|
|
|
}
|
|
public function switchStatus($id)
|
|
{
|
|
$status = $this->request->param('status', 0) == 1 ? 1 : 0;
|
|
if(!$ret = $this->repository->get($id)) return app('json')->fail('数据不存在');
|
|
$this->repository->update($id, ['status' => $status]);
|
|
app()->make(SpuRepository::class)->changeStatus($id,2);
|
|
return app('json')->success('修改成功');
|
|
}
|
|
|
|
|
|
public function checkParams(validate $validate)
|
|
{
|
|
$data = $this->request->params(['is_hot','is_best','is_benefit','is_new','store_name','keyword','content','rank','star']);
|
|
$validate->check($data);
|
|
return $data;
|
|
}
|
|
|
|
public function switchAudit()
|
|
{
|
|
$id = $this->request->param('id');
|
|
$data = $this->request->params(['status','refusal']);
|
|
if($data['status'] == -1 && empty($data['refusal']))
|
|
return app('json')->fail('请填写拒绝理由');
|
|
$this->repository->switchStatus($id, $data);
|
|
return app('json')->success('操作成功');
|
|
}
|
|
|
|
public function setLabels($id)
|
|
{
|
|
$data = $this->request->params(['sys_labels']);
|
|
// if (empty($data['sys_labels'])) return app('json')->fail('标签为空');
|
|
|
|
app()->make(SpuRepository::class)->setLabels($id,2,$data,0);
|
|
return app('json')->success('修改成功');
|
|
}
|
|
|
|
}
|