Browse Source

bug处理第一阶段

wufeng 2 năm trước cách đây
mục cha
commit
1a4f0097f6

+ 2 - 1
app/admin/controller/Brand.php

@@ -102,7 +102,8 @@ class Brand extends Base
             ->where($where)
             ->page($page,$size)
             ->order("addtime desc,id desc")
-            ->select();
+            ->select()
+            ->toArray();
 
         $all_createrid = array_column($list,'createrid');
         $item = get_company_name_by_uid($all_createrid);

+ 1 - 0
app/admin/controller/Cat.php

@@ -48,6 +48,7 @@ class Cat extends Base
             ->alias('c')
             ->where($where)
             ->page($param['page'], $param['size'])
+            ->order(['c.id'=>'desc'])
             ->select()
             ->toArray();
         $var = [];

+ 22 - 5
app/admin/controller/Specs.php

@@ -33,6 +33,13 @@ class Specs extends Base
         $creater= $this->uname;//isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
         $exam_status = isset($this->post['exam_status']) &&$this->post['exam_status'] !==""? intval($this->post['exam_status']):"0";
         $status = isset($this->post['status']) &&$this->post['status'] !==""? intval($this->post['status']):"1";
+
+        $tmp = Db::name('specs')
+            ->field('id')
+            ->where(['is_del'=>0,'spec_name'=>$spec_name])
+            ->findOrEmpty();
+        if(!$tmp) return json_show(1004,'该规格值已存在');
+
         $data = [
             "spec_name"=>$spec_name,
             "creater"=>$creater,
@@ -44,11 +51,13 @@ class Specs extends Base
             "updatetime"=>date("Y-m-d H:i:s")
         ];
         $datainfo = Db::name('specs')->insert($data);
-        if($datainfo){
-            return error_show(0,"新建成功");
-        }else{
-            return error_show(1002,"创建失败");
-        }
+
+        return $datainfo?json_show(0,"新建成功"):json_show(1002,"创建失败");
+//        if($datainfo){
+//            return error_show(0,"新建成功");
+//        }else{
+//            return error_show(1002,"创建失败");
+//        }
     }
     public function list(){
         $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
@@ -164,6 +173,14 @@ class Specs extends Base
         }
         $exam_status = isset($this->post['exam_status']) &&$this->post['exam_status'] !==""? intval($this->post['exam_status']):"0";
         $status = isset($this->post['status']) &&$this->post['status'] !==""? intval($this->post['status']):"0";
+
+        $tmp = Db::name('specs')
+            ->field('id')
+            ->where(['is_del'=>0,'spec_name'=>$spec_name])
+            ->where('id','<>',$id)
+            ->findOrEmpty();
+        if(!$tmp) return json_show(1004,'该规格值已存在');
+
         $data = [
             "id"=>$id,
             "spec_name"=>$spec_name,

+ 137 - 109
app/admin/controller/Unit.php

@@ -10,17 +10,27 @@ use think\facade\Db;
 //单位
 class Unit extends Base
 {
-    public $post ="";
+    public $post = "";
+
     public function __construct(App $app)
     {
         parent::__construct($app);
-        $this->post=$this->request->post();
+        $this->post = $this->request->post();
     }
-    public function create(){
-        $unit = isset($this->post['unit']) && $this->post['unit'] !==""? trim($this->post['unit']):"";
-        if($unit==""){
-            return error_show(1002,"参数unit不能为空");
-        }
+
+    public function create()
+    {
+
+        $param = $this->request->only(['unit', 'status' => 1], 'post', 'trim');
+//        $unit = isset($this->post['unit']) && $this->post['unit'] !==""? trim($this->post['unit']):"";
+        if ($param['unit'] == "") return error_show(1002, "参数unit不能为空");
+
+        $tmp = Db::name("unit")
+            ->field('id')
+            ->where(['is_del' => 0, "unit" => $param['unit']])
+            ->findOrEmpty();
+        if (!$tmp) return json_show(1004, '该单位已存在');
+
 //        $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
 //        if($token==''){
 //            return error_show(105,"参数token不能为空");
@@ -29,50 +39,54 @@ class Unit extends Base
 //        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'] : "";
-        $status = isset($this->post['status']) &&$this->post['status'] !==""? intval($this->post['status']):"1";
-        $data=[
-            "unit"=>$unit,
-            "creater"=>$creater,
-            "createrid"=>$createrid,
-            "status"=>$status,
-            "is_del"=>0,
-            "addtime"=>date("Y-m-d H:i:s"),
-            "updatetime"=>date("Y-m-d H:i:s")
+        $createrid = $this->uid;//isset($user["data"]['id']) ?  $user["data"]['id'] : "";
+        $creater = $this->uname;//isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
+//        $status = isset($this->post['status']) &&$this->post['status'] !==""? intval($this->post['status']):"1";
+        $data = [
+            "unit" => $param['unit'],
+            "creater" => $creater,
+            "createrid" => $createrid,
+            "status" => $param['status'],
+            "is_del" => 0,
+            "addtime" => date("Y-m-d H:i:s"),
+            "updatetime" => date("Y-m-d H:i:s")
         ];
         $info = Db::name("unit")->insert($data);
-        if($info){
-            return error_show(0,"新建成功");
-        }else{
-            return error_show(1002,"新建失败");
-        }
+
+        return $info ? json_show(0, "新建成功") : json_show(1002, "新建失败");
+//        if($info){
+//            return error_show(0,"新建成功");
+//        }else{
+//            return error_show(1002,"新建失败");
+//        }
     }
-    public function list(){
-        $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
-        $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
-        $where=[["u.is_del","=",0]];
-        $unit = isset($this->post['unit']) && $this->post['unit'] !=="" ? trim($this->post['unit']):"";
-        if($unit!==""){
-            $where[]=['u.unit',"like","%$unit%"];
-        }
-        $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
-        if($status!==""){
-            $where[]=['u.status',"=",$status];
-        }
-        $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
-        if($creater!=""){
-            $where[]=['u.creater',"like","%$creater%"];
-        }
-        $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
-        if($start!==""){
-           // $where[]=['u.addtime',">=",date('Y-m-d H:i:s')];//,strtotime($start)
-            $where[]=['u.addtime',">=",$start];
-        }
-        $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
-        if($end!==""){
-           // $where[]=['u.addtime',"<",date('Y-m-d H:i:s')];//,strtotime($end)+24*3600
-            $where[]=['u.addtime',"<=",$end];
+
+    public function list()
+    {
+        $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
+        $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
+        $where = [["u.is_del", "=", 0]];
+        $unit = isset($this->post['unit']) && $this->post['unit'] !== "" ? trim($this->post['unit']) : "";
+        if ($unit !== "") {
+            $where[] = ['u.unit', "like", "%$unit%"];
+        }
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
+        if ($status !== "") {
+            $where[] = ['u.status', "=", $status];
+        }
+        $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
+        if ($creater != "") {
+            $where[] = ['u.creater', "like", "%$creater%"];
+        }
+        $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
+        if ($start !== "") {
+            // $where[]=['u.addtime',">=",date('Y-m-d H:i:s')];//,strtotime($start)
+            $where[] = ['u.addtime', ">=", $start];
+        }
+        $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
+        if ($end !== "") {
+            // $where[]=['u.addtime',"<",date('Y-m-d H:i:s')];//,strtotime($end)+24*3600
+            $where[] = ['u.addtime', "<=", $end];
         }
         $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
         if ($company_name !== "") $where[] = ["u.createrid", 'in', get_company_item_user_by_name($company_name)];
@@ -88,35 +102,37 @@ class Unit extends Base
             ->alias('u')
             ->where($where)
             ->append(['company_name'])
-            ->page($page,$size)
+            ->page($page, $size)
             ->order("addtime desc")
             ->select()
             ->toArray();
 
-        $all_createrid = array_column($list,'createrid');
+        $all_createrid = array_column($list, 'createrid');
         $item = get_company_name_by_uid($all_createrid);
 
-        foreach ($list as &$val){
-            $val['company_name']=$item[$val['createrid']]??'';
+        foreach ($list as &$val) {
+            $val['company_name'] = $item[$val['createrid']] ?? '';
         }
 
-        return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
+        return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
     }
-    public function edit(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
-        if($id==""){
-            return error_show(1002,"参数id不能为空");
+
+    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('unit')->where(['id'=>$id,'is_del'=>0])->find();
-        if($info==""){
-            return error_show(1003,"未找到数据");
+        $info = Db::name('unit')->where(['id' => $id, 'is_del' => 0])->find();
+        if ($info == "") {
+            return error_show(1003, "未找到数据");
         }
-        if($info['status']==1){
-            return error_show(1002,"状态是启用状态,无法编辑");
+        if ($info['status'] == 1) {
+            return error_show(1002, "状态是启用状态,无法编辑");
         }
-        $unit = isset($this->post['unit']) && $this->post['unit'] !==""? trim($this->post['unit']):"";
-        if($unit==""){
-            return error_show(1002,"参数unit不能为空");
+        $unit = isset($this->post['unit']) && $this->post['unit'] !== "" ? trim($this->post['unit']) : "";
+        if ($unit == "") {
+            return error_show(1002, "参数unit不能为空");
         }
 //        $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
 //        if($token==''){
@@ -128,63 +144,75 @@ class Unit extends Base
 //        }
 //        $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
 //        $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-        $status = isset($this->post['status']) &&$this->post['status'] !==""? intval($this->post['status']):"0";
-        $data=[
-            "id"=>$id,
-            "unit"=>$unit,
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
+
+        $tmp = Db::name("unit")
+            ->field('id')
+            ->where(['is_del' => 0, "unit" => $unit])
+            ->where('id','<>',$id)
+            ->findOrEmpty();
+        if (!$tmp) return json_show(1004, '该单位已存在');
+
+        $data = [
+            "id" => $id,
+            "unit" => $unit,
 //            "creater"=>$creater,
 //            "createrid"=>$createrid,
-          // "status"=>$status,
-            "is_del"=>0,
-            "updatetime"=>date("Y-m-d H:i:s")
+            // "status"=>$status,
+            "is_del" => 0,
+            "updatetime" => date("Y-m-d H:i:s")
         ];
-        $datainfo = Db::name('unit')->save($data);
-        $item = array_diff($data,$info);
-        $json = json_encode($item,JSON_UNESCAPED_UNICODE);
-        $jsp = json_encode($info,JSON_UNESCAPED_UNICODE);
-        if($datainfo){
-            ChangeLog::logAdd(4,$info['id'],$jsp,$json,['id'=>$this->uid,'nickname'=>$this->uname],$this->post);
-            return error_show(0,"更新成功");
-        }else{
-            return error_show(1002,"更新失败");
+        $datainfo = Db::name('unit')->where(['is_del'=>0,'id'=>$id])->save($data);
+        $item = array_diff($data, $info);
+        $json = json_encode($item, JSON_UNESCAPED_UNICODE);
+        $jsp = json_encode($info, JSON_UNESCAPED_UNICODE);
+        if ($datainfo) {
+            ChangeLog::logAdd(4, $info['id'], $jsp, $json, ['id' => $this->uid, 'nickname' => $this->uname], $this->post);
+            return error_show(0, "更新成功");
+        } else {
+            return error_show(1002, "更新失败");
         }
     }
-    public function del(){
-        $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
-        if($id===""){
-            return  error_show(1004,"参数id不能为空");
+
+    public function del()
+    {
+        $id = $this->post['id'] && $this->post['id'] !== "" ? intval($this->post['id']) : "";
+        if ($id === "") {
+            return error_show(1004, "参数id不能为空");
         }
-        $str= Db::name('unit')->where(['id'=>$id,'is_del'=>0])->find();
-        if(empty($str)){
-            return error_show(1002,"未找到数据");
+        $str = Db::name('unit')->where(['id' => $id, 'is_del' => 0])->find();
+        if (empty($str)) {
+            return error_show(1002, "未找到数据");
         }
-        $end = Db::name('unit')->update(['id'=>$id,'is_del'=>1]);
-        if($end){
-            return error_show(0,"删除成功");
-        }else{
-            return error_show(1002,"删除失败");
+        $end = Db::name('unit')->update(['id' => $id, 'is_del' => 1]);
+        if ($end) {
+            return error_show(0, "删除成功");
+        } else {
+            return error_show(1002, "删除失败");
         }
     }
-    public function status(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
-        if($id==""){
-            return error_show(1002,"参数id不能为空");
+
+    public function status()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
+        if ($id == "") {
+            return error_show(1002, "参数id不能为空");
         }
-        $info =  Db::name("unit")->where([["id","=",$id],["is_del","=",0]])->find();
-        if(!$info){
-            return error_show(1002,"未找到对应数据");
+        $info = Db::name("unit")->where([["id", "=", $id], ["is_del", "=", 0]])->find();
+        if (!$info) {
+            return error_show(1002, "未找到对应数据");
         }
-        $status =  isset($this->post['status']) && $this->post['status']!==""? intval($this->post['status']):"";
-        if($status===""){
-            return error_show(1002,"参数status不能为空");
+        $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
+        if ($status === "") {
+            return error_show(1002, "参数status不能为空");
         }
-        if(!in_array($status,[0,1])){
-            return error_show(1002,"参数status无效");
+        if (!in_array($status, [0, 1])) {
+            return error_show(1002, "参数status无效");
         }
-        $info['status']=$status;
-        $info['updatetime']=date("Y-m-d H:i:s");
-        $msg = $status==1?"启用":"禁用";
+        $info['status'] = $status;
+        $info['updatetime'] = date("Y-m-d H:i:s");
+        $msg = $status == 1 ? "启用" : "禁用";
         $update = Db::name("unit")->save($info);
-        return  $update? error_show(0,"{$msg}成功"):error_show(1004,"{$msg}失败");
+        return $update ? error_show(0, "{$msg}成功") : error_show(1004, "{$msg}失败");
     }
 }