Ver Fonte

细节优化

wufeng há 2 anos atrás
pai
commit
55dd2bcc18
2 ficheiros alterados com 44 adições e 39 exclusões
  1. 13 6
      app/controller/UserCompany.php
  2. 31 33
      app/controller/UserCompanyBasic.php

+ 13 - 6
app/controller/UserCompany.php

@@ -16,11 +16,10 @@ class UserCompany extends BaseController
     //列表
     public function getList()
     {
-        $post = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10], 'post');
+        $post = $this->request->only(['account_id' => '', 'status' => '', 'page' => 1, 'size' => 10], 'post');
         $condition = [['a.is_del', '=', 0]];
 
-        if ($post['nickname'] != '') $condition[] = ['b.nickname', 'like', "%{$post['nickname']}%"];
-        if ($post['username'] != '') $condition[] = ['c.username', 'like', "%{$post['username']}%"];
+        if ($post['account_id'] != '') $condition[] = ['a.account_id', '=', $post['account_id']];
         if ($post['status'] != '') $condition[] = ['a.status', '=', $post['status']];
 
         $count = Db::name('account_company')
@@ -107,12 +106,20 @@ class UserCompany extends BaseController
         $validate = Validate::rule(['id|主键ID' => 'require|number|gt:0', 'status|状态' => 'require|number|in:0,1']);
         if ($validate->check($post) == false) return json_show(1004, $validate->getError());
 
-        Db::name('account_company')
+        $tmp = Db::name('account_company')
+            ->field('id,account_id,companyCode companyNo')
+            ->where(['id' => $post['id'], 'is_del' => 0])
+            ->findOrEmpty();
+
+        if (empty($tmp)) return json_show(1004, '该记录不存在');
+        if ($tmp['status'] == $post['status']) return json_show(1004, '重复操作');
+
+        $rs = Db::name('account_company')
             ->where('status', '<>', $post['status'])
             ->where(['id' => $post['id'], 'is_del' => 0])
-            ->save(['status' => $post['status'], 'updatetime' => date('Y-m-d H:i:s')]);
+            ->update(['status' => $post['status'], 'updatetime' => date('Y-m-d H:i:s')]);
 
-        return json_show(0, '操作成功');
+        return $rs ? json_show(0, '操作成功',$tmp) : json_show(1004, '操作失败');
 
     }
 

+ 31 - 33
app/controller/UserCompanyBasic.php

@@ -35,23 +35,23 @@ class UserCompanyBasic extends BaseController
             ->leftJoin('user b', 'a.id=b.account_id and b.status=1')
             ->where($condition)
             ->page($post['page'], $post['size'])
-            ->append(['plat', 'company_relaton'])
-            ->withAttr('plat', function ($val, $da) {
-                return Db::name('account_plat')
-                    ->alias('a')
-                    ->leftJoin('platform b', 'a.plat_code=b.plat_code and b.is_del=0 and b.status=1')
-                    ->where(['a.status' => 1, 'a.is_del' => 0, 'a.account_id' => $da['id']])
-                    ->field('a.plat_code,plat_name')
-                    ->select()
-                    ->toArray();
-            })
-            ->withAttr('company_relaton', function ($val, $da) {
-                return Db::name('account_company')
-                    ->where(['account_id' => $da['id'], 'is_del' => 0])
-                    ->field('companyCode,companyName,company_type,is_main,status')
-                    ->select()
-                    ->toArray();
-            })
+//            ->append(['plat', 'company_relaton'])
+//            ->withAttr('plat', function ($val, $da) {
+//                return Db::name('account_plat')
+//                    ->alias('a')
+//                    ->leftJoin('platform b', 'a.plat_code=b.plat_code and b.is_del=0 and b.status=1')
+//                    ->where(['a.status' => 1, 'a.is_del' => 0, 'a.account_id' => $da['id']])
+//                    ->field('a.plat_code,plat_name')
+//                    ->select()
+//                    ->toArray();
+//            })
+//            ->withAttr('company_relaton', function ($val, $da) {
+//                return Db::name('account_company')
+//                    ->where(['account_id' => $da['id'], 'is_del' => 0])
+//                    ->field('companyCode,companyName,company_type,is_main,status')
+//                    ->select()
+//                    ->toArray();
+//            })
             ->order('a.addtime desc')
             ->select()
             ->toArray();
@@ -130,7 +130,7 @@ class UserCompanyBasic extends BaseController
                         $acount->saveAll($company_insert);
                     }
                     Db::commit();
-                    return json_show(0, '账户注册成功');
+                    return json_show(0, '账户注册成功',['uid'=>$reuslt]);
                 }
             } else throw new Exception();
 
@@ -163,7 +163,6 @@ class UserCompanyBasic extends BaseController
                     'updatetime' => date('Y-m-d H:i:s')
                 ]);
 
-
             Db::name('account_company')
                 ->where(['is_del' => 0])
                 ->whereIn('account_id', $param['ids'])
@@ -172,7 +171,6 @@ class UserCompanyBasic extends BaseController
                     'updatetime' => date('Y-m-d H:i:s')
                 ]);
 
-
             Db::commit();
             return json_show(0, '删除成功');
         } catch (Exception $exception) {
@@ -287,19 +285,19 @@ class UserCompanyBasic extends BaseController
             ->alias('a')
             ->field('a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime')
             ->leftJoin('user b', 'a.id=b.account_id')
-            ->append(['plat','company_relaton'])
-            ->withAttr('plat',function($val,$da){
-                return Db::name('account_plat')
-                    ->alias('a')
-                    ->leftJoin('platform b', 'a.plat_code=b.plat_code and b.status=1')
-                    ->where(['a.status' => 1, 'a.is_del' => 0, 'a.account_id' => $da['id']])
-                    ->column('a.plat_code,plat_name');
-            })
-            ->withAttr('company_relaton',function($val,$da){
-                return Db::name('account_company')
-                    ->where(['account_id' => $da['id'], 'is_del' => 0, 'status' => 1])
-                    ->column('companyCode,companyName,company_type,is_main,status');
-            })
+//            ->append(['plat','company_relaton'])
+//            ->withAttr('plat',function($val,$da){
+//                return Db::name('account_plat')
+//                    ->alias('a')
+//                    ->leftJoin('platform b', 'a.plat_code=b.plat_code and b.status=1')
+//                    ->where(['a.status' => 1, 'a.is_del' => 0, 'a.account_id' => $da['id']])
+//                    ->column('a.plat_code,plat_name');
+//            })
+//            ->withAttr('company_relaton',function($val,$da){
+//                return Db::name('account_company')
+//                    ->where(['account_id' => $da['id'], 'is_del' => 0, 'status' => 1])
+//                    ->column('companyCode,companyName,company_type,is_main,status');
+//            })
             ->where(['a.id' => $id, 'a.is_del' => 0])
             ->findOrEmpty();
         if (empty($list)) return json_show(1004, '未找到用户信息');