addBetweenCondition('create_date', $today, $today . ' 23:59:59') ->setSelect('count(id) as num'); // 今日新增校方跟进记录 $ret[] = [ 'num' => DB::getScalerWithCriteria('school_follow', $cri), 'des' => '今日新增校方跟进记录', 'detail_path' => '/school/follow' ]; // 今日新增食堂跟进记录 $ret[] = [ 'num' => DB::getScalerWithCriteria('canteen_follow', $cri), 'des' => '今日新增食堂跟进记录', 'detail_path' => '/canteen/follow' ]; // 今日新增餐饮公司跟进记录 $ret[] = [ 'num' => DB::getScalerWithCriteria('company_follow', $cri), 'des' => '今日新增餐饮公司跟进记录', 'detail_path' => '/company/follow' ]; $cri->addCondition('is_del = 0'); // 今日新增校方关系 $ret[] = [ 'num' => DB::getScalerWithCriteria('school_contact', $cri), 'des' => '今日新增校方关系', 'detail_path' => '/school/relation' ]; // 今日新增餐饮公司关系 $ret[] = [ 'num' => DB::getScalerWithCriteria('company_contact', $cri), 'des' => '今日新增餐饮公司关系', 'detail_path' => '/company/relation' ]; Helper::ok($ret); } /** * 统一获取下拉列表: 主要是减少前端请求数量,以及方便统一的操作及权限管理 * @return void * @throws CException */ public function actionGetSelectList() { $types = Helper::getArrParam($_POST, 'types', Helper::PARAM_KEY_TYPE['array_string']); $ret = []; foreach ($types as $type) { switch ($type) { case 'user': $cri = DbCriteria::simpleCompare(['id' => '!=1', 'status' => 1]) ->setSelect('id, username as name'); $data = DB::getListWithCriteria('useradmin', $cri); $ret['user'] = $data['records']??[]; break; case 'role': $cri = DbCriteria::simpleCompare([])->setSelect('id, name'); $data = DB::getListWithCriteria('role', $cri); $ret['role'] = $data['records']??[]; break; case 'school': $cri = DbCriteria::simpleCompare(['is_del' => 0, 'id' => $this->getSchoolFilter()]) ->setSelect('id, name'); $data = DB::getListWithCriteria('school', $cri); $ret['school'] = $data['records']??[]; break; case 'canteen': $cri = DbCriteria::simpleCompare(['is_del' => 0, 'school_id' => $this->getSchoolFilter()]) ->setSelect('id, name'); $data = DB::getListWithCriteria('canteen', $cri); $ret['canteen'] = $data['records']??[]; break; case 'company': $cri = DbCriteria::simpleCompare(['is_del' => 0, 'id' => $this->getCompanyFilter()]) ->setSelect('id, name'); $data = DB::getListWithCriteria('company', $cri); $ret['company'] = $data['records']??[]; break; case 'school_canteen': $filter = ['is_del' => 0, 'id' => $this->getSchoolFilter()]; $company_id = Helper::getPostInt('company_id'); $exclude_canteen_ids = []; if ($company_id) { $exclude_canteen_ids = Helper::arrayColumn(DB::getListWithCriteria('company_canteen_relation', DbCriteria::simpleCompare(['company_id' => '!=' . $company_id])), 'canteen_id'); } $cri = DbCriteria::simpleCompare($filter)->setSelect('id, name'); $schools = Helper::arrayColumn(DB::getListWithCriteria('school', $cri), null, 'id'); if (empty($schools)) { $ret['school_canteen'] = []; break; } $cri1 = DbCriteria::simpleCompare(['is_del' => 0, 'school_id' => array_keys($schools)]) ->setSelect('id, name, school_id as parent_id') ->addNotInCondition('id', $exclude_canteen_ids); $relations = DB::getListWithCriteria('canteen', $cri1); $ret['school_canteen'] = $this->formatRelationList($relations['records'], $schools); break; case 'school_relation': $filter = ['is_del' => 0, 'id' => $this->getSchoolFilter()]; $cri = DbCriteria::simpleCompare($filter)->setSelect('id, name'); $schools = Helper::arrayColumn(DB::getListWithCriteria('school', $cri), null, 'id'); if (empty($schools)) { $ret['school_relation'] = []; break; } $cri1 = DbCriteria::simpleCompare(['is_del' => 0, 'school_id' => array_keys($schools)])->setSelect('id, name, school_id as parent_id'); $relations = DB::getListWithCriteria('school_contact', $cri1); $ret['school_relation'] = $this->formatRelationList($relations['records'], $schools); break; case 'company_relation': $filter = ['is_del' => 0, 'id' => $this->getCompanyFilter()]; $cri = DbCriteria::simpleCompare($filter)->setSelect('id, name'); $compamnys = Helper::arrayColumn(DB::getListWithCriteria('company', $cri), null, 'id'); if (empty($compamnys)) { $ret['company_relation'] = []; break; } $cri1 = DbCriteria::simpleCompare(['is_del' => 0, 'company_id' => array_keys($compamnys)])->setSelect('id, name, company_id as parent_id'); $relations = DB::getListWithCriteria('company_contact', $cri1); $ret['company_relation'] = $this->formatRelationList($relations['records'], $compamnys); break; default: Helper::error('参数错误'); break; } } Helper::ok($ret); } private function formatRelationList($list, $parentList) { foreach ($list as $relation) { $sid = $relation['parent_id']; if (!isset($parentList[$sid])) { continue; } if (!isset($parentList[$sid]['children'])) { $parentList[$sid]['children'] = []; } $parentList[$sid]['children'][] = [ 'id' => $relation['id'], 'name' => $relation['name'], ]; } return array_values($parentList); } /** * 图片上传 * 不同类型放到不同目录,返回格式也会不同 */ public function actionUploadImg() { $upType = ''; $maxSize = 3; if (!empty($_FILES['follow'])) { $upType = 'follow'; $upArr = $_FILES['follow']; } elseif (!empty($_FILES['editor'])) { $upType = 'editor'; $upArr = $_FILES['editor']; } elseif (!empty($_FILES['avatar'])) { $upType = 'avatar'; $upArr = $_FILES['avatar']; $maxSize = 0.3; } elseif (!empty($_FILES['canteen'])) { $upType = 'canteen'; $upArr = $_FILES['canteen']; } else { Helper::error('上传有误'); } $type = strtolower($upArr['type']); if (!Helper::hasAnyString($type, ['png', 'jpeg', 'jpg'])) { Helper::error('图片格式不正确 ' . $type); } if ($upArr['size'] > $maxSize * 1024 * 1024) { Helper::error("图片大小不能超过{$maxSize}M"); } $ext = strtolower(pathinfo($upArr['name'], PATHINFO_EXTENSION)); $upPath = "zqcrm/{$upType}/" . date('Ymd') . '/' . Helper::getRandomString(16) . '.' . $ext; $res = Helper::imageUpload($upArr['tmp_name'], $upPath); if (empty($res['code']) || $res['code'] != 200) { Helper::error($res['msg'] ?? '上传出错'); } if ($upType == 'avatar') { $info = DB::getInfoById('useradmin', $this->getUserId()); Helper::imageDelete($info['avatar']); DB::updateById('useradmin', ['avatar' => $upPath], $this->getUserId()); } if ($upType == 'editor') { exit(json_encode([ 'errno' => 0, 'data' => [ 'url' => Helper::getImageUrl($upPath), ], ])); } else { Helper::ok(['name' => $upPath, 'url' => Helper::getImageUrl($upPath)]); } } public function actionDeleteImg() { $path = Helper::getPostString('path'); if (empty($path)) { Helper::error('参数错误'); } Helper::dealCommonResult(Helper::imageDelete($path)); } public function actionChangePassword() { $old = Helper::getPostString('password'); $new = Helper::getPostString('newPassword'); $new1 = Helper::getPostString('confirmPassword'); if (!$old || !$new) { Helper::error('参数错误'); } if ( $new != $new1){ Helper::error('新密码不一致'); } $info = DB::getInfoById('useradmin', $this->getUserId()); if (!$info) { Helper::error('用户未找到'); } if (md5($old) != $info['password']) { Helper::error('旧密码错误'); } DB::updateById('useradmin', ['password' => md5($new)], $this->getUserId()); Helper::ok(); } public function actionEditUser() { $info = [ 'username' => Helper::getPostString('username'), 'phone' => Helper::getPostString('phone'), 'email' => Helper::getPostString('email'), 'descr' => Helper::getPostString('descr'), 'sex' => Helper::getPostInt('sex'), ]; if (!Helper::checkEmptyKey($info, ['username', 'phone'])) { Helper::error('用户名称和手机号不能为空'); } DB::updateById('useradmin', $info, $this->getUserId()); Helper::ok(); } /** * Logs out the current user and redirect to homepage. */ public function actionLogout() { $token = $_SERVER['HTTP_AUTHORIZATION']?? ''; if ($token) { RedisInstance::getInstance()->delete('user_token:'.$token); } Helper::ok(); } }