|
@@ -119,7 +119,7 @@ class UserCompany extends BaseController
|
|
|
->where(['id' => $post['id'], 'is_del' => 0])
|
|
|
->update(['status' => $post['status'], 'updatetime' => date('Y-m-d H:i:s')]);
|
|
|
|
|
|
- return $rs ? json_show(0, '操作成功',$tmp) : json_show(1004, '操作失败');
|
|
|
+ return $rs ? json_show(0, '操作成功', $tmp) : json_show(1004, '操作失败');
|
|
|
|
|
|
}
|
|
|
|
|
@@ -143,5 +143,46 @@ class UserCompany extends BaseController
|
|
|
return json_show(0, '获取成功', $rs);
|
|
|
}
|
|
|
|
|
|
+ //切换默认公司
|
|
|
+ public function changeMain()
|
|
|
+ {
|
|
|
+
|
|
|
+ $param = $this->request->only(['account_id','companyCode'], 'post', 'trim');
|
|
|
+
|
|
|
+ $val = Validate::rule([
|
|
|
+ 'account_id|账号id' => 'require|number|gt:0',
|
|
|
+ 'companyCode|公司编码' => 'require',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($val->check($param) == false) return json_show(1004, $val->getError());
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+
|
|
|
+ $rs = Db::name('account_company')
|
|
|
+ ->field('id')
|
|
|
+ ->where(['account_id' => $param['account_id'], 'companyCode' => $param['companyCode'], 'is_del' => 0])
|
|
|
+ ->findOrEmpty();
|
|
|
+
|
|
|
+ if (empty($rs)) throw new Exception('该账号尚未绑定该公司');
|
|
|
+
|
|
|
+ Db::name('account_company')
|
|
|
+ ->where(['account_id' => $param['account_id'], 'is_main' => 1, 'is_del' => 0])
|
|
|
+ ->update(['is_main' => 0, 'updatetime' => date('Y-m-d H:i:s')]);
|
|
|
+
|
|
|
+ Db::name('account_company')
|
|
|
+ ->where('id', $rs['id'])
|
|
|
+ ->update(['is_main' => 1]);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, '切换成功');
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1005, '切换失败,' . $exception->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|