|
@@ -4,7 +4,7 @@ namespace app\admin\controller;
|
|
|
|
|
|
use app\BaseController;
|
|
|
use think\App;
|
|
|
-use think\facade\Db;
|
|
|
+use think\facade\Db;use think\facade\Validate;
|
|
|
|
|
|
//品牌授权
|
|
|
class Keepbrand extends Base
|
|
@@ -14,70 +14,44 @@ class Keepbrand extends Base
|
|
|
parent::__construct($app);
|
|
|
}
|
|
|
public function create(){
|
|
|
- $brand_book = isset($this->post['brand_book']) && $this->post['brand_book'] !=="" ? trim($this->post['brand_book']):"";
|
|
|
-// if($brand_book==""){
|
|
|
-// return error_show(1003,"参数brand_book不能为空");
|
|
|
-// }
|
|
|
- $gyscode = isset($this->post['gyscode']) && $this->post['gyscode'] !=="" ? trim($this->post['gyscode']):"";
|
|
|
-// if($gyscode==""){
|
|
|
-// return error_show(1003,"参数gyscode不能为空");
|
|
|
-// }
|
|
|
- $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !=="" ? trim($this->post['brand_id']):"";
|
|
|
- if($brand_id==""){
|
|
|
- return error_show(1003,"参数brand_id不能为空");
|
|
|
- }
|
|
|
- $rename = Db::name('brand_book')->where(['brand_id' => $brand_id,"gyscode"=>$gyscode,'is_del' => 0])->find();
|
|
|
- if (!empty($rename)) {
|
|
|
- return error_show(1002, "品牌名称已存在");
|
|
|
- }
|
|
|
-// $is_book = isset($this->post['is_book']) && $this->post['is_book'] !=="" ? trim($this->post['is_book']):"";
|
|
|
-// if($is_book==""){
|
|
|
-// return error_show(1003,"参数is_book不能为空");
|
|
|
-// }
|
|
|
- $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
|
|
|
- if($token==''){
|
|
|
- return error_show(105,"参数token不能为空");
|
|
|
- }
|
|
|
-// $user =GetUserInfo($token);
|
|
|
-// if(empty($user)||$user['code']!=0){
|
|
|
-// return error_show(1002,"创建人数据不存在");
|
|
|
-// }
|
|
|
- $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
- $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
- $long = isset($this->post['long']) && $this->post['long'] !=="" ? intval($this->post['long']):"0";
|
|
|
-
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
|
|
|
- $data=[
|
|
|
- "brand_book"=>$brand_book,
|
|
|
- "gyscode"=>$gyscode,
|
|
|
- // "is_book"=>$is_book,
|
|
|
- "brand_id"=>$brand_id,
|
|
|
- "createrid"=>$createrid,
|
|
|
- "creater"=>$creater,
|
|
|
- "long"=>$long,
|
|
|
- "is_del"=>0,
|
|
|
- "status"=>$status,
|
|
|
- "addtime"=>date("Y-m-d H:i:s"),
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- if($long===1){
|
|
|
- $starttime = isset($this->post['starttime']) && $this->post['starttime'] !==""
|
|
|
- ?$this->post['starttime']:null;
|
|
|
-// if($starttime==""){
|
|
|
-// return error_show(1005,'参数starttime不能为空');
|
|
|
-// }
|
|
|
- $endtime= isset($this->post['endtime']) && $this->post['endtime'] !=="" ?$this->post['endtime']:null;
|
|
|
-// if($endtime==""){
|
|
|
-// return error_show(1005,'修改时间不能为空');
|
|
|
-// }
|
|
|
- $data['starttime']=$starttime;
|
|
|
- $data['endtime']=$endtime;
|
|
|
- }
|
|
|
- $info = Db::name("brand_book")->insert($data);
|
|
|
- if($info){
|
|
|
- return error_show(0,"新建成功");
|
|
|
- }else{
|
|
|
- return error_show(1002,"新建失败");
|
|
|
+
|
|
|
+ $param = $this->request->only([
|
|
|
+ "brand_book",
|
|
|
+ "gyscode",
|
|
|
+ "brand_id",
|
|
|
+ "is_del"=>0,
|
|
|
+ 'remark',
|
|
|
+ 'long',
|
|
|
+ "status",
|
|
|
+ "starttime"=>date("Y-m-d H:i:s"),
|
|
|
+ "endtime"=>null],"post","trim");
|
|
|
+ $valud= Validate::rule([
|
|
|
+ "brand_book|授权书图片"=>"url",
|
|
|
+ "gyscode|供应商编号"=>"require|max:255",
|
|
|
+ "brand_id|品牌id"=>"require|number|gt:0|unique:brand_book,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,0|date|dateFormat:Y-m-d H:i:s",
|
|
|
+ ]);
|
|
|
+ if($valud->check($param)==false) return error_show(1004,$valud->getError());
|
|
|
+ $data=[];
|
|
|
+ $data['creater']= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
|
|
|
+ $data['creater']= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
|
|
|
+ if($param['long']===1){
|
|
|
+ $data['endtime']=null;
|
|
|
+ }
|
|
|
+ $userCommon = \app\admin\common\User::getIns();
|
|
|
+ $companyinfo =$userCommon->handle('getCodeAndName',['code'=>$param['gyscode']]);
|
|
|
+ if(isset($companyinfo['data']) && !empty($companyinfo['data'])){
|
|
|
+ return error_show(1004,'供应商信息未找到');
|
|
|
+ }
|
|
|
+ $data['gysname'] =$companyinfo['data']['name']?:"";
|
|
|
+ $info = Db::name("brand_book")->save(array_merge($param,$data));
|
|
|
+ if($info){
|
|
|
+ return error_show(0,"新建成功");
|
|
|
+ }else{
|
|
|
+ return error_show(1002,"新建失败");
|
|
|
}
|
|
|
}
|
|
|
public function list(){
|
|
@@ -92,19 +66,16 @@ class Keepbrand extends Base
|
|
|
if($name!=""){
|
|
|
$where[]=['b.name',"like","%$name%"];
|
|
|
}
|
|
|
- $registerCode = isset($this->post['registerCode']) && $this->post['registerCode'] !=="" ? trim($this->post['registerCode']):"";
|
|
|
- if($registerCode!=""){
|
|
|
- $where[]=['b.registerCode',"like","%$registerCode%"];
|
|
|
- }
|
|
|
$count = Db::name('brand_book')
|
|
|
- ->alias('a')->join("supplier b","a.gyscode=b.code","left")
|
|
|
+ ->alias('a')
|
|
|
->where($where)->count();
|
|
|
$total = ceil($count / $size);
|
|
|
$page = $page >= $total ? $total : $page;
|
|
|
$list = Db::name('brand_book')->alias('a')
|
|
|
- ->join("supplier b","a.gyscode=b.code","left")
|
|
|
->join("brand c","a.brand_id=c.id","left")
|
|
|
- ->where($where)->page($page,$size)->field("a.*,c.brand_name,b.name as supplier_name")->order("addtime desc")
|
|
|
+ ->where($where)
|
|
|
+ ->page($page,$size)
|
|
|
+ ->field("a.*,c.brand_name")->order("addtime desc")
|
|
|
->select();
|
|
|
return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
|
|
|
}
|
|
@@ -119,7 +90,7 @@ class Keepbrand extends Base
|
|
|
}
|
|
|
$data = Db::name("brand")->alias('a')
|
|
|
->join("brand_book b","b.brand_id=a.id")
|
|
|
- ->join("supplier c","b.gyscode=c.code","left")->field("b.*,a.brand_name,c.name")
|
|
|
+ ->field("b.*,a.brand_name")
|
|
|
->where(["a.id"=>$info['brand_id']])->find();
|
|
|
if($data){
|
|
|
return app_show(0,"获取成功",$data);
|
|
@@ -166,67 +137,58 @@ class Keepbrand extends Base
|
|
|
}
|
|
|
}
|
|
|
public function edit(){
|
|
|
- $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
|
|
|
- if($id == ""){
|
|
|
- return error_show(1002,"参数id不能为空");
|
|
|
- }
|
|
|
- $info = Db::name('brand_book')->where(['id'=>$id,'is_del'=>0])->find();
|
|
|
- if($info==""){
|
|
|
- return error_show(1002,"未找到数据");
|
|
|
- }
|
|
|
- $brand_book = isset($this->post['brand_book']) && $this->post['brand_book'] !=="" ? trim($this->post['brand_book']):"";
|
|
|
-// if($brand_book==""){
|
|
|
-// return error_show(1002,"参数brand_book不能为空");
|
|
|
-// }
|
|
|
-// $gyscode = isset($this->post['gyscode']) && $this->post['gyscode'] !== "" ? trim($this->post['gyscode']):"";
|
|
|
-// if($gyscode==""){
|
|
|
-// return error_show(1002,"参数gyscode不能为空");
|
|
|
-// }
|
|
|
- $brand_id = isset($this->post['brand_id']) && $this->post['brand_id'] !== "" ? intval($this->post['brand_id']):"";
|
|
|
- if($brand_id==""){
|
|
|
- return error_show(1002,"参数brand_id不能为空");
|
|
|
- }
|
|
|
- $rename = Db::name('brand_book')->where(['brand_id' => $brand_id, 'is_del' => 0])->find();
|
|
|
- if (empty($rename)) {
|
|
|
- return error_show(1002, "品牌名称已存在");
|
|
|
- }
|
|
|
-// $is_book = isset($this->post['is_book']) && $this->post['is_book'] !== "" ? intval($this->post['is_book']):"";
|
|
|
-// if($is_book==""){
|
|
|
-// return error_show(1002,"参数is_book不能为空");
|
|
|
-// }
|
|
|
- $long = isset($this->post['long']) && $this->post['long'] !=="" ? intval($this->post['long']):"0";
|
|
|
- $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
|
|
|
- if($status==""){
|
|
|
- return error_show(1002,"参数status不能为空");
|
|
|
- }
|
|
|
- $data=[
|
|
|
- "id"=>$id,
|
|
|
- "brand_book"=>$brand_book,
|
|
|
- // "gyscode"=>$gyscode,
|
|
|
- // "is_book"=>$is_book,
|
|
|
- "brand_id"=>$brand_id,
|
|
|
- "long"=>$long,
|
|
|
- "is_del"=>0,
|
|
|
- "status"=>$status,
|
|
|
- "updatetime"=>date("Y-m-d H:i:s")
|
|
|
- ];
|
|
|
- if($long===1){
|
|
|
- $starttime = isset($this->post['starttime']) && $this->post['starttime'] !=="" ?$this->post['starttime']:null;
|
|
|
-// if($starttime==""){
|
|
|
-// return error_show(1005,'参数starttime不能为空');
|
|
|
-// }
|
|
|
- $endtime= isset($this->post['endtime']) && $this->post['endtime'] !=="" ?$this->post['endtime']:null;
|
|
|
-// if($endtime==""){
|
|
|
-// return error_show(1005,'修改时间不能为空');
|
|
|
-// }
|
|
|
- $data['starttime']=$starttime;
|
|
|
- $data['endtime']=$endtime;
|
|
|
- }
|
|
|
- $info = Db::name("brand_book")->save($data);
|
|
|
+ $param = $this->request->only([
|
|
|
+ "id",
|
|
|
+ 'brand_book',
|
|
|
+ 'gyscode',
|
|
|
+ 'brand_id',
|
|
|
+ 'is_del'=>0,
|
|
|
+ 'remark',
|
|
|
+ 'long',
|
|
|
+ 'status',
|
|
|
+ 'starttime'=>date('Y-m-d H:i:s'),
|
|
|
+ 'endtime'=>null],'post','trim');
|
|
|
+ $valud= Validate::rule([
|
|
|
+ 'id|主键id'=>'require|number|gt:0',
|
|
|
+ 'brand_book|授权书图片'=>'url',
|
|
|
+ 'gyscode|供应商编号'=>'require|max:255',
|
|
|
+ 'brand_id|品牌id'=>'require|number|gt:0|unique:brand_book,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,0|date|dateFormat:Y-m-d H:i:s',
|
|
|
+ ]);
|
|
|
+ if($valud->check($param)==false) return error_show(1004,$valud->getError());
|
|
|
+ $info = Db::name('brand_book')->findOrEmpty($param['id']);
|
|
|
+ if(empty($info))return error_show(1004,"未找到数据");
|
|
|
+
|
|
|
+ if($param['long']!=$info['long']&&$param['long']===1){
|
|
|
+ $data['endtime']=null;
|
|
|
+ }
|
|
|
+ if($param['gyscode']!=$info['gyscode']){
|
|
|
+ $userCommon = \app\admin\common\User::getIns();
|
|
|
+ $companyinfo =$userCommon->handle('getCodeAndName',['code'=>$param['gyscode']]);
|
|
|
+ if(isset($companyinfo['data']) && !empty($companyinfo['data'])){
|
|
|
+ return error_show(1004,'供应商信息未找到');
|
|
|
+ }
|
|
|
+ $data['gysname'] =$companyinfo['data']['name']?:'';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $info = Db::name('brand_book')->save(array_merge($param,$data));
|
|
|
if($info){
|
|
|
- return error_show(0,"更新成功");
|
|
|
+ return error_show(0,'更新成功');
|
|
|
}else{
|
|
|
- return error_show(1002,"更新失败");
|
|
|
- }
|
|
|
+ return error_show(1002,'更新失败');
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ public function query(){
|
|
|
+ $param =$this->request->only(["brand_id"=>"","gyscode"=>""],"post","trim");
|
|
|
+ $valid = Validate::rule(["brand_id|品牌id"=>"require|number|gt:0","gyscode|供应商编号"=>"require"]);
|
|
|
+ if($valid->check($param)==false)return error_show(1002,$valid->getError());
|
|
|
+ $info = Db::name('brand_book')->where($param)->findOrEmpty();
|
|
|
+ return app_show(0,"获取成功",$info);
|
|
|
+ }
|
|
|
+
|
|
|
}
|