rootId = $this->request->employee->root_id; } /** * 运营账号管理 */ public function index() { if (!$this->request->isAjax()) { return View::fetch(); } $page = input('get.page'); $limit = input('get.limit'); $keyword = input('get.keyword'); $where = [ ['root_id', '=', $this->rootId], ['grant_id', '<>', 0] ]; if(!empty($keyword)){ $where[] = ['name|opt_name', 'like', '%' . $keyword . '%']; } $data = Employee::with(['grant' => function ($query) { $query->field('id,name'); }])->field(['id,name,opt_name,phone,grant_id,top_one'])->where($where)->page($page, $limit)->select(); $rData = []; foreach ($data as $item) { $rData[] = [ 'id' => $item['id'], 'name' => $item['opt_name'] ?? $item['name'], 'phone' => $item['phone'], 'grant' => $item['grant']['name'], 'grant_id' => $item['grant_id'], 'top_one' => $item['top_one'] ]; } $count = Employee::where($where)->count(); return json(['code' => 0, 'data' => $rData, 'count' => $count]); } /** * 账号添加/修改 */ public function edit() { $grant = Grant::where(['root_id' => $this->rootId])->field('id,name')->select(); View::assign('grant', $grant); $id = input('id', '', 'intval'); if ($id) { $info = Employee::where('id', '=', $id)->findOrEmpty(); View::assign('info', $info); } return View::fetch(); } /* * 账号添加/修改 保存 */ public function editSave() { $data = $this->request->only(['name', 'phone', 'grant_id', 'id'=> '']); if ($data['id']) { $old = Employee::where([['id', '=', $data['id']], ['root_id', '=', $this->rootId]])->findOrEmpty(); if ($old->isEmpty()) { $new = Employee::where(['phone' => cypherphone($data['phone']), 'root_id' => $this->rootId])->findOrEmpty(); $new->save([ 'opt_name' => $data['name'], 'phone' => $data['phone'], 'grant_id' => $data['grant_id'], 'root_id' => $this->rootId ]); } else { if ($data['phone'] != $old['phone']) { $old->grant_id = 0; $old->save(); } $new = Employee::where([['id', '=', $data['id']], ['root_id', '=', $this->rootId]])->findOrEmpty(); $new->save([ 'opt_name' => $data['name'], 'phone' => $data['phone'], 'grant_id' => $data['grant_id'], 'root_id' => $this->rootId ]); } } else { $new = Employee::where(['phone' => cypherphone($data['phone']), 'root_id' => $this->rootId])->findOrEmpty(); $new->save([ 'opt_name' => $data['name'], 'phone' => $data['phone'], 'grant_id' => $data['grant_id'], 'root_id' => $this->rootId ]); dataStatistics(request()->employee->root_id,'motion_count',1,'inc');//manage应用首页统计数据 } return json(['code' => 0, 'msg' => '操作成功']); } /** * 账号删除 */ public function del() { $id = $this->request->param('id'); $emp = Employee::where(['id' => $id, 'root_id' => $this->rootId])->findOrEmpty(); if (!$emp->isEmpty()) { $emp->grant_id = 0; $emp->save(); dataStatistics(request()->employee->root_id,'motion_count',1,'dec');//manage应用首页统计数据 } return json(['code' => 0, 'msg' => '删除成功']); } /** * 操作日志 */ public function log($id, $page = 1, $limit = 10) { if (!$this->request->isAjax()) { View::assign('id', $id); return View::fetch(); } $data = OperateLog::where(['employee_id' => $id, 'root_id' => $this->request->employee['root_id']])->order('addtime desc')->page($page, $limit)->select(); $count = OperateLog::where(['employee_id' => $id, 'root_id' => $this->request->employee['root_id']])->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } }