|
@@ -16,12 +16,14 @@ class UserCompanyBasic extends BaseController
|
|
|
//列表
|
|
|
public function getList()
|
|
|
{
|
|
|
- $post = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10], 'post');
|
|
|
+ $post = $this->request->only(['nickname' => '', 'username' => '', 'status' => '', 'page' => 1, 'size' => 10, 'islevel' => 1], 'post');
|
|
|
$condition = [['a.is_del', '=', 0]];
|
|
|
|
|
|
if ($post['nickname'] != '') $condition[] = ['nickname', 'like', "%{$post['nickname']}%"];
|
|
|
if ($post['username'] != '') $condition[] = ['username', 'like', "%{$post['username']}%"];
|
|
|
if ($post['status'] != '') $condition[] = ['a.status', '=', $post['status']];
|
|
|
+ if ($post['islevel'] == 1) $condition[] = ['a.level', '=', 1];
|
|
|
+ else $condition[] = ['a.level', '<>', 1];
|
|
|
|
|
|
$count = Db::name('account')
|
|
|
->alias('a')
|
|
@@ -35,7 +37,7 @@ 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'])
|
|
|
+ ->append(['plat', 'company_relaton'])
|
|
|
// ->withAttr('plat', function ($val, $da) {
|
|
|
// return Db::name('account_plat')
|
|
|
// ->alias('a')
|
|
@@ -45,13 +47,13 @@ class UserCompanyBasic extends BaseController
|
|
|
// ->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();
|
|
|
-// })
|
|
|
+ ->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 +132,7 @@ class UserCompanyBasic extends BaseController
|
|
|
$acount->saveAll($company_insert);
|
|
|
}
|
|
|
Db::commit();
|
|
|
- return json_show(0, '账户注册成功',['uid'=>$reuslt]);
|
|
|
+ return json_show(0, '账户注册成功', ['uid' => $reuslt]);
|
|
|
}
|
|
|
} else throw new Exception();
|
|
|
|
|
@@ -183,13 +185,11 @@ class UserCompanyBasic extends BaseController
|
|
|
//编辑
|
|
|
public function update()
|
|
|
{
|
|
|
- $post = $this->request->only(['id', 'nickname', 'mobile', 'email' => '', 'portrait' => '', 'sex' => '',], 'post');
|
|
|
+ $post = $this->request->only(['id', 'itemid'], 'post');
|
|
|
+
|
|
|
$validate = Validate::rule([
|
|
|
'id|主键ID' => 'require|number|gt:0',
|
|
|
- 'nickname|名称' => 'require|max:255',
|
|
|
- 'mobile|手机号' => 'require|number|length:11|mobile',
|
|
|
- 'email|名称' => 'email',
|
|
|
- 'sex|性别' => 'number|in:0,1,2',
|
|
|
+ 'itemid|部门ID' => 'require|number|gt:0',
|
|
|
]);
|
|
|
if ($validate->check($post) == false) return json_show(1004, $validate->getError());
|
|
|
$account = Db::name('account')
|
|
@@ -198,41 +198,62 @@ class UserCompanyBasic extends BaseController
|
|
|
->findOrEmpty();
|
|
|
if (empty($account)) return json_show(1003, '账户不存在');
|
|
|
|
|
|
- $accountinfo = Db::name('user')
|
|
|
+ $tmp = Db::name('account_item')
|
|
|
->field('id')
|
|
|
- ->where([['account_id', '=', $post['id']]])
|
|
|
+ ->where(['account_id' => $post['id']])
|
|
|
->findOrEmpty();
|
|
|
- if (empty($accountinfo)) return json_show(1003, '账户信息不存在');
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
-
|
|
|
- Db::name('user')
|
|
|
- ->where($accountinfo)
|
|
|
- ->update([
|
|
|
- 'nickname' => $post['nickname'],
|
|
|
- 'mobile' => $post['mobile'],
|
|
|
- 'email' => $post['email'],
|
|
|
- 'portrait' => $post['portrait'],
|
|
|
- 'sex' => $post['sex'],
|
|
|
- 'updatetime' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
-
|
|
|
- Db::name('account')
|
|
|
- ->where('id', $post['id'])
|
|
|
- ->update([
|
|
|
- 'id' => $post['id'],
|
|
|
- 'mobile' => $post['mobile'],
|
|
|
- 'username' => $post['mobile'],
|
|
|
- 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
-
|
|
|
- Db::commit();
|
|
|
- return json_show(0, '信息修改成功');
|
|
|
- } catch (Exception $exception) {
|
|
|
- Db::rollback();
|
|
|
- return json_show(1005, '信息修改失败,' . $exception->getMessage());
|
|
|
- }
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
+ if (empty($tmp)) $rs = Db::name('account_item')
|
|
|
+ ->insert([
|
|
|
+ 'account_id' => $post['id'],
|
|
|
+ 'itemid' => $post['itemid'],
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
+ else $rs = Db::name('account_item')
|
|
|
+ ->where(['id' => $tmp['id']])
|
|
|
+ ->update([
|
|
|
+ 'itemid' => $post['itemid'],
|
|
|
+ 'updatetime' => $date
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return $rs ? json_show(0, '信息修改成功') : json_show(0, '信息修改失败');;
|
|
|
+
|
|
|
+// $accountinfo = Db::name('user')
|
|
|
+// ->field('id')
|
|
|
+// ->where([['account_id', '=', $post['id']]])
|
|
|
+// ->findOrEmpty();
|
|
|
+// if (empty($accountinfo)) return json_show(1003, '账户信息不存在');
|
|
|
+
|
|
|
+// Db::startTrans();
|
|
|
+// try {
|
|
|
+
|
|
|
+// Db::name('user')
|
|
|
+// ->where($accountinfo)
|
|
|
+// ->update([
|
|
|
+// 'nickname' => $post['nickname'],
|
|
|
+// 'mobile' => $post['mobile'],
|
|
|
+// 'email' => $post['email'],
|
|
|
+// 'portrait' => $post['portrait'],
|
|
|
+// 'sex' => $post['sex'],
|
|
|
+// 'updatetime' => date('Y-m-d H:i:s')
|
|
|
+// ]);
|
|
|
+//
|
|
|
+// Db::name('account')
|
|
|
+// ->where('id', $post['id'])
|
|
|
+// ->update([
|
|
|
+// 'id' => $post['id'],
|
|
|
+// 'mobile' => $post['mobile'],
|
|
|
+// 'username' => $post['mobile'],
|
|
|
+// 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
+// ]);
|
|
|
+
|
|
|
+// Db::commit();
|
|
|
+// return json_show(0, '信息修改成功');
|
|
|
+// } catch (Exception $exception) {
|
|
|
+// Db::rollback();
|
|
|
+// return json_show(1005, '信息修改失败,' . $exception->getMessage());
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -283,21 +304,23 @@ class UserCompanyBasic extends BaseController
|
|
|
|
|
|
$list = Db::name('account')
|
|
|
->alias('a')
|
|
|
- ->field('a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime')
|
|
|
+ ->field('a.id,a.username,a.mobile,a.source,a.status,b.nickname,b.sex,b.email,a.addtime,a.updatetime,c.itemid,d.name item_name')
|
|
|
->leftJoin('user b', 'a.id=b.account_id')
|
|
|
-// ->append(['plat','company_relaton'])
|
|
|
-// ->withAttr('plat',function($val,$da){
|
|
|
+ ->leftJoin('account_item c', 'c.account_id=a.id')
|
|
|
+ ->leftJoin('company_item d', 'd.id=c.itemid')
|
|
|
+ ->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');
|
|
|
-// })
|
|
|
+ ->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, '未找到用户信息');
|