table, $id); if (!$data) { Helper::error('数据不存在'); } if (!$this->checkCompanyId($data['company_id'])) { Helper::error('您没有权限操作此数据'); } Helper::ok($data); } public function actionList() { $filter = [ 'r.is_del' => 0, 'r.phone' => Helper::getPostString('phone'), ]; $companyId = Helper::getPostString('company_id'); if ($companyId) { if (!$this->checkCompanyId($companyId)) { $filter['r.company_id'] = -1; } else { $filter['r.company_id'] = $companyId; } } else { $filter['r.company_id'] = $this->getCompanyFilter(); } if ($name = Helper::getPostString('name')) { $filter['r.name'] = '%'.$name; } $cri = DbCriteria::simpleCompareWithPage($filter) ->setAlias('r') ->setSelect('r.*, s.name as company_name, group_concat(sf.id) AS follow_ids') ->setJoin('LEFT JOIN wx_company s ON s.id=r.company_id') ->addJoin('LEFT JOIN wx_company_follow AS sf ON sf.contact_id = r.id') ->setGroup('r.id') ->setOrder('r.id desc'); if ($date = Helper::getPostDate('date')) { $cri->addBetweenCondition('r.create_date', $date, $date . ' 23:59:59'); } $data = DB::getListWithCriteria($this->table, $cri); if (!empty($data['records'])) { $users = Helper::arrayColumn( DB::getListWithCriteria('useradmin', DbCriteria::simpleCompare([])->setSelect('id, username,avatar')), null, 'id' ); $data['records'] = FollowSrv::formatWithFollowList($data['records'], 'wx_school_follow', $users); $data['records'] = array_map(function ($item) use ($users) { $item['last_user_name'] = $users[$item['last_user_id']]['username'] ?? '-'; return $item; }, $data['records']); } Helper::ok($data); } public function actionDelete() { $id = Helper::getPostInt('id'); if ($id < 1) { Helper::error('参数错误'); } $data = DB::getInfoById($this->table, $id); if (!$data || !$this->checkCompanyId($data['company_id'])) { Helper::error('您没有权限操作此数据'); } Db::updateById($this->table, ['is_del' => 1], $id); Helper::ok(); } public function actionAdd() { $this->_save(); } public function actionEdit() { $id = Helper::getPostInt('id'); if (!$id) { Helper::error('参数错误'); } $data = DB::getInfoById($this->table, $id); if (!$data || !$this->checkCompanyId($data['company_id'])) { Helper::error('您没有权限操作此数据'); } $this->_save($id); } private function _save($id = 0) { $data = [ 'name' => Helper::getPostString('name'), 'company_id' => Helper::getPostInt('company_id'), 'phone' => Helper::getPostString('phone'), 'weixin' => Helper::getPostString('weixin'), 'position' => Helper::getPostString('position'), 'memo' => Helper::getPostString('memo'), ]; $notNullField = ["name", "company_id", "phone", "weixin", "position"]; $allowEmptyField = ['weixin']; // 空字段检测 if (!Helper::checkEmptyKey($data, $notNullField, $allowEmptyField)) { Helper::error('参数错误'); } $this->dobuleCheck(); if ($id) { DB::updateById($this->table, $data, $id); } else { DB::addData($this->table, $data); } Helper::ok(); } public function actionUpdateAttr() { $id = Helper::getPostInt('id'); $attr = Helper::getPostString('attr'); $value = Helper::getPostString('value'); if ($id <= 0 || !$attr) { Helper::error('参数错误'); } $data = DB::getInfoById($this->table, $id); if (!$data || !$this->checkCompanyId($data['company_id'])) { Helper::error('您没有权限操作此数据'); } if (!in_array($attr, [])) { Helper::error('参数错误2'); } if (DB::updateById($this->table, [$attr => $value], $id) === false) { Helper::error('更新失败'); } Helper::ok(); } }