|
@@ -0,0 +1,237 @@
|
|
|
+<?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,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']==1?"":$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,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']==1?'':$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);
|
|
|
+ }
|
|
|
+}
|