mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-30 06:11:38 +08:00
优化代码
This commit is contained in:
parent
4168f184e9
commit
9c4e10ccda
@ -26,7 +26,7 @@ class ImFriendUserList extends Builder
|
||||
|
||||
$columns = [
|
||||
'id', 'name', 'avatar', 'title', 'about', 'vip',
|
||||
'gender', 'location', 'active_time',
|
||||
'gender', 'area', 'active_time',
|
||||
];
|
||||
|
||||
$users = $userRepo->findByIds($ids, $columns);
|
||||
|
@ -127,9 +127,6 @@ class Controller extends \Phalcon\Mvc\Controller
|
||||
'cs' => [
|
||||
'enabled' => $im['cs_enabled'],
|
||||
],
|
||||
'robot' => [
|
||||
'enabled' => $im['robot_enabled'],
|
||||
],
|
||||
'websocket' => [
|
||||
'url' => $this->config->websocket->url,
|
||||
],
|
||||
@ -141,7 +138,7 @@ class Controller extends \Phalcon\Mvc\Controller
|
||||
if ($this->siteInfo['enabled'] == 0) {
|
||||
$this->dispatcher->forward([
|
||||
'controller' => 'error',
|
||||
'action' => 'shutdown',
|
||||
'action' => 'maintain',
|
||||
'params' => ['message' => $this->siteInfo['closed_tips']],
|
||||
]);
|
||||
}
|
||||
|
@ -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');
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
</div>
|
||||
<div class="info">
|
||||
<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>
|
||||
</div>
|
||||
{% if user.about %}
|
||||
|
@ -125,9 +125,8 @@ function kg_site_base_url()
|
||||
{
|
||||
$scheme = filter_input(INPUT_SERVER, 'REQUEST_SCHEME');
|
||||
$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
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $style
|
||||
* @return string
|
||||
*/
|
||||
function kg_ci_img_url($path)
|
||||
function kg_ci_img_url($path, $style = null)
|
||||
{
|
||||
if (!$path) return '';
|
||||
|
||||
@ -196,33 +196,35 @@ function kg_ci_img_url($path)
|
||||
|
||||
$storage = new StorageService();
|
||||
|
||||
return $storage->getCiImageUrl($path);
|
||||
return $storage->getCiImageUrl($path, $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取头像数据万象URL
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $style
|
||||
* @return string
|
||||
*/
|
||||
function kg_ci_avatar_img_url($path)
|
||||
function kg_ci_avatar_img_url($path, $style = null)
|
||||
{
|
||||
$path = $path ?: kg_default_avatar_path();
|
||||
|
||||
return kg_ci_img_url($path);
|
||||
return kg_ci_img_url($path, $style);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取封面数据万象URL
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $style
|
||||
* @return string
|
||||
*/
|
||||
function kg_ci_cover_img_url($path)
|
||||
function kg_ci_cover_img_url($path, $style = null)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有路由权限
|
||||
*
|
||||
* @param string $route
|
||||
* @return bool
|
||||
*/
|
||||
function kg_can($route = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造icon路径
|
||||
*
|
||||
@ -370,7 +361,7 @@ function kg_icon_link($path, $local = true, $version = null)
|
||||
{
|
||||
$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);
|
||||
|
||||
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);
|
||||
|
||||
return '<script type="text/javascript" src="' . $src . '"></script>' . PHP_EOL;
|
||||
return sprintf('<script type="text/javascript" src="%s"></script>', $src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,9 +17,11 @@ class Logger
|
||||
{
|
||||
$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;
|
||||
|
||||
|
@ -100,7 +100,7 @@ class Chapter extends Model
|
||||
/**
|
||||
* 模式类型
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $model;
|
||||
|
||||
|
@ -147,14 +147,14 @@ class Course extends Model
|
||||
/**
|
||||
* 模式类型
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $model;
|
||||
|
||||
/**
|
||||
* 难度级别
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $level;
|
||||
|
||||
|
@ -40,7 +40,7 @@ class ImGroup extends Model
|
||||
/**
|
||||
* 群组类型
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $type;
|
||||
|
||||
|
@ -44,7 +44,7 @@ class ImMessage extends Model
|
||||
/**
|
||||
* 接收方类型
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $receiver_type;
|
||||
|
||||
|
@ -7,13 +7,6 @@ use Phalcon\Mvc\Model\Behavior\SoftDelete;
|
||||
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)) {
|
||||
$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();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -36,14 +36,14 @@ class Task extends Model
|
||||
/**
|
||||
* 条目编号
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $item_id;
|
||||
|
||||
/**
|
||||
* 条目类型
|
||||
*
|
||||
* @var string
|
||||
* @var int
|
||||
*/
|
||||
public $item_type;
|
||||
|
||||
|
@ -59,11 +59,11 @@ class User extends Model
|
||||
public $about;
|
||||
|
||||
/**
|
||||
* 所在地
|
||||
* 地区
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $location;
|
||||
public $area;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
@ -72,20 +72,6 @@ class User extends Model
|
||||
*/
|
||||
public $gender;
|
||||
|
||||
/**
|
||||
* 教学角色
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $edu_role;
|
||||
|
||||
/**
|
||||
* 后台角色
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $admin_role;
|
||||
|
||||
/**
|
||||
* 会员标识
|
||||
*
|
||||
@ -107,6 +93,20 @@ class User extends Model
|
||||
*/
|
||||
public $deleted;
|
||||
|
||||
/**
|
||||
* 教学角色
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $edu_role;
|
||||
|
||||
/**
|
||||
* 后台角色
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $admin_role;
|
||||
|
||||
/**
|
||||
* 课程数
|
||||
*
|
||||
|
@ -54,10 +54,6 @@ class Volt extends Provider
|
||||
return 'kg_substr(' . $resolvedArgs . ')';
|
||||
});
|
||||
|
||||
$compiler->addFunction('can', function ($resolvedArgs) {
|
||||
return 'kg_can(' . $resolvedArgs . ')';
|
||||
});
|
||||
|
||||
$compiler->addFilter('duration', function ($resolvedArgs) {
|
||||
return 'kg_duration(' . $resolvedArgs . ')';
|
||||
});
|
||||
|
@ -19,7 +19,7 @@ class ProfileInfo extends FrontendService
|
||||
{
|
||||
$user->avatar = kg_ci_img_url($user->avatar);
|
||||
|
||||
$area = $this->handleArea($user->location);
|
||||
$user->area = $this->handleArea($user->area);
|
||||
|
||||
return [
|
||||
'id' => $user->id,
|
||||
@ -27,9 +27,8 @@ class ProfileInfo extends FrontendService
|
||||
'avatar' => $user->avatar,
|
||||
'title' => $user->title,
|
||||
'about' => $user->about,
|
||||
'area' => $user->area,
|
||||
'gender' => $user->gender,
|
||||
'location' => $user->location,
|
||||
'area' => $area,
|
||||
'vip' => $user->vip,
|
||||
'locked' => $user->locked,
|
||||
'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 [
|
||||
'province' => $area[0] ?? '',
|
||||
|
@ -31,7 +31,7 @@ class ProfileUpdate extends FrontendService
|
||||
}
|
||||
|
||||
if (!empty($post['area'])) {
|
||||
$data['location'] = $validator->checkArea($post['area']);
|
||||
$data['area'] = $validator->checkArea($post['area']);
|
||||
}
|
||||
|
||||
if (!empty($post['about'])) {
|
||||
|
@ -59,12 +59,6 @@ class OrderCreate extends FrontendService
|
||||
|
||||
$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) {
|
||||
|
||||
list($courseId, $rewardId) = explode('-', $post['item_id']);
|
||||
@ -73,6 +67,12 @@ class OrderCreate extends FrontendService
|
||||
$reward = $validator->checkReward($rewardId);
|
||||
|
||||
$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);
|
||||
@ -186,7 +186,7 @@ class OrderCreate extends FrontendService
|
||||
$order = new OrderModel();
|
||||
|
||||
$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_info = $itemInfo;
|
||||
$order->client_type = $this->getClientType();
|
||||
|
@ -64,7 +64,7 @@ class User extends FrontendService
|
||||
'about' => $item['about'],
|
||||
'vip' => (int)$item['vip'],
|
||||
'gender' => (int)$item['gender'],
|
||||
'location' => $item['location'],
|
||||
'area' => $item['area'],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -2,37 +2,17 @@
|
||||
|
||||
namespace App\Services\Frontend\Teacher;
|
||||
|
||||
use App\Models\User as UserModel;
|
||||
use App\Services\Frontend\Service as FrontendService;
|
||||
use App\Services\Frontend\UserTrait;
|
||||
use App\Services\Frontend\User\UserInfo as UserInfoService;
|
||||
|
||||
class TeacherInfo extends FrontendService
|
||||
{
|
||||
|
||||
use UserTrait;
|
||||
|
||||
public function getUser($id)
|
||||
{
|
||||
$user = $this->checkUser($id);
|
||||
$service = new UserInfoService();
|
||||
|
||||
return $this->handleUser($user);
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
return $service->handle($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class UserInfo extends FrontendService
|
||||
'avatar' => $user->avatar,
|
||||
'title' => $user->title,
|
||||
'about' => $user->about,
|
||||
'location' => $user->location,
|
||||
'area' => $user->area,
|
||||
'gender' => $user->gender,
|
||||
'vip' => $user->vip,
|
||||
'locked' => $user->locked,
|
||||
|
@ -40,7 +40,7 @@ class UserDocument extends Component
|
||||
'avatar' => $user->avatar,
|
||||
'about' => $user->about,
|
||||
'gender' => $user->gender,
|
||||
'location' => $user->location,
|
||||
'area' => $user->area,
|
||||
'vip' => $user->vip,
|
||||
];
|
||||
}
|
||||
|
@ -144,11 +144,14 @@ class Storage extends Service
|
||||
* 获取数据万象图片URL
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $style
|
||||
* @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'];
|
||||
$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'];
|
||||
$domain = $this->settings['ci_domain'];
|
||||
|
||||
return $protocol . '://' . $domain;
|
||||
return sprintf('%s://%s', $protocol, trim($domain, '/'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,9 +50,9 @@ layui.use(['jquery', 'layim'], function () {
|
||||
members: {
|
||||
url: '/im/group/users'
|
||||
},
|
||||
maxLength: 1000,
|
||||
msgbox: '/im/msgbox',
|
||||
chatLog: '/im/chatlog'
|
||||
chatLog: '/im/chatlog',
|
||||
maxLength: 1000
|
||||
});
|
||||
|
||||
layim.on('ready', function (options) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user