123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wugg
- * @DateTime : 2024-06-28 16:01
- * @Description : 品牌授权
- * @Version : 1.0
- */
- namespace app\admin\controller;
- use app\admin\model\BrandBook;
- use think\App;
- use think\facade\Validate;
- class BrandAuth extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new \app\admin\model\BrandBook();
- }
- /**
- * 添加品牌授权
- * @param \think\Request $request
- * @return \think\Response|\think\response\Json|void
- */
- public function create(){
- $param = $this->request->param([
- 'brand_book',
- 'gyscode',
- 'brand_id',
- 'is_del'=>0,
- 'remark',
- 'long',
- 'status'=>0,
- 'starttime'=>"",
- 'endtime'=>''],'post','trim');
- $valid= Validate::rule([
- 'brand_book|授权书图片'=>'max:255',
- 'gyscode|供应商编号'=>'require|max:255',
- 'brand_id|品牌id'=>'require|number|gt:0|unique:app\admin\model\BrandBook,brand_id^gyscode^is_del',
- 'long|授权类型'=>'require|number|in:0,1',
- 'status|状态'=>'require|number|in:0,1',
- 'starttime|开始日期'=>'require|date|dateFormat:Y-m-d H:i:s',
- 'endtime|结束日期'=>'requireIf:long,1|date|dateFormat:Y-m-d H:i:s',
- ]);
- if($valid->check($param)==false) return error($valid->getError());
- $data=[
- "brand_book"=>$param['brand_book'],
- "gyscode"=>$param['gyscode'],
- "gysname"=>\app\user\model\Supplier::where('code',$param['gyscode'])->value('name'),
- "brand_id"=>$param['brand_id'],
- "remark"=>$param['remark'],
- "long"=>$param['long'],
- "status"=>$param['status'],
- "starttime"=>$param['starttime'],
- "endtime"=>$param['long']==0?"":$param['endtime'],
- "createrid"=>$this->uid,
- "creater"=>$this->uname,
- ];
- $create=$this->model->create($data);
- if($create==false)return error('添加失败');
- return success("添加成功");
- }
- /**
- * 品牌授权列表
- * @param $param page size gyscode name
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function list(){
- $param = $this->request->param([
- 'page'=>1,
- 'size'=>10,
- 'gyscode'=>'',
- 'name'=>'',
- ],'post','trim');
- $where=[['is_del','=',0]];
- if($param['gyscode']!=''){
- $where[]=['gyscode','like','%'.$param['gyscode'].'%'];
- }
- if($param['name']!=''){
- $where[]=['name','like','%'.$param['name'].'%'];
- }
- $list= $this->model->with(["brandInfo"])->where($where)->paginate(["list_rows"=>$param['size'],
- "page"=>$param['page']]);
- return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
- }
- /**
- * 品牌授权详情
- * @param $param id
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function info(){
- $id = $this->request->post('id/d');
- $info=$this->model->with(["brandInfo"])->findOrEmpty($id);
- if($info->isEmpty()){
- return error('未找到对应数据');
- }
- return success('获取成功',$info);
- }
- /**
- * 品牌授权状态
- * @param $param id 主键id status 状态
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function status(){
- $param = $this->request->param([
- 'id',
- 'status',
- ],'post','intval');
- $valid= Validate::rule([
- 'id|主键id'=>'require|number|gt:0',
- 'status|状态'=>'require|number|in:0,1',
- ]);
- if($valid->check($param)==false) return error($valid->getError());
- $info=$this->model->findOrEmpty($param['id']);
- if($info->isEmpty()){
- return error('未找到对应数据');
- }
- $info->status=$param['status'];
- $save=$info->save();
- if($save==false)return error(BrandBook::$statusCn[$param['status']].'失败');
- return success(BrandBook::$statusCn[$param['status']].'成功');
- }
- /**
- * 品牌授权删除
- * @param $param id
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function delete(){
- $id=$this->request->post('id/d');
- $info = $this->model->findOrEmpty($id);
- if($info->isEmpty()){
- return error('未找到对应数据');
- }
- $info->is_del=1;
- $save=$info->save();
- if($save==false)return error('删除失败');
- return success('删除成功');
- }
- /**
- * 品牌授权编辑
- * @param id 主键id
- * @param brand_book 授权书图片
- * @param gyscode 供应商编号
- * @param brand_id 品牌id
- * @param is_del 删除状态
- * @param remark 备注
- * @param long 授权类型
- * @param status 状态
- * @param starttime 开始日期
- * @param endtime 结束日期
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit(){
- $param = $this->request->param([
- 'id',
- 'brand_book',
- 'gyscode',
- 'brand_id',
- 'is_del'=>0,
- 'remark',
- 'long',
- 'status',
- 'starttime'=>date('Y-m-d H:i:s'),
- 'endtime'=>''],'post','trim');
- $valid= Validate::rule([
- 'id|主键id'=>'require|number|gt:0',
- 'brand_book|授权书图片'=>'url',
- 'gyscode|供应商编号'=>'require|max:255',
- 'brand_id|品牌id'=>'require|number|gt:0|unique:app\admin\model\BrandBook,brand_id^gyscode^is_del',
- 'long|授权类型'=>'require|number|in:0,1',
- 'status|状态'=>'require|number|in:0,1',
- 'starttime|开始日期'=>'require|date|dateFormat:Y-m-d H:i:s',
- 'endtime|结束日期'=>'requireIf:long,1|date|dateFormat:Y-m-d H:i:s',
- ]);
- if($valid->check($param)==false) return error($valid->getError());
- $info=$this->model->findOrEmpty($param['id']);
- if($info->isEmpty()){
- return error('未找到对应数据');
- }
- $info->brand_book=$param['brand_book'];
- $info->gyscode=$param['gyscode'];
- $info->gysname=\app\user\model\Supplier::where('code',$param['gyscode'])->value('name');
- $info->brand_id=$param['brand_id'];
- $info->remark=$param['remark'];
- $info->long=$param['long'];
- $info->status=$param['status'];
- $info->starttime=$param['starttime'];
- $info->endtime=$param['long']==0?'':$param['endtime'];
- $save=$info->save();
- if($save==false)return error('修改失败');
- return success('修改成功');
- }
- /**
- * 品牌授权查询
- * @param brand_id 品牌id
- * @param gyscode 供应商编号
- * @param is_del 删除状态
- * @return \think\Response|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function query(){
- $param =$this->request->param(['brand_id'=>'','gyscode'=>'','is_del'=>0],'post','trim');
- $valid = Validate::rule(['brand_id|品牌id'=>'require|number|gt:0','gyscode|供应商编号'=>'require']);
- if($valid->check($param)==false) return error($valid->getError());
- $where=[["is_del","=",0]];
- if($param['brand_id']!=''){
- $where[]=["brand_id","=",$param['brand_id']];
- }
- if($param['gyscode']!=''){
- $where[]=["gyscode","=",$param['gyscode']];
- }
- $info = $this->model->with(["brandInfo"])->where($where)->findOrEmpty();
- if($info->isEmpty()){
- return error('未找到对应数据');
- }
- return success('获取成功',$info);
- }
- }
|