Explorar el Código

细节优化,客户创建及详情接口优化

wufeng hace 2 años
padre
commit
a6ae6b15dc
Se han modificado 2 ficheros con 165 adiciones y 13 borrados
  1. 164 13
      app/controller/Headquarters.php
  2. 1 0
      route/app.php

+ 164 - 13
app/controller/Headquarters.php

@@ -16,7 +16,7 @@ class Headquarters extends BaseController
     public function getList()
     {
 
-        $post = $this->request->only(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' => '', 'account_id' => '','type'=>''], 'post');
+        $post = $this->request->only(['code' => '', 'name' => '', 'status' => '', 'page' => 1, 'size' => 10, 'level' => '', 'account_id' => '', 'type' => ''], 'post');
         $condition = [['is_del', '=', 0]];
 
         if ($post['code'] != '') $condition[] = is_array($post['code']) ? ['code', 'in', $post['code']] : ['code', 'like', "%{$post['code']}%"];
@@ -217,9 +217,13 @@ class Headquarters extends BaseController
                     Db::name('business')->where($where)->update(['is_del' => 1, 'updatetime' => $date]);
                     break;
                 case 2:
-                    Db::name('company_info')
-                        ->where('is_del', 0)
-                        ->whereIn('companyNo', $param['codes'])
+                    $where = [['is_del', '=', 0], ['id', 'in', $param['ids']]];
+                    $temp = Db::name('customer_info')->field('id,companyNo')->where($where)->where('status', 1)->findOrEmpty();
+                    if (!empty($temp)) throw new Exception($temp['companyNo'] . '启用状态,不允许删除');
+
+                    $codes = Db::name('customer_info')->where($where)->column('companyNo');
+                    Db::name('customer_info')
+                        ->where($where)
                         ->update(['is_del' => 1, 'updatetime' => $date]);
                     break;
                 case 3:
@@ -523,7 +527,7 @@ class Headquarters extends BaseController
     public function sGetList()
     {
 
-        $param = $this->request->only(['page' => 1, 'size' => 10, 'name' => '', 'code' => '', 'creater' => '', 'person' => '', 'status' => '', 'ocr_status' => '', 'start' => '', 'end' => '', 'company_name' => '', 'is_platform' => '','more_code'=>''], 'post', 'trim');
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'name' => '', 'code' => '', 'creater' => '', 'person' => '', 'status' => '', 'ocr_status' => '', 'start' => '', 'end' => '', 'company_name' => '', 'is_platform' => '', 'more_code' => ''], 'post', 'trim');
 
         $where = [['s.is_del', "=", 0]];
         if ($param['name'] !== "") $where[] = ["s.name", "like", '%' . $param['name'] . '%'];
@@ -659,6 +663,7 @@ class Headquarters extends BaseController
 
             $id = Db::name('supplier')
                 ->where(['id' => $param['data']['id'], 'is_del' => 0])
+                ->strict(false)
                 ->update($param['data']);
 
             $tmp = Db::name('supplier_contact')
@@ -670,7 +675,7 @@ class Headquarters extends BaseController
             else Db::name('supplier_contact')->where(['id' => $tmp['id'], 'is_del' => 0])->update($param['contact']);
 
             Db::name('headquarters')
-                ->where(['code' => $param['data']['code'], 'is_del' => 0])
+                ->where(['code' => $param['contact']['code'], 'is_del' => 0])
                 ->update([
                     'name' => $param['data']['name'],
                     'type' => 3,
@@ -684,8 +689,8 @@ class Headquarters extends BaseController
                     'invoice_img' => $param['data']['license_img'],
                     'remark' => $param['data']['remark'],
                     'is_del' => $param['data']['is_del'],
-                    'updater' => $param['data']['creater'],
-                    'updaterid' => $param['data']['createrid'],
+                    'updater' => $param['data']['updater'],
+                    'updaterid' => $param['data']['updaterid'],
                     'updatetime' => $param['data']['updatetime'],
                 ]);
 
@@ -701,13 +706,19 @@ class Headquarters extends BaseController
     //客户
     public function cInfo()
     {
-        $companyNo = $this->request->post('companyNo','','trim');
+        $companyNo = $this->request->post('companyNo', '', 'trim');
 
         $info = Db::name('customer_info')
-            ->where(['is_del'=>0,'companyNo'=>$companyNo])
+            ->where(['is_del' => 0, 'companyNo' => $companyNo])
             ->field(true)
             ->findOrEmpty();
 
+        $info['member'] = Db::name("customer_member")
+            ->where(['companyNo' => $companyNo, "is_del" => 0])
+            ->order('id')
+            ->select()
+            ->toArray();
+
         return json_show(0, "获取成功", $info);
 
     }
@@ -743,6 +754,146 @@ class Headquarters extends BaseController
 
     }
 
+    public function cCreate()
+    {
+        $param = $this->request->only(['companyName', 'parent' => 0, 'customer_member', 'uid', 'uname'], 'post', 'trim');
+
+        $val = Validate::rule([
+            'companyName' => 'require',
+            'customer_member' => 'require|array|max:100',
+            'uid' => 'require|number|gt:0',
+            'uname' => 'require',
+        ]);
+
+        if ($val->check($param) == false) return json_show(1004, $val->getError());
+
+//        $token = isset($this->post['token']) && $this->post['token'] != '' ? trim($this->post['token']) : "";
+//        if ($token == '') {
+//            return json_show(1005, "参数token不能为空");
+//        }
+        $companyNo = makeNo("KH");
+//        $companyName = isset($this->post['companyName']) && $this->post['companyName'] !== "" ? $this->post['companyName'] : "";
+//        if ($companyName == "") {
+//            return json_show(1002, "参数companyName不能为空");
+//        }
+//        $parent = isset($this->post['parent']) && $this->post['parent'] !== "" ? intval($this->post['parent'] ) : "";
+        $rename = Db::name('customer_org1')
+            ->field('id')
+            ->where(['is_del' => 0, 'id' => $param['parent']])
+            ->findOrEmpty();
+        $item = Db::name('customer_info')
+            ->field('id')
+            ->where(['itemid' => $rename['id'], 'companyName' => $param['companyName'], 'is_del' => 0])
+            ->findOrEmpty();
+
+        if (empty($item)) return json_show(1002, "公司名称已存在");
+
+//        if ($parent === "") {
+//            return json_show(1002, "参数parent不能为空");
+//        }
+        //$itemid = isset($this->post['itemid']) && $this->post['itemid'] !== "" ? intval($this->post['itemid'] ) : "";
+//        $customer_member = isset($this->post['customer_member']) && $this->post['customer_member'] !== "" ? $this->post['customer_member'] : "";
+//        if ($customer_member == "") {
+//            return json_show(1002, "参数customer_member不能为空");
+//        }
+//        $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
+//        if($status==""){
+//            return json_show(1002,"参数status不能为空");
+//        }
+//        $user = GetUserInfo($token);
+//        if (empty($user) || $user['code'] != 0) {
+//            return json_show(102, "创建人数据不存在");
+//        }
+        $createrid = $param['uid'];//isset($user["data"]['id']) ? $user["data"]['id'] : "";
+        $creater = $param['uname'];//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
+        Db::startTrans();
+        try {
+
+            $date = date('Y-m-d H:i:s');
+
+            $data = [
+                "companyNo" => $companyNo,
+                "companyName" => $param['companyName'],
+                "parent" => $param['parent'],
+                "itemid" => $param['parent'],
+                "area" => "",
+                "comdepart" => "",
+                "commobile" => "",
+                "comtel" => "",
+                "contactor" => "",
+                "depart" => "",
+                "mobile" => "",
+                "invoice_title" => "",
+                "invoice_people" => "",
+                "invoice_addr" => "",
+                "invoice_mobile" => "",
+                "invoice_code" => "",
+                "invoice_bank" => "",
+                "invoice_bankNo" => "",
+                "companyCode" => "",
+                "status" => 0,
+                "sales_name" => "",
+                "sales_depart" => "",
+                "branch" => "",
+                "middle" => "",
+                "country" => "",
+                "is_del" => 0,
+                "creater" => $creater,
+                "modifier" => "",
+                "addtime" => $date,
+                "updatetime" => $date,
+            ];
+            $datainfo = Db::name('customer_info')->insert($data);
+            if ($datainfo) {
+
+                $var = [];
+
+                foreach ($param['customer_member'] as $value) {
+                    $var[] = [
+                        'commobile' => $value['commobile'] ?? '',
+                        'comtel' => '',
+                        'contactor' => $value['contactor'] ?? '',
+                        'position' => $value['position'] ?? '',
+                        'wxaccount' => $value['wxaccount'] ?? '',
+                        'qqaccount' => $value['qqaccount'] ?? '',
+                        'email' => $value['email'] ?? '',
+                        'comdepart' => $value['comdepart'] ?? '',
+                        'status' => $value['status'] ?? '',
+                        'createrid' => $createrid,
+                        'creater' => $creater,
+                        'companyNo' => $companyNo,
+                        'is_del' => 0,
+                        'addtime' => $date,
+                        'updatetime' => $date,
+                    ];
+                }
+                $vp = Db::name('customer_member')->insertAll($var);
+                if ($vp == "") throw new Exception('新建联系人失败');
+
+                //汇总表
+                Db::name('headquarters')
+                    ->insert([
+                        'code' => $companyNo,
+                        'name' => $param['companyName'],
+                        'type' => 2,
+                        'creater' => $param['uname'],
+                        'createrid' => $param['uid'],
+                        "addtime" => $date,
+                        'updater' => $param['uname'],
+                        'updaterid' => $param['uid'],
+                        "updatetime" => $date,
+                    ]);
+
+                Db::commit();
+                return json_show(0, "新建成功");
+            } else throw new Exception('新建失败');
+        } catch (Exception $e) {
+            Db::rollback();
+            return json_show(1005, $e->getMessage());
+        }
+    }
+
+
     //供应商升级成业务公司
     public function supplerUpgrade()
     {
@@ -827,10 +978,10 @@ class Headquarters extends BaseController
 
             Db::name('headquarters')
                 ->insert(array_merge($temp_supplier, [
-                    'id'=>null,
+                    'id' => null,
                     'code' => $business_code,
                     'type' => 1,//业务公司
-                    'relation_code'=> $post['code']
+                    'relation_code' => $post['code']
                 ]));
 
             //供应商
@@ -871,7 +1022,7 @@ class Headquarters extends BaseController
         $list = Db::name('business')
             ->alias('a')
             ->field('a.*,b.code as supplierNo')
-            ->leftJoin('headquarters b','b.relation_code=a.companyNo')
+            ->leftJoin('headquarters b', 'b.relation_code=a.companyNo')
             ->where($where)
             ->select()
             ->toArray();

+ 1 - 0
route/app.php

@@ -61,6 +61,7 @@ Route::rule('sInfo', 'Headquarters/sInfo');
 Route::rule('sEdit', 'Headquarters/sEdit');
 Route::rule('cInfo', 'Headquarters/cInfo');
 Route::rule('cTitle', 'Headquarters/cTitle');
+Route::rule('cCreate', 'Headquarters/cCreate');
 Route::rule('delete', 'Headquarters/delete');
 Route::rule('status', 'Headquarters/status');
 Route::rule('getCodeAndName', 'Headquarters/getCodeAndName');