Ver Fonte

创建账号接口优化

wufeng há 2 anos atrás
pai
commit
4b04e12a1e
3 ficheiros alterados com 216 adições e 199 exclusões
  1. 13 0
      app/controller/Headquarters.php
  2. 200 197
      app/controller/UserInfo.php
  3. 3 2
      route/app.php

+ 13 - 0
app/controller/Headquarters.php

@@ -822,5 +822,18 @@ class Headquarters extends BaseController
 
     }
 
+    //获取业务公司列表(为了采销临时脚本同步数据到结算平台使用,正式上线要删除)
+    public function getBusinessListTmp(){
+
+        $where = $this->request->filter('trim')->post('where',[]);
+
+        $list = Db::name('business')
+            ->where($where)
+            ->select()
+            ->toArray();
+        return json_show(0,'获取成功',$list);
+
+    }
+
 
 }

+ 200 - 197
app/controller/UserInfo.php

@@ -377,23 +377,25 @@ class UserInfo extends BaseController
      */
     public function userAdd()
     {
-        $post = $this->request->only(["nickname" => "", "mobile" => "", "email" => "", "companyArr" => []], "post", "trim");
+        $post = $this->request->only(["nickname" => "", "mobile" => "", "email" => "", "companyArr" => [],'level'], "post", "trim");
         $validate = Validate::rule([
             'nickname|真实姓名' => 'require|min:2|max:200',
             'mobile|手机号' => 'require|number|length:11|mobile',
             'email|邮箱' => 'email',
-            'companyArr|关联业务公司' => 'array',
+            'level|账号等级' => 'require|number|in:1,2,3',
+            'companyArr|关联公司' => 'requireIf:level,2|requireIf:level,3|array',
         ]);
         if ($validate->check($post) == false) return json_show(1004, $validate->getError());
         Db::startTrans();
         $uiq = Db::table("sys_account")->field('id')->where(["mobile" => $post['mobile']])->find();
-        if ($uiq) {
-            return json_show(1002, "手机号已注册!");
-        }
+        if ($uiq)  return json_show(1002, "手机号已注册!");
+
 
         Db::startTrans();
 
         try {
+            $date = date('Y-m-d H:i:s');
+
             $salt = makeSalt();
             $password = sha1("dingding123" . $salt);
             $da = [
@@ -403,8 +405,9 @@ class UserInfo extends BaseController
                 "mobile" => $post['mobile'],
                 "source" => "paltadd",
                 "status" => 1,
-                "addtime" => date("Y-m-d H:i:s"),
-                "updatetime" => date("Y-m-d H:i:s")
+                'level'=>$post['level'],
+                "addtime" => $date,
+                "updatetime" => $date
             ];
             $reuslt = Db::table('sys_account')->insert($da, true);
             if ($reuslt) {
@@ -418,8 +421,8 @@ class UserInfo extends BaseController
                     "department" => "",
                     "account_id" => $reuslt,
                     "status" => 1,
-                    "addtime" => date("Y-m-d H:i:s"),
-                    "updatetime" => date("Y-m-d H:i:s")
+                    "addtime" => $date,
+                    "updatetime" => $date
                 ];
                 $user = Db::table("sys_user")->insert($data);
                 if ($user != false) {
@@ -427,15 +430,15 @@ class UserInfo extends BaseController
                     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) . '不是业务公司');
+//                        //判断关联条件是否都是供应商
+//                        $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) {
@@ -447,8 +450,8 @@ class UserInfo extends BaseController
                                 "is_main" => $company['is_main'],
                                 "status" => 1,
                                 "is_del" => 0,
-                                "addtime" => date("Y-m-d H:i:s"),
-                                "updatetime" => date("Y-m-d H:i:s"),
+                                "addtime" => $date,
+                                "updatetime" => $date,
                             ];
                         }
                         $u = $acount->saveAll($company_insert);
@@ -477,189 +480,189 @@ class UserInfo extends BaseController
 
         } catch (\Exception $e) {
             Db::rollback();
-            return json_show(1002, "账户注册失败" . $e->getMessage());
+            return json_show(1002, "账户注册失败," . $e->getMessage());
         }
     }
 
     //添加超管账号
-    public function addAdminAccount()
-    {
-
-        $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, "手机号已注册");
-
-        Db::startTrans();
-        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" => 1,
-                "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) {
-                    $acount = new AccountCompany();
-                    if (!empty($post['companyArr'])) {
-                        $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,
-                            ];
-                        }
-                        $u = $acount->saveAll($company_insert);
-                    } else {
-                        $company_insert = [
-                            "account_id" => $reuslt,
-                            "companyCode" => '',
-                            "companyName" => '',
-                            "company_type" => '0',
-                            "is_main" => 1,
-                            "status" => 1,
-                            "is_del" => 0,
-                            "addtime" => $date,
-                            "updatetime" => $date,
-                        ];
-                        $u = $acount->save($company_insert);
-                    }
-
-                    if ($u == false) throw new Exception("账户新建失败");
-                    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 addAdminAccount()
+//    {
+//
+//        $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, "手机号已注册");
+//
+//        Db::startTrans();
+//        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" => 1,
+//                "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) {
+//                    $acount = new AccountCompany();
+//                    if (!empty($post['companyArr'])) {
+//                        $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,
+//                            ];
+//                        }
+//                        $u = $acount->saveAll($company_insert);
+//                    } else {
+//                        $company_insert = [
+//                            "account_id" => $reuslt,
+//                            "companyCode" => '',
+//                            "companyName" => '',
+//                            "company_type" => '0',
+//                            "is_main" => 1,
+//                            "status" => 1,
+//                            "is_del" => 0,
+//                            "addtime" => $date,
+//                            "updatetime" => $date,
+//                        ];
+//                        $u = $acount->save($company_insert);
+//                    }
+//
+//                    if ($u == false) throw new Exception("账户新建失败");
+//                    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 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, "手机号已注册");
-
-        Db::startTrans();
-
-        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" => 1,
-                            "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 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, "手机号已注册");
+//
+//        Db::startTrans();
+//
+//        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" => 1,
+//                            "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()

+ 3 - 2
route/app.php

@@ -23,8 +23,8 @@ Route::rule('setpasswd', 'UserInfo/PassSet');
 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('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');
@@ -62,6 +62,7 @@ Route::rule('delete', 'Headquarters/delete');
 Route::rule('status', 'Headquarters/status');
 Route::rule('getCodeAndName', 'Headquarters/getCodeAndName');
 Route::rule('supplerUpgrade', 'Headquarters/supplerUpgrade');
+Route::rule('get_business_list_tmp', 'Headquarters/getBusinessListTmp');
 
 //组织架构
 Route::rule('ulist', 'CompanyItem/getList');