Ver Fonte

细节优化

wufeng há 2 anos atrás
pai
commit
bc126111a0
4 ficheiros alterados com 148 adições e 51 exclusões
  1. 17 3
      app/common.php
  2. 53 3
      app/controller/CompanyItem.php
  3. 76 45
      app/controller/Headquarters.php
  4. 2 0
      route/app.php

+ 17 - 3
app/common.php

@@ -79,9 +79,23 @@ if(!function_exists("checkToken")){
 	}
 }
 
-if(!function_exists('GetPart')){
-    function GetPart(int $item_id=0){
-        return '';
+//获取部门的层级名称
+if (!function_exists('get_part')) {
+    function get_part(int $item_id = 0,array $data=[])
+    {
+        $db = Db::name("company_item")
+            ->field('id,name,pid')
+            ->where(['id' => $item_id, 'is_del' => 0])
+            ->findOrEmpty();
+
+        if (empty($db)) return [];
+
+//        $tem=[];
+//        $tem['id']=$db['id'];
+//        $tem['name']=$db['name'];
+        array_unshift($data, $db);
+        if ($db['pid'] == 0) return $data;
+        else  return get_part($db['pid'], $data);
     }
 }
 

+ 53 - 3
app/controller/CompanyItem.php

@@ -220,10 +220,10 @@ class CompanyItem extends BaseController
     //查询,层级列表
     public function query()
     {
-        $param = $this->request->filter('trim')->only(['companyNo'=>''],'post');
+        $param = $this->request->filter('trim')->only(['companyNo' => ''], 'post');
 
-        $where=[['pid','=',0],['is_del','=',0]];
-        if($param['companyNo'] != '') $where[]=['companyNo','=',$param['companyNo']];
+        $where = [['pid', '=', 0], ['is_del', '=', 0]];
+        if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
 
         //所有已经存在的公司
         $companyNo = Db::name('company_item')
@@ -312,5 +312,55 @@ class CompanyItem extends BaseController
 
     }
 
+    //获取部门层级列表
+    public function getPart()
+    {
+        $itemids = $this->request->filter('trim')->post('itemid');
+
+        if (is_array($itemids)) {
+            $tmp = [];
+            foreach ($itemids as $itemid) {
+                if (!isset($tmp[$itemid])) $tmp[$itemid] = get_part($itemid);
+            }
+            return json_show(0, '获取成功', $tmp);
+        } else return json_show(0, '获取成功', get_part($itemids));
+    }
+
+    //获取某个用户所属部门名称
+    //$uid int 用户id
+    //$cache bool 是否启用缓存,(默认启用,不启用的话直接从数据库查)
+    //$get_tops bool 是否获取多级部门,例如 万宇恒通/采购部/仓储物流,默认不获取
+    public function getCompanyNameByUid()
+    {
+        $param = $this->request->only(['uid' => '', 'get_tops' => 1], 'post', 'trim');
+
+        $itemids = Db::name('account_item')
+            ->whereIn('account_id', $param['uid'])
+            ->column('itemid', 'account_id');
+        $res = $item_tmp = [];
+
+        //获取所有部门id对应的部门名称
+        foreach ($itemids as $itemid) {
+            if (!isset($item_tmp[$itemid])) {
+                if ($param['get_tops']==1) $tmp = get_part($itemid);
+                else $tmp = Db::name('company_item')
+                    ->field('id,name,pid')
+                    ->where(['is_del' => 0, 'id' => $itemid])
+                    ->select()
+                    ->toArray();//为了跟上面保持数据一致
+
+                $item_tmp[$itemid] = implode('/', array_column($tmp, 'name'));
+            }
+        }
+
+        if (is_numeric($param['uid'])) $param['uid'] = [$param['uid']];
+        foreach ($param['uid'] as $uid) {
+            if(!isset($res[$uid])) $res[$uid] = $item_tmp[$itemids[$uid]] ?? '';
+        }
+
+        return json_show(0, '获取成功', $res);
+
+    }
+
 
 }

+ 76 - 45
app/controller/Headquarters.php

@@ -347,7 +347,7 @@ class Headquarters extends BaseController
     }
 
 
-    //业务企业
+    //业务公司
     public function bGetList()
     {
         $param = $this->request->only([
@@ -475,13 +475,6 @@ class Headquarters extends BaseController
                 ->findOrEmpty();
             if (empty($info)) throw new Exception('未找到数据');
 
-            $tmp = Db::name('business')
-                ->field('id')
-                ->where(['company' => $param['company'], 'is_del' => 0])
-                ->where('id', '<>', $param['id'])
-                ->findOrEmpty();
-            if (!empty($tmp)) throw new Exception('该公司名称已存在');
-
             Db::name('business')
                 ->where(['id' => $param['id'], 'is_del' => 0])
                 ->update($param);
@@ -489,22 +482,11 @@ class Headquarters extends BaseController
             Db::name('headquarters')
                 ->where(['code' => $info['companyNo'], 'is_del' => 0])
                 ->update([
-                    'name' => $param['company'],
-                    'type' => 1,
-                    'invoice_title' => '',
-                    'invoice_people' => '',
                     'invoice_addr' => $param['inv_addr'],
                     'invoice_mobile' => $param['mobile'],
-                    'invoice_code' => $param['inv_code'],
                     'invoice_bank' => $param['inv_bank'],
                     'invoice_bankNo' => $param['inv_bankNo'],
-                    'invoice_img' => $param['license_img'],
-                    'remark' => '',
-                    'status' => $param['status'],
-                    'is_del' => $param['is_del'],
-                    'updater' => $param['creater'],
-                    'updaterid' => $param['createrid'],
-                    'updatetime' => $param['updatetime'],
+                    'updatetime' => date("Y-m-d H:i:s"),
                 ]);
 
             Db::commit();
@@ -741,46 +723,95 @@ class Headquarters extends BaseController
     public function supplerUpgrade()
     {
 
-        $post = $this->request->only(['code', 'type', 'inv_bank', 'inv_bankNo', 'addr', 'mobile'], 'post', 'trim');
+        $post = $this->request->only(['code', 'inv_bank', 'inv_bankNo', 'inv_addr', 'mobile', 'uid', 'uname'], 'post', 'trim');
 
         $val = Validate::rule([
-            'code|供应商编码' => 'require|number|gt:0',
-            'type|公司类型' => 'require|number|gt:0',
+            'code|供应商编码' => 'require',
             'inv_bank|银行名称' => 'require|max:255',
             'inv_bankNo|银行卡号' => 'require|number',
-            'addr|联系地址' => 'require|max:255',
-            'mobile|联系电话' => 'require|mobile',
+            'inv_addr|联系地址' => 'require|max:255',
+            'mobile|联系电话' => 'require',
         ]);
 
         if ($val->check($post) == false) return json_show(1004, $val->getError());
 
-        $tmp = Db::name('headquarters')
-            ->field('id,status')
-            ->where(['code' => $post['code'], 'type' => 3, 'is_del' => 0])
+        $res = Db::name('supplier')
+            ->alias('a')
+            ->field('a.id,a.status,a.nature,b.contactor,b.mobile,a.name,a.code,a.registercode,a.legaler,a.registertime,a.addr,a.scope,a.license_img,a.is_upgrade')
+            ->leftJoin('supplier_contact b', 'b.code=a.code')
+            ->where(['a.code' => $post['code'], 'a.is_del' => 0])
             ->findOrEmpty();
 
-        if (empty($tmp)) return json_show(1004, '该供应商不存在');
-        if ($tmp['status'] != 1) return json_show(1004, '该供应商已禁用');
+        if (empty($res)) return json_show(1004, '该供应商不存在');
+        if ($res['status'] != 1) return json_show(1004, '该供应商已禁用');
+        if ($res['is_upgrade'] == 1) return json_show(1004, '不能重复升级');
 
         $temp = Db::name('company_type')
-            ->field('id,status')
-            ->where(['id' => $post['type'], 'is_del' => 0])
+            ->field('id')
+            ->where(['company_type' => $res['nature'], 'is_del' => 0])
             ->findOrEmpty();
-        if (empty($temp)) return json_show(1004, '该公司类型不存在');
-        if ($temp['status'] != 1) return json_show(1004, '该公司类型已禁用');
+//        if (empty($temp)) return json_show(1004, '对应公司类型不存在');
 
-        $rs = Db::name('headquarters')
-            ->where('id', $tmp['id'])
-            ->update([
-                'type' => 1,
-                'company_type' => $post['type'],
-                'invoice_addr' => $post['addr'],
-                'invoice_mobile' => $post['mobile'],
-                'invoice_bank' => $post['inv_bank'],
-                'invoice_bankNo' => $post['inv_bankNo'],
-            ]);
+        Db::startTrans();
+
+        try {
+
+            $date = date('Y-m-d H:i:s');
 
-        return $rs ? json_show(0, '升级成功') : json_show(1005, '升级失败');
+            //原业务公司列表
+            Db::name('business')
+                ->insert([
+                    'company' => $res['name'],
+                    'companyNo' => $res['code'],
+                    'inv_code' => $res['registercode'],
+                    'company_type' => $res['nature'],
+                    'type' => $temp['id'] ?? 0,
+                    'creater' => $post['uname'],
+                    'createrid' => $post['uid'],
+                    'inv_legaler' => $res['legaler'],
+                    'inv_time' => $res['registertime'],
+                    'inv_addr' => $post['inv_addr'],
+                    'inv_bank' => $post['inv_bank'],
+                    'inv_bankNo' => $post['inv_bankNo'],
+                    'contactor' => $res['contactor'],
+                    'mobile' => $res['mobile'],
+                    'addr' => $res['addr'],
+                    'inv_scope' => $res['scope'],
+                    'license_img' => $res['license_img'],
+                    'status' => 1,
+                    'is_del' => 0,
+                    'addtime' => $date,
+                    'updatetime' => $date,
+                ]);
+
+            //汇总表
+            Db::name('headquarters')
+                ->where(['code' => $post['code'], 'type' => 3])
+                ->update([
+                    'type' => 1,
+                    'company_type' => $temp['id'] ?? 0,
+                    'invoice_addr' => $post['inv_addr'],
+                    'invoice_mobile' => $post['mobile'],
+                    'invoice_bank' => $post['inv_bank'],
+                    'invoice_bankNo' => $post['inv_bankNo'],
+                    'updater' => $post['uname'],
+                    'updaterid' => $post['uid'],
+                    'updatetime' => $date,
+                ]);
+
+            //供应商
+            Db::name('supplier')
+                ->where(['code' => $post['code'], 'is_upgrade' => 0, 'is_del' => 0])
+                ->update(['is_upgrade' => 1, 'updatetime' => $date]);
+
+            Db::commit();
+            return json_show(0, '升级成功');
+
+        } catch (Exception $exception) {
+            Db::rollback();
+            return json_show(1004, '升级失败,' . $exception->getMessage());
+
+        }
 
     }
 

+ 2 - 0
route/app.php

@@ -68,5 +68,7 @@ Route::rule('itemdel', 'CompanyItem/delete');
 Route::rule('stat', 'CompanyItem/status');
 Route::rule('userp', 'CompanyItem/userp');
 Route::rule('query', 'CompanyItem/query');
+Route::rule('get_part', 'CompanyItem/getPart');
+Route::rule('get_company_name_by_uid', 'CompanyItem/getCompanyNameByUid');