$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', \Yii::app()->user->_id); Helper::imageDelete($info['avatar']); DB::updateById('useradmin', ['avatar' => $upPath], \Yii::app()->user->_id); } 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', \Yii::app()->user->_id); if (!$info) { Helper::error('用户未找到'); } if (md5($old) != $info['password']) { Helper::error('旧密码错误'); } DB::updateById('useradmin', ['password' => md5($new)], \Yii::app()->user->_id); 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', 'email'])) { Helper::error('参数错误'); } DB::updateById('useradmin', $info, \Yii::app()->user->_id); Helper::ok(); } /** * Logs out the current user and redirect to homepage. */ public function actionLogout() { Yii::app()->user->logout(); Helper::ok(); } }