diff --git a/.gitignore b/.gitignore index c1687295..2f894c4f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ /config/xs.course.ini /config/xs.group.ini /config/xs.user.ini +/config/alipay/*.crt +/config/wxpay/*.pem /public/robots.txt /public/sitemap.xml *KgTest* diff --git a/README.md b/README.md index 1a478c4f..a97005b5 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,28 @@ 酷瓜云课堂,依托腾讯云基础服务架构,采用 C 扩展框架 Phalcon 开发,致力网络教育软件。 +#### 系统功能 + 都有些什么功能?我也不想写一大堆,自己体验吧! -帐号:100015@163.com / 123456 (前后台通用) - -PS:**系统后台已禁止提交并隐藏私人配置** - - [前台演示](https://ctc.koogua.com) - [后台演示](https://ctc.koogua.com/admin) +帐号:100015@163.com / 123456 (前后台通用,请不要修改密码) + +友情提示: + +- 系统配置低(1核 1G 1M 跑多个容器),手下留情 +- 课程数据来源于网络(无实质内容),切莫购买 +- 管理后台已禁止提交(私密配置已过滤) + #### 项目组件 - 后台框架:[phalcon 3.4.5](https://phalcon.io) - 前端框架:[layui 2.5.6](https://layui.com), [layim 3.9.5](https://www.layui.com/layim)(已授权) - 全文检索:[xunsearch 1.4.9](http://www.xunsearch.com) - 即时通讯:[workerman 3.5.22](https://workerman.net) -- 其它依赖:[php7.3](https://php.net), [mysql5.7](https://mysql.com), [redis5.0](https://redis.io) +- 基础依赖:[php7.3](https://php.net), [mysql5.7](https://mysql.com), [redis5.0](https://redis.io) #### 使用协议 @@ -32,32 +38,7 @@ PS:**系统后台已禁止提交并隐藏私人配置** #### 安装指南 - [运行环境搭建](https://gitee.com/koogua/course-tencent-cloud-docker) -- [系统服务配置](https://gitee.com/koogua/course-tencent-cloud/wikis/服务配置) - -#### 会推出商业服务吗? - -- 如果不符合您对“开源”的认知,请移步其它同类产品,毕竟同类“免费”产品也很多。 -- 如果“开源”版本不能满足您的需求,或者您希望有更好的支持,商业服务是不错的选择。 - -我们为用户提供的服务包括: - -- 系统安装 -- 系统定制 -- 企业会员 - -#### 会有阿里云版吗? - -阿里云版规划中,之前阿里云服务过期未续费,所以腾讯云版本先出。 - -#### 代码有加密吗? - -所有代码都公开(授权代码除外,例如layim),没有所谓的商业版和付费插件。 - -#### 通过这个项目能学到什么? - -1. 项目规划,phalcon实战,缓存,JWT,即时通讯,全文检索 -2. docker操作,docker服务编排,supervisor,devops -3. git,linux,php,mysql,redis,nginx +- [系统服务配置](https://gitee.com/koogua/course-tencent-cloud/wikis) #### 开发计划 @@ -73,7 +54,29 @@ PS:**系统后台已禁止提交并隐藏私人配置** #### 加入我们 -这是我的创业项目,个人能力和精力有限,要兼顾产品规划以及开发,还要处理除报税记账之外的所有琐碎事情。 -目前在南山科技园某个众创空间,希望有能独挡一面的**深圳前端同学**加入我们。 +这是一个创业项目,个人能力和精力有限,要兼顾产品规划以及开发,还要处理很多琐碎事情。目前在南山科技园某个众创空间,希望有 **深圳前端同学** 加入我们。 联系邮箱:76632555@qq.com + +#### 通过这个项目能学到什么? + +- 项目规划,phalcon,缓存,JWT,即时通讯,全文检索 +- docker,supervisor,devops +- git,linux,php,mysql,redis,nginx + +#### 有阿里云版吗? + +阿里云版规划中,之前阿里云服务过期未续费,所以腾讯云版本先出。 + +#### 代码有加密吗? + +所有代码都公开(授权代码除外,例如layim),没有所谓的商业版和付费插件。 + +#### 有商业服务吗? + +生存是一个问题,生存才能发展,我们为用户提供的服务包括: + +- 系统安装 +- 系统定制 +- 企业授权 + diff --git a/app/Builders/CourseCatalog.php b/app/Builders/CourseChapterList.php similarity index 98% rename from app/Builders/CourseCatalog.php rename to app/Builders/CourseChapterList.php index 5415dae2..bd544a4b 100644 --- a/app/Builders/CourseCatalog.php +++ b/app/Builders/CourseChapterList.php @@ -7,7 +7,7 @@ use App\Models\Course as CourseModel; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; -class CourseCatalog extends Builder +class CourseChapterList extends Builder { /** diff --git a/app/Caches/Cache.php b/app/Caches/Cache.php index c832247c..f0b2cee4 100644 --- a/app/Caches/Cache.php +++ b/app/Caches/Cache.php @@ -15,7 +15,7 @@ abstract class Cache extends Component public function __construct() { - $this->cache = $this->getDI()->get('cache'); + $this->cache = $this->getDI()->getShared('cache'); } /** diff --git a/app/Caches/Counter.php b/app/Caches/Counter.php index 7c2dcbca..ad52c178 100644 --- a/app/Caches/Counter.php +++ b/app/Caches/Counter.php @@ -20,7 +20,7 @@ abstract class Counter extends Component public function __construct() { - $this->cache = $this->getDI()->get('cache'); + $this->cache = $this->getDI()->getShared('cache'); $this->redis = $this->cache->getRedis(); } diff --git a/app/Caches/CourseCatalog.php b/app/Caches/CourseChapterList.php similarity index 62% rename from app/Caches/CourseCatalog.php rename to app/Caches/CourseChapterList.php index 687a50ab..512dec28 100644 --- a/app/Caches/CourseCatalog.php +++ b/app/Caches/CourseChapterList.php @@ -2,9 +2,9 @@ namespace App\Caches; -use App\Builders\CourseCatalog as CourseCatalogBuilder; +use App\Builders\CourseChapterList as CourseChapterListBuilder; -class CourseCatalog extends Cache +class CourseChapterList extends Cache { protected $lifetime = 7 * 86400; @@ -16,12 +16,12 @@ class CourseCatalog extends Cache public function getKey($id = null) { - return "course_catalog:{$id}"; + return "course_chapter_list:{$id}"; } public function getContent($id = null) { - $builder = new CourseCatalogBuilder(); + $builder = new CourseChapterListBuilder(); $list = $builder->handle($id); diff --git a/app/Caches/IndexCarouselList.php b/app/Caches/IndexCarouselList.php deleted file mode 100644 index 94ccde8c..00000000 --- a/app/Caches/IndexCarouselList.php +++ /dev/null @@ -1,72 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'index_carousel_list'; - } - - public function getContent($id = null) - { - $limit = 5; - - $carousels = $this->findCarousels($limit); - - if ($carousels->count() == 0) { - return []; - } - - return $this->handleContent($carousels); - } - - /** - * @param CarouselModel[] $carousels - * @return array - */ - protected function handleContent($carousels) - { - $result = []; - - foreach ($carousels as $carousel) { - $result[] = [ - 'id' => $carousel->id, - 'title' => $carousel->title, - 'cover' => $carousel->cover, - 'style' => $carousel->style, - 'target' => $carousel->target, - 'content' => $carousel->content, - ]; - } - - return $result; - } - - /** - * @param int $limit - * @return ResultsetInterface|Resultset|CarouselModel[] - */ - public function findCarousels($limit = 5) - { - return CarouselModel::query() - ->where('published = 1') - ->orderBy('priority ASC') - ->limit($limit) - ->execute(); - } - -} diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index b6c69d67..2783b4ce 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -30,7 +30,7 @@ class IndexFreeCourseList extends Cache { $categoryLimit = 5; - $courseLimit = 10; + $courseLimit = 8; $categories = $this->findCategories($categoryLimit); @@ -100,7 +100,7 @@ class IndexFreeCourseList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|CourseModel[] */ - protected function findCategoryCourses($categoryId, $limit = 10) + protected function findCategoryCourses($categoryId, $limit = 8) { $categoryService = new CategoryService(); diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 7cb627cf..9a2a89b6 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -30,7 +30,7 @@ class IndexNewCourseList extends Cache { $categoryLimit = 5; - $courseLimit = 10; + $courseLimit = 8; $categories = $this->findCategories($categoryLimit); @@ -100,7 +100,7 @@ class IndexNewCourseList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|CourseModel[] */ - protected function findCategoryCourses($categoryId, $limit = 10) + protected function findCategoryCourses($categoryId, $limit = 8) { $categoryService = new CategoryService(); diff --git a/app/Caches/IndexSimpleFreeCourseList.php b/app/Caches/IndexSimpleFreeCourseList.php new file mode 100644 index 00000000..a91174a4 --- /dev/null +++ b/app/Caches/IndexSimpleFreeCourseList.php @@ -0,0 +1,70 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_simple_free_course_list'; + } + + public function getContent($id = null) + { + $limit = 8; + + $courses = $this->findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'market_price' => $course->market_price, + 'vip_price' => $course->vip_price, + 'model' => $course->model, + 'level' => $course->level, + 'user_count' => $course->user_count, + 'lesson_count' => $course->lesson_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('published = 1') + ->andWhere('market_price = 0') + ->orderBy('score DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexSimpleNewCourseList.php b/app/Caches/IndexSimpleNewCourseList.php new file mode 100644 index 00000000..4d9dcd89 --- /dev/null +++ b/app/Caches/IndexSimpleNewCourseList.php @@ -0,0 +1,69 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_simple_new_course_list'; + } + + public function getContent($id = null) + { + $limit = 8; + + $courses = $this->findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'market_price' => $course->market_price, + 'vip_price' => $course->vip_price, + 'model' => $course->model, + 'level' => $course->level, + 'user_count' => $course->user_count, + 'lesson_count' => $course->lesson_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('published = 1') + ->orderBy('id DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexSimpleVipCourseList.php b/app/Caches/IndexSimpleVipCourseList.php new file mode 100644 index 00000000..bfb10e59 --- /dev/null +++ b/app/Caches/IndexSimpleVipCourseList.php @@ -0,0 +1,70 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_simple_vip_course_list'; + } + + public function getContent($id = null) + { + $limit = 8; + + $courses = $this->findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'market_price' => $course->market_price, + 'vip_price' => $course->vip_price, + 'model' => $course->model, + 'level' => $course->level, + 'user_count' => $course->user_count, + 'lesson_count' => $course->lesson_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('published = 1') + ->andWhere('vip_price >= 0') + ->orderBy('score DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexSlideList.php b/app/Caches/IndexSlideList.php new file mode 100644 index 00000000..72899070 --- /dev/null +++ b/app/Caches/IndexSlideList.php @@ -0,0 +1,71 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_slide_list'; + } + + public function getContent($id = null) + { + $limit = 5; + + $slides = $this->findSlides($limit); + + if ($slides->count() == 0) { + return []; + } + + return $this->handleContent($slides); + } + + /** + * @param SlideModel[] $slides + * @return array + */ + protected function handleContent($slides) + { + $result = []; + + foreach ($slides as $slide) { + $result[] = [ + 'id' => $slide->id, + 'title' => $slide->title, + 'cover' => $slide->cover, + 'target' => $slide->target, + 'content' => $slide->content, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|SlideModel[] + */ + public function findSlides($limit = 5) + { + return SlideModel::query() + ->where('published = 1') + ->orderBy('priority ASC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index ab869db0..36fe1d0a 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -30,7 +30,7 @@ class IndexVipCourseList extends Cache { $categoryLimit = 5; - $courseLimit = 10; + $courseLimit = 8; $categories = $this->findCategories($categoryLimit); @@ -100,7 +100,7 @@ class IndexVipCourseList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|CourseModel[] */ - protected function findCategoryCourses($categoryId, $limit = 10) + protected function findCategoryCourses($categoryId, $limit = 8) { $categoryService = new CategoryService(); diff --git a/app/Console/Tasks/CleanLogTask.php b/app/Console/Tasks/CleanLogTask.php index 4e171edb..2b242985 100644 --- a/app/Console/Tasks/CleanLogTask.php +++ b/app/Console/Tasks/CleanLogTask.php @@ -2,8 +2,6 @@ namespace App\Console\Tasks; -use Phalcon\Cli\Task; - class CleanLogTask extends Task { @@ -15,8 +13,8 @@ class CleanLogTask extends Task $this->cleanSqlLog(); $this->cleanListenerLog(); $this->cleanCaptchaLog(); - $this->cleanMailerLog(); - $this->cleanSmserLog(); + $this->cleanMailLog(); + $this->cleanSmsLog(); $this->cleanVodLog(); $this->cleanLiveLog(); $this->cleanStorageLog(); @@ -101,17 +99,17 @@ class CleanLogTask extends Task /** * 清理短信服务日志 */ - protected function cleanSmserLog() + protected function cleanSmsLog() { - $this->cleanLog('smser', 7); + $this->cleanLog('sms', 7); } /** * 清理邮件服务日志 */ - protected function cleanMailerLog() + protected function cleanMailLog() { - $this->cleanLog('mailer', 7); + $this->cleanLog('mail', 7); } /** @@ -165,9 +163,9 @@ class CleanLogTask extends Task if (strtotime($today) - strtotime($date) >= $keepDays * 86400) { $deleted = unlink($file); if ($deleted) { - echo "Delete {$file} success" . PHP_EOL; + echo "delete {$file} success" . PHP_EOL; } else { - echo "Delete {$file} failed" . PHP_EOL; + echo "delete {$file} failed" . PHP_EOL; } } } diff --git a/app/Console/Tasks/CleanSessionTask.php b/app/Console/Tasks/CleanSessionTask.php index 2be57e51..fb27ddef 100644 --- a/app/Console/Tasks/CleanSessionTask.php +++ b/app/Console/Tasks/CleanSessionTask.php @@ -2,20 +2,14 @@ namespace App\Console\Tasks; -use App\Library\Cache\Backend\Redis as RedisCache; -use Phalcon\Cli\Task; -use Phalcon\Config; - class CleanSessionTask extends Task { public function mainAction() { $config = $this->getConfig(); - $cache = $this->getCache(); - - $redis = $cache->getRedis(); + $redis = $this->getRedis(); $redis->select($config->path('session.db')); @@ -47,24 +41,4 @@ class CleanSessionTask extends Task return $cache->queryKeys('_PHCR', $limit); } - protected function getConfig() - { - /** - * @var Config $config - */ - $config = $this->getDI()->get('config'); - - return $config; - } - - protected function getCache() - { - /** - * @var RedisCache $cache - */ - $cache = $this->getDI()->get('cache'); - - return $cache; - } - } diff --git a/app/Console/Tasks/CloseOrderTask.php b/app/Console/Tasks/CloseOrderTask.php index b6818ba7..713d225c 100644 --- a/app/Console/Tasks/CloseOrderTask.php +++ b/app/Console/Tasks/CloseOrderTask.php @@ -3,7 +3,6 @@ namespace App\Console\Tasks; use App\Models\Order as OrderModel; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; diff --git a/app/Console/Tasks/CloseTradeTask.php b/app/Console/Tasks/CloseTradeTask.php index 28665b6e..3918d40c 100644 --- a/app/Console/Tasks/CloseTradeTask.php +++ b/app/Console/Tasks/CloseTradeTask.php @@ -5,7 +5,6 @@ namespace App\Console\Tasks; use App\Models\Trade as TradeModel; use App\Services\Pay\Alipay as AlipayService; use App\Services\Pay\Wxpay as WxpayService; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; diff --git a/app/Console/Tasks/CourseIndexTask.php b/app/Console/Tasks/CourseIndexTask.php index 050e50b5..23a148cc 100644 --- a/app/Console/Tasks/CourseIndexTask.php +++ b/app/Console/Tasks/CourseIndexTask.php @@ -5,7 +5,6 @@ namespace App\Console\Tasks; use App\Models\Course as CourseModel; use App\Services\Search\CourseDocument; use App\Services\Search\CourseSearcher; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -24,7 +23,7 @@ class CourseIndexTask extends Task $query = $params[0] ?? null; if (!$query) { - exit("please special a query word" . PHP_EOL); + exit('please special a query word' . PHP_EOL); } $result = $this->searchCourses($query); @@ -61,11 +60,11 @@ class CourseIndexTask extends Task $index = $handler->getXS()->getIndex(); - echo "start clean index" . PHP_EOL; + echo 'start clean index' . PHP_EOL; $index->clean(); - echo "end clean index" . PHP_EOL; + echo 'end clean index' . PHP_EOL; } /** @@ -75,9 +74,7 @@ class CourseIndexTask extends Task { $courses = $this->findCourses(); - if ($courses->count() == 0) { - return; - } + if ($courses->count() == 0) return; $handler = new CourseSearcher(); @@ -85,7 +82,7 @@ class CourseIndexTask extends Task $index = $handler->getXS()->getIndex(); - echo "start rebuild index" . PHP_EOL; + echo 'start rebuild index' . PHP_EOL; $index->beginRebuild(); @@ -96,7 +93,7 @@ class CourseIndexTask extends Task $index->endRebuild(); - echo "end rebuild index" . PHP_EOL; + echo 'end rebuild index' . PHP_EOL; } /** diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index 5c39371d..9b9ddebd 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -9,7 +9,7 @@ use App\Models\Task as TaskModel; use App\Models\Trade as TradeModel; use App\Repos\Order as OrderRepo; use App\Repos\User as UserRepo; -use App\Services\Smser\Order as OrderSmser; +use App\Services\Sms\Order as OrderSms; use Phalcon\Mvc\Model; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -74,7 +74,6 @@ class DeliverTask extends Task $task->update(); $logger->info('Order Process Exception ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getCode(), 'message' => $e->getMessage(), 'task' => $task->toArray(), @@ -165,9 +164,9 @@ class DeliverTask extends Task protected function handleOrderNotice(OrderModel $order) { - $smser = new OrderSmser(); + $sms = new OrderSms(); - $smser->handle($order); + $sms->handle($order); } protected function handleOrderRefund(OrderModel $order) diff --git a/app/Console/Tasks/GroupIndexTask.php b/app/Console/Tasks/GroupIndexTask.php index 2cd79419..4e9c2918 100644 --- a/app/Console/Tasks/GroupIndexTask.php +++ b/app/Console/Tasks/GroupIndexTask.php @@ -5,7 +5,6 @@ namespace App\Console\Tasks; use App\Models\ImGroup as GroupModel; use App\Services\Search\GroupDocument; use App\Services\Search\GroupSearcher; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -24,7 +23,7 @@ class GroupIndexTask extends Task $query = $params[0] ?? null; if (!$query) { - exit("please special a query word" . PHP_EOL); + exit('please special a query word' . PHP_EOL); } $result = $this->searchGroups($query); @@ -61,11 +60,11 @@ class GroupIndexTask extends Task $index = $handler->getXS()->getIndex(); - echo "start clean index" . PHP_EOL; + echo 'start clean index' . PHP_EOL; $index->clean(); - echo "end clean index" . PHP_EOL; + echo 'end clean index' . PHP_EOL; } /** @@ -75,9 +74,7 @@ class GroupIndexTask extends Task { $groups = $this->findGroups(); - if ($groups->count() == 0) { - return; - } + if ($groups->count() == 0) return; $handler = new GroupSearcher(); @@ -85,7 +82,7 @@ class GroupIndexTask extends Task $index = $handler->getXS()->getIndex(); - echo "start rebuild index" . PHP_EOL; + echo 'start rebuild index' . PHP_EOL; $index->beginRebuild(); @@ -96,7 +93,7 @@ class GroupIndexTask extends Task $index->endRebuild(); - echo "end rebuild index" . PHP_EOL; + echo 'end rebuild index' . PHP_EOL; } /** diff --git a/app/Console/Tasks/LiveNotifyTask.php b/app/Console/Tasks/LiveNotifyTask.php index b2f792c4..a36c3cf7 100644 --- a/app/Console/Tasks/LiveNotifyTask.php +++ b/app/Console/Tasks/LiveNotifyTask.php @@ -2,54 +2,42 @@ namespace App\Console\Tasks; -use App\Library\Cache\Backend\Redis as RedisCache; use App\Models\CourseUser as CourseUserModel; use App\Repos\Chapter as ChapterRepo; use App\Services\LiveNotify as LiveNotifyService; -use App\Services\Smser\Live as LiveSmser; -use Phalcon\Cli\Task; +use App\Services\Sms\Live as LiveSms; class LiveNotifyTask extends Task { - /** - * @var RedisCache - */ - protected $cache; - - /** - * @var \Redis - */ - protected $redis; - public function mainAction() { - $this->cache = $this->getDI()->get('cache'); + $cache = $this->getCache(); - $this->redis = $this->cache->getRedis(); + $redis = $this->getRedis(); $service = new LiveNotifyService(); $key = $service->getNotifyKey(); - $chapterIds = $this->redis->sMembers($key); + $chapterIds = $redis->sMembers($key); if (!$chapterIds) return; $sentKey = $service->getSentNotifyKey(); - $sentChapterIds = $this->redis->sMembers($sentKey); + $sentChapterIds = $redis->sMembers($sentKey); foreach ($chapterIds as $chapterId) { if (!in_array($chapterId, $sentChapterIds)) { $this->sendNotification($chapterId); } else { - $this->redis->sAdd($sentKey, $chapterId); + $redis->sAdd($sentKey, $chapterId); } } - if ($this->redis->sCard($sentKey) == 1) { - $this->redis->expire($sentKey, 86400); + if ($redis->sCard($sentKey) == 1) { + $redis->expire($sentKey, 86400); } } @@ -65,18 +53,15 @@ class LiveNotifyTask extends Task if (!$targetUserIds) return; - $smser = new LiveSmser(); + $sms = new LiveSms(); foreach ($targetUserIds as $userId) { - $smser->handle($chapterId, $userId, $chapterLive->start_time); + $sms->handle($chapterId, $userId, $chapterLive->start_time); } } protected function findTargetUserIds($courseId) { - /** - * 只给付费和vip用户发通知 - */ $sourceTypes = [ CourseUserModel::SOURCE_CHARGE, CourseUserModel::SOURCE_VIP, @@ -88,11 +73,11 @@ class LiveNotifyTask extends Task ->inWhere('source_type', $sourceTypes) ->execute(); - if ($rows->count() > 0) { - return kg_array_column($rows->toArray(), 'user_id'); + if ($rows->count() == 0) { + return []; } - return []; + return kg_array_column($rows->toArray(), 'user_id'); } } diff --git a/app/Console/Tasks/MaintainTask.php b/app/Console/Tasks/MaintainTask.php index f8b1d1e6..4b526448 100644 --- a/app/Console/Tasks/MaintainTask.php +++ b/app/Console/Tasks/MaintainTask.php @@ -2,149 +2,31 @@ namespace App\Console\Tasks; -use App\Caches\Setting as SettingCache; -use App\Library\Cache\Backend\Redis as RedisCache; -use App\Models\Setting as SettingModel; -use Phalcon\Cli\Task; -use Phalcon\Config; +use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache; +use App\Caches\IndexNewCourseList as IndexNewCourseListCache; +use App\Caches\IndexVipCourseList as IndexVipCourseListCache; class MaintainTask extends Task { - public function mainAction() + public function rebuildIndexCourseCacheAction($params) { - $this->resetSettingAction(); - $this->resetAnnotationAction(); - $this->resetMetadataAction(); - $this->resetVoltAction(); - } + $section = $params[0] ?? null; - /** - * 重置设置 - * - * @command: php console.php maintain reset_setting - */ - public function resetSettingAction() - { - echo "start reset setting..." . PHP_EOL; - - $rows = SettingModel::query()->columns('section')->distinct(true)->execute(); - - foreach ($rows as $row) { - $cache = new SettingCache(); - $cache->rebuild($row->section); + if (!$section || $section == 'new_course') { + $cache = new IndexNewCourseListCache(); + $cache->rebuild(); } - echo "end reset setting..." . PHP_EOL; - } - - /** - * 重置注解 - * - * @command: php console.php maintain reset_annotation - */ - public function resetAnnotationAction() - { - $config = $this->getConfig(); - $cache = $this->getCache(); - $redis = $cache->getRedis(); - - $dbIndex = $config->path('annotation.db'); - $statsKey = $config->path('annotation.statsKey'); - - $redis->select($dbIndex); - - $keys = $redis->sMembers($statsKey); - - echo "start reset annotation..." . PHP_EOL; - - if (count($keys) > 0) { - - $keys = $this->handlePhKeys($keys); - - $redis->del(...$keys); - $redis->del($statsKey); + if (!$section || $section == 'free_course') { + $cache = new IndexFreeCourseListCache(); + $cache->rebuild(); } - echo "end reset annotation..." . PHP_EOL; - } - - /** - * 重置元数据 - * - * @command: php console.php maintain reset_metadata - */ - public function resetMetadataAction() - { - $config = $this->getConfig(); - $cache = $this->getCache(); - $redis = $cache->getRedis(); - - $dbIndex = $config->path('metadata.db'); - $statsKey = $config->path('metadata.statsKey'); - - $redis->select($dbIndex); - - $keys = $redis->sMembers($statsKey); - - echo "start reset metadata..." . PHP_EOL; - - if (count($keys) > 0) { - - $keys = $this->handlePhKeys($keys); - - $redis->del(...$keys); - $redis->del($statsKey); + if (!$section || $section == 'vip_course') { + $cache = new IndexVipCourseListCache(); + $cache->rebuild(); } - - echo "start reset metadata..." . PHP_EOL; - } - - /** - * 重置模板 - * - * @command: php console.php maintain reset_volt - */ - public function resetVoltAction() - { - echo "start reset volt..." . PHP_EOL; - - $dir = cache_path('volt'); - - foreach (scandir($dir) as $file) { - if (strpos($file, '.php')) { - unlink($dir . '/' . $file); - } - } - - echo "end reset volt..." . PHP_EOL; - } - - protected function getConfig() - { - /** - * @var Config $config - */ - $config = $this->getDI()->get('config'); - - return $config; - } - - protected function getCache() - { - /** - * @var RedisCache $cache - */ - $cache = $this->getDI()->get('cache'); - - return $cache; - } - - protected function handlePhKeys($keys) - { - return array_map(function ($key) { - return "_PHCR{$key}"; - }, $keys); } } diff --git a/app/Console/Tasks/RefundTask.php b/app/Console/Tasks/RefundTask.php index 0af0a715..0edf1a67 100644 --- a/app/Console/Tasks/RefundTask.php +++ b/app/Console/Tasks/RefundTask.php @@ -13,7 +13,7 @@ use App\Repos\Trade as TradeRepo; use App\Repos\User as UserRepo; use App\Services\Pay\Alipay as AlipayService; use App\Services\Pay\Wxpay as WxpayService; -use App\Services\Smser\Refund as RefundSmser; +use App\Services\Sms\Refund as RefundSms; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -111,7 +111,6 @@ class RefundTask extends Task $task->update(); $logger->info('Refund Task Exception ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getCode(), 'message' => $e->getMessage(), 'task' => $task->toArray(), @@ -284,9 +283,9 @@ class RefundTask extends Task */ protected function handleRefundNotice(RefundModel $refund) { - $smser = new RefundSmser(); + $sms = new RefundSms(); - $smser->handle($refund); + $sms->handle($refund); } /** diff --git a/app/Console/Tasks/RevokeVipTask.php b/app/Console/Tasks/RevokeVipTask.php index 56a11e1d..58380c4b 100644 --- a/app/Console/Tasks/RevokeVipTask.php +++ b/app/Console/Tasks/RevokeVipTask.php @@ -3,7 +3,6 @@ namespace App\Console\Tasks; use App\Models\User as UserModel; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; diff --git a/app/Console/Tasks/SiteMapTask.php b/app/Console/Tasks/SiteMapTask.php index b698b533..d78ce46d 100644 --- a/app/Console/Tasks/SiteMapTask.php +++ b/app/Console/Tasks/SiteMapTask.php @@ -49,9 +49,9 @@ class SiteMapTask extends Task { $service = new AppService(); - $settings = $service->getSectionSettings('site'); + $settings = $service->getSettings('site'); - return $settings['base_url'] ?? ''; + return $settings['url'] ?? ''; } protected function addIndex() @@ -62,7 +62,7 @@ class SiteMapTask extends Task protected function addCourses() { /** - * @var Resultset $courses + * @var Resultset|CourseModel[] $courses */ $courses = CourseModel::query()->where('published = 1')->execute(); diff --git a/app/Console/Tasks/SyncCourseIndexTask.php b/app/Console/Tasks/SyncCourseIndexTask.php index 8911734d..1578f036 100644 --- a/app/Console/Tasks/SyncCourseIndexTask.php +++ b/app/Console/Tasks/SyncCourseIndexTask.php @@ -2,39 +2,23 @@ namespace App\Console\Tasks; -use App\Library\Cache\Backend\Redis as RedisCache; use App\Repos\Course as CourseRepo; use App\Services\Search\CourseDocument; use App\Services\Search\CourseSearcher; -use App\Services\Syncer\CourseIndex as CourseIndexSyncer; +use App\Services\Sync\CourseIndex as CourseIndexSync; class SyncCourseIndexTask extends Task { - /** - * @var RedisCache - */ - protected $cache; - - /** - * @var \Redis - */ - protected $redis; - public function mainAction() { - $this->cache = $this->getDI()->get('cache'); + $cache = $this->getCache(); - $this->redis = $this->cache->getRedis(); + $redis = $this->getRedis(); - $this->rebuild(); - } - - protected function rebuild() - { $key = $this->getSyncKey(); - $courseIds = $this->redis->sRandMember($key, 1000); + $courseIds = $redis->sRandMember($key, 1000); if (!$courseIds) return; @@ -42,9 +26,7 @@ class SyncCourseIndexTask extends Task $courses = $courseRepo->findByIds($courseIds); - if ($courses->count() == 0) { - return; - } + if ($courses->count() == 0) return; $document = new CourseDocument(); @@ -67,14 +49,14 @@ class SyncCourseIndexTask extends Task $index->closeBuffer(); - $this->redis->sRem($key, ...$courseIds); + $redis->sRem($key, ...$courseIds); } protected function getSyncKey() { - $syncer = new CourseIndexSyncer(); + $sync = new CourseIndexSync(); - return $syncer->getSyncKey(); + return $sync->getSyncKey(); } } diff --git a/app/Console/Tasks/SyncGroupIndexTask.php b/app/Console/Tasks/SyncGroupIndexTask.php index ebb81e2f..d48223de 100644 --- a/app/Console/Tasks/SyncGroupIndexTask.php +++ b/app/Console/Tasks/SyncGroupIndexTask.php @@ -2,39 +2,23 @@ namespace App\Console\Tasks; -use App\Library\Cache\Backend\Redis as RedisCache; use App\Repos\ImGroup as GroupRepo; use App\Services\Search\GroupDocument; use App\Services\Search\GroupSearcher; -use App\Services\Syncer\GroupIndex as GroupIndexSyncer; +use App\Services\Sync\GroupIndex as GroupIndexSync; class SyncGroupIndexTask extends Task { - /** - * @var RedisCache - */ - protected $cache; - - /** - * @var \Redis - */ - protected $redis; - public function mainAction() { - $this->cache = $this->getDI()->get('cache'); + $cache = $this->getCache(); - $this->redis = $this->cache->getRedis(); + $redis = $this->getRedis(); - $this->rebuild(); - } - - protected function rebuild() - { $key = $this->getSyncKey(); - $groupIds = $this->redis->sRandMember($key, 1000); + $groupIds = $redis->sRandMember($key, 1000); if (!$groupIds) return; @@ -42,9 +26,7 @@ class SyncGroupIndexTask extends Task $groups = $groupRepo->findByIds($groupIds); - if ($groups->count() == 0) { - return; - } + if ($groups->count() == 0) return; $document = new GroupDocument(); @@ -67,14 +49,14 @@ class SyncGroupIndexTask extends Task $index->closeBuffer(); - $this->redis->sRem($key, ...$groupIds); + $redis->sRem($key, ...$groupIds); } protected function getSyncKey() { - $syncer = new GroupIndexSyncer(); + $sync = new GroupIndexSync(); - return $syncer->getSyncKey(); + return $sync->getSyncKey(); } } diff --git a/app/Console/Tasks/SyncLearningTask.php b/app/Console/Tasks/SyncLearningTask.php index d44006c5..8adbc36e 100644 --- a/app/Console/Tasks/SyncLearningTask.php +++ b/app/Console/Tasks/SyncLearningTask.php @@ -2,7 +2,6 @@ namespace App\Console\Tasks; -use App\Library\Cache\Backend\Redis as RedisCache; use App\Models\Course as CourseModel; use App\Models\Learning as LearningModel; use App\Repos\Chapter as ChapterRepo; @@ -10,43 +9,32 @@ use App\Repos\ChapterUser as ChapterUserRepo; use App\Repos\Course as CourseRepo; use App\Repos\CourseUser as CourseUserRepo; use App\Repos\Learning as LearningRepo; -use App\Services\Syncer\Learning as LearningSyncer; -use Phalcon\Cli\Task; +use App\Services\Sync\Learning as LearningSync; class SyncLearningTask extends Task { - /** - * @var RedisCache - */ - protected $cache; - - /** - * @var \Redis - */ - protected $redis; - public function mainAction() { - $this->cache = $this->getDI()->get('cache'); + $cache = $this->getCache(); - $this->redis = $this->cache->getRedis(); + $redis = $this->getRedis(); - $syncer = new LearningSyncer(); + $sync = new LearningSync(); - $syncKey = $syncer->getSyncKey(); + $syncKey = $sync->getSyncKey(); - $requestIds = $this->redis->sMembers($syncKey); + $requestIds = $redis->sMembers($syncKey); if (!$requestIds) return; foreach ($requestIds as $requestId) { - $itemKey = $syncer->getItemKey($requestId); + $itemKey = $sync->getItemKey($requestId); $this->handleLearning($itemKey); - $this->redis->sRem($syncKey, $requestId); + $redis->sRem($syncKey, $requestId); } } @@ -153,15 +141,11 @@ class SyncLearningTask extends Task $courseLessons = $courseRepo->findLessons($learning->course_id); - if ($courseLessons->count() == 0) { - return; - } + if ($courseLessons->count() == 0) return; $userLearnings = $courseRepo->findUserLearnings($learning->course_id, $learning->user_id, $learning->plan_id); - if ($userLearnings->count() == 0) { - return; - } + if ($userLearnings->count() == 0) return; $consumedUserLearnings = []; @@ -171,9 +155,7 @@ class SyncLearningTask extends Task } } - if (count($consumedUserLearnings) == 0) { - return; - } + if (count($consumedUserLearnings) == 0) return; $duration = 0; diff --git a/app/Console/Tasks/SyncUserIndexTask.php b/app/Console/Tasks/SyncUserIndexTask.php index bd7c8aea..7e55f3da 100644 --- a/app/Console/Tasks/SyncUserIndexTask.php +++ b/app/Console/Tasks/SyncUserIndexTask.php @@ -2,39 +2,23 @@ namespace App\Console\Tasks; -use App\Library\Cache\Backend\Redis as RedisCache; use App\Repos\User as UserRepo; use App\Services\Search\UserDocument; use App\Services\Search\UserSearcher; -use App\Services\Syncer\UserIndex as UserIndexSyncer; +use App\Services\Sync\UserIndex as UserIndexSync; class SyncUserIndexTask extends Task { - /** - * @var RedisCache - */ - protected $cache; - - /** - * @var \Redis - */ - protected $redis; - public function mainAction() { - $this->cache = $this->getDI()->get('cache'); + $cache = $this->getCache(); - $this->redis = $this->cache->getRedis(); + $redis = $this->getRedis(); - $this->rebuild(); - } - - protected function rebuild() - { $key = $this->getSyncKey(); - $userIds = $this->redis->sRandMember($key, 1000); + $userIds = $redis->sRandMember($key, 1000); if (!$userIds) return; @@ -42,9 +26,7 @@ class SyncUserIndexTask extends Task $users = $userRepo->findByIds($userIds); - if ($users->count() == 0) { - return; - } + if ($users->count() == 0) return; $document = new UserDocument(); @@ -67,14 +49,14 @@ class SyncUserIndexTask extends Task $index->closeBuffer(); - $this->redis->sRem($key, ...$userIds); + $redis->sRem($key, ...$userIds); } protected function getSyncKey() { - $syncer = new UserIndexSyncer(); + $sync = new UserIndexSync(); - return $syncer->getSyncKey(); + return $sync->getSyncKey(); } } diff --git a/app/Console/Tasks/Task.php b/app/Console/Tasks/Task.php index dc875cd1..44f9e1d4 100644 --- a/app/Console/Tasks/Task.php +++ b/app/Console/Tasks/Task.php @@ -2,14 +2,46 @@ namespace App\Console\Tasks; -use App\Library\Logger; +use App\Library\Cache\Backend\Redis as RedisCache; +use App\Library\Logger as AppLogger; +use Phalcon\Config as PhConfig; +use Phalcon\Logger\Adapter\File as PhLogger; + class Task extends \Phalcon\Cli\Task { + /** + * @return PhConfig + */ + public function getConfig() + { + return $this->getDI()->getShared('config'); + } + + /** + * @return RedisCache + */ + public function getCache() + { + return $this->getDI()->getShared('cache'); + } + + /** + * @return \Redis + */ + public function getRedis() + { + return $this->getCache()->getRedis(); + } + + /** + * @param null $channel + * @return PhLogger + */ public function getLogger($channel = null) { - $logger = new Logger(); + $logger = new AppLogger(); return $logger->getInstance($channel); } diff --git a/app/Console/Tasks/UnlockUserTask.php b/app/Console/Tasks/UnlockUserTask.php index 0f21f6a0..d499c8f8 100644 --- a/app/Console/Tasks/UnlockUserTask.php +++ b/app/Console/Tasks/UnlockUserTask.php @@ -3,7 +3,6 @@ namespace App\Console\Tasks; use App\Models\User as UserModel; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -14,13 +13,10 @@ class UnlockUserTask extends Task { $users = $this->findUsers(); - if ($users->count() == 0) { - return; - } + if ($users->count() == 0) return; foreach ($users as $user) { - $user->locked = 0; - $user->update(); + $user->update(['locked' => 0]); } } diff --git a/app/Console/Tasks/UpgradeTask.php b/app/Console/Tasks/UpgradeTask.php new file mode 100644 index 00000000..a8600332 --- /dev/null +++ b/app/Console/Tasks/UpgradeTask.php @@ -0,0 +1,127 @@ +resetSettingAction(); + $this->resetAnnotationAction(); + $this->resetMetadataAction(); + $this->resetVoltAction(); + } + + /** + * 重置系统设置 + * + * @command: php console.php upgrade reset_setting + */ + public function resetSettingAction() + { + echo "start reset setting..." . PHP_EOL; + + $rows = SettingModel::query()->columns('section')->distinct(true)->execute(); + + foreach ($rows as $row) { + $cache = new SettingCache(); + $cache->rebuild($row->section); + } + + echo "end reset setting..." . PHP_EOL; + } + + /** + * 重置注解 + * + * @command: php console.php upgrade reset_annotation + */ + public function resetAnnotationAction() + { + $config = $this->getConfig(); + $cache = $this->getCache(); + $redis = $this->getRedis(); + + $dbIndex = $config->path('annotation.db'); + $statsKey = $config->path('annotation.statsKey'); + + $redis->select($dbIndex); + + $keys = $redis->sMembers($statsKey); + + echo "start reset annotation..." . PHP_EOL; + + if (count($keys) > 0) { + + $keys = $this->handlePhKeys($keys); + + $redis->del(...$keys); + $redis->del($statsKey); + } + + echo "end reset annotation..." . PHP_EOL; + } + + /** + * 重置元数据 + * + * @command: php console.php upgrade reset_metadata + */ + public function resetMetadataAction() + { + $config = $this->getConfig(); + $cache = $this->getCache(); + $redis = $this->getRedis(); + + $dbIndex = $config->path('metadata.db'); + $statsKey = $config->path('metadata.statsKey'); + + $redis->select($dbIndex); + + $keys = $redis->sMembers($statsKey); + + echo "start reset metadata..." . PHP_EOL; + + if (count($keys) > 0) { + + $keys = $this->handlePhKeys($keys); + + $redis->del(...$keys); + $redis->del($statsKey); + } + + echo "start reset metadata..." . PHP_EOL; + } + + /** + * 重置模板 + * + * @command: php console.php upgrade reset_volt + */ + public function resetVoltAction() + { + echo "start reset volt..." . PHP_EOL; + + $dir = cache_path('volt'); + + foreach (scandir($dir) as $file) { + if (strpos($file, '.php')) { + unlink($dir . '/' . $file); + } + } + + echo "end reset volt..." . PHP_EOL; + } + + protected function handlePhKeys($keys) + { + return array_map(function ($key) { + return "_PHCR{$key}"; + }, $keys); + } + +} diff --git a/app/Console/Tasks/UserIndexTask.php b/app/Console/Tasks/UserIndexTask.php index 3ec4ce51..6ce9c7d6 100644 --- a/app/Console/Tasks/UserIndexTask.php +++ b/app/Console/Tasks/UserIndexTask.php @@ -5,7 +5,6 @@ namespace App\Console\Tasks; use App\Models\User as UserModel; use App\Services\Search\UserDocument; use App\Services\Search\UserSearcher; -use Phalcon\Cli\Task; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -24,7 +23,7 @@ class UserIndexTask extends Task $query = $params[0] ?? null; if (!$query) { - exit("please special a query word" . PHP_EOL); + exit('please special a query word' . PHP_EOL); } $result = $this->searchUsers($query); @@ -61,11 +60,11 @@ class UserIndexTask extends Task $index = $handler->getXS()->getIndex(); - echo "start clean index" . PHP_EOL; + echo 'start clean index' . PHP_EOL; $index->clean(); - echo "end clean index" . PHP_EOL; + echo 'end clean index' . PHP_EOL; } /** @@ -75,9 +74,7 @@ class UserIndexTask extends Task { $users = $this->findUsers(); - if ($users->count() == 0) { - return; - } + if ($users->count() == 0) return; $handler = new UserSearcher(); @@ -85,7 +82,7 @@ class UserIndexTask extends Task $index = $handler->getXS()->getIndex(); - echo "start rebuild index" . PHP_EOL; + echo 'start rebuild index' . PHP_EOL; $index->beginRebuild(); @@ -96,7 +93,7 @@ class UserIndexTask extends Task $index->endRebuild(); - echo "end rebuild index" . PHP_EOL; + echo 'end rebuild index' . PHP_EOL; } /** diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index 07795c5b..c51e0c1d 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -6,7 +6,6 @@ use App\Models\Chapter as ChapterModel; use App\Repos\Chapter as ChapterRepo; use App\Services\CourseStat as CourseStatService; use App\Services\Vod as VodService; -use Phalcon\Cli\Task; class VodEventTask extends Task { diff --git a/app/Http/Admin/Controllers/ChapterController.php b/app/Http/Admin/Controllers/ChapterController.php index bbef2879..6cfc8e7c 100644 --- a/app/Http/Admin/Controllers/ChapterController.php +++ b/app/Http/Admin/Controllers/ChapterController.php @@ -35,24 +35,24 @@ class ChapterController extends Controller */ public function addAction() { - $courseId = $this->request->getQuery('course_id'); - $parentId = $this->request->getQuery('parent_id'); - $type = $this->request->getQuery('type'); + $courseId = $this->request->getQuery('course_id', 'int'); + $parentId = $this->request->getQuery('parent_id', 'int'); + $type = $this->request->getQuery('type', 'string', 'chapter'); $courseService = new CourseService(); $course = $courseService->getCourse($courseId); $chapters = $courseService->getChapters($courseId); + $this->view->pick('chapter/add_chapter'); + + if ($type == 'lesson') { + $this->view->pick('chapter/add_lesson'); + } + $this->view->setVar('course', $course); $this->view->setVar('parent_id', $parentId); $this->view->setVar('chapters', $chapters); - - if ($type == 'chapter') { - $this->view->pick('chapter/add_chapter'); - } else { - $this->view->pick('chapter/add_lesson'); - } } /** @@ -89,11 +89,12 @@ class ChapterController extends Controller $chapter = $chapterService->getChapter($id); $course = $courseService->getCourse($chapter->course_id); - $this->view->setVar('chapter', $chapter); - $this->view->setVar('course', $course); + $this->view->pick('chapter/edit_chapter'); if ($chapter->parent_id > 0) { + $this->view->pick('chapter/edit_lesson'); + switch ($course->model) { case CourseModel::MODEL_VOD: $vod = $contentService->getChapterVod($chapter->id); @@ -110,12 +111,10 @@ class ChapterController extends Controller $this->view->setVar('read', $read); break; } - - $this->view->pick('chapter/edit_lesson'); - - } else { - $this->view->pick('chapter/edit_chapter'); } + + $this->view->setVar('chapter', $chapter); + $this->view->setVar('course', $course); } /** diff --git a/app/Http/Admin/Controllers/PublicController.php b/app/Http/Admin/Controllers/PublicController.php index 5e0a1ab4..e5b84bbc 100644 --- a/app/Http/Admin/Controllers/PublicController.php +++ b/app/Http/Admin/Controllers/PublicController.php @@ -43,7 +43,7 @@ class PublicController extends \Phalcon\Mvc\Controller */ public function ip2regionAction() { - $ip = $this->request->getQuery('ip', 'trim'); + $ip = $this->request->getQuery('ip', 'string'); $region = kg_ip2region($ip); diff --git a/app/Http/Admin/Controllers/SessionController.php b/app/Http/Admin/Controllers/SessionController.php index d868f531..3c67806f 100644 --- a/app/Http/Admin/Controllers/SessionController.php +++ b/app/Http/Admin/Controllers/SessionController.php @@ -48,7 +48,7 @@ class SessionController extends \Phalcon\Mvc\Controller $settingService = new SettingService(); - $captcha = $settingService->getSectionSettings('captcha'); + $captcha = $settingService->getSettings('captcha'); $this->view->pick('public/login'); $this->view->setVar('app_info', $appInfo); diff --git a/app/Http/Admin/Controllers/SettingController.php b/app/Http/Admin/Controllers/SettingController.php index 1531065b..820b0ac0 100644 --- a/app/Http/Admin/Controllers/SettingController.php +++ b/app/Http/Admin/Controllers/SettingController.php @@ -29,7 +29,7 @@ class SettingController extends Controller } else { - $site = $settingService->getSectionSettings($section); + $site = $settingService->getSettings($section); $site['url'] = $site['url'] ?: kg_site_url(); @@ -56,7 +56,7 @@ class SettingController extends Controller } else { - $secret = $settingService->getSectionSettings($section); + $secret = $settingService->getSettings($section); $this->view->setVar('secret', $secret); } @@ -81,7 +81,7 @@ class SettingController extends Controller } else { - $cos = $settingService->getSectionSettings($section); + $cos = $settingService->getSettings($section); $this->view->setVar('cos', $cos); } @@ -106,7 +106,7 @@ class SettingController extends Controller } else { - $vod = $settingService->getSectionSettings($section); + $vod = $settingService->getSettings($section); $this->view->setVar('vod', $vod); } @@ -121,7 +121,7 @@ class SettingController extends Controller if ($this->request->isPost()) { - $section = $this->request->getPost('section'); + $section = $this->request->getPost('section', 'string'); $data = $this->request->getPost(); @@ -150,7 +150,7 @@ class SettingController extends Controller if ($this->request->isPost()) { - $section = $this->request->getPost('section'); + $section = $this->request->getPost('section', 'string'); $data = $this->request->getPost(); @@ -169,11 +169,11 @@ class SettingController extends Controller } /** - * @Route("/smser", name="admin.setting.smser") + * @Route("/sms", name="admin.setting.sms") */ - public function smserAction() + public function smsAction() { - $section = 'smser'; + $section = 'sms'; $settingService = new SettingService(); @@ -181,24 +181,24 @@ class SettingController extends Controller $data = $this->request->getPost(); - $settingService->updateSmserSettings($section, $data); + $settingService->updateSmsSettings($section, $data); return $this->jsonSuccess(['msg' => '更新配置成功']); } else { - $smser = $settingService->getSectionSettings($section); + $sms = $settingService->getSettings($section); - $this->view->setVar('smser', $smser); + $this->view->setVar('sms', $sms); } } /** - * @Route("/mailer", name="admin.setting.mailer") + * @Route("/mail", name="admin.setting.mail") */ - public function mailerAction() + public function mailAction() { - $section = 'mailer'; + $section = 'mail'; $settingService = new SettingService(); @@ -212,9 +212,9 @@ class SettingController extends Controller } else { - $mailer = $settingService->getSectionSettings($section); + $mail = $settingService->getSettings($section); - $this->view->setVar('mailer', $mailer); + $this->view->setVar('mail', $mail); } } @@ -242,7 +242,7 @@ class SettingController extends Controller } else { - $captcha = $settingService->getSectionSettings($section); + $captcha = $settingService->getSettings($section); $this->view->setVar('captcha', $captcha); } @@ -257,7 +257,7 @@ class SettingController extends Controller if ($this->request->isPost()) { - $data = $this->request->getPost('vip'); + $data = $this->request->getPost('vip', 'string'); $settingService->updateVipSettings($data); @@ -280,7 +280,7 @@ class SettingController extends Controller if ($this->request->isPost()) { - $section = $this->request->getPost('section'); + $section = $this->request->getPost('section', 'string'); $data = $this->request->getPost(); @@ -290,8 +290,8 @@ class SettingController extends Controller } else { - $main = $settingService->getSectionSettings('im.main'); - $cs = $settingService->getSectionSettings('im.cs'); + $main = $settingService->getSettings('im.main'); + $cs = $settingService->getSettings('im.cs'); $this->view->setVar('main', $main); $this->view->setVar('cs', $cs); diff --git a/app/Http/Admin/Controllers/CarouselController.php b/app/Http/Admin/Controllers/SlideController.php similarity index 50% rename from app/Http/Admin/Controllers/CarouselController.php rename to app/Http/Admin/Controllers/SlideController.php index 2d2472b5..8369c875 100644 --- a/app/Http/Admin/Controllers/CarouselController.php +++ b/app/Http/Admin/Controllers/SlideController.php @@ -2,28 +2,28 @@ namespace App\Http\Admin\Controllers; -use App\Http\Admin\Services\Carousel as CarouselService; +use App\Http\Admin\Services\Slide as SlideService; /** - * @RoutePrefix("/admin/carousel") + * @RoutePrefix("/admin/slide") */ -class CarouselController extends Controller +class SlideController extends Controller { /** - * @Get("/list", name="admin.carousel.list") + * @Get("/list", name="admin.slide.list") */ public function listAction() { - $carouselService = new CarouselService(); + $slideService = new SlideService(); - $pager = $carouselService->getCarousels(); + $pager = $slideService->getSlides(); $this->view->setVar('pager', $pager); } /** - * @Get("/add", name="admin.carousel.add") + * @Get("/add", name="admin.slide.add") */ public function addAction() { @@ -31,17 +31,17 @@ class CarouselController extends Controller } /** - * @Post("/create", name="admin.carousel.create") + * @Post("/create", name="admin.slide.create") */ public function createAction() { - $carouselService = new CarouselService(); + $slideService = new SlideService(); - $carousel = $carouselService->createCarousel(); + $slide = $slideService->createSlide(); $location = $this->url->get([ - 'for' => 'admin.carousel.edit', - 'id' => $carousel->id, + 'for' => 'admin.slide.edit', + 'id' => $slide->id, ]); $content = [ @@ -53,27 +53,27 @@ class CarouselController extends Controller } /** - * @Get("/{id:[0-9]+}/edit", name="admin.carousel.edit") + * @Get("/{id:[0-9]+}/edit", name="admin.slide.edit") */ public function editAction($id) { - $carouselService = new CarouselService(); + $slideService = new SlideService(); - $carousel = $carouselService->getCarousel($id); + $slide = $slideService->getSlide($id); - $this->view->setVar('carousel', $carousel); + $this->view->setVar('slide', $slide); } /** - * @Post("/{id:[0-9]+}/update", name="admin.carousel.update") + * @Post("/{id:[0-9]+}/update", name="admin.slide.update") */ public function updateAction($id) { - $carouselService = new CarouselService(); + $slideService = new SlideService(); - $carouselService->updateCarousel($id); + $slideService->updateSlide($id); - $location = $this->url->get(['for' => 'admin.carousel.list']); + $location = $this->url->get(['for' => 'admin.slide.list']); $content = [ 'location' => $location, @@ -84,13 +84,13 @@ class CarouselController extends Controller } /** - * @Post("/{id:[0-9]+}/delete", name="admin.carousel.delete") + * @Post("/{id:[0-9]+}/delete", name="admin.slide.delete") */ public function deleteAction($id) { - $carouselService = new CarouselService(); + $slideService = new SlideService(); - $carouselService->deleteCarousel($id); + $slideService->deleteSlide($id); $location = $this->request->getHTTPReferer(); @@ -103,13 +103,13 @@ class CarouselController extends Controller } /** - * @Post("/{id:[0-9]+}/restore", name="admin.carousel.restore") + * @Post("/{id:[0-9]+}/restore", name="admin.slide.restore") */ public function restoreAction($id) { - $carouselService = new CarouselService(); + $slideService = new SlideService(); - $carouselService->restoreCarousel($id); + $slideService->restoreSlide($id); $location = $this->request->getHTTPReferer(); diff --git a/app/Http/Admin/Controllers/StudentController.php b/app/Http/Admin/Controllers/StudentController.php index 5ef6e5d2..9b2707fb 100644 --- a/app/Http/Admin/Controllers/StudentController.php +++ b/app/Http/Admin/Controllers/StudentController.php @@ -84,7 +84,7 @@ class StudentController extends Controller */ public function editAction() { - $relationId = $this->request->getQuery('relation_id'); + $relationId = $this->request->getQuery('relation_id', 'int'); $studentService = new StudentService(); diff --git a/app/Http/Admin/Controllers/TestController.php b/app/Http/Admin/Controllers/TestController.php index fa017431..ec650dc8 100644 --- a/app/Http/Admin/Controllers/TestController.php +++ b/app/Http/Admin/Controllers/TestController.php @@ -7,11 +7,10 @@ use App\Http\Admin\Services\Setting as SettingService; use App\Http\Admin\Services\WxpayTest as WxpayTestService; use App\Services\Captcha as CaptchaService; use App\Services\Live as LiveService; -use App\Services\Mailer\Test as TestMailerService; +use App\Services\Mail\Test as TestMailService; use App\Services\MyStorage as StorageService; -use App\Services\Smser\Test as TestSmserService; +use App\Services\Sms\Test as TestSmsService; use App\Services\Vod as VodService; -use Phalcon\Mvc\View; /** * @RoutePrefix("/admin/test") @@ -60,14 +59,14 @@ class TestController extends Controller */ public function livePushAction() { - $streamName = $this->request->getQuery('stream'); + $streamName = $this->request->getQuery('stream', 'string'); $liveService = new LiveService(); $pushUrl = $liveService->getPushUrl($streamName); $qrcode = $this->url->get( - ['for' => 'desktop.qrcode'], + ['for' => 'home.qrcode'], ['text' => urlencode($pushUrl)] ); @@ -92,21 +91,20 @@ class TestController extends Controller $pullUrls = $liveService->getPullUrls('test'); - $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->pick('public/live_player'); $this->view->setVar('pull_urls', $pullUrls); } /** - * @Post("/smser", name="admin.test.smser") + * @Post("/sms", name="admin.test.sms") */ - public function smserAction() + public function smsAction() { - $phone = $this->request->getPost('phone'); + $phone = $this->request->getPost('phone', 'string'); - $smserService = new TestSmserService(); + $smsService = new TestSmsService(); - $response = $smserService->handle($phone); + $response = $smsService->handle($phone); if ($response) { return $this->jsonSuccess(['msg' => '发送短信成功,请到收件箱确认']); @@ -116,15 +114,15 @@ class TestController extends Controller } /** - * @Post("/mailer", name="admin.test.mailer") + * @Post("/mail", name="admin.test.mail") */ - public function mailerAction() + public function mailAction() { - $email = $this->request->getPost('email'); + $email = $this->request->getPost('email', 'string'); - $mailerService = new TestMailerService(); + $mailService = new TestMailService(); - $result = $mailerService->handle($email); + $result = $mailService->handle($email); if ($result) { return $this->jsonSuccess(['msg' => '发送邮件成功,请到收件箱确认']); @@ -166,7 +164,7 @@ class TestController extends Controller $this->db->begin(); - $order = $alipayTestService->createOrder(); + $order = $alipayTestService->createAlipayOrder(); $trade = $alipayTestService->createTrade($order); $qrcode = $alipayTestService->scan($trade); @@ -190,7 +188,7 @@ class TestController extends Controller $this->db->begin(); - $order = $wxpayTestService->createOrder(); + $order = $wxpayTestService->createWxpayOrder(); $trade = $wxpayTestService->createTrade($order); $qrcode = $wxpayTestService->scan($trade); @@ -210,7 +208,7 @@ class TestController extends Controller */ public function alipayStatusAction() { - $sn = $this->request->getQuery('sn'); + $sn = $this->request->getQuery('sn', 'string'); $alipayTestService = new AlipayTestService(); @@ -224,7 +222,7 @@ class TestController extends Controller */ public function wxpayStatusAction() { - $sn = $this->request->getQuery('sn'); + $sn = $this->request->getQuery('sn', 'string'); $wxpayTestService = new WxpayTestService(); diff --git a/app/Http/Admin/Controllers/TradeController.php b/app/Http/Admin/Controllers/TradeController.php index 0eb539ce..b4781320 100644 --- a/app/Http/Admin/Controllers/TradeController.php +++ b/app/Http/Admin/Controllers/TradeController.php @@ -70,13 +70,16 @@ class TradeController extends Controller { $tradeService = new TradeService(); - $tradeService->refundTrade($id); + $refund = $tradeService->refundTrade($id); - $location = $this->request->getHTTPReferer(); + $location = $this->url->get([ + 'for' => 'admin.refund.show', + 'id' => $refund->id, + ]); $content = [ 'location' => $location, - 'msg' => '申请退款成功,请到退款管理中审核确认', + 'msg' => '申请退款成功', ]; return $this->jsonSuccess($content); diff --git a/app/Http/Admin/Controllers/UploadController.php b/app/Http/Admin/Controllers/UploadController.php index eb251179..86709468 100644 --- a/app/Http/Admin/Controllers/UploadController.php +++ b/app/Http/Admin/Controllers/UploadController.php @@ -53,13 +53,13 @@ class UploadController extends Controller } /** - * @Post("/editor/img", name="admin.upload.editor_img") + * @Post("/content/img", name="admin.upload.content_img") */ - public function uploadEditorImageAction() + public function uploadContentImageAction() { $service = new StorageService(); - $file = $service->uploadEditorImage(); + $file = $service->uploadContentImage(); if ($file) { return $this->jsonSuccess([ diff --git a/app/Http/Admin/Controllers/VodController.php b/app/Http/Admin/Controllers/VodController.php index 72f4c35f..d2ffdfa5 100644 --- a/app/Http/Admin/Controllers/VodController.php +++ b/app/Http/Admin/Controllers/VodController.php @@ -3,7 +3,6 @@ namespace App\Http\Admin\Controllers; use App\Services\Vod as VodService; -use Phalcon\Mvc\View; /** * @RoutePrefix("/admin/vod") @@ -28,13 +27,12 @@ class VodController extends Controller */ public function playerAction() { - $chapterId = $this->request->getQuery('chapter_id'); - $playUrl = $this->request->getQuery('play_url'); + $chapterId = $this->request->getQuery('chapter_id', 'int'); + $playUrl = $this->request->getQuery('play_url', 'string'); - $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->pick('public/vod_player'); $this->view->setVar('chapter_id', $chapterId); - $this->view->setVar('play_url', urldecode($playUrl)); + $this->view->setVar('play_url', $playUrl); } } diff --git a/app/Http/Admin/Services/AlipayTest.php b/app/Http/Admin/Services/AlipayTest.php index 832f0514..dfc9269f 100644 --- a/app/Http/Admin/Services/AlipayTest.php +++ b/app/Http/Admin/Services/AlipayTest.php @@ -20,7 +20,7 @@ class AlipayTest extends PayTest if ($code) { $codeUrl = $this->url->get( - ['for' => 'desktop.qrcode'], + ['for' => 'home.qrcode'], ['text' => urlencode($code)] ); } diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index c30d4d0f..44482bb0 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -385,25 +385,25 @@ class AuthNode extends Service 'id' => '2-5-1', 'title' => '轮播列表', 'type' => 'menu', - 'route' => 'admin.carousel.list', + 'route' => 'admin.slide.list', ], [ 'id' => '2-5-2', 'title' => '添加轮播', 'type' => 'menu', - 'route' => 'admin.carousel.add', + 'route' => 'admin.slide.add', ], [ 'id' => '2-5-3', 'title' => '编辑轮播', 'type' => 'button', - 'route' => 'admin.carousel.edit', + 'route' => 'admin.slide.edit', ], [ 'id' => '2-5-4', 'title' => '删除轮播', 'type' => 'button', - 'route' => 'admin.carousel.delete', + 'route' => 'admin.slide.delete', ], ], ], @@ -675,13 +675,13 @@ class AuthNode extends Service 'id' => '5-1-6', 'title' => '短信设置', 'type' => 'menu', - 'route' => 'admin.setting.smser', + 'route' => 'admin.setting.sms', ], [ 'id' => '5-1-7', 'title' => '邮件设置', 'type' => 'menu', - 'route' => 'admin.setting.mailer', + 'route' => 'admin.setting.mail', ], [ 'id' => '5-1-8', diff --git a/app/Http/Admin/Services/Chapter.php b/app/Http/Admin/Services/Chapter.php index 6071a2f4..4eeb8264 100644 --- a/app/Http/Admin/Services/Chapter.php +++ b/app/Http/Admin/Services/Chapter.php @@ -3,7 +3,7 @@ namespace App\Http\Admin\Services; use App\Caches\Chapter as ChapterCache; -use App\Caches\CourseCatalog as CourseCatalogCache; +use App\Caches\CourseChapterList as CatalogCache; use App\Models\Chapter as ChapterModel; use App\Models\ChapterLive as ChapterLiveModel; use App\Models\ChapterRead as ChapterReadModel; @@ -249,7 +249,7 @@ class Chapter extends Service protected function rebuildCatalogCache(ChapterModel $chapter) { - $cache = new CourseCatalogCache(); + $cache = new CatalogCache(); $cache->rebuild($chapter->course_id); } diff --git a/app/Http/Admin/Services/ChapterContent.php b/app/Http/Admin/Services/ChapterContent.php index 1fbc24c6..665992bf 100644 --- a/app/Http/Admin/Services/ChapterContent.php +++ b/app/Http/Admin/Services/ChapterContent.php @@ -2,6 +2,7 @@ namespace App\Http\Admin\Services; +use App\Caches\CourseChapterList as CatalogCache; use App\Library\Utils\Word as WordUtil; use App\Models\Chapter as ChapterModel; use App\Models\Course as CourseModel; @@ -63,6 +64,8 @@ class ChapterContent extends Service $this->updateChapterRead($chapter); break; } + + $this->rebuildCatalogCache($chapter); } protected function updateChapterVod(ChapterModel $chapter) @@ -166,4 +169,11 @@ class ChapterContent extends Service $courseStats->updateReadAttrs($chapter->course_id); } + protected function rebuildCatalogCache(ChapterModel $chapter) + { + $cache = new CatalogCache(); + + $cache->rebuild($chapter->course_id); + } + } diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index 503e96b2..9dba1d7c 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -21,7 +21,7 @@ use App\Repos\CourseCategory as CourseCategoryRepo; use App\Repos\CourseRelated as CourseRelatedRepo; use App\Repos\CourseUser as CourseUserRepo; use App\Repos\User as UserRepo; -use App\Services\Syncer\CourseIndex as CourseIndexSyncer; +use App\Services\Sync\CourseIndex as CourseIndexSync; use App\Validators\Course as CourseValidator; class Course extends Service @@ -363,9 +363,9 @@ class Course extends Service protected function rebuildCourseIndex(CourseModel $course) { - $syncer = new CourseIndexSyncer(); + $sync = new CourseIndexSync(); - $syncer->addItem($course->id); + $sync->addItem($course->id); } protected function saveTeachers(CourseModel $course, $teacherIds) diff --git a/app/Http/Admin/Services/PayTest.php b/app/Http/Admin/Services/PayTest.php index 6aa3134d..ea563b0c 100644 --- a/app/Http/Admin/Services/PayTest.php +++ b/app/Http/Admin/Services/PayTest.php @@ -15,11 +15,11 @@ abstract class PayTest extends Service protected $channel; /** - * 创建订单 + * 创建支付宝订单 * * @return OrderModel */ - public function createOrder() + public function createAlipayOrder() { /** * @var AdminAuth $auth @@ -30,8 +30,45 @@ abstract class PayTest extends Service $order = new OrderModel(); - $order->subject = '测试 - 支付测试0.01元'; - $order->amount = 0.01; + $order->subject = '测试 - 支付测试3.01元'; + $order->amount = 3.01; + $order->owner_id = $authUser['id']; + $order->item_type = OrderModel::ITEM_TEST; + + $order->create(); + + return $order; + } + + /** + * 创建微信订单 + * + * @return OrderModel + */ + public function createWxpayOrder() + { + /** + * @var AdminAuth $auth + */ + $auth = $this->getDI()->get('auth'); + + $authUser = $auth->getAuthInfo(); + + $config = $this->getConfig(); + + $order = new OrderModel(); + + /** + * 微信沙箱环境金额不能自定义,只能是测试用例值(沙吊的不行) + */ + if ($config->get('env') == ENV_DEV) { + $order->subject = '测试 - 支付测试3.01元'; + $order->amount = 3.01; + } else { + $order->subject = '测试 - 支付测试0.01元'; + $order->amount = 0.01; + } + $order->owner_id = $authUser['id']; $order->item_type = OrderModel::ITEM_TEST; diff --git a/app/Http/Admin/Services/Session.php b/app/Http/Admin/Services/Session.php index 41064122..9ce79803 100644 --- a/app/Http/Admin/Services/Session.php +++ b/app/Http/Admin/Services/Session.php @@ -24,7 +24,7 @@ class Session extends Service $currentUser = $this->getCurrentUser(); if ($currentUser->id > 0) { - $this->response->redirect(['for' => 'desktop.index']); + $this->response->redirect(['for' => 'home.index']); } $post = $this->request->getPost(); @@ -33,7 +33,7 @@ class Session extends Service $user = $accountValidator->checkAdminLogin($post['account'], $post['password']); - $captchaSettings = $this->getSectionSettings('captcha'); + $captchaSettings = $this->getSettings('captcha'); /** * 验证码是一次性的,放到最后检查,减少第三方调用 diff --git a/app/Http/Admin/Services/Setting.php b/app/Http/Admin/Services/Setting.php index 0899b47f..a11be838 100644 --- a/app/Http/Admin/Services/Setting.php +++ b/app/Http/Admin/Services/Setting.php @@ -11,18 +11,18 @@ class Setting extends Service public function getAlipaySettings() { - $alipay = $this->getSectionSettings('pay.alipay'); + $alipay = $this->getSettings('pay.alipay'); - $alipay['notify_url'] = $alipay['notify_url'] ?: kg_full_url(['for' => 'desktop.alipay_notify']); + $alipay['notify_url'] = $alipay['notify_url'] ?: kg_full_url(['for' => 'home.alipay_notify']); return $alipay; } public function getWxpaySettings() { - $wxpay = $this->getSectionSettings('pay.wxpay'); + $wxpay = $this->getSettings('pay.wxpay'); - $wxpay['notify_url'] = $wxpay['notify_url'] ?: kg_full_url(['for' => 'desktop.wxpay_notify']); + $wxpay['notify_url'] = $wxpay['notify_url'] ?: kg_full_url(['for' => 'home.wxpay_notify']); return $wxpay; } @@ -36,20 +36,20 @@ class Setting extends Service public function getLiveSettings($section) { - $result = $this->getSectionSettings($section); + $result = $this->getSettings($section); if ($section == 'live.notify') { - $result['stream_begin_url'] = $result['stream_begin_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'streamBegin']); - $result['stream_end_url'] = $result['stream_end_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'streamEnd']); - $result['record_url'] = $result['record_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'record']); - $result['snapshot_url'] = $result['snapshot_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'snapshot']); - $result['porn_url'] = $result['porn_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'porn']); + $result['stream_begin_url'] = $result['stream_begin_url'] ?: kg_full_url(['for' => 'home.live_notify'], ['action' => 'streamBegin']); + $result['stream_end_url'] = $result['stream_end_url'] ?: kg_full_url(['for' => 'home.live_notify'], ['action' => 'streamEnd']); + $result['record_url'] = $result['record_url'] ?: kg_full_url(['for' => 'home.live_notify'], ['action' => 'record']); + $result['snapshot_url'] = $result['snapshot_url'] ?: kg_full_url(['for' => 'home.live_notify'], ['action' => 'snapshot']); + $result['porn_url'] = $result['porn_url'] ?: kg_full_url(['for' => 'home.live_notify'], ['action' => 'porn']); } return $result; } - public function getSectionSettings($section) + public function getSettings($section) { $settingsRepo = new SettingRepo(); @@ -119,7 +119,7 @@ class Setting extends Service $this->updateSectionSettings($section, $settings); } - public function updateSmserSettings($section, $settings) + public function updateSmsSettings($section, $settings) { $settings['template'] = kg_json_encode($settings['template']); diff --git a/app/Http/Admin/Services/Carousel.php b/app/Http/Admin/Services/Slide.php similarity index 52% rename from app/Http/Admin/Services/Carousel.php rename to app/Http/Admin/Services/Slide.php index cd746de6..54c7895b 100644 --- a/app/Http/Admin/Services/Carousel.php +++ b/app/Http/Admin/Services/Slide.php @@ -2,16 +2,16 @@ namespace App\Http\Admin\Services; -use App\Caches\IndexCarouselList as IndexCarouselListCache; +use App\Caches\IndexSlideList as IndexSlideListCache; use App\Library\Paginator\Query as PagerQuery; -use App\Models\Carousel as CarouselModel; -use App\Repos\Carousel as CarouselRepo; -use App\Validators\Carousel as CarouselValidator; +use App\Models\Slide as SlideModel; +use App\Repos\Slide as SlideRepo; +use App\Validators\Slide as SlideValidator; -class Carousel extends Service +class Slide extends Service { - public function getCarousels() + public function getSlides() { $pagerQuery = new PagerQuery(); @@ -23,55 +23,55 @@ class Carousel extends Service $page = $pagerQuery->getPage(); $limit = $pagerQuery->getLimit(); - $carouselRepo = new CarouselRepo(); + $slideRepo = new SlideRepo(); - return $carouselRepo->paginate($params, $sort, $page, $limit); + return $slideRepo->paginate($params, $sort, $page, $limit); } - public function getCarousel($id) + public function getSlide($id) { return $this->findOrFail($id); } - public function createCarousel() + public function createSlide() { $post = $this->request->getPost(); - $validator = new CarouselValidator(); + $validator = new SlideValidator(); $data['title'] = $validator->checkTitle($post['title']); $data['target'] = $validator->checkTarget($post['target']); - if ($post['target'] == CarouselModel::TARGET_COURSE) { + if ($post['target'] == SlideModel::TARGET_COURSE) { $course = $validator->checkCourse($post['content']); $data['content'] = $course->id; $data['cover'] = $course->cover; $data['summary'] = $course->summary; - } elseif ($post['target'] == CarouselModel::TARGET_PAGE) { + } elseif ($post['target'] == SlideModel::TARGET_PAGE) { $page = $validator->checkPage($post['content']); $data['content'] = $page->id; - } elseif ($post['target'] == CarouselModel::TARGET_LINK) { + } elseif ($post['target'] == SlideModel::TARGET_LINK) { $data['content'] = $validator->checkLink($post['content']); } $data['priority'] = 20; - $carousel = new CarouselModel(); + $slide = new SlideModel(); - $carousel->create($data); + $slide->create($data); - $this->rebuildCarouselCache(); + $this->rebuildSlideCache(); - return $carousel; + return $slide; } - public function updateCarousel($id) + public function updateSlide($id) { - $carousel = $this->findOrFail($id); + $slide = $this->findOrFail($id); $post = $this->request->getPost(); - $validator = new CarouselValidator(); + $validator = new SlideValidator(); $data = []; @@ -87,18 +87,14 @@ class Carousel extends Service $data['cover'] = $validator->checkCover($post['cover']); } - if (isset($post['style']['bg_color'])) { - $data['style']['bg_color'] = $validator->checkBgColor($post['style']['bg_color']); - } - if (isset($post['content'])) { - if ($carousel->target == CarouselModel::TARGET_COURSE) { + if ($slide->target == SlideModel::TARGET_COURSE) { $course = $validator->checkCourse($post['content']); $data['content'] = $course->id; - } elseif ($carousel->target == CarouselModel::TARGET_PAGE) { + } elseif ($slide->target == SlideModel::TARGET_PAGE) { $page = $validator->checkPage($post['content']); $data['content'] = $page->id; - } elseif ($carousel->target == CarouselModel::TARGET_LINK) { + } elseif ($slide->target == SlideModel::TARGET_LINK) { $data['content'] = $validator->checkLink($post['content']); } } @@ -111,51 +107,51 @@ class Carousel extends Service $data['published'] = $validator->checkPublishStatus($post['published']); } - $carousel->update($data); + $slide->update($data); - $this->rebuildCarouselCache(); + $this->rebuildSlideCache(); - return $carousel; + return $slide; } - public function deleteCarousel($id) + public function deleteSlide($id) { - $carousel = $this->findOrFail($id); + $slide = $this->findOrFail($id); - $carousel->deleted = 1; + $slide->deleted = 1; - $carousel->update(); + $slide->update(); - $this->rebuildCarouselCache(); + $this->rebuildSlideCache(); - return $carousel; + return $slide; } - public function restoreCarousel($id) + public function restoreSlide($id) { - $carousel = $this->findOrFail($id); + $slide = $this->findOrFail($id); - $carousel->deleted = 0; + $slide->deleted = 0; - $carousel->update(); + $slide->update(); - $this->rebuildCarouselCache(); + $this->rebuildSlideCache(); - return $carousel; + return $slide; } - protected function rebuildCarouselCache() + protected function rebuildSlideCache() { - $cache = new IndexCarouselListCache(); + $cache = new IndexSlideListCache(); $cache->rebuild(); } protected function findOrFail($id) { - $validator = new CarouselValidator(); + $validator = new SlideValidator(); - return $validator->checkCarousel($id); + return $validator->checkSlide($id); } } diff --git a/app/Http/Admin/Services/Trade.php b/app/Http/Admin/Services/Trade.php index b471c9c0..7205ce6c 100644 --- a/app/Http/Admin/Services/Trade.php +++ b/app/Http/Admin/Services/Trade.php @@ -101,7 +101,7 @@ class Trade extends Service $refund->create(); - return $trade; + return $refund; } protected function findOrFail($id) diff --git a/app/Http/Admin/Views/carousel/add.volt b/app/Http/Admin/Views/carousel/add.volt index a1a7e1e2..ba0cb7f9 100644 --- a/app/Http/Admin/Views/carousel/add.volt +++ b/app/Http/Admin/Views/carousel/add.volt @@ -2,7 +2,7 @@ {% block content %} -