Просмотр исходного кода

公司分类及毛利、用户分组、快递公司和离职交接

wufeng 2 лет назад
Родитель
Сommit
c759202e3e

+ 570 - 531
app/admin/controller/Cat.php

@@ -6,614 +6,653 @@ use app\admin\model\ActionLog;
 use app\admin\model\ChangeLog;
 use app\BaseController;
 use think\App;
+use think\Exception;
 use think\facade\Db;
+use think\facade\Validate;
 
 //分类
 class Cat extends Base
 {
 
-public function __construct(App $app)
-{
-    parent::__construct($app);
-}
-public function list(){
-    $where=[["is_del","=",0]];
-    $pid =  isset($this->post['pid']) &&$this->post['pid']!=="" ?intval($this->post['pid']): "0";
-    $where[]=["pid","=",$pid];
-
-    $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? intval($this->post['cat_name']) :"";
-    if($cat_name!==""){
-        $where[]=['cat_name',"like","%$cat_name%"];
-    }
-    $data = Db::name("cat")->where($where)->select();
-    $vmp = [];
-    foreach ($data as $sts){
-        $vmp[]=stro($sts);
-    }
-    return app_show(0,"获取成功",$vmp);
-}
-public function plist(){
-    $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 =[["c.is_del","=",0]];
-    $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
-    if($cat_name!==""){
-        $where[]=['c.cat_name',"like","%$cat_name%"];
-    }
-    $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
-    if($pid!==""){
-        $where[]=['c.pid',"=",$pid];
-    }
-    $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
-    if($status!==""){
-        $where[]=['c.status',"=",$status];
-    }
-    $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
-    if ($company_name !== "") $where[] = ["c.createrid", 'in', get_company_item_user_by_name($company_name)];
-
-    $count = Db::name("cat")->alias('c')->where($where)->count();
-    $total = ceil($count / $size);
-    $page = $page >= $total ? $total : $page;
-    $list = Db::name('cat')
-        ->alias('c')
-        ->field('c.*,u.itemid')
-        ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
-        ->where($where)
-        ->page($page, $size)
-        ->cursor();
-    $var =[];
-    foreach ($list as $value){
-        $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
-        $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
-        if(empty($temp)){
-            $temp=[];
-        }
-        $value['im']=$temp;
-        $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
-        $var[]=$value;
-    }
-    return app_show(0, "获取成功", ['list' =>$var, 'count' => $count]);
-}
-
-    public function wlist(){
-        $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 =[["is_del","=",0],['level',"=",3]];
-        $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
-        if($cat_name!==""){
-            $where[]=['cat_name',"like","%$cat_name%"];
-        }
-        $search=isset($this->post['search']) && $this->post['search'] !==""? trim($this->post['search']) :"";
-        if($search!==""){
-            $where[]=['search',"like","%$search%"];
-        }
-        $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
-        if($pid!==""){
-            $where[]=['pid',"=",$pid];
-        }
-        $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
-        if($status!==""){
-            $where[]=['status',"=",$status];
-        }
-        $count = Db::name("cat")->where($where)->count();
-        $total = ceil($count / $size);
-        $page = $page >= $total ? $total : $page;
-        $list = Db::name('cat')->where($where)->page($page, $size)->select();
-        $data=[];
-        foreach ($list as $value){
-            $temp= isset($value['id']) && $value['id'] !=0 ? made($value['id']):[];
-            $value['item'] = array_column($temp,'id');
-            $data[]=$value;
-        }
-        return app_show(0, "获取成功", ['list' =>$data, 'count' => $count]);
-    }
+    //树状列表
+    public function list()
+    {
+        $param = $this->request->only(['pid' => 0, 'cat_name' => '', 'supplierNo' => ''], 'post', 'trim');
 
-public function title(){
-    $where =[["is_del","=",0]];
-    $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
-    if($cat_name!==""){
-        $where[]=['cat_name',"like","%$cat_name%"];
-    }
-    $pid=isset($this->post['pid']) && $this->post['pid'] !==""? intval($this->post['pid']) :"";
-    if($pid!==""){
-        $where[]=["pid","=",$pid];
-    }
-    $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
-    if($status!==""){
-        $where[]=['status',"=",$status];
-    }
-    $list = Db::name('cat')->where($where)->select();
-    return app_show(0, "获取成功",$list);
-}
-    public function tlist(){
-        $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 =[['c.is_del',"=",0]];
-        $cat_name=isset($this->post['cat_name']) && $this->post['cat_name'] !==""? trim($this->post['cat_name']) :"";
-        if($cat_name!==""){
-            $where[]=['c.cat_name',"like","%$cat_name%"];
-        }
-        $status=isset($this->post['status']) && $this->post['status'] !==""? intval($this->post['status']) :"";
-        if($status!==""){
-            $where[]=['c.status',"=",$status];
-        }
-        $creater=isset($this->post['creater']) && $this->post['creater'] !==""? trim($this->post['creater']) :"";
-        if($creater!==""){
-            $where[]=['c.creater',"like","%$creater%"];
-        }
+        $where = [['is_del', '=', 0], ['pid', '=', $param['pid']]];
 
-        $start = isset($this->post['start']) && $this->post['start'] !== "" ?  $this->post['start']:"";
-        if($start!==""){
-            $where[]=['c.addtime',">=",$start];
-        }
-        $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
-        if($end !==""){
-            $where[]=['c.addtime',"<=",$end];
+        if ($param['cat_name'] !== '') $where[] = ['cat_name', 'like', '%' . $param['cat_name'] . '%'];
+        if ($param['supplierNo'] !== '') $where[] = ['supplierNo', '=', $param['supplierNo']];
+
+        $data = Db::name('cat')->where($where)->cursor();
+        $vmp = [];
+        foreach ($data as $sts) {
+            $vmp[] = stro($sts);
         }
-        $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
-        if ($company_name !== "") $where[] = ["c.createrid", 'in', get_company_item_user_by_name($company_name)];
+        return app_show(0, '获取成功', $vmp);
+    }
+
+    //列表(含规格和创建人部门)
+    public function plist()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_name' => '', 'pid' => '', 'status' => '', 'company_name' => '', 'supplierNo' => ''], 'post', 'trim');
+        $where = [['c.is_del', '=', 0]];
+        if ($param['cat_name'] !== '') $where[] = ['c.cat_name', 'like', '%' . $param['cat_name'] . '%'];
+        if ($param['supplierNo'] !== '') $where[] = ['c.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
+        if ($param['pid'] !== '') $where[] = ['c.pid', '=', $param['pid']];
+        if ($param['status'] !== '') $where[] = ['c.status', '=', $param['status']];
+        if ($param['company_name'] !== '') $where[] = ['c.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
 
         $count = Db::name('cat')->alias('c')->where($where)->count();
-        $total = ceil($count / $size);
-        $page = $page >= $total ? $total : $page;
+//        $total = ceil($count / $size);
+//        $page = $page >= $total ? $total : $page;
         $list = Db::name('cat')
             ->alias('c')
             ->field('c.*,u.itemid')
-            ->leftJoin("depart_user u", "u.uid=c.createrid AND u.is_del=0")
+            ->leftJoin('depart_user u', 'u.uid=c.createrid AND u.is_del=0')
             ->where($where)
-            ->page($page, $size)
+            ->page($param['page'], $param['size'])
             ->cursor();
-        $var =[];
-        foreach ($list as $value){
-            $info = Db::name('cat_specs')->where(['cat_id'=>$value['id'],'is_del'=>0])->column('specs_id');
-            $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id as specid,spec_name")->select()->toArray();
-            if(empty($temp)){
-                 $temp=[];
+        $var = [];
+
+        foreach ($list as $value) {
+            $temp = Db::name('cat_specs')
+                ->field('a.specs_id,b.spec_name')
+                ->alias('a')
+                ->leftJoin('specs b', 'b.id=a.specs_id')
+                ->where(['a.cat_id' => $value['id'], 'a.is_del' => 0])
+                ->select()
+                ->toArray();
+//            $temp = Db::name('specs')
+//                ->where(['id' => $info, 'is_del' => 0])
+//                ->field('id as specid,spec_name')
+//                ->select()
+//                ->toArray();
+            if (empty($temp)) {
+                $temp = [];
             }
-            $value['im']=$temp;
+            $value['im'] = $temp;
             $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
-            $var[]=$value;
+            $var[] = $value;
         }
-        return app_show(0, "获取成功", ['list' => $var, 'count' => $count]);
+        return app_show(0, '获取成功', ['list' => $var, 'count' => $count]);
     }
 
-public function create()
-{
-    $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== "" ? trim($this->post['cat_name']) : "";
-    if ($cat_name == "") {
-        return error_show(1002, "参数cat_name不能为空");
-    }
-    $pid = isset($this->post['pid']) && $this->post['pid'] !== "" ? intval($this->post['pid']) : "0";
-    if ($pid === "") {
-        return error_show(1002, "参数pid不能为空");
-    }
+    //查看所有三级分类
+    public function wlist()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_name' => '', 'search' => '', 'pid' => '', 'status' => '', 'supplierNo' => ''], 'post', 'trim');
 
-    $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== "" ? trim($this->post['cat_desc']) : "";
-    $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
+        $where = [['is_del', '=', 0], ['level', '=', 3]];
+        if ($param['cat_name'] !== '') $where[] = ['cat_name', 'like', '%' . $param['cat_name'] . '%'];
+        if ($param['search'] !== '') $where[] = ['search', 'like', '%' . $param['search'] . '%'];
+        if ($param['pid'] !== '') $where[] = ['pid', '=', $param['pid']];
+        if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
+        if ($param['supplierNo'] !== '') $where[] = ['supplierNo', '=', $param['supplierNo']];
 
-    $level =1;
-    if ($pid !== 0) {
-        $levl=Db::name('cat')->where(['id'=>$pid])->find();
-        if(empty($levl)){
-            return error_show(1002,"未找到父级数据");
+        $count = Db::name('cat')
+            ->where($where)
+            ->count();
+
+        $list = Db::name('cat')
+            ->where($where)
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+        $data = [];
+        foreach ($list as $value) {
+            $value['item'] = array_column(made($value['id'] ?? 0), 'id');
+            $data[] = $value;
         }
-        $level =$levl['level']+1;
-        $temp = $levl['search'];
-    }
-    if($level==1){
-        $search = $cat_name;
-    }else{
-        $search= $temp."-".$cat_name;
+        return app_show(0, '获取成功', ['list' => $data, 'count' => $count]);
     }
-    $repeat_name = Db::name("cat")->where(["is_del"=>0,"cat_name"=>$cat_name])->find();
-    $int =isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
-    $im = array_column($int,'name');
-    $in=implode('/',$im);
-    if(!empty($repeat_name)){
-        return error_show(1004,"分类名称已在{$in}存在");
-    }
-    $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
-    if (empty($specs_id)) {
-        return error_show(1002, "参数specs_id不能为空");
-    }
-    $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
-    if($token==''){
-        return error_show(105,"参数token不能为空");
+
+    //列表
+    public function title()
+    {
+        $param = $this->request->only(['cat_name' => '', 'pid' => '', 'status' => '', 'supplierNo' => ''], 'post', 'trim');
+
+
+        $where = [['is_del', '=', 0]];
+        if ($param['cat_name'] !== '') $where[] = ['cat_name', 'like', '%' . $param['cat_name'] . '%'];
+        if ($param['pid'] !== '') $where[] = ['pid', '=', $param['pid']];
+        if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
+        if ($param['supplierNo'] !== '') $where[] = ['supplierNo', '=', $param['supplierNo']];
+
+        $list = Db::name('cat')
+            ->where($where)
+            ->select()
+            ->toArray();
+        return app_show(0, '获取成功', $list);
     }
-    $user =GetUserInfo($token);
-    if(empty($user)||$user['code']!=0){
-        return error_show(102,"创建人数据不存在");
+
+    //列表
+    public function tlist()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'cat_name' => '', 'status' => '', 'creater' => '', 'start' => '', 'end' => '', 'company_name' => '', 'supplierNo' => ''], 'post', 'trim');
+
+
+        $where = [['c.is_del', '=', 0]];
+        if ($param['cat_name'] !== '') $where[] = ['c.cat_name', 'like', '%' . $param['cat_name'] . '%'];
+        if ($param['status'] !== '') $where[] = ['c.status', '=', $param['status']];
+        if ($param['creater'] !== '') $where[] = ['c.creater', 'like', '%' . $param['creater'] . '%'];
+        if ($param['start'] !== '') $where[] = ['c.addtime', '>=', $param['start']];
+        if ($param['end'] !== '') $where[] = ['c.addtime', '<=', $param['end']];
+        if ($param['company_name'] !== '') $where[] = ['c.createrid', 'in', get_company_item_user_by_name($param['company_name'])];
+        if ($param['supplierNo'] !== '') $where[] = ['c.supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
+
+        $count = Db::name('cat')
+            ->alias('c')
+            ->leftJoin('depart_user u', 'u.uid=c.createrid AND u.is_del=0')
+            ->where($where)
+            ->count();
+//        $total = ceil($count / $size);
+//        $page = $page >= $total ? $total : $page;
+        $list = Db::name('cat')
+            ->alias('c')
+            ->field('c.*,u.itemid')
+            ->leftJoin('depart_user u', 'u.uid=c.createrid AND u.is_del=0')
+            ->where($where)
+            ->page($param['page'], $param['size'])
+            ->cursor();
+        $var = [];
+        foreach ($list as $value) {
+            $temp = Db::name('cat_specs')
+                ->field('a.specs_id,b.spec_name')
+                ->alias('a')
+                ->leftJoin('specs b', 'b.id=a.specs_id')
+                ->where(['a.cat_id' => $value['id'], 'a.is_del' => 0])
+                ->select()
+                ->toArray();
+
+            $value['im'] = $temp;
+            $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
+            $var[] = $value;
+        }
+        return app_show(0, '获取成功', ['list' => $var, 'count' => $count]);
     }
-    $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
-    $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-    $weight = isset($this->post['weight']) && $this->post['weight'] !== "" ? intval($this->post['weight']) : "0";
-    $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
-    Db::startTrans();
-    try{
-        $data = [
-            "cat_name" => $cat_name,
-            "pid" => $pid,
-            "level" => $level,
-            "search" => $search,
-            "weight" => $weight,
-            "status" => $status,
-            "cat_desc"=>$cat_desc,
-            "fund_code"=>$fund_code,
-            "creater"=>$creater,
-            "createrid"=>$createrid,
-            "is_del"=>0,
-            "addtime" => date("Y-m-d H:i:s"),
-            "updatetime" => date("Y-m-d H:i:s"),
-        ];
-        $datainfo = Db::name('cat')->insert($data,true);
-        $vat =[];
-        if ($datainfo>0) {
-            $stx = ["order_code"=>$pid,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
-            ActionLog::logAdd($this->post['token'],$stx,"sxd",$status,$stx);
-            $spc =[];
-            $spc['cat_id']=$datainfo;
-            $spc['exam_status']=0;
-            $spc['status']=0;
-            $spc['creater']=$creater;
-            $spc['createrid']=$createrid;
-            $spc['is_del']=0;
-            $spc['addtime']=date("Y-m-d H:i:d");
-            $spc['updatetime']=date("Y-m_d H:i:s");
-            $vpn = Db::name('cat_spec')->insert($spc,true);
-            if ($vpn == "") {
-                Db::rollback();
-                return error_show(1002, "新建失败");
-            }
-            foreach ($specs_id as $value){
-                $item =[];
-                $item['cat_id']=$datainfo;
-                $item['specs_id']=$value;
-                $item['is_del']=0;
-                $item['addtime']=date("Y-m-d H:i:s");
-                $vat[] = $item;
-            }
-            $vp = Db::name('cat_specs')->insertAll($vat);
-            if ($vp==0) {
-                Db::rollback();
-                return error_show(1005, "新建失败");
-            }
 
-                $catinfo=['cat_id'=>$datainfo,'apply_name'=>$creater,"apply_id"=>$createrid,"fund_code"=>$fund_code,"status"=>0];
+    //创建
+    public function create()
+    {
+        $param = $this->request->only(['cat_name', 'pid', 'cat_desc' => '', 'fund_code' => '', 'specs_id', 'weight' => 0, 'status' => 0, 'ssupplierNo'], 'post', 'trim');
+//        $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== '' ? trim($this->post['cat_name']) : '';
+        $val = Validate::rule([
+            'cat_name|分类名称' => 'require|max:255',
+            'pid|父级id' => 'require|number|egt:0',
+            'specs_id' => 'require|array|max:100',
+            'weight|权重' => 'number|egt:0',
+            'status|状态' => 'number|in:0,1',
+            'ssupplierNo|公司编码' => 'require|length:18',
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+//        if ($cat_name == '') {
+//            return error_show(1002, '参数cat_name不能为空');
+//        }
+//        $pid = isset($this->post['pid']) && $this->post['pid'] !== '' ? intval($this->post['pid']) : '0';
+//        if ($pid === '') {
+//            return error_show(1002, '参数pid不能为空');
+//        }
+
+//        $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== '' ? trim($this->post['cat_desc']) : '';
+//        $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== '' ? trim($this->post['fund_code']) : '';
+
+        $level = 1;
+        if ($param['pid'] !== 0) {
+            $levl = Db::name('cat')
+                ->field('id,level,search')
+                ->where(['id' => $param['pid']])
+                ->find();
+            if (empty($levl)) return json_show(1002, '未找到父级数据');
+
+            $level = $levl['level'] + 1;
+            $temp = $levl['search'];
+        }
+        if ($level == 1) $search = $param['cat_name'];
+        else $search = $temp . '-' . $param['cat_name'];
+
+        $repeat_name = Db::name('cat')
+            ->field('id')
+            ->where(['is_del' => 0, 'cat_name' => $param['cat_name']])
+            ->find();
+
+        $int = isset($repeat_name['id']) && $repeat_name['id'] != 0 ? made($repeat_name['id']) : [];
+        $im = array_column($int, 'name');
+        $in = implode('/', $im);
+        if (!empty($repeat_name)) {
+            return json_show(1004, "分类名称已在{$in}存在");
+        }
+//        $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== '' ? $this->post['specs_id'] : [];
+//        if (empty($specs_id)) {
+//            return error_show(1002, '参数specs_id不能为空');
+//        }
+//        $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(102, '创建人数据不存在');
+//        }
+        $createrid = $this->uid;//isset($user['data']['id']) ? $user['data']['id'] : '';
+        $creater = $this->uname;//($user['data']['nickname']) ? $user['data']['nickname'] : '';
+//        $weight = isset($this->post['weight']) && $this->post['weight'] !== '' ? intval($this->post['weight']) : '0';
+//        $status = isset($this->post['status']) && $this->post['status'] !== '' ? intval($this->post['status']) : '0';
+        Db::startTrans();
+        try {
+            $date = date('Y-m-d H:i:s');
+            $data = [
+                'cat_name' => $param['cat_name'],
+                'pid' => $param['pid'],
+                'level' => $level,
+                'search' => $search,
+                'weight' => $param['weight'],
+                'status' => $param['status'],
+                'cat_desc' => $param['cat_desc'],
+                'fund_code' => $param['fund_code'],
+                'supplierNo' => $param['ssupplierNo'],
+                'creater' => $creater,
+                'createrid' => $createrid,
+                'is_del' => 0,
+                'addtime' => $date,
+                'updatetime' => $date,
+            ];
+            $datainfo = Db::name('cat')->insertGetId($data);
+            $vat = [];
+            if ($datainfo > 0) {
+                $stx = ['order_code' => $param['pid'], 'status' => $param['status'], 'action_remark' => '', 'action_type' => 'create'];
+                ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], $stx, 'sxd', $param['status'], $stx);
+                $spc = [];
+                $spc['cat_id'] = $datainfo;
+                $spc['exam_status'] = 0;
+                $spc['status'] = 0;
+                $spc['creater'] = $creater;
+                $spc['createrid'] = $createrid;
+                $spc['is_del'] = 0;
+                $spc['addtime'] = $date;
+                $spc['updatetime'] = $date;
+                $vpn = Db::name('cat_spec')->insertGetId($spc);
+                if ($vpn == '') throw new Exception('新建失败');
+
+                foreach ($param['specs_id'] as $value) {
+                    $item = [];
+                    $item['cat_id'] = $datainfo;
+                    $item['specs_id'] = $value;
+                    $item['is_del'] = 0;
+                    $item['addtime'] = $date;
+                    $vat[] = $item;
+                }
+                $vp = Db::name('cat_specs')->insertAll($vat);
+                if ($vp == 0) throw new Exception('新建失败');
+
+
+                $catinfo = ['cat_id' => $datainfo, 'apply_name' => $creater, 'apply_id' => $createrid, 'fund_code' => $param['fund_code'], 'status' => 0];
                 $this->addPlat($catinfo);
-           Db::commit();
-            return error_show(0, "新建成功");
-        } else {
+                Db::commit();
+                return json_show(0, '新建成功');
+            } else {
+                Db::rollback();
+                return json_show(1002, '新建失败');
+            }
+        } catch (Exception $exception) {
             Db::rollback();
-            return error_show(1002, "新建失败");
+            return json_show(1005, $exception->getMessage());
         }
-    }catch (\Exception $e){
-        Db::rollback();
-        return error_show(1005,$e->getMessage());
-    }
 
-}
-public function edit(){
-    $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
-    $idinfo = Db::name('cat')->where(['id'=>$id])->find();
-    if($idinfo==""){
-        return error_show(1002,"未找到商品数据");
-    }
-    $cat_name= isset($this->post['cat_name']) && $this->post['cat_name'] !=="" ? trim($this->post['cat_name']) :"";
-    if($cat_name==""){
-        return error_show(1002,"参数cat_name不能为空");
-    }
-    $pid = isset($this->post['pid']) && $this->post['pid'] !=="" ? intval($this->post['pid']) :"";
-    if($pid===""){
-        return error_show(1002,"参数pid不能为空");
-    }
-    $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !=="" ? trim($this->post['cat_desc']) :"";
-    $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== "" ? trim($this->post['fund_code']) : "";
-    $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== "" ? $this->post['specs_id'] : [];
-    if (empty($specs_id)) {
-        return error_show(1002, "参数specs_id不能为空");
-    }
-    $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(102,"创建人数据不存在");
     }
 
-    $level =1;
-    if ($pid !== 0) {
-        $levl=Db::name('cat')->where(['id'=>$pid])->find();
-        if(empty($levl)){
-            return error_show(1002,"未找到父级数据");
+    //编辑
+    public function edit()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
+        $idinfo = Db::name('cat')->where(['id' => $id])->find();
+        if ($idinfo == '') {
+            return error_show(1002, '未找到商品数据');
         }
-        $level =$levl['level']+1;
-        $temp = $levl['search'];
-    }
-    if($level==1){
-        $search = $cat_name;
-    }else{
-        $search= $temp."_".$cat_name;
-    }
-    $createrid= isset($user["data"]['id']) ?  $user["data"]['id'] : "";
-    $creater= isset($user["data"]['nickname']) ?  $user["data"]['nickname'] : "";
-    //$level = isset($this->post['level']) && $this->post['level'] !=="" ? intval($this->post['level']) :"";
-
-    $weight = isset($this->post['weight']) && $this->post['weight']!==""? intval($this->post['weight']):"0";
-    $status = isset($this->post['status']) && $this->post['status'] !==""?intval($this->post['status']) :"0";
-    Db::startTrans();
-    try{
-        $str = [
-            "id"=>$id,
-            "cat_name"=>$cat_name,
-            "pid"=>$pid,
-            "level"=>$level,
-            "weight"=>$weight,
-           // "status"=>$status,
-            "cat_desc"=>$cat_desc,
-            "is_del"=>0,
-            "fund_code"=>$fund_code,
-            "updatetime"=>date("Y-m-d H:i:s"),
-            "search"=>$search
-        ];
-        $strinfo = Db::name('cat')->where(['id'=>$id])->save($str);
-        $temp = array_diff($str,$idinfo);
-        $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
-        $jsp = json_encode($idinfo,JSON_UNESCAPED_UNICODE);
-        if($strinfo){
-            $order = ["order_code"=>$id,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
-            ActionLog::logAdd($this->post['token'],$order,"sxd",$status,$order);
-            ChangeLog::logAdd(7,$idinfo['id'],$jsp,$json,$this->post['token'],$this->post);
-            $spc =[];
-            $vp = Db::name('cat_spec')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->find();
-          $str ="";
-            if($vp!=false){
-                isset($vp['id']) && $vp['id'] !== "" ? $spc['id'] = $vp['id'] : '';
-            $spc['cat_id']=$idinfo['id'];
-            $spc['exam_status']=0;
-            $spc['status']=0;
-            $spc['is_del']=0;
-            $spc['updatetime']=date("Y-m_d H:i:s");
-            $str=$vp['id'];
-                $vpn = Db::name('cat_spec')->save($spc);
-        }else{
-
-                $spc['cat_id']=$idinfo['id'];
-                $spc['exam_status']=0;
-                $spc['status']=0;
-                 $spc['creater']=$creater;
-                  $spc['createrid']=$createrid;
-                $spc['is_del']=0;
-                $spc['addtime']=date("Y-m-d H:i:d");
-                $spc['updatetime']=date("Y-m_d H:i:s");
-
-                $vpn = Db::name('cat_spec')->insert($spc,true);
-                $str=$vpn;
+        $cat_name = isset($this->post['cat_name']) && $this->post['cat_name'] !== '' ? trim($this->post['cat_name']) : '';
+        if ($cat_name == '') {
+            return error_show(1002, '参数cat_name不能为空');
         }
-            if ($vpn == false) {
-                Db::rollback();
-                return error_show(1002, "更新失败");
+        $pid = isset($this->post['pid']) && $this->post['pid'] !== '' ? intval($this->post['pid']) : '';
+        if ($pid === '') {
+            return error_show(1002, '参数pid不能为空');
+        }
+        $cat_desc = isset($this->post['cat_desc']) && $this->post['cat_desc'] !== '' ? trim($this->post['cat_desc']) : '';
+        $fund_code = isset($this->post['fund_code']) && $this->post['fund_code'] !== '' ? trim($this->post['fund_code']) : '';
+        $specs_id = isset($this->post['specs_id']) && $this->post['specs_id'] !== '' ? $this->post['specs_id'] : [];
+        if (empty($specs_id)) {
+            return error_show(1002, '参数specs_id不能为空');
+        }
+        $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(102, '创建人数据不存在');
+        }
+
+        $level = 1;
+        if ($pid !== 0) {
+            $levl = Db::name('cat')->where(['id' => $pid])->find();
+            if (empty($levl)) {
+                return error_show(1002, '未找到父级数据');
             }
-            $db = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column("specs_id");
-           if(empty($db)){
-               $db=[];
-           }
-            $sn = array_diff($specs_id,$db);
-
-            $st = array_diff($db,$specs_id);
-            if(!empty($st)){
-                $int['is_del']=1;
-                $dn = Db::name('cat_specs')->where(['specs_id'=>$st,'is_del'=>0])->save($int);
-                if ($dn==false) {
+            $level = $levl['level'] + 1;
+            $temp = $levl['search'];
+        }
+        if ($level == 1) {
+            $search = $cat_name;
+        } else {
+            $search = $temp . '_' . $cat_name;
+        }
+        $createrid = isset($user['data']['id']) ? $user['data']['id'] : '';
+        $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+        //$level = isset($this->post['level']) && $this->post['level'] !=='' ? intval($this->post['level']) :'';
+
+        $weight = isset($this->post['weight']) && $this->post['weight'] !== '' ? intval($this->post['weight']) : '0';
+        $status = isset($this->post['status']) && $this->post['status'] !== '' ? intval($this->post['status']) : '0';
+        Db::startTrans();
+        try {
+            $str = [
+                'id' => $id,
+                'cat_name' => $cat_name,
+                'pid' => $pid,
+                'level' => $level,
+                'weight' => $weight,
+                // 'status'=>$status,
+                'cat_desc' => $cat_desc,
+                'is_del' => 0,
+                'fund_code' => $fund_code,
+                'updatetime' => date('Y-m-d H:i:s'),
+                'search' => $search
+            ];
+            $strinfo = Db::name('cat')->where(['id' => $id])->save($str);
+            $temp = array_diff($str, $idinfo);
+            $json = json_encode($temp, JSON_UNESCAPED_UNICODE);
+            $jsp = json_encode($idinfo, JSON_UNESCAPED_UNICODE);
+            if ($strinfo) {
+                $order = ['order_code' => $id, 'status' => $status, 'action_remark' => '', 'action_type' => 'edit'];
+                ActionLog::logAdd($this->post['token'], $order, 'sxd', $status, $order);
+                ChangeLog::logAdd(7, $idinfo['id'], $jsp, $json, $this->post['token'], $this->post);
+                $spc = [];
+                $vp = Db::name('cat_spec')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->find();
+                $str = '';
+                if ($vp != false) {
+                    isset($vp['id']) && $vp['id'] !== '' ? $spc['id'] = $vp['id'] : '';
+                    $spc['cat_id'] = $idinfo['id'];
+                    $spc['exam_status'] = 0;
+                    $spc['status'] = 0;
+                    $spc['is_del'] = 0;
+                    $spc['updatetime'] = date('Y-m_d H:i:s');
+                    $str = $vp['id'];
+                    $vpn = Db::name('cat_spec')->save($spc);
+                } else {
+
+                    $spc['cat_id'] = $idinfo['id'];
+                    $spc['exam_status'] = 0;
+                    $spc['status'] = 0;
+                    $spc['creater'] = $creater;
+                    $spc['createrid'] = $createrid;
+                    $spc['is_del'] = 0;
+                    $spc['addtime'] = date('Y-m-d H:i:d');
+                    $spc['updatetime'] = date('Y-m_d H:i:s');
+
+                    $vpn = Db::name('cat_spec')->insert($spc, true);
+                    $str = $vpn;
+                }
+                if ($vpn == false) {
                     Db::rollback();
-                    return error_show(1002, "编辑失败");
+                    return error_show(1002, '更新失败');
                 }
-            }
-            if(!empty($sn)){
-                $vat=[];
-                foreach ($sn as $value){
-                    $item=[];
-                    $item['cat_id']=$idinfo['id'];
-                    $item['specs_id']=$value;
-                    $item['is_del']=0;
-                    $item['addtime'] = date("Y-m-d H:i:s");
-                    $vat[] = $item;
+                $db = Db::name('cat_specs')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->column('specs_id');
+                if (empty($db)) {
+                    $db = [];
                 }
-                $vp = Db::name('cat_specs')->insertAll($vat);
-                if ($vp==0) {
-                    Db::rollback();
-                    return error_show(1002, "编辑失败");
+                $sn = array_diff($specs_id, $db);
+
+                $st = array_diff($db, $specs_id);
+                if (!empty($st)) {
+                    $int['is_del'] = 1;
+                    $dn = Db::name('cat_specs')->where(['specs_id' => $st, 'is_del' => 0])->save($int);
+                    if ($dn == false) {
+                        Db::rollback();
+                        return error_show(1002, '编辑失败');
+                    }
+                }
+                if (!empty($sn)) {
+                    $vat = [];
+                    foreach ($sn as $value) {
+                        $item = [];
+                        $item['cat_id'] = $idinfo['id'];
+                        $item['specs_id'] = $value;
+                        $item['is_del'] = 0;
+                        $item['addtime'] = date('Y-m-d H:i:s');
+                        $vat[] = $item;
+                    }
+                    $vp = Db::name('cat_specs')->insertAll($vat);
+                    if ($vp == 0) {
+                        Db::rollback();
+                        return error_show(1002, '编辑失败');
+                    }
                 }
+                $itn = sear($id);
+                Db::commit();
+                return error_show(0, '编辑成功');
+            } else {
+                Db::rollback();
+                return error_show(1002, '编辑失败');
             }
-            $itn =sear($id);
-            Db::commit();
-            return error_show(0,"编辑成功");
-        }else{
+        } catch (\Exception $e) {
             Db::rollback();
-            return error_show(1002,"编辑失败");
+            return error_show(1005, $e->getMessage());
         }
-    }catch (\Exception $e){
-        Db::rollback();
-        return error_show(1005,$e->getMessage());
     }
-}
 
-    public function ratedit(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
-        $idinfo = Db::name('cat')->where(['id'=>$id])->find();
-        if($idinfo==""){
-            return error_show(1002,"未找到商品数据");
+    //更新分类利率相关
+    public function ratedit()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
+        $idinfo = Db::name('cat')->where(['id' => $id])->find();
+        if ($idinfo == '') {
+            return error_show(1002, '未找到商品数据');
         }
-        $rate = isset($this->post['rate']) && $this->post['rate'] !== "" ? floatval($this->post['rate']) : "";
-        $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== "" ? floatval($this->post['order_rate']) : "";
-        $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== "" ?  floatval($this->post['sale_rate']) : "";
-        $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== "" ?  floatval($this->post['lower_rate']) :"";
-        $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !=="" ? floatval($this->post['money_rate']):"";
-        $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !=="" ? floatval($this->post['low_rate']):"";
-        if($idinfo['pid']==0){
-            if($rate===""){
-                return error_show(1003,"参数rate不能为空");
+        $rate = isset($this->post['rate']) && $this->post['rate'] !== '' ? floatval($this->post['rate']) : '';
+        $order_rate = isset($this->post['order_rate']) && $this->post['order_rate'] !== '' ? floatval($this->post['order_rate']) : '';
+        $sale_rate = isset($this->post['sale_rate']) && $this->post['sale_rate'] !== '' ? floatval($this->post['sale_rate']) : '';
+        $lower_rate = isset($this->post['lower_rate']) && $this->post['lower_rate'] !== '' ? floatval($this->post['lower_rate']) : '';
+        $money_rate = isset($this->post['money_rate']) && $this->post['money_rate'] !== '' ? floatval($this->post['money_rate']) : '';
+        $low_rate = isset($this->post['low_rate']) && $this->post['low_rate'] !== '' ? floatval($this->post['low_rate']) : '';
+        if ($idinfo['pid'] == 0) {
+            if ($rate === '') {
+                return error_show(1003, '参数rate不能为空');
             }
-            if($order_rate===""){
-                return error_show(1003,"参数order_rate不能为空");
+            if ($order_rate === '') {
+                return error_show(1003, '参数order_rate不能为空');
             }
-            if($sale_rate===""){
-                return error_show(1003,"参数sale_rate不能为空");
+            if ($sale_rate === '') {
+                return error_show(1003, '参数sale_rate不能为空');
             }
-            if($lower_rate===""){
-                return error_show(1003,"参数lower_rate不能为空");
+            if ($lower_rate === '') {
+                return error_show(1003, '参数lower_rate不能为空');
             }
-            if($money_rate==""){
-                return error_show(1003,"参数money_rate不能为空");
+            if ($money_rate == '') {
+                return error_show(1003, '参数money_rate不能为空');
             }
-            if($low_rate==""){
-                return error_show(1003,"参数low_rate不能为空");
+            if ($low_rate == '') {
+                return error_show(1003, '参数low_rate不能为空');
             }
         }
-        $data =[
-            "id"=>$id,
-            "rate" => $rate,
-            "lower_rate"=>$lower_rate,
-            "order_rate"=>$order_rate,
-            "sale_rate"=>$sale_rate,
-            "money_rate"=>$money_rate,
-            "low_rate"=>$low_rate,
-            "is_del"=>0,
-            "updatetime"=>date("Y-m-d H:i:s"),
+        $data = [
+            'id' => $id,
+            'rate' => $rate,
+            'lower_rate' => $lower_rate,
+            'order_rate' => $order_rate,
+            'sale_rate' => $sale_rate,
+            'money_rate' => $money_rate,
+            'low_rate' => $low_rate,
+            'is_del' => 0,
+            'updatetime' => date('Y-m-d H:i:s'),
         ];
-        $strinfo = Db::name('cat')->where(['id'=>$id])->save($data);
-        if($strinfo){
-            return error_show(0,"更新成功");
-        }else{
-            return error_show(1002,"更新失败");
+        $strinfo = Db::name('cat')->where(['id' => $id])->save($data);
+        if ($strinfo) {
+            return error_show(0, '更新成功');
+        } else {
+            return error_show(1002, '更新失败');
         }
     }
 
-public function info(){
-    $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
-    if($id==""){
-        return error_show(1002,"参数id不能为空");
-    }
-    $idinfo = Db::name('cat')->where(['id'=>$id])->find();
-    if($idinfo==""){
-        return error_show(1002,"未找到数据");
-    }
-    $info = Db::name('cat_specs')->where(['cat_id'=>$idinfo['id'],'is_del'=>0])->column('specs_id');
-    $temp = Db::name('specs')->where(['id'=>$info,'is_del'=>0])->field("id,spec_name")->select();
-    //$idinfo['cat_id']=$info['cat_id'];
-    $idinfo['spec']=$temp;
-   // $idinfo['specs_id']=$info;
-    return app_show(0,"获取成功",$idinfo);
-}
-public function status(){
-    $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']):"";
-    if($id===""){
-        return error_show(1002,"参数id不能为空");
-    }
-    $stn = Db::name('cat')->where(['id'=>$id])->find();
-    if(empty($stn)){
-        return error_show(1002,"未找到商品数据");
-    }
-    $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
-    if($status===""){
-        return error_show(1002,"参数status不能为空");
-    }
-    if($status==1){
-        if($stn['rate']===""){
-            return error_show(1003,"单品修改下限未设置");
+    //详情
+    public function info()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
+        if ($id == '') {
+            return error_show(1002, '参数id不能为空');
         }
-        if($stn['order_rate']===""){
-            return error_show(1003,"预算成本利率未设置");
+        $idinfo = Db::name('cat')->where(['id' => $id])->find();
+        if ($idinfo == '') {
+            return error_show(1002, '未找到数据');
         }
-        if($stn['sale_rate']===""){
-            return error_show(1003,"分类成本售价利率未设置");
+        $info = Db::name('cat_specs')->where(['cat_id' => $idinfo['id'], 'is_del' => 0])->column('specs_id');
+        $temp = Db::name('specs')->where(['id' => $info, 'is_del' => 0])->field('id,spec_name')->select();
+        //$idinfo['cat_id']=$info['cat_id'];
+        $idinfo['spec'] = $temp;
+        // $idinfo['specs_id']=$info;
+        return app_show(0, '获取成功', $idinfo);
+    }
+
+    //启禁用
+    public function status()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
+        if ($id === '') {
+            return error_show(1002, '参数id不能为空');
         }
-        if($stn['lower_rate']===""){
-            return error_show(1003,"分类最低毛利率未设置");
+        $stn = Db::name('cat')->where(['id' => $id])->find();
+        if (empty($stn)) {
+            return error_show(1002, '未找到商品数据');
         }
-//        if($stn['money_rate']==""){
-//            return error_show(1003,"分类财务利率未设置");
+        $status = isset($this->post['status']) && $this->post['status'] !== '' ? intval($this->post['status']) : '';
+        if ($status === '') {
+            return error_show(1002, '参数status不能为空');
+        }
+        if ($status == 1) {
+            if ($stn['rate'] === '') {
+                return error_show(1003, '单品修改下限未设置');
+            }
+            if ($stn['order_rate'] === '') {
+                return error_show(1003, '预算成本利率未设置');
+            }
+            if ($stn['sale_rate'] === '') {
+                return error_show(1003, '分类成本售价利率未设置');
+            }
+            if ($stn['lower_rate'] === '') {
+                return error_show(1003, '分类最低毛利率未设置');
+            }
+//        if($stn['money_rate']==''){
+//            return error_show(1003,'分类财务利率未设置');
 //        }
-//        if($stn['low_rate']==""){
-//            return error_show(1003,"分类最低毛利未设置");
+//        if($stn['low_rate']==''){
+//            return error_show(1003,'分类最低毛利未设置');
 //        }
-//        if($stn['fund_code']==""){
-//            return error_show(1003,"分类核算码未设置");
+//        if($stn['fund_code']==''){
+//            return error_show(1003,'分类核算码未设置');
 //        }
-    }
-    if ($stn['level']==3) {
-        if($status==1){
-            $can = made($stn['id']);
-            $cat=array_column($can,'id');
-        }else{
-           $cat =$stn['id'];
         }
-       // return error_show(1002, "所在级别不能启用");
-    }
-    if($stn['level']==2 || $stn['level']==1){
-        if($status==1){
-            return error_show(1002,"所在等级不能启用");
-        }else{
-            $db= Db::name('cat')->where(['pid'=>$stn['id'],'status'=>1,'is_del'=>0])->count();
-            if($db==0){
+        if ($stn['level'] == 3) {
+            if ($status == 1) {
+                $can = made($stn['id']);
+                $cat = array_column($can, 'id');
+            } else {
                 $cat = $stn['id'];
-            }else{
-                return error_show(1002,"子级分类未禁用");
             }
+            // return error_show(1002, '所在级别不能启用');
         }
-    }
-   // $pd= $stn['status'];
-    $it=[];
-    $it['status']=$status;
-    $it['updatetime']=date("Y-m-d H:i:s");
-    $str = Db::name('cat')->where(['id'=>$cat,'is_del'=>0])->save($it);
-    if($str){
-
-                $catinfo=['cat_id'=>$id,"status"=>$status];
-                $this->addPlat($catinfo);
-            if (!empty($cat)){
-                $catinfo=['cat_id'=> $cat,"status"=>$status];
+        if ($stn['level'] == 2 || $stn['level'] == 1) {
+            if ($status == 1) {
+                return error_show(1002, '所在等级不能启用');
+            } else {
+                $db = Db::name('cat')->where(['pid' => $stn['id'], 'status' => 1, 'is_del' => 0])->count();
+                if ($db == 0) {
+                    $cat = $stn['id'];
+                } else {
+                    return error_show(1002, '子级分类未禁用');
+                }
+            }
+        }
+        // $pd= $stn['status'];
+        $it = [];
+        $it['status'] = $status;
+        $it['updatetime'] = date('Y-m-d H:i:s');
+        $str = Db::name('cat')->where(['id' => $cat, 'is_del' => 0])->save($it);
+        if ($str) {
+
+            $catinfo = ['cat_id' => $id, 'status' => $status];
+            $this->addPlat($catinfo);
+            if (!empty($cat)) {
+                $catinfo = ['cat_id' => $cat, 'status' => $status];
                 $this->addPlat($catinfo);
             }
-        return error_show(0,"状态更新成功");
-    }else{
-        return error_show(1002,"状态更新失败");
+            return error_show(0, '状态更新成功');
+        } else {
+            return error_show(1002, '状态更新失败');
+        }
     }
-}
-    public function delete(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
-        $info = Db::name('cat')->where(["is_del"=>0,'id'=>$id])->find();
-        if($info==false){
-            return error_show(1002,"未找到数据");
+
+    //删除
+    public function delete()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== '' ? intval($this->post['id']) : '';
+        $info = Db::name('cat')->where(['is_del' => 0, 'id' => $id])->find();
+        if ($info == false) {
+            return error_show(1002, '未找到数据');
         }
-        $supp= Db::name('cat')->update(['id'=>$id,'is_del'=>1,"updatetime"=>date("Y-m-d H:i:s")]);
-        if($supp){
-            return error_show(0,"删除成功");
-        }else{
-            return error_show(1002,"删除失败");
+        $supp = Db::name('cat')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
+        if ($supp) {
+            return error_show(0, '删除成功');
+        } else {
+            return error_show(1002, '删除失败');
         }
     }
-    /** 平台添加分类 **/
-    private  function  addPlat($cat){
-        $plat =Db::name("platform")->where(["platform_type"=>1,"is_del"=>0])->select()->toArray();
-        if (empty($plat)){
-            return '';
-        }
-        foreach ($plat as $value){
-               $cat['platform_id']=$value['id'];
-               $cat['addtime']=date("Y-m-d H:i:s");
-               $cat['updatetime']=date("Y-m-d H:i:s");
-               $isT = Db::name("cat_plat")->where(["cat_id"=>$cat['cat_id'],"platform_id"=>$cat['platform_id'],"is_del"=>0])->column("cat_id");
-               if($isT){
-                   $data=$cat;
-                   unset($data['cat_id']);
-                   unset($data['addtime']);
-                   Db::name("cat_plat")->where(["cat_id"=>$cat['cat_id'],"platform_id"=>$cat['platform_id'],"is_del"=>0])->update($data);
-               }else{
-                    Db::name("cat_plat")->save($cat);
-               }
+
+    //平台添加分类
+    private function addPlat($cat)
+    {
+        $plat = Db::name('platform')
+            ->field('id')
+            ->where(['platform_type' => 1, 'is_del' => 0])
+            ->select()
+            ->toArray();
+        if (empty($plat)) return false;
+
+        $date = date('Y-m-d H:i:s');
+
+        $isT = Db::name('cat_plat')
+            ->where(['cat_id' => $cat['cat_id'], 'is_del' => 0])
+            ->column('id', 'platform_id');
+
+        foreach ($plat as $value) {
+            $cat['platform_id'] = $value['id'];
+            $cat['addtime'] = $date;
+            $cat['updatetime'] = $date;
+//            $isT = Db::name('cat_plat')
+//                ->where(['cat_id' => $cat['cat_id'], 'platform_id' => $cat['platform_id'], 'is_del' => 0])
+//                ->column('cat_id');
+            if (isset($isT[$cat['platform_id']])) {
+                $data = $cat;
+                unset($data['cat_id']);
+                unset($data['addtime']);
+                Db::name('cat_plat')
+                    ->where('id', $isT[$cat['platform_id']])
+                    ->update($data);
+            } else  Db::name('cat_plat')->save($cat);
+
 
         }
 
+        return true;
+
     }
 }

+ 13 - 10
app/admin/controller/DataGroup.php

@@ -14,7 +14,7 @@ class DataGroup extends Base
     //用户组列表
     public function getDataGroupList()
     {
-        $param = $this->request->filter('trim')->only(['page' => 1, 'size' => 10, 'status' => '', 'title' => '', 'nickname' => '', 'type' => '']);
+        $param = $this->request->filter('trim')->only(['page' => 1, 'size' => 10, 'status' => '', 'title' => '', 'nickname' => '', 'type' => '', 'supplierNo' => '']);
 
         $db = new DataGroupModel();
 
@@ -39,13 +39,14 @@ class DataGroup extends Base
         if ($param['status'] != '') $rs->where('a.status', $param['status']);
         if ($param['title'] != '') $rs->whereLike('a.title', '%' . $param['title'] . '%');
         if ($param['nickname'] != '') {
-        	$a =$param['nickname'];
-		    $rs->where( "a.id","IN",function ($query) use($a){
-			    $query->name("data_group_userid")->alias("m")->leftJoin('depart_user f', 'f.uid=m.uid AND f.is_del=0')
-			          ->where('f.nickname',"like","%$a%")->where("m.is_del","=",0)->field("m.data_group_id");
-        });
+            $a = $param['nickname'];
+            $rs->where("a.id", "IN", function ($query) use ($a) {
+                $query->name("data_group_userid")->alias("m")->leftJoin('depart_user f', 'f.uid=m.uid AND f.is_del=0')
+                    ->where('f.nickname', "like", "%$a%")->where("m.is_del", "=", 0)->field("m.data_group_id");
+            });
         }
         if ($param['type'] != '') $rs->where('a.type', $param['type']);
+        if ($param['supplierNo'] != '') $rs->where('a.supplierNo', '%' . $param['supplierNo'], '%');
 
         $count = $rs->count('a.id');
 
@@ -64,9 +65,10 @@ class DataGroup extends Base
     public function addDataGroup()
     {
 
-        $param = $this->request->filter('trim')->only(['title', 'uids', 'type', 'remark' => '']);
+        $param = $this->request->filter('trim')->only(['title', 'uids', 'type', 'remark' => '', 'supplierNo']);
 
         $val = Validate::rule([
+            'supplierNo|公司名称' => 'require|length:18',
             'title|用户组名称' => 'require|max:100',
             'uids|组成员' => 'require|array|max:100',
             'type|共享类型' => 'require|number|in:' . DataGroupModel::$type_可编辑 . ',' . DataGroupModel::$type_只读 . ',' . DataGroupModel::$type_不共享,
@@ -80,6 +82,7 @@ class DataGroup extends Base
 
             //添加用户组
             $group_id = Db::name('data_group')->insertGetId([
+                'supplierNo' => $param['supplierNo'],
                 'title' => $param['title'],
                 'type' => $param['type'],
                 'remark' => $param['remark'],
@@ -280,12 +283,12 @@ class DataGroup extends Base
 
         $db = new DataGroupModel();
 
-        $rs = $db
-            ->alias('a')
+//        $rs = $db
+//            ->alias('a')
 //            ->leftJoin('data_group_userid b', 'b.data_group_id=a.id AND b.is_del=' . DataGroupModel::$delete_正常)
 //            ->leftJoin('depart_user u', 'u.uid=b.uid AND u.is_del=0')
 //            ->group('a.id')
-            ->where('a.is_del', DataGroupModel::$delete_正常);
+//            ->where('a.is_del', DataGroupModel::$delete_正常);
 
 //        $val = Validate::rule([
 //            'status|状态' => 'number|in:' . DataGroupModel::$status_启用 . ',' . DataGroupModel::$status_禁用,

+ 208 - 46
app/admin/controller/Express.php

@@ -2,72 +2,234 @@
 
 
 namespace app\admin\controller;
+
 use app\admin\model\ActionLog;
 use think\App;
+use think\Exception;
 use think\facade\Db;
+use think\facade\Validate;
 
 //物流信息
 class Express extends Base
 {
 
     //获取快递公司列表
-    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;
-        $type = isset($this->post['type']) &&$this->post['type'] !=="" ? intval($this->post['type']):'0';
-        $where = [["type","=",$type]];
-        $name =  isset($this->post['name']) &&$this->post['name'] !="" ? trim($this->post['name']):'';
-        if($name!=''){
-            $where[]=["name|shortName","like","%{$name}%"];
-        }
-        $plat_type =  isset($this->post['plat_type']) &&$this->post['plat_type'] !="" ? trim($this->post['plat_type']):'';
-        if($plat_type!=''){
-            $where[]=["plat_type","=",$plat_type];
-        }
-        $count = Db::name("express")->where($where)->count();
-        $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
-        $list= Db::name("express")->where($where)->field('id,type,comTypeName,name,plat_type,shortName,shortNameEn,shortNumber,canOrder')
-            ->page($page,$size)->select();
-        return app_show(0,'获取成功',['list'=>$list,"count"=>$count]);
+    public function list()
+    {
+
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'type' => 0, 'name' => '', 'plat_type' => ''], 'post', 'trim');
+        $where = [['type', '=', $param['type']]];
+        if ($param['name'] != '') $where[] = ['name|shortName', 'like', '%' . $param['name'] . '%'];
+        if ($param['plat_type'] != '') $where[] = ['plat_type', '=', $param['plat_type']];
+
+        $count = Db::name('express')
+            ->where($where)
+            ->count('id');
+
+        $list = Db::name("express")
+            ->field('id,type,comTypeName,name,plat_type,shortName,shortNameEn,shortNumber,canOrder')
+            ->where($where)
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+        return app_show(0, '获取成功', ['list' => $list, 'count' => $count]);
     }
 
     //快递公司启禁用
-    public function  SetUse(){
-        $id = isset($this->post['id']) &&$this->post['id'] !="" ? intval($this->post['id']):'';
-        if($id==''){
-            return error_show(1004,"参数id不能为空");
-        }
-        $express = Db::name("express")->where(["id"=>$id])->find();
-        if(empty($express)){
-            return error_show(1004,"未找到数据");
+    public function SetUse()
+    {
+        $param = $this->request->only(['id' => 0], 'post', 'trim');
+
+        $express = Db::name('express')
+            ->field('id,canOrder')
+            ->where(['id' => $param['id']])
+            ->findOrEmpty();
+        if (empty($express)) return error_show(1004, '未找到数据');
+
+        Db::startTrans();
+
+        try {
+
+            $express['canOrder'] = $express['canOrder'] == 0 ? 1 : 0;
+
+            $up = Db::name('express')
+                ->save($express);
+
+            $orde = ['order_code' => $param['id'], 'status' => 0, 'action_remark' => '', 'action_type' => 'edit'];
+            ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, 'express', 0, $orde);
+            Db::commit();
+            return $up ? app_show(0, '更新成功') : error_show(1005, '更新失败');
+        } catch (Exception $exception) {
+            Db::rollback();
+            return json_show(1004, '更新失败,' . $exception->getMessage());
         }
-        $express['canOrder'] = $express['canOrder']==0 ?1:0;
-        $up = Db::name("express")->save($express);
-        $orde = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
-        ActionLog::logAdd($this->post['token'],$orde,'express',0,$orde);
-        return $up?app_show(0,"更新成功"):error_show(1005,"更新失败");
     }
 
     //获取可用的快递公司列表
-    public function GetExpress(){
-        $type = isset($this->post['type']) &&$this->post['type'] !=="" ? intval($this->post['type']):'';
-        $where[] = ['canOrder',"=",1];
-        if($type===0){
-            $where[]=["type","=",$type];
+    public function GetExpress()
+    {
+        $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : '';
+        $where[] = ['canOrder', "=", 1];
+        if ($type === 0) {
+            $where[] = ["type", "=", $type];
         }
-        $order_source = isset($this->post['order_source']) &&$this->post['order_source'] !=="" ? intval($this->post['order_source']):'1';
+        $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : '1';
 
-            $plat_type=1;
-        if( $order_source==5){
-              $plat_type=2;
+        $plat_type = 1;
+        if ($order_source == 5) {
+            $plat_type = 2;
         }
-         $where[]=["plat_type","=",$plat_type];
-        $name =  isset($this->post['name']) &&$this->post['name'] !="" ? trim($this->post['name']):'';
-        if($name!=''){
-            $where[]=["name|shortName","like","%{$name}%"];
+        $where[] = ["plat_type", "=", $plat_type];
+        $name = isset($this->post['name']) && $this->post['name'] != "" ? trim($this->post['name']) : '';
+        if ($name != '') {
+            $where[] = ["name|shortName", "like", "%{$name}%"];
         }
-        $list= Db::name("express")->where($where)->field('id,type,comTypeName,name,shortName,shortNameEn,shortNumber,canOrder')
+        $list = Db::name("express")->where($where)->field('id,type,comTypeName,name,shortName,shortNameEn,shortNumber,canOrder')
             ->select();
-        return app_show(0,'获取成功',$list);
+        return app_show(0, '获取成功', $list);
+    }
+
+    //获取公司关联的快递公司
+    public function getSupplierExpress()
+    {
+
+        $param = $this->request->only(['page'=>1,'size'=>10, 'key_supplierNo'=>''], 'post', 'trim');
+
+        $where=[['a.is_del','=',0]];
+        if($param['key_supplierNo']!='') $where[]=['a.supplierNo','like','%'.$param['key_supplierNo'].'%'];
+
+        $count = Db::name('express_supplier')
+            ->alias('a')
+            ->leftJoin('supplier b','b.code=a.supplierNo')
+            ->where($where)
+            ->count('a.id');
+
+        $rs = Db::name('express_supplier')
+            ->field('a.id,a.supplierNo,a.addtime,a.status,a.express_ids,b.name supplierName')
+            ->alias('a')
+            ->where($where)
+            ->leftJoin('supplier b','b.code=a.supplierNo')
+            ->order('a.id','desc')
+            ->page($param['page'],$param['size'])
+            ->append(['express_list'])
+            ->withAttr('express_list',function($val,$da){
+                return Db::name('express')
+                    ->field('id,name')
+                    ->whereIn('id',$da['express_ids'])
+                    ->order('id','desc')
+                    ->select()
+                    ->toArray();
+            })
+            ->select()
+            ->toArray();
+
+        return json_show(0, '操作成功',['count'=>$count,'list'=>$rs]);
+    }
+
+    //详情公司关联的快递公司
+    public function infoSupplierExpress()
+    {
+        $id = $this->request->param('id/d', 0, 'trim');
+
+        $rs = Db::name('express_supplier')
+            ->field('a.*,b.name supplierName')
+            ->alias('a')
+            ->where(['a.id'=>$id,'a.is_del'=>0])
+            ->leftJoin('supplier b','b.code=a.supplierNo')
+            ->withAttr('express_ids',function($val,$da){
+                return explode(',',$val);
+            })
+            ->findOrEmpty();
+
+        return $rs ? json_show(0, '获取详情成功',$rs) : json_show(1004, '当前记录不存在');
+
+    }
+
+    //编辑公司关联的快递公司
+    public function setSupplierExpress()
+    {
+
+        $param = $this->request->only(['express_ids', 'supplierNo'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'express_ids|快递公司id集合' => 'require|array|max:100',
+            'supplierNo|公司编码' => 'require|length:18'
+        ]);
+
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        $tmp = Db::name('express_supplier')
+            ->field('id')
+            ->where('supplierNo', $param['supplierNo'])
+            ->findOrEmpty();
+
+        $date = date('Y-m-d H:i:s');
+        if ($tmp) {
+            $rs = Db::name('express_supplier')
+                ->where('supplierNo', $param['supplierNo'])
+                ->update([
+                    'express_ids' => implode(',',$param['express_ids']),
+                    'updatetime' => $date
+                ]);
+        } else {
+            $rs = Db::name('express_supplier')
+                ->where('supplierNo', $param['supplierNo'])
+                ->insert([
+                    'supplierNo' => $param['supplierNo'],
+                    'express_ids' => implode(',',$param['express_ids']),
+                    'addtime' => $date,
+                    'updatetime' => $date
+                ]);
+        }
+
+        return $rs ? json_show(0, '操作成功') : json_show(1004, '操作失败');
+    }
+
+    //启禁用公司关联的快递公司
+    public function statusSupplierExpress()
+    {
+        $param = $this->request->only(['id', 'status'], 'post', 'trim');
+        $val = Validate::rule([
+            'id' => 'require|number|gt:0',
+            'status|状态' => 'require|number|in:0,1'
+        ]);
+        if (!$val->check($param)) return json_show(1004, $val->getError());
+
+        $tmp = Db::name('express_supplier')
+            ->field('id,status')
+            ->where('id', $param['id'])
+            ->findOrEmpty();
+
+        if (empty($tmp)) return json_show(1004, '该记录不存在');
+        if ($tmp['status'] == $param['status']) return json_show(1005, '重复操作');
+
+        $rs = Db::name('express_supplier')
+            ->where('id', $param['id'])
+            ->where('status', '<>', $param['status'])
+            ->update([
+                'status' => $param['status'],
+                'updatetime' => date('Y-m-d H:i:s')
+            ]);
+
+        return $rs ? json_show(0, '操作成功') : json_show(1004, '操作失败');
+
+    }
+
+    //删除公司关联的快递公司
+    public function deleteSupplierExpress()
+    {
+        $id = $this->request->param('id/d', 0, 'trim');
+
+        $rs = Db::name('express_supplier')
+            ->where(['id' => $id, 'is_del' => 0])
+            ->update([
+                'is_del' => 1,
+                'updatetime' => date('Y-m-d H:i:s')
+            ]);
+
+        return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败,当前记录不存在');
+
     }
+
+
 }

+ 173 - 174
app/admin/controller/Resigninfo.php

@@ -19,193 +19,188 @@ class Resigninfo extends Base
     {
         parent::__construct($app);
     }
-    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 =[['is_del',"=",0]];
-//       $resign_depart_id = isset($this->post['resign_depart_id']) && $this->post['resign_depart_id'] !== "" ? intval($this->post['resign_depart_id']) : "";
-//       if ($resign_depart_id !== "") {
-//            $where = ["resign_depart_id"=>$resign_depart_id];
-//        }
-//        $hand_depart_id = isset($this->post['hand_depart_id']) && $this->post['hand_depart_id'] !== "" ? intval($this->post['hand_depart_id']) : "";
-//        if ($hand_depart_id !== "") {
-//            $where = ["hand_depart_id"=>$hand_depart_id];
-//        }
-        $status =isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
-        if ($status !== "") {
-            $where[]= ["status",'=',$status];
-        }
-        $resign_uid = isset($this->post['resign_uid']) && $this->post['resign_uid'] !== "" ? intval($this->post['resign_uid']) : "";
-        if ($resign_uid !== "") {
-            //$where = ["resign_uid"=>$resign_uid];
-            $where[]= ["resign_uid",'=',$resign_uid];
-        }
-        $hand_uid = isset($this->post['hand_uid']) && $this->post['hand_uid'] !== "" ? intval($this->post['hand_uid']) : "";
-        if ($hand_uid !== "") {
-           // $where = ["hand_uid"=>$hand_uid];
-            $where[]= ["hand_uid",'=',$hand_uid];
-        }
-        $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
-        if ($start !="") {
-           // $where = ["addtime"=>Db::raw(">= '{$start}'")];
-            $where[]= ["addtime",'>=',$start];
-        }
-        $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
-        if($end !=""){
-           // $where = ["addtime"=>Db::raw("<= '{$end}'")];
-            $where[]= ["addtime",'<=',$end];
-        }
+
+    //列表
+    public function list()
+    {
+
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => '', 'resign_uid' => '', 'hand_uid' => '', 'start' => '', 'end' => '', 'supplierNo' => ''], 'post', 'trim');
+        $where = [['is_del', "=", 0]];
+        if ($param['status'] !== '') $where[] = ['status', '=', $param['status']];
+        if ($param['resign_uid'] !== '') $where[] = ['resign_uid', '=', $param['resign_uid']];
+        if ($param['hand_uid'] !== '') $where[] = ['hand_uid', '=', $param['hand_uid']];
+        if ($param['start'] != '') $where[] = ['addtime', '>=', $param['start']];
+        if ($param['end'] != '') $where[] = ['addtime', '<=', $param['end']];
+        if ($param['supplierNo'] != '') $where[] = ['supplierNo', 'like', '%' . $param['supplierNo'] . '%'];
 
 //        $role = $this->checkDataShare();
 //        if (!empty($role[DataGroupModel::$type_全部])) $where[] = ["hand_uid", "in", $role[DataGroupModel::$type_全部]];
-          $role = $this->checkDataShare();
-        $hand = resign_hand_user($this->uid,0);
+        $role = $this->checkDataShare();
+        $hand = resign_hand_user($this->uid, 0);
         if (!empty($role[DataGroupModel::$type_全部])) {
-        	$arr= array_unique(array_merge($hand,$role[DataGroupModel::$type_全部]));
-			$where[] = ['hand_uid|resign_uid', 'in',$arr];
+            $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
+            $where[] = ['hand_uid|resign_uid', 'in', $arr];
         }
 
-        $count = Db::name('resign_info')->where($where)->count();
-        $total = ceil($count/$size);
-        $page = $page >= $total ? $total : $page;
+        $count = Db::name('resign_info')
+            ->where($where)
+            ->count('id');
+
         $list = Db::name('resign_info')
             ->where($where)
             ->order("addtime desc")
-            ->page($page,$size)
+            ->page($param['page'], $param['size'])
             ->append(['is_allow_update'])
             ->withAttr('is_allow_update', function ($val, $data) use ($role) {
                 return (in_array($this->roleid, [1, 33]) || in_array($data['hand_uid'], $role[DataGroupModel::$type_可编辑])) ? 1 : 0; //是否具有编辑权限
             })
             ->select()
             ->toArray();
-        return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
+        return app_show(0, "获取成功", ['list' => $list, 'count' => $count]);
     }
-    public function create(){
-        $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
-        $condition=[];
-        $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !==""? trim($this->post['resign_uid']) :"";
-        if($resign_id==""){
-            return error_show(1002,"离职人id不能为空");
+
+    //创建
+    public function create()
+    {
+        $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
+        $condition = [];
+        $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !== "" ? trim($this->post['resign_uid']) : "";
+        if ($resign_id == "") {
+            return error_show(1002, "离职人id不能为空");
         }
-        $condition['id']=$resign_id;
-        $resign_uid=GetInfoById($token,$condition);
-        if(empty($resign_uid)||$resign_uid['code']!=0){
-            return error_show(1002,"离职人员信息不存在");
+        $condition['id'] = $resign_id;
+        $resign_uid = GetInfoById($token, $condition);
+        if (empty($resign_uid) || $resign_uid['code'] != 0) {
+            return error_show(1002, "离职人员信息不存在");
         }
-        $ri= isset($resign_uid["data"]['nickname']) ?  $resign_uid["data"]['nickname'] : "";
-        $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !==""? trim($this->post['hand_uid']) :"";
-        if($hand_id==""){
-            return error_show(1002,"交接人名称不能为空");
+        $ri = isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
+        $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !== "" ? trim($this->post['hand_uid']) : "";
+        if ($hand_id == "") {
+            return error_show(1002, "交接人名称不能为空");
         }
-        $condition['id']=$hand_id;
-        $hand_uid = GetInfoById($token,$condition);
-        if(empty($hand_uid)||$hand_uid['code']!=0){
-            return error_show(1002,"交接人员信息不存在");
+        $condition['id'] = $hand_id;
+        $hand_uid = GetInfoById($token, $condition);
+        if (empty($hand_uid) || $hand_uid['code'] != 0) {
+            return error_show(1002, "交接人员信息不存在");
         }
-        $rp= isset($hand_uid["data"]['nickname']) ?  $hand_uid["data"]['nickname'] : "";
-        $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
-        if($resign_date==""){
-            return error_show(1005,'离职日期不能为空');
+        $rp = isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
+        $resign_date = isset($this->post['resign_date']) && $this->post['resign_date'] !== "" ? $this->post['resign_date'] : date("Y-m-d H:i:s");
+        if ($resign_date == "") {
+            return error_show(1005, '离职日期不能为空');
         }
-        $expire_date = isset($this->post['expire_date']) && $this->post['expire_date']!== "" ?
-            $this->post['expire_date']:date("Y-m-d H:i:s");
-        if($expire_date==""){
-            return error_show(1005,'生效时间不能为空');
+        $expire_date = isset($this->post['expire_date']) && $this->post['expire_date'] !== "" ? $this->post['expire_date'] : date("Y-m-d H:i:s");
+        if ($expire_date == "") {
+            return error_show(1005, '生效时间不能为空');
         }
-        $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
+
+        $supplierNo = isset($this->post['resign_supplierNo']) && $this->post['resign_supplierNo'] !== '' ? $this->post['resign_supplierNo'] : '';
+        if ($supplierNo == '') return error_show(1005, '公司编码不能为空');
+
+        $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !== "" ? trim($this->post['is_hand']) : "0";
         $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
         $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? intval($this->post['remark']) : "";
-        $data=[
-            "resign_uid"=>$resign_id,
-            "hand_uid"=>$hand_id,
+        $data = [
+            'supplierNo' => $supplierNo,
+            "resign_uid" => $resign_id,
+            "hand_uid" => $hand_id,
 //            "resign_depart_id"=>$resign_depart_id,
 //            "hand_depart_id"=>$hand_depart_id,
-            "resign_name"=>$ri,
-            "hand_name"=>$rp,
-            "resign_date"=> $resign_date,
-            "expire_date"=>$expire_date,
-            "is_hand"=>$is_hand,
-            "apply_id"=>$this->uid,
-            "apply_name"=>$this->uname,
-            "status"=>$status,
-            "remark"=>$remark,
-            "is_del"=>0,
-            "addtime"=>date("Y-m-d H:i:s"),
-            "updatetime"=>date("Y-m-d H:i:s"),
+            "resign_name" => $ri,
+            "hand_name" => $rp,
+            "resign_date" => $resign_date,
+            "expire_date" => $expire_date,
+            "is_hand" => $is_hand,
+            "apply_id" => $this->uid,
+            "apply_name" => $this->uname,
+            "status" => $status,
+            "remark" => $remark,
+            "is_del" => 0,
+            "addtime" => date("Y-m-d H:i:s"),
+            "updatetime" => date("Y-m-d H:i:s"),
         ];
         $in = Db::name('resign_info')->insertGetId($data);
-        $stn = ["order_code"=>'',"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
-        ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$status,$stn);
+        $stn = ["order_code" => '', "status" => $status, "action_remark" => '', "action_type" => "create"];
+        ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "LZJJ", $status, $stn);
 
-        $process=["order_code"=>'',"order_id"=>$in,"order_status"=>$status,"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
-        ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
-        return $in ? error_show(0,"添加成功") : error_show(1002,"添加失败");
+        $process = ["order_code" => '', "order_id" => $in, "order_status" => $status, "order_type" => 'LZJJ', "before_status" => 0, 'holder_id' => $this->uid];
+        ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
+        return $in ? error_show(0, "添加成功") : error_show(1002, "添加失败");
     }
-    public function selec(){
-        $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']) :"";
-        if($id==""){
-            return error_show(1002,"离职人员信息不存在");
-        }
-        $rid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
-            return app_show(0,"获取成功",$rid);
+
+    //详情
+    public function selec()
+    {
+        $id = $this->request->post('id/d', 0, 'trim');
+        if ($id == 0) return error_show(1002, "离职人员信息不存在");
+
+        $rid = Db::name('resign_info')
+            ->where(['is_del' => 0, 'id' => $id])
+            ->findOrEmpty();
+        return app_show(0, "获取成功", $rid);
     }
-    public function edit(){
-        $condition=[];
-        $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
-      $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
-      $eid = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->find();
-      if($eid==""){
-          return error_show(1002,"离职信息不存在");
-      }
-      $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !=="" ? trim($this->post['resign_uid']):"";
-      if($resign_id==""){
-          return error_show(1002,"离职人员ID不能为空");
-      }
-      $condition['id']=$resign_id;
-      $resign_uid=GetInfoById($token,$condition);
-      if(empty($resign_uid)||$resign_uid['code']!=0){
-          return error_show(1002,"离职人员信息不存在");
-      }
-        $rr= isset($resign_uid["data"]['nickname']) ?  $resign_uid["data"]['nickname'] : "";
 
-      $resign_date = isset($this->post['resign_date']) && $this->post['resign_date']!== "" ? $this->post['resign_date']:date("Y-m-d H:i:s");
-      if($resign_date==""){
-          return error_show(1005,'离职日期不能为空');
+    //编辑
+    public function edit()
+    {
+        $condition = [];
+        $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
+        $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
+        $eid = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->find();
+        if ($eid == "") {
+            return error_show(1002, "离职信息不存在");
+        }
+        $resign_id = isset($this->post['resign_uid']) && $this->post['resign_uid'] !== "" ? trim($this->post['resign_uid']) : "";
+        if ($resign_id == "") {
+            return error_show(1002, "离职人员ID不能为空");
+        }
+        $condition['id'] = $resign_id;
+        $resign_uid = GetInfoById($token, $condition);
+        if (empty($resign_uid) || $resign_uid['code'] != 0) {
+            return error_show(1002, "离职人员信息不存在");
+        }
+        $rr = isset($resign_uid["data"]['nickname']) ? $resign_uid["data"]['nickname'] : "";
+
+        $resign_date = isset($this->post['resign_date']) && $this->post['resign_date'] !== "" ? $this->post['resign_date'] : date("Y-m-d H:i:s");
+        if ($resign_date == "") {
+            return error_show(1005, '离职日期不能为空');
         }
-      $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !=="" ? trim($this->post['hand_uid']) :"";
-      if($hand_id=="") {
-          return error_show(1002, "交接人员id不能为空");
-      }
-      $condition['id']=$hand_id;
-      $hand_uid = GetInfoById($token,$condition);
-        if(empty($hand_uid)||$hand_uid['code']!=0){
-            return error_show(1002,"交接人员信息不存在");
+        $hand_id = isset($this->post['hand_uid']) && $this->post['hand_uid'] !== "" ? trim($this->post['hand_uid']) : "";
+        if ($hand_id == "") {
+            return error_show(1002, "交接人员id不能为空");
+        }
+        $condition['id'] = $hand_id;
+        $hand_uid = GetInfoById($token, $condition);
+        if (empty($hand_uid) || $hand_uid['code'] != 0) {
+            return error_show(1002, "交接人员信息不存在");
+        }
+        $r = isset($hand_uid["data"]['nickname']) ? $hand_uid["data"]['nickname'] : "";
+        $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !== "" ? trim($this->post['is_hand']) : "0";
+        $str = [
+            "hand_name" => $r,
+            "resign_name" => $rr,
+            "id" => $id,
+            "resign_uid" => $resign_id,
+            "hand_uid" => $hand_id,
+            "is_hand" => $is_hand,
+            "resign_date" => date('Y-m-d H:i:s'),
+            "is_del" => 0,
+            "updatetime" => date('Y-m-d H:i:s'),
+        ];
+        $it = Db::name('resign_info')->where(['is_del' => 0, 'id' => $id])->save($str);
+        if ($it) {
+            $stn = ["order_code" => $id, "status" => 0, "action_remark" => '', "action_type" => "edit"];
+            ActionLog::logAdd($this->post['token'], $stn, "LZJJ", 0, $stn);
+            $process = ["order_code" => '', "order_id" => $id, "order_status" => $eid['status'], "order_type" => 'LZJJ', "before_status" => 0, 'holder_id' => $this->uid];
+            ProcessOrder::AddProcess(['id' => $hand_id, 'nickname' => $r], $process);
+            return error_show(0, "编辑成功");
+        } else {
+            return error_show(1002, "编辑失败");
         }
-        $r= isset($hand_uid["data"]['nickname']) ?  $hand_uid["data"]['nickname'] : "";
-        $is_hand = isset($this->post['is_hand']) && $this->post['is_hand'] !=="" ? trim($this->post['is_hand']):"0";
-      $str=[
-          "hand_name"=>$r,
-          "resign_name"=>$rr,
-          "id"=>$id,
-          "resign_uid"=>$resign_id,
-          "hand_uid"=>$hand_id,
-          "is_hand"=>$is_hand,
-          "resign_date"=>date('Y-m-d H:i:s'),
-          "is_del"=>0,
-          "updatetime"=>date('Y-m-d H:i:s'),
-      ];
-      $it = Db::name('resign_info')->where(['is_del'=>0,'id'=>$id])->save($str);
-      if($it){
-          $stn = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
-          ActionLog::logAdd($this->post['token'],$stn,"LZJJ",0,$stn);
-          $process=["order_code"=>'',"order_id"=>$id,"order_status"=>$eid['status'],"order_type"=>'LZJJ',"before_status"=>0, 'holder_id' => $this->uid];
-          ProcessOrder::AddProcess(['id'=>$hand_id,'nickname'=>$r],$process);
-          return error_show(0,"编辑成功");
-      }else{
-          return error_show(1002,"编辑失败");
-      }
     }
-    public function del(){
+
+    //删除
+    public function del()
+    {
 
         $id = isset($this->post['id']) && $this->post['id'] !== "" ? $this->post['id'] : "";
 
@@ -256,33 +251,37 @@ class Resigninfo extends Base
 //            return error_show(1002,"删除失败");
 //        }
     }
-    public function statu(){
-        $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
-        if($id==""){
-            return error_show(1002,"离职人id不能为空");
+
+    //启禁用
+    public function statu()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
+        if ($id == "") {
+            return error_show(1002, "离职人id不能为空");
         }
-        $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
-        $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
-        if($stauts===""){
-            return error_show(1002,"状态不能为空");
+        $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
+        $stauts = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
+        if ($stauts === "") {
+            return error_show(1002, "状态不能为空");
         }
-        $st = Db::name('resign_info')->where(['id'=>$id,"is_del"=>0])->find();
-        if(empty($st)){
-            return error_show(1002,"离职人员信息未找到");
+        $st = Db::name('resign_info')->where(['id' => $id, "is_del" => 0])->find();
+        if (empty($st)) {
+            return error_show(1002, "离职人员信息未找到");
         }
-        $tn =$st['status'];
-        $st['remark']=$remark;
-        $st['status']=$stauts==3 && strtotime($st['expire_date'])<=time() ? 4 :$stauts;
-        $st['updatetime']= date('Y-m-d H:i:s');
+        $tn = $st['status'];
+        $st['remark'] = $remark;
+        $st['status'] = $stauts == 3 && strtotime($st['expire_date']) <= time() ? 4 : $stauts;
+        $st['updatetime'] = date('Y-m-d H:i:s');
         $sv = Db::name('resign_info')->save($st);
-        if($sv){
-            $stn = ["order_code"=>$id,"status"=>$tn,"action_remark"=>'',"action_type"=>"edit"];
-            ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$stn,"LZJJ",$stauts,$st);
+        if ($sv) {
+            $stn = ["order_code" => $id, "status" => $tn, "action_remark" => '', "action_type" => "edit"];
+            ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $stn, "LZJJ", $stauts, $st);
             $process = ["order_code" => '', "order_id" => $id, "order_status" => $st['status'], "order_type" => 'LZJJ', "before_status" => $tn, 'holder_id' => $this->uid];
-            ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
-            return error_show(0,"状态更新成功");
-        }else{
-            return error_show(1002,"状态更新失败");
+            ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
+            return error_show(0, "状态更新成功");
+        } else {
+            return error_show(1002, "状态更新失败");
         }
     }
+
 }

+ 5 - 0
app/admin/route/app.php

@@ -254,6 +254,11 @@ Route::rule('action_process_all', 'admin/ActionProcess/getAll');
 Route::rule("expresslist", "admin/Express/list");
 Route::rule("expressuse", "admin/Express/SetUse");
 Route::rule("express", "admin/Express/GetExpress");
+Route::rule('getSupplierExpress', 'admin/Express/getSupplierExpress');
+Route::rule('setSupplierExpress', 'admin/Express/setSupplierExpress');
+Route::rule('statusSupplierExpress', 'admin/Express/statusSupplierExpress');
+Route::rule('infoSupplierExpress', 'admin/Express/infoSupplierExpress');
+Route::rule('deleteSupplierExpress', 'admin/Express/deleteSupplierExpress');
 
 Route::rule('catlist', 'admin/Cat/list');
 Route::rule('catplist', 'admin/Cat/plist');