Ver Fonte

添加供应商账号,公司汇总优化

wufeng há 2 anos atrás
pai
commit
bc7025c927
3 ficheiros alterados com 103 adições e 2 exclusões
  1. 4 2
      app/controller/Headquarters.php
  2. 98 0
      app/controller/UserInfo.php
  3. 1 0
      route/app.php

+ 4 - 2
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' => ''], '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']}%"];
@@ -28,6 +28,8 @@ class Headquarters extends BaseController
                 ->column('companyCode');
             $condition[] = ['code', 'in', $companyCode];
         }
+        if ($post['type'] !== '') $condition[] = ['', 'exp', Db::raw("FIND_IN_SET({$post['type']},type)")];
+
         //兼容原有各个接口的筛选
         $count = Db::name('headquarters')
             ->where($condition)
@@ -788,7 +790,7 @@ class Headquarters extends BaseController
             Db::name('headquarters')
                 ->where(['code' => $post['code'], 'type' => 3])
                 ->update([
-                    'type' => 1,
+                    'type' => '1,3',//既是供应商,也是业务公司
                     'company_type' => $temp['id'] ?? 0,
                     'invoice_addr' => $post['inv_addr'],
                     'invoice_mobile' => $post['mobile'],

+ 98 - 0
app/controller/UserInfo.php

@@ -423,6 +423,18 @@ class UserInfo extends BaseController
                 if ($user != false) {
                     $acount = new AccountCompany();
                     if (!empty($post['companyArr'])) {
+
+
+                        //判断关联条件是否都是供应商
+                        $all_companyNo = array_column($post['companyArr'], 'companyCode');
+
+                        $tmp = Db::name('headquarters')
+                            ->where(['is_del' => 0, 'status' => 1])
+                            ->whereFindInSet('type', '1')
+                            ->column('code');
+                        $temp = array_diff($all_companyNo, $tmp);
+                        if (!empty($temp)) throw new Exception(implode(',', $temp) . '不是业务公司');
+
                         $company_insert = [];
                         foreach ($post['companyArr'] as $company) {
                             $company_insert[] = [
@@ -558,6 +570,92 @@ class UserInfo extends BaseController
 
     }
 
+    //添加供应商账号
+    public function addSupplierAccount()
+    {
+
+        $post = $this->request->filter('trim')->post();
+
+        $tmp = Db::table("sys_account")
+            ->field('id')
+            ->where(["mobile" => $post['mobile'], 'is_del' => 0])
+            ->findOrEmpty();
+        if ($tmp) return json_show(1002, "手机号已注册");
+
+        try {
+            $date = date("Y-m-d H:i:s");
+            $salt = makeSalt();
+            $password = sha1("dingding123" . $salt);
+            $da = [
+                'username' => $post['mobile'],
+                "password" => $password,
+                "salt" => $salt,
+                "mobile" => $post['mobile'],
+                "source" => "paltadd",
+                "status" => 1,
+                "level" => 3,//供应商端账号
+                "addtime" => date("Y-m-d H:i:s"),
+                "updatetime" => date("Y-m-d H:i:s")
+            ];
+            $reuslt = Db::table('sys_account')->insert($da, true);
+            if ($reuslt) {
+                $data = [
+                    "nickname" => $post['nickname'],
+                    "mobile" => $post['mobile'],
+                    "email" => $post['email'],
+                    "portrait" => "",
+                    "sex" => 1,
+                    "post" => "",
+                    "department" => "",
+                    "account_id" => $reuslt,
+                    "status" => 1,
+                    "addtime" => $date,
+                    "updatetime" => $date
+                ];
+                $user = Db::table("sys_user")->insert($data);
+                if ($user != false) {
+
+                    //判断关联条件是否都是供应商
+                    $all_companyNo = array_column($post['companyArr'], 'companyCode');
+
+                    $tmp = Db::name('headquarters')
+                        ->where(['is_del' => 0, 'status' => 1])
+                        ->whereFindInSet('type', '3')
+                        ->column('code');
+                    $temp = array_diff($all_companyNo, $tmp);
+                    if (!empty($temp)) throw new Exception(implode(',', $temp) . '不是供应商');
+
+                    $company_insert = [];
+                    foreach ($post['companyArr'] as $company) {
+                        $company_insert[] = [
+                            "account_id" => $reuslt,
+                            "companyCode" => $company['companyCode'],
+                            "companyName" => $company['companyName'],
+                            "company_type" => $company['company_type'],
+                            "is_main" => $company['is_main'],
+                            "status" => 1,
+                            "is_del" => 0,
+                            "addtime" => $date,
+                            "updatetime" => $date,
+                        ];
+                    }
+
+                    if ($company_insert) Db::name('account_company')->insertAll($company_insert);
+
+                    Db::commit();
+                    return json_show(0, "注册成功", ["userid" => $reuslt, "nickname" => $post['nickname']]);
+                }
+            }
+            Db::rollback();
+            return json_show(1002, "注册失败");
+
+        } catch (\Exception $e) {
+            Db::rollback();
+            return json_show(1002, "注册失败," . $e->getMessage());
+        }
+
+    }
+
     //修改密码通过旧密码
     public function passSetByPassword()
     {

+ 1 - 0
route/app.php

@@ -24,6 +24,7 @@ Route::rule('setcompany', 'UserInfo/setCompany');
 Route::rule('companystatus', 'UserInfo/setCompanyStatus');
 Route::rule('useradd', 'UserInfo/userAdd');
 Route::rule('add_admin_account', 'UserInfo/addAdminAccount');
+Route::rule('add_supplier_account', 'UserInfo/addSupplierAccount');
 Route::rule('userDelete', 'UserInfo/userDelete');
 Route::rule('userlistbycompany', 'UserInfo/UserListByCompany');
 Route::rule('passSetByPassword', 'UserInfo/passSetByPassword');