1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-30 22:24:55 +08:00

优化代码

This commit is contained in:
xiaochong0302 2020-08-25 20:11:17 +08:00
parent 4168f184e9
commit 9c4e10ccda
24 changed files with 74 additions and 115 deletions

View File

@ -26,7 +26,7 @@ class ImFriendUserList extends Builder
$columns = [ $columns = [
'id', 'name', 'avatar', 'title', 'about', 'vip', 'id', 'name', 'avatar', 'title', 'about', 'vip',
'gender', 'location', 'active_time', 'gender', 'area', 'active_time',
]; ];
$users = $userRepo->findByIds($ids, $columns); $users = $userRepo->findByIds($ids, $columns);

View File

@ -127,9 +127,6 @@ class Controller extends \Phalcon\Mvc\Controller
'cs' => [ 'cs' => [
'enabled' => $im['cs_enabled'], 'enabled' => $im['cs_enabled'],
], ],
'robot' => [
'enabled' => $im['robot_enabled'],
],
'websocket' => [ 'websocket' => [
'url' => $this->config->websocket->url, 'url' => $this->config->websocket->url,
], ],
@ -141,7 +138,7 @@ class Controller extends \Phalcon\Mvc\Controller
if ($this->siteInfo['enabled'] == 0) { if ($this->siteInfo['enabled'] == 0) {
$this->dispatcher->forward([ $this->dispatcher->forward([
'controller' => 'error', 'controller' => 'error',
'action' => 'shutdown', 'action' => 'maintain',
'params' => ['message' => $this->siteInfo['closed_tips']], 'params' => ['message' => $this->siteInfo['closed_tips']],
]); ]);
} }

View File

@ -68,9 +68,9 @@ class ErrorController extends \Phalcon\Mvc\Controller
} }
/** /**
* @Get("/shutdown", name="desktop.error.shutdown") * @Get("/maintain", name="desktop.error.maintain")
*/ */
public function shutdownAction() public function maintainAction()
{ {
$message = $this->dispatcher->getParam('message'); $message = $this->dispatcher->getParam('message');

View File

@ -29,7 +29,7 @@
</div> </div>
<div class="info"> <div class="info">
<p><span class="name">{{ user.name }}</span><span>{{ gender_info(user.gender) }}</span></p> <p><span class="name">{{ user.name }}</span><span>{{ gender_info(user.gender) }}</span></p>
<p><span><i class="layui-icon layui-icon-location"></i></span><span>{{ user.location }}</span></p> <p><span><i class="layui-icon layui-icon-location"></i></span><span>{{ user.area }}</span></p>
<p><span><i class="layui-icon layui-icon-time"></i></span><span>{{ date('Y-m-d H:i',user.active_time) }}</span></p> <p><span><i class="layui-icon layui-icon-time"></i></span><span>{{ date('Y-m-d H:i',user.active_time) }}</span></p>
</div> </div>
{% if user.about %} {% if user.about %}

View File

@ -125,9 +125,8 @@ function kg_site_base_url()
{ {
$scheme = filter_input(INPUT_SERVER, 'REQUEST_SCHEME'); $scheme = filter_input(INPUT_SERVER, 'REQUEST_SCHEME');
$host = filter_input(INPUT_SERVER, 'HTTP_HOST'); $host = filter_input(INPUT_SERVER, 'HTTP_HOST');
$path = filter_input(INPUT_SERVER, 'SCRIPT_NAME');
return "{$scheme}://{$host}" . rtrim(dirname($path), '/'); return sprintf('%s://%s', $scheme, $host);
} }
/** /**
@ -184,9 +183,10 @@ function kg_ci_base_url()
* 获取数据万象URL * 获取数据万象URL
* *
* @param string $path * @param string $path
* @param string $style
* @return string * @return string
*/ */
function kg_ci_img_url($path) function kg_ci_img_url($path, $style = null)
{ {
if (!$path) return ''; if (!$path) return '';
@ -196,33 +196,35 @@ function kg_ci_img_url($path)
$storage = new StorageService(); $storage = new StorageService();
return $storage->getCiImageUrl($path); return $storage->getCiImageUrl($path, $style);
} }
/** /**
* 获取头像数据万象URL * 获取头像数据万象URL
* *
* @param string $path * @param string $path
* @param string $style
* @return string * @return string
*/ */
function kg_ci_avatar_img_url($path) function kg_ci_avatar_img_url($path, $style = null)
{ {
$path = $path ?: kg_default_avatar_path(); $path = $path ?: kg_default_avatar_path();
return kg_ci_img_url($path); return kg_ci_img_url($path, $style);
} }
/** /**
* 获取封面数据万象URL * 获取封面数据万象URL
* *
* @param string $path * @param string $path
* @param string $style
* @return string * @return string
*/ */
function kg_ci_cover_img_url($path) function kg_ci_cover_img_url($path, $style = null)
{ {
$path = $path ?: kg_default_cover_path(); $path = $path ?: kg_default_cover_path();
return kg_ci_img_url($path); return kg_ci_img_url($path, $style);
} }
/** /**
@ -347,17 +349,6 @@ function kg_duration($time, $mode = 'simple')
return $result; return $result;
} }
/**
* 判断是否有路由权限
*
* @param string $route
* @return bool
*/
function kg_can($route = null)
{
return true;
}
/** /**
* 构造icon路径 * 构造icon路径
* *
@ -370,7 +361,7 @@ function kg_icon_link($path, $local = true, $version = null)
{ {
$href = kg_static_url($path, $local, $version); $href = kg_static_url($path, $local, $version);
return '<link rel="shortcut icon" href="' . $href . '" />' . PHP_EOL; return sprintf('<link rel="shortcut icon" href="%s">', $href);
} }
/** /**
@ -385,7 +376,7 @@ function kg_css_link($path, $local = true, $version = null)
{ {
$href = kg_static_url($path, $local, $version); $href = kg_static_url($path, $local, $version);
return '<link rel="stylesheet" type="text/css" href="' . $href . '" />' . PHP_EOL; return sprintf('<link rel="stylesheet" type="text/css" href="%s">', $href);
} }
/** /**
@ -400,7 +391,7 @@ function kg_js_include($path, $local = true, $version = null)
{ {
$src = kg_static_url($path, $local, $version); $src = kg_static_url($path, $local, $version);
return '<script type="text/javascript" src="' . $src . '"></script>' . PHP_EOL; return sprintf('<script type="text/javascript" src="%s"></script>', $src);
} }
/** /**

View File

@ -17,9 +17,11 @@ class Logger
{ {
$config = Di::getDefault()->get('config'); $config = Di::getDefault()->get('config');
$channel = $channel ? $channel . '-' : ''; $channel = $channel ? $channel : 'common';
$path = log_path() . '/' . $channel . date('Y-m-d') . '.log'; $filename = sprintf('%s-%s.log', $channel, date('Y-m-d'));
$path = log_path($filename);
$level = $config->env != ENV_DEV ? $config->log->level : PhalconLogger::DEBUG; $level = $config->env != ENV_DEV ? $config->log->level : PhalconLogger::DEBUG;

View File

@ -100,7 +100,7 @@ class Chapter extends Model
/** /**
* 模式类型 * 模式类型
* *
* @var string * @var int
*/ */
public $model; public $model;

View File

@ -147,14 +147,14 @@ class Course extends Model
/** /**
* 模式类型 * 模式类型
* *
* @var string * @var int
*/ */
public $model; public $model;
/** /**
* 难度级别 * 难度级别
* *
* @var string * @var int
*/ */
public $level; public $level;

View File

@ -40,7 +40,7 @@ class ImGroup extends Model
/** /**
* 群组类型 * 群组类型
* *
* @var string * @var int
*/ */
public $type; public $type;

View File

@ -44,7 +44,7 @@ class ImMessage extends Model
/** /**
* 接收方类型 * 接收方类型
* *
* @var string * @var int
*/ */
public $receiver_type; public $receiver_type;

View File

@ -7,13 +7,6 @@ use Phalcon\Mvc\Model\Behavior\SoftDelete;
class ImNotice extends Model class ImNotice extends Model
{ {
/**
* 请求状态
*/
const REQUEST_PENDING = 'pending'; // 待处理
const REQUEST_ACCEPTED = 'accepted'; // 已接受
const REQUEST_REFUSED = 'refused'; // 已拒绝
/** /**
* 通知类型 * 通知类型
*/ */
@ -117,8 +110,6 @@ class ImNotice extends Model
if (!empty($this->item_info)) { if (!empty($this->item_info)) {
$this->item_info = kg_json_encode($this->item_info); $this->item_info = kg_json_encode($this->item_info);
} else {
$this->item_info = '';
} }
} }
@ -126,14 +117,14 @@ class ImNotice extends Model
{ {
$this->update_time = time(); $this->update_time = time();
if (is_array($this->item_info) && !empty($this->item_info)) { if (is_array($this->item_info)) {
$this->item_info = kg_json_encode($this->item_info); $this->item_info = kg_json_encode($this->item_info);
} }
} }
public function afterFetch() public function afterFetch()
{ {
if (!empty($this->item_info)) { if (!empty($this->item_info) && is_string($this->item_info)) {
$this->item_info = json_decode($this->item_info, true); $this->item_info = json_decode($this->item_info, true);
} }
} }

View File

@ -36,14 +36,14 @@ class Task extends Model
/** /**
* 条目编号 * 条目编号
* *
* @var string * @var int
*/ */
public $item_id; public $item_id;
/** /**
* 条目类型 * 条目类型
* *
* @var string * @var int
*/ */
public $item_type; public $item_type;

View File

@ -59,11 +59,11 @@ class User extends Model
public $about; public $about;
/** /**
* 所在 *
* *
* @var string * @var string
*/ */
public $location; public $area;
/** /**
* 性别 * 性别
@ -72,20 +72,6 @@ class User extends Model
*/ */
public $gender; public $gender;
/**
* 教学角色
*
* @var int
*/
public $edu_role;
/**
* 后台角色
*
* @var int
*/
public $admin_role;
/** /**
* 会员标识 * 会员标识
* *
@ -107,6 +93,20 @@ class User extends Model
*/ */
public $deleted; public $deleted;
/**
* 教学角色
*
* @var int
*/
public $edu_role;
/**
* 后台角色
*
* @var int
*/
public $admin_role;
/** /**
* 课程数 * 课程数
* *

View File

@ -54,10 +54,6 @@ class Volt extends Provider
return 'kg_substr(' . $resolvedArgs . ')'; return 'kg_substr(' . $resolvedArgs . ')';
}); });
$compiler->addFunction('can', function ($resolvedArgs) {
return 'kg_can(' . $resolvedArgs . ')';
});
$compiler->addFilter('duration', function ($resolvedArgs) { $compiler->addFilter('duration', function ($resolvedArgs) {
return 'kg_duration(' . $resolvedArgs . ')'; return 'kg_duration(' . $resolvedArgs . ')';
}); });

View File

@ -19,7 +19,7 @@ class ProfileInfo extends FrontendService
{ {
$user->avatar = kg_ci_img_url($user->avatar); $user->avatar = kg_ci_img_url($user->avatar);
$area = $this->handleArea($user->location); $user->area = $this->handleArea($user->area);
return [ return [
'id' => $user->id, 'id' => $user->id,
@ -27,9 +27,8 @@ class ProfileInfo extends FrontendService
'avatar' => $user->avatar, 'avatar' => $user->avatar,
'title' => $user->title, 'title' => $user->title,
'about' => $user->about, 'about' => $user->about,
'area' => $user->area,
'gender' => $user->gender, 'gender' => $user->gender,
'location' => $user->location,
'area' => $area,
'vip' => $user->vip, 'vip' => $user->vip,
'locked' => $user->locked, 'locked' => $user->locked,
'vip_expiry_time' => $user->vip_expiry_time, 'vip_expiry_time' => $user->vip_expiry_time,
@ -39,9 +38,9 @@ class ProfileInfo extends FrontendService
]; ];
} }
protected function handleArea($location) protected function handleArea($area)
{ {
$area = explode('/', $location); $area = explode('/', $area);
return [ return [
'province' => $area[0] ?? '', 'province' => $area[0] ?? '',

View File

@ -31,7 +31,7 @@ class ProfileUpdate extends FrontendService
} }
if (!empty($post['area'])) { if (!empty($post['area'])) {
$data['location'] = $validator->checkArea($post['area']); $data['area'] = $validator->checkArea($post['area']);
} }
if (!empty($post['about'])) { if (!empty($post['about'])) {

View File

@ -59,12 +59,6 @@ class OrderCreate extends FrontendService
$order = $this->createPackageOrder($package, $user); $order = $this->createPackageOrder($package, $user);
} elseif ($post['item_type'] == OrderModel::ITEM_VIP) {
$vip = $validator->checkVip($post['item_id']);
$order = $this->createVipOrder($vip, $user);
} elseif ($post['item_type'] == OrderModel::ITEM_REWARD) { } elseif ($post['item_type'] == OrderModel::ITEM_REWARD) {
list($courseId, $rewardId) = explode('-', $post['item_id']); list($courseId, $rewardId) = explode('-', $post['item_id']);
@ -73,6 +67,12 @@ class OrderCreate extends FrontendService
$reward = $validator->checkReward($rewardId); $reward = $validator->checkReward($rewardId);
$order = $this->createRewardOrder($course, $reward, $user); $order = $this->createRewardOrder($course, $reward, $user);
} elseif ($post['item_type'] == OrderModel::ITEM_VIP) {
$vip = $validator->checkVip($post['item_id']);
$order = $this->createVipOrder($vip, $user);
} }
$this->incrUserDailyOrderCount($user); $this->incrUserDailyOrderCount($user);
@ -186,7 +186,7 @@ class OrderCreate extends FrontendService
$order = new OrderModel(); $order = new OrderModel();
$order->owner_id = $user->id; $order->owner_id = $user->id;
$order->item_id = "{$course->id}-{$reward->id}"; $order->item_id = $course->id;
$order->item_type = OrderModel::ITEM_REWARD; $order->item_type = OrderModel::ITEM_REWARD;
$order->item_info = $itemInfo; $order->item_info = $itemInfo;
$order->client_type = $this->getClientType(); $order->client_type = $this->getClientType();

View File

@ -64,7 +64,7 @@ class User extends FrontendService
'about' => $item['about'], 'about' => $item['about'],
'vip' => (int)$item['vip'], 'vip' => (int)$item['vip'],
'gender' => (int)$item['gender'], 'gender' => (int)$item['gender'],
'location' => $item['location'], 'area' => $item['area'],
]; ];
} }

View File

@ -2,37 +2,17 @@
namespace App\Services\Frontend\Teacher; namespace App\Services\Frontend\Teacher;
use App\Models\User as UserModel;
use App\Services\Frontend\Service as FrontendService; use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait; use App\Services\Frontend\User\UserInfo as UserInfoService;
class TeacherInfo extends FrontendService class TeacherInfo extends FrontendService
{ {
use UserTrait;
public function getUser($id) public function getUser($id)
{ {
$user = $this->checkUser($id); $service = new UserInfoService();
return $this->handleUser($user); return $service->handle($id);
}
protected function handleUser(UserModel $user)
{
$user->avatar = kg_ci_img_url($user->avatar);
return [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar,
'title' => $user->title,
'about' => $user->about,
'location' => $user->location,
'gender' => $user->gender,
'vip' => $user->vip,
'locked' => $user->locked,
];
} }
} }

View File

@ -31,7 +31,7 @@ class UserInfo extends FrontendService
'avatar' => $user->avatar, 'avatar' => $user->avatar,
'title' => $user->title, 'title' => $user->title,
'about' => $user->about, 'about' => $user->about,
'location' => $user->location, 'area' => $user->area,
'gender' => $user->gender, 'gender' => $user->gender,
'vip' => $user->vip, 'vip' => $user->vip,
'locked' => $user->locked, 'locked' => $user->locked,

View File

@ -40,7 +40,7 @@ class UserDocument extends Component
'avatar' => $user->avatar, 'avatar' => $user->avatar,
'about' => $user->about, 'about' => $user->about,
'gender' => $user->gender, 'gender' => $user->gender,
'location' => $user->location, 'area' => $user->area,
'vip' => $user->vip, 'vip' => $user->vip,
]; ];
} }

View File

@ -144,11 +144,14 @@ class Storage extends Service
* 获取数据万象图片URL * 获取数据万象图片URL
* *
* @param string $key * @param string $key
* @param string $style
* @return string * @return string
*/ */
public function getCiImageUrl($key) public function getCiImageUrl($key, $style = null)
{ {
return $this->getCiBaseUrl() . $key; $style = $style ?: '';
return $this->getCiBaseUrl() . $key . $style;
} }
/** /**
@ -161,7 +164,7 @@ class Storage extends Service
$protocol = $this->settings['bucket_protocol']; $protocol = $this->settings['bucket_protocol'];
$domain = $this->settings['bucket_domain']; $domain = $this->settings['bucket_domain'];
return $protocol . '://' . $domain; return sprintf('%s://%s', $protocol, trim($domain, '/'));
} }
/** /**
@ -174,7 +177,7 @@ class Storage extends Service
$protocol = $this->settings['ci_protocol']; $protocol = $this->settings['ci_protocol'];
$domain = $this->settings['ci_domain']; $domain = $this->settings['ci_domain'];
return $protocol . '://' . $domain; return sprintf('%s://%s', $protocol, trim($domain, '/'));
} }
/** /**

View File

@ -50,9 +50,9 @@ layui.use(['jquery', 'layim'], function () {
members: { members: {
url: '/im/group/users' url: '/im/group/users'
}, },
maxLength: 1000,
msgbox: '/im/msgbox', msgbox: '/im/msgbox',
chatLog: '/im/chatlog' chatLog: '/im/chatlog',
maxLength: 1000
}); });
layim.on('ready', function (options) { layim.on('ready', function (options) {