From 86c66baece174901574d57a0dd0c555f6f4679a2 Mon Sep 17 00:00:00 2001 From: koogua Date: Tue, 2 Mar 2021 19:57:57 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=95=B4=E7=90=86=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BB=A5=E5=8F=8Adeleted=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/CleanLogTask.php | 4 +- app/Console/Tasks/DeliverTask.php | 2 - app/Console/Tasks/NoticeTask.php | 25 ++-- app/Console/Tasks/OptimizeTableTask.php | 30 +++++ app/Console/Tasks/PointGiftDeliverTask.php | 7 +- app/Console/Tasks/RefundTask.php | 30 ++++- app/Console/Tasks/ServerMonitorTask.php | 2 +- app/Console/Tasks/TeacherLiveNoticeTask.php | 2 +- .../Admin/Controllers/SettingController.php | 4 +- app/Http/Admin/Controllers/TestController.php | 12 +- app/Http/Admin/Services/AuthNode.php | 12 +- app/Http/Admin/Services/PointRedeem.php | 12 +- app/Http/Admin/Services/Setting.php | 8 +- app/Http/Admin/Services/Student.php | 1 - app/Http/Admin/Views/consult/list.volt | 2 +- app/Http/Admin/Views/course/list.volt | 5 +- app/Http/Admin/Views/point/history/list.volt | 2 +- app/Http/Admin/Views/review/list.volt | 2 +- app/Http/Admin/Views/setting/point.volt | 26 ++--- app/Http/Admin/Views/setting/sms.volt | 54 +++++++-- .../Admin/Views/setting/wechat_oa_notice.volt | 44 +++++-- app/Http/Admin/Views/student/list.volt | 8 +- .../Home/Controllers/ConnectController.php | 2 +- .../Controllers/UserConsoleController.php | 4 +- .../WechatOfficialAccountController.php | 12 +- app/Http/Home/Services/Connect.php | 4 - app/Http/Home/Services/ImMessageTrait.php | 2 +- ...lAccount.php => WeChatOfficialAccount.php} | 51 +++------ app/Models/ChapterLike.php | 21 ---- app/Models/ChapterUser.php | 21 ---- app/Models/Connect.php | 21 ---- app/Models/ConsultLike.php | 21 ---- app/Models/CourseFavorite.php | 21 ---- app/Models/CourseUser.php | 14 --- app/Models/Learning.php | 7 -- app/Models/PointHistory.php | 21 ---- app/Models/ReviewLike.php | 21 ---- app/Models/Task.php | 2 + app/Models/UserBalance.php | 21 ---- app/Models/UserContact.php | 22 ---- app/Models/UserSession.php | 18 +-- app/Models/UserToken.php | 18 +-- ...echatSubscribe.php => WeChatSubscribe.php} | 23 +--- app/Repos/Chapter.php | 4 +- app/Repos/ChapterUser.php | 4 +- app/Repos/Course.php | 2 +- ...echatSubscribe.php => WeChatSubscribe.php} | 18 +-- app/Services/Auth/Api.php | 25 ++-- app/Services/Auth/Home.php | 21 ++-- app/Services/Logic/Chapter/ChapterInfo.php | 40 +++++-- app/Services/Logic/Chapter/ChapterLike.php | 13 +-- app/Services/Logic/ChapterTrait.php | 8 +- app/Services/Logic/Consult/ConsultCreate.php | 2 +- app/Services/Logic/Consult/ConsultLike.php | 13 +-- app/Services/Logic/Course/CourseFavorite.php | 17 +-- app/Services/Logic/Course/CourseInfo.php | 2 +- app/Services/Logic/CourseTrait.php | 9 +- app/Services/Logic/Notice/AccountLogin.php | 30 ++++- app/Services/Logic/Notice/ConsultReply.php | 48 ++++++-- .../Notice/DingTalk}/ConsultCreate.php | 2 +- .../Notice/DingTalk}/CustomService.php | 2 +- .../Notice/DingTalk}/PointRedeem.php | 2 +- .../Notice/DingTalk}/ServerMonitor.php | 2 +- .../Notice/DingTalk/TeacherLive.php} | 2 +- app/Services/Logic/Notice/LiveBegin.php | 48 ++++++-- app/Services/{ => Logic/Notice}/Mail/Test.php | 2 +- .../{ => Logic/Notice}/Mail/Verify.php | 2 +- app/Services/Logic/Notice/OrderFinish.php | 48 ++++++-- .../Logic/Notice/PointGoodsDeliver.php | 108 ++++++++++++++++++ .../Logic/Notice/PointRedeemFinish.php | 78 ------------- app/Services/Logic/Notice/RefundFinish.php | 48 ++++++-- .../Notice/Sms}/ConsultReply.php | 2 +- .../Logic/Notice/Sms/GoodsDeliver.php | 38 ++++++ .../Notice => Logic/Notice/Sms}/LiveBegin.php | 2 +- .../Notice/Sms}/OrderFinish.php | 2 +- .../Notice/Sms}/RefundFinish.php | 2 +- app/Services/{ => Logic/Notice}/Sms/Test.php | 2 +- .../{ => Logic/Notice}/Sms/Verify.php | 2 +- .../Notice/WeChat}/AccountLogin.php | 12 +- .../Notice/WeChat}/ConsultReply.php | 12 +- .../Logic/Notice/WeChat/GoodsDeliver.php | 37 ++++++ .../Notice/WeChat}/LiveBegin.php | 12 +- .../Notice/WeChat}/OrderFinish.php | 12 +- .../Notice/WeChat}/RefundFinish.php | 12 +- app/Services/Logic/Review/ReviewLike.php | 13 +-- .../Logic/User/Console/ConnectDelete.php | 4 +- app/Services/Logic/Verify/SmsCode.php | 4 +- app/Services/{Wechat.php => WeChat.php} | 2 +- .../{WechatNotice.php => WeChatNotice.php} | 6 +- .../20200827112717_insert_setting_data.php | 6 +- .../20200827113559_insert_user_data.php | 2 - .../20200827120717_insert_nav_data.php | 2 - .../20200901114014_insert_vip_data.php | 2 - .../20200901114122_insert_reward_data.php | 2 - .../20200901121917_insert_role_data.php | 1 - ...201205112717_insert_oauth_setting_data.php | 2 - .../20201212112717_data_202012121830.php | 20 +++- .../20210106112717_data_202101061830.php | 2 - .../20210126081614_schema_202101261615.php | 5 +- .../20210228035113_data_202102280351.php | 92 +++++++++++++++ .../20210302021013_schema_202103021010.php | 91 +++++++++++++++ 101 files changed, 971 insertions(+), 673 deletions(-) rename app/Http/Home/Services/{WechatOfficialAccount.php => WeChatOfficialAccount.php} (80%) rename app/Models/{WechatSubscribe.php => WeChatSubscribe.php} (64%) rename app/Repos/{WechatSubscribe.php => WeChatSubscribe.php} (68%) rename app/Services/{DingTalk/Notice => Logic/Notice/DingTalk}/ConsultCreate.php (97%) rename app/Services/{DingTalk/Notice => Logic/Notice/DingTalk}/CustomService.php (97%) rename app/Services/{DingTalk/Notice => Logic/Notice/DingTalk}/PointRedeem.php (96%) rename app/Services/{DingTalk/Notice => Logic/Notice/DingTalk}/ServerMonitor.php (94%) rename app/Services/{DingTalk/Notice/LiveTeacher.php => Logic/Notice/DingTalk/TeacherLive.php} (96%) rename app/Services/{ => Logic/Notice}/Mail/Test.php (94%) rename app/Services/{ => Logic/Notice}/Mail/Verify.php (96%) create mode 100644 app/Services/Logic/Notice/PointGoodsDeliver.php delete mode 100644 app/Services/Logic/Notice/PointRedeemFinish.php rename app/Services/{Sms/Notice => Logic/Notice/Sms}/ConsultReply.php (94%) create mode 100644 app/Services/Logic/Notice/Sms/GoodsDeliver.php rename app/Services/{Sms/Notice => Logic/Notice/Sms}/LiveBegin.php (95%) rename app/Services/{Sms/Notice => Logic/Notice/Sms}/OrderFinish.php (95%) rename app/Services/{Sms/Notice => Logic/Notice/Sms}/RefundFinish.php (95%) rename app/Services/{ => Logic/Notice}/Sms/Test.php (86%) rename app/Services/{ => Logic/Notice}/Sms/Verify.php (93%) rename app/Services/{Wechat/Notice => Logic/Notice/WeChat}/AccountLogin.php (78%) rename app/Services/{Wechat/Notice => Logic/Notice/WeChat}/ConsultReply.php (73%) create mode 100644 app/Services/Logic/Notice/WeChat/GoodsDeliver.php rename app/Services/{Wechat/Notice => Logic/Notice/WeChat}/LiveBegin.php (72%) rename app/Services/{Wechat/Notice => Logic/Notice/WeChat}/OrderFinish.php (71%) rename app/Services/{Wechat/Notice => Logic/Notice/WeChat}/RefundFinish.php (73%) rename app/Services/{Wechat.php => WeChat.php} (97%) rename app/Services/{WechatNotice.php => WeChatNotice.php} (94%) create mode 100644 db/migrations/20210228035113_data_202102280351.php create mode 100644 db/migrations/20210302021013_schema_202103021010.php diff --git a/app/Console/Tasks/CleanLogTask.php b/app/Console/Tasks/CleanLogTask.php index 581d6163..3db52cd5 100644 --- a/app/Console/Tasks/CleanLogTask.php +++ b/app/Console/Tasks/CleanLogTask.php @@ -15,7 +15,7 @@ class CleanLogTask extends Task $this->cleanSqlLog(); $this->cleanListenLog(); $this->cleanCaptchaLog(); - $this->cleanWechatLog(); + $this->cleanWeChatLog(); $this->cleanMailLog(); $this->cleanSmsLog(); $this->cleanVodLog(); @@ -166,7 +166,7 @@ class CleanLogTask extends Task /** * 清理微信服务日志 */ - protected function cleanWechatLog() + protected function cleanWeChatLog() { $type = 'wechat'; diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index e15007da..09cc77db 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -176,8 +176,6 @@ class DeliverTask extends Task if ($groupUser->create() === false) { throw new \RuntimeException('Create Group User Failed'); } - - continue; } } } diff --git a/app/Console/Tasks/NoticeTask.php b/app/Console/Tasks/NoticeTask.php index 8d3abe45..1f1d084c 100644 --- a/app/Console/Tasks/NoticeTask.php +++ b/app/Console/Tasks/NoticeTask.php @@ -3,14 +3,15 @@ namespace App\Console\Tasks; use App\Models\Task as TaskModel; -use App\Services\DingTalk\Notice\ConsultCreate as ConsultCreateNotice; -use App\Services\DingTalk\Notice\CustomService as CustomServiceNotice; -use App\Services\DingTalk\Notice\ServerMonitor as ServerMonitorNotice; -use App\Services\DingTalk\Notice\TeacherLive as TeacherLiveNotice; use App\Services\Logic\Notice\AccountLogin as AccountLoginNotice; use App\Services\Logic\Notice\ConsultReply as ConsultReplyNotice; +use App\Services\Logic\Notice\DingTalk\ConsultCreate as ConsultCreateNotice; +use App\Services\Logic\Notice\DingTalk\CustomService as CustomServiceNotice; +use App\Services\Logic\Notice\DingTalk\ServerMonitor as ServerMonitorNotice; +use App\Services\Logic\Notice\DingTalk\TeacherLive as TeacherLiveNotice; use App\Services\Logic\Notice\LiveBegin as LiveBeginNotice; use App\Services\Logic\Notice\OrderFinish as OrderFinishNotice; +use App\Services\Logic\Notice\PointGoodsDeliver as PointGoodsDeliverNotice; use App\Services\Logic\Notice\RefundFinish as RefundFinishNotice; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -24,9 +25,7 @@ class NoticeTask extends Task $tasks = $this->findTasks(300); - if ($tasks->count() == 0) { - return; - } + if ($tasks->count() == 0) return; foreach ($tasks as $task) { @@ -48,6 +47,9 @@ class NoticeTask extends Task case TaskModel::TYPE_NOTICE_CONSULT_REPLY: $this->handleConsultReplyNotice($task); break; + case TaskModel::TYPE_NOTICE_POINT_GOODS_DELIVER: + $this->handlePointGoodsDeliverNotice($task); + break; case TaskModel::TYPE_NOTICE_CONSULT_CREATE: $this->handleConsultCreateNotice($task); break; @@ -122,6 +124,13 @@ class NoticeTask extends Task $notice->handleTask($task); } + protected function handlePointGoodsDeliverNotice(TaskModel $task) + { + $notice = new PointGoodsDeliverNotice(); + + $notice->handleTask($task); + } + protected function handleConsultCreateNotice(TaskModel $task) { $notice = new ConsultCreateNotice(); @@ -162,6 +171,8 @@ class NoticeTask extends Task TaskModel::TYPE_NOTICE_ORDER_FINISH, TaskModel::TYPE_NOTICE_REFUND_FINISH, TaskModel::TYPE_NOTICE_CONSULT_REPLY, + TaskModel::TYPE_NOTICE_POINT_GOODS_DELIVER, + TaskModel::TYPE_NOTICE_LUCKY_GOODS_DELIVER, TaskModel::TYPE_NOTICE_CONSULT_CREATE, TaskModel::TYPE_NOTICE_TEACHER_LIVE, TaskModel::TYPE_NOTICE_SERVER_MONITOR, diff --git a/app/Console/Tasks/OptimizeTableTask.php b/app/Console/Tasks/OptimizeTableTask.php index 7143c0b7..f690cb8a 100644 --- a/app/Console/Tasks/OptimizeTableTask.php +++ b/app/Console/Tasks/OptimizeTableTask.php @@ -5,17 +5,47 @@ namespace App\Console\Tasks; use App\Models\ImMessage as ImMessageModel; use App\Models\Learning as LearningModel; use App\Models\Task as TaskModel; +use App\Models\UserSession as UserSessionModel; +use App\Models\UserToken as UserTokenModel; class OptimizeTableTask extends Task { public function mainAction() { + $this->optimizeUserSessionTable(); + $this->optimizeUserTokenTable(); $this->optimizeImMessageTable(); $this->optimizeLearningTable(); $this->optimizeTaskTable(); } + protected function optimizeUserSessionTable() + { + $sessionModel = new UserSessionModel(); + + $tableName = $sessionModel->getSource(); + + $this->db->delete($tableName, "expire_time < :expire_time", [ + 'expire_time' => strtotime('-3 days'), + ]); + + $this->db->execute("OPTIMIZE TABLE {$tableName}"); + } + + protected function optimizeUserTokenTable() + { + $tokenModel = new UserTokenModel(); + + $tableName = $tokenModel->getSource(); + + $this->db->delete($tableName, "expire_time < :expire_time", [ + 'expire_time' => strtotime('-3 days'), + ]); + + $this->db->execute("OPTIMIZE TABLE {$tableName}"); + } + protected function optimizeImMessageTable() { $count = ImMessageModel::count(); diff --git a/app/Console/Tasks/PointGiftDeliverTask.php b/app/Console/Tasks/PointGiftDeliverTask.php index 1af243e7..0f0778ab 100644 --- a/app/Console/Tasks/PointGiftDeliverTask.php +++ b/app/Console/Tasks/PointGiftDeliverTask.php @@ -13,7 +13,7 @@ use App\Repos\ImGroup as ImGroupRepo; use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\PointGift as PointGiftRepo; use App\Repos\PointRedeem as PointRedeemRepo; -use App\Services\DingTalk\Notice\PointRedeem as PointRedeemNotice; +use App\Services\Logic\Notice\DingTalk\PointRedeem as PointRedeemNotice; use App\Services\Logic\Point\PointHistory as PointHistoryService; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; @@ -181,11 +181,6 @@ class PointGiftDeliverTask extends Task $service->handlePointRefund($redeem); } - protected function handleRedeemFinishNotice(PointRedeemModel $redeem) - { - - } - /** * @param int $limit * @return ResultsetInterface|Resultset|TaskModel[] diff --git a/app/Console/Tasks/RefundTask.php b/app/Console/Tasks/RefundTask.php index 9689542c..1a3556ff 100644 --- a/app/Console/Tasks/RefundTask.php +++ b/app/Console/Tasks/RefundTask.php @@ -6,7 +6,9 @@ use App\Models\Order as OrderModel; use App\Models\Refund as RefundModel; use App\Models\Task as TaskModel; use App\Models\Trade as TradeModel; +use App\Repos\Course as CourseRepo; use App\Repos\CourseUser as CourseUserRepo; +use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\Order as OrderRepo; use App\Repos\Refund as RefundRepo; use App\Repos\Trade as TradeRepo; @@ -172,17 +174,26 @@ class RefundTask extends Task protected function handleCourseOrderRefund(OrderModel $order) { $courseUserRepo = new CourseUserRepo(); - $courseUser = $courseUserRepo->findCourseStudent($order->item_id, $order->owner_id); if ($courseUser) { - $courseUser->deleted = 1; - if ($courseUser->update() === false) { throw new \RuntimeException('Delete Course User Failed'); } } + + $courseRepo = new CourseRepo(); + $group = $courseRepo->findImGroup($order->item_id); + + $groupUserRepo = new ImGroupUserRepo(); + $groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id); + + if ($groupUser) { + if ($groupUser->delete() === false) { + throw new \RuntimeException('Delete Group User Failed'); + } + } } /** @@ -193,6 +204,8 @@ class RefundTask extends Task protected function handlePackageOrderRefund(OrderModel $order) { $courseUserRepo = new CourseUserRepo(); + $groupUserRepo = new ImGroupUserRepo(); + $courseRepo = new CourseRepo(); $itemInfo = $order->item_info; @@ -201,13 +214,20 @@ class RefundTask extends Task $courseUser = $courseUserRepo->findCourseStudent($course['id'], $order->owner_id); if ($courseUser) { - $courseUser->deleted = 1; - if ($courseUser->update() === false) { throw new \RuntimeException('Delete Course User Failed'); } } + + $group = $courseRepo->findImGroup($course['id']); + $groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id); + + if ($groupUser) { + if ($groupUser->delete() === false) { + throw new \RuntimeException('Delete Group User Failed'); + } + } } } diff --git a/app/Console/Tasks/ServerMonitorTask.php b/app/Console/Tasks/ServerMonitorTask.php index 7eff21ca..b6fefeb9 100644 --- a/app/Console/Tasks/ServerMonitorTask.php +++ b/app/Console/Tasks/ServerMonitorTask.php @@ -4,7 +4,7 @@ namespace App\Console\Tasks; use App\Library\Benchmark; use App\Models\User as UserModel; -use App\Services\DingTalk\Notice\ServerMonitor as ServerMonitorNotice; +use App\Services\Logic\Notice\DingTalk\ServerMonitor as ServerMonitorNotice; use App\Services\Search\UserSearcher; use GatewayClient\Gateway; diff --git a/app/Console/Tasks/TeacherLiveNoticeTask.php b/app/Console/Tasks/TeacherLiveNoticeTask.php index fac00d68..d3849e82 100644 --- a/app/Console/Tasks/TeacherLiveNoticeTask.php +++ b/app/Console/Tasks/TeacherLiveNoticeTask.php @@ -4,7 +4,7 @@ namespace App\Console\Tasks; use App\Models\ChapterLive as ChapterLiveModel; use App\Repos\ChapterLive as ChapterLiveRepo; -use App\Services\DingTalk\Notice\TeacherLive as TeacherLiveNotice; +use App\Services\Logic\Notice\DingTalk\TeacherLive as TeacherLiveNotice; use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\ResultsetInterface; diff --git a/app/Http/Admin/Controllers/SettingController.php b/app/Http/Admin/Controllers/SettingController.php index c7734972..1a79a60e 100644 --- a/app/Http/Admin/Controllers/SettingController.php +++ b/app/Http/Admin/Controllers/SettingController.php @@ -365,13 +365,13 @@ class SettingController extends Controller $data = $this->request->getPost(); - $settingService->updateWechatOASettings($section, $data); + $settingService->updateWeChatOASettings($section, $data); return $this->jsonSuccess(['msg' => '更新配置成功']); } else { - $oa = $settingService->getWechatOASettings(); + $oa = $settingService->getWeChatOASettings(); $this->view->pick('setting/wechat_oa'); $this->view->setVar('oa', $oa); diff --git a/app/Http/Admin/Controllers/TestController.php b/app/Http/Admin/Controllers/TestController.php index d159935d..8ee8b549 100644 --- a/app/Http/Admin/Controllers/TestController.php +++ b/app/Http/Admin/Controllers/TestController.php @@ -8,11 +8,11 @@ use App\Http\Admin\Services\WxpayTest as WxpayTestService; use App\Services\Captcha as CaptchaService; use App\Services\DingTalkNotice as DingTalkNoticeService; use App\Services\Live as LiveService; -use App\Services\Mail\Test as TestMailService; +use App\Services\Logic\Notice\Mail\Test as MailTestService; +use App\Services\Logic\Notice\Sms\Test as SmsTestService; use App\Services\MyStorage as StorageService; -use App\Services\Sms\Test as TestSmsService; use App\Services\Vod as VodService; -use App\Services\Wechat as WechatService; +use App\Services\WeChat as WeChatService; /** * @RoutePrefix("/admin/test") @@ -61,7 +61,7 @@ class TestController extends Controller */ public function wechatOaAction() { - $wechatService = new WechatService(); + $wechatService = new WeChatService(); $oa = $wechatService->getOfficialAccount(); @@ -122,7 +122,7 @@ class TestController extends Controller { $phone = $this->request->getPost('phone', 'string'); - $smsService = new TestSmsService(); + $smsService = new SmsTestService(); $response = $smsService->handle($phone); @@ -140,7 +140,7 @@ class TestController extends Controller { $email = $this->request->getPost('email', 'string'); - $mailService = new TestMailService(); + $mailService = new MailTestService(); $result = $mailService->handle($email); diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index a0978c90..9bb89df8 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -794,6 +794,12 @@ class AuthNode extends Service 'type' => 'menu', 'route' => 'admin.setting.vip', ], + [ + 'id' => '5-1-14', + 'title' => '积分设置', + 'type' => 'menu', + 'route' => 'admin.setting.point', + ], [ 'id' => '5-1-11', 'title' => '微聊设置', @@ -818,12 +824,6 @@ class AuthNode extends Service 'type' => 'menu', 'route' => 'admin.setting.dingtalk_robot', ], - [ - 'id' => '5-1-14', - 'title' => '积分设置', - 'type' => 'menu', - 'route' => 'admin.setting.point', - ], ], ], ], diff --git a/app/Http/Admin/Services/PointRedeem.php b/app/Http/Admin/Services/PointRedeem.php index f3812807..a3a2b354 100644 --- a/app/Http/Admin/Services/PointRedeem.php +++ b/app/Http/Admin/Services/PointRedeem.php @@ -6,6 +6,7 @@ use App\Library\Paginator\Query as PagerQuery; use App\Models\PointGift as PointGiftModel; use App\Models\PointRedeem as PointRedeemModel; use App\Repos\PointRedeem as PointRedeemRepo; +use App\Services\Logic\Notice\PointGoodsDeliver as PointGoodsDeliverNotice; use App\Validators\PointRedeem as PointRedeemValidator; class PointRedeem extends Service @@ -17,8 +18,6 @@ class PointRedeem extends Service $params = $pagerQuery->getParams(); - $params['deleted'] = $params['deleted'] ?? 0; - $sort = $pagerQuery->getSort(); $page = $pagerQuery->getPage(); $limit = $pagerQuery->getLimit(); @@ -45,9 +44,18 @@ class PointRedeem extends Service $redeem->update(); + $this->handleGoodsDeliverNotice($redeem); + return $redeem; } + protected function handleGoodsDeliverNotice(PointRedeemModel $redeem) + { + $notice = new PointGoodsDeliverNotice(); + + $notice->createTask($redeem); + } + protected function findOrFail($id) { $validator = new PointRedeemValidator(); diff --git a/app/Http/Admin/Services/Setting.php b/app/Http/Admin/Services/Setting.php index c076eb4e..5989b2ac 100644 --- a/app/Http/Admin/Services/Setting.php +++ b/app/Http/Admin/Services/Setting.php @@ -5,7 +5,7 @@ namespace App\Http\Admin\Services; use App\Caches\Setting as SettingCache; use App\Repos\Setting as SettingRepo; use App\Repos\Vip as VipRepo; -use App\Services\Wechat as WechatService; +use App\Services\WeChat as WeChatService; class Setting extends Service { @@ -58,7 +58,7 @@ class Setting extends Service return $wxpay; } - public function getWechatOASettings() + public function getWeChatOASettings() { $oa = $this->getSettings('wechat.oa'); @@ -205,7 +205,7 @@ class Setting extends Service } } - public function updateWechatOASettings($section, $settings) + public function updateWeChatOASettings($section, $settings) { if (!empty($settings['notice_template'])) { $settings['notice_template'] = kg_json_encode($settings['notice_template']); @@ -232,7 +232,7 @@ class Setting extends Service } if (!empty($buttons)) { - $service = new WechatService(); + $service = new WeChatService(); $oa = $service->getOfficialAccount(); $oa->menu->create($buttons); } diff --git a/app/Http/Admin/Services/Student.php b/app/Http/Admin/Services/Student.php index 2e8b9b4f..188693e8 100644 --- a/app/Http/Admin/Services/Student.php +++ b/app/Http/Admin/Services/Student.php @@ -45,7 +45,6 @@ class Student extends Service $params = $pagerQuery->getParams(); $params['role_type'] = CourseUserModel::ROLE_STUDENT; - $params['deleted'] = $params['deleted'] ?? 0; $sort = $pagerQuery->getSort(); $page = $pagerQuery->getPage(); diff --git a/app/Http/Admin/Views/consult/list.volt b/app/Http/Admin/Views/consult/list.volt index 65f0f5ee..c4bba140 100644 --- a/app/Http/Admin/Views/consult/list.volt +++ b/app/Http/Admin/Views/consult/list.volt @@ -55,7 +55,7 @@ {% set restore_url = url({'for':'admin.consult.restore','id':item.id}) %} -

课程:{{ item.course.title }}{{ private_info(item.private) }}

+

课程:{{ item.course.title }}({{ item.course.id }}){{ private_info(item.private) }}

提问:{{ item.question }}

回复:{{ item.answer }}

diff --git a/app/Http/Admin/Views/course/list.volt b/app/Http/Admin/Views/course/list.volt index 9af90372..77429637 100644 --- a/app/Http/Admin/Views/course/list.volt +++ b/app/Http/Admin/Views/course/list.volt @@ -65,7 +65,8 @@ - + + @@ -75,6 +76,7 @@ + @@ -96,6 +98,7 @@ {% set review_url = url({'for':'admin.review.list'},{'course_id':item.id}) %} {% set consult_url = url({'for':'admin.consult.list'},{'course_id':item.id}) %} + - - - - - - - + + + + + + +
编号 课程 课时数 用户数
{{ item.id }}

标题:{{ item.title }} {{ model_info(item.model) }}

{{ category_info(item.category) }}  {{ teacher_info(item.teacher) }}  {{ level_info(item.level) }}

diff --git a/app/Http/Admin/Views/point/history/list.volt b/app/Http/Admin/Views/point/history/list.volt index 145ecffa..dc792276 100644 --- a/app/Http/Admin/Views/point/history/list.volt +++ b/app/Http/Admin/Views/point/history/list.volt @@ -21,7 +21,7 @@ - + diff --git a/app/Http/Admin/Views/review/list.volt b/app/Http/Admin/Views/review/list.volt index 5ae6b73d..9662d707 100644 --- a/app/Http/Admin/Views/review/list.volt +++ b/app/Http/Admin/Views/review/list.volt @@ -48,7 +48,7 @@ {% set restore_url = url({'for':'admin.review.restore','id':item.id}) %} diff --git a/app/Http/Admin/Views/setting/point.volt b/app/Http/Admin/Views/setting/point.volt index e3fd8ed8..93fc26cd 100644 --- a/app/Http/Admin/Views/setting/point.volt +++ b/app/Http/Admin/Views/setting/point.volt @@ -38,64 +38,64 @@
-

课程:{{ item.course.title }}

+

课程:{{ item.course.title }}({{ item.course.id }})

评价:{{ item.content }}

时间:{{ date('Y-m-d H:i:s',item.create_time) }}

- - + + + - - - + + - - + + - - + + - - + + - - + +
行为类型启用规则 奖励积分 每日上限启用规则
帐号注册N/A N/A
站点访问N/A N/A
课程评价N/A N/A
课时学习N/A N/A
微聊讨论N/A N/A
diff --git a/app/Http/Admin/Views/setting/sms.volt b/app/Http/Admin/Views/setting/sms.volt index b0f337a8..402798f3 100644 --- a/app/Http/Admin/Views/setting/sms.volt +++ b/app/Http/Admin/Views/setting/sms.volt @@ -32,13 +32,15 @@ - + + + @@ -46,32 +48,62 @@ - - + + + - - + + + + + + + + + + - - + + + - - + + + - - + + + diff --git a/app/Http/Admin/Views/setting/wechat_oa_notice.volt b/app/Http/Admin/Views/setting/wechat_oa_notice.volt index 0b7eee16..2040b9a1 100644 --- a/app/Http/Admin/Views/setting/wechat_oa_notice.volt +++ b/app/Http/Admin/Views/setting/wechat_oa_notice.volt @@ -3,35 +3,65 @@
名称启用模板 模板编号 模板内容 操作
身份验证用户身份验证 + + + 复制
订单通知商品发货通知 + + + 复制
购买成功通知 + + + 复制
退款通知退款成功通知 + + + 复制
直播提醒课程直播提醒 + + + 复制
咨询通知咨询回复通知 + + + 复制
+ + - + + - - + + + + + + + + - + + - + + - - + + +
模板名称启用模板 模板编号
登录成功通知 + + +
购买成功提醒购买成功通知 + + +
商品发货通知 + + +
退款成功通知 + + +
课程直播提醒 + + +
咨询结果通知咨询回复通知 + + +
diff --git a/app/Http/Admin/Views/student/list.volt b/app/Http/Admin/Views/student/list.volt index c8554604..fee41bea 100644 --- a/app/Http/Admin/Views/student/list.volt +++ b/app/Http/Admin/Views/student/list.volt @@ -75,8 +75,12 @@
{{ source_type_info(item.source_type) }} -

开始:{{ date('Y-m-d H:i',item.create_time) }}

-

结束:{{ date('Y-m-d H:i',item.expiry_time) }}

+ {% if item.source_type in [1,3] %} + N/A + {% else %} +

开始:{{ date('Y-m-d H:i',item.create_time) }}

+

结束:{{ date('Y-m-d H:i',item.expiry_time) }}

+ {% endif %}
diff --git a/app/Http/Home/Controllers/ConnectController.php b/app/Http/Home/Controllers/ConnectController.php index 708e3e81..17bfa3ff 100644 --- a/app/Http/Home/Controllers/ConnectController.php +++ b/app/Http/Home/Controllers/ConnectController.php @@ -123,7 +123,7 @@ class ConnectController extends Controller return $this->response->redirect(['for' => 'home.uc.account']); } } else { - if ($connect && $connect->deleted == 0) { + if ($connect) { $service->authLogin($connect); return $this->response->redirect(['for' => 'home.index']); } diff --git a/app/Http/Home/Controllers/UserConsoleController.php b/app/Http/Home/Controllers/UserConsoleController.php index de6a035f..8fc7486a 100644 --- a/app/Http/Home/Controllers/UserConsoleController.php +++ b/app/Http/Home/Controllers/UserConsoleController.php @@ -2,7 +2,7 @@ namespace App\Http\Home\Controllers; -use App\Repos\WechatSubscribe as WechatSubscribeRepo; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; use App\Services\Logic\Account\OAuthProvider as OAuthProviderService; use App\Services\Logic\User\Console\AccountInfo as AccountInfoService; use App\Services\Logic\User\Console\ConnectDelete as ConnectDeleteService; @@ -255,7 +255,7 @@ class UserConsoleController extends Controller */ public function subscribeAction() { - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($this->authUser->id); diff --git a/app/Http/Home/Controllers/WechatOfficialAccountController.php b/app/Http/Home/Controllers/WechatOfficialAccountController.php index 223170e7..b67cab4f 100644 --- a/app/Http/Home/Controllers/WechatOfficialAccountController.php +++ b/app/Http/Home/Controllers/WechatOfficialAccountController.php @@ -2,13 +2,13 @@ namespace App\Http\Home\Controllers; -use App\Http\Home\Services\WechatOfficialAccount as WechatOAService; +use App\Http\Home\Services\WeChatOfficialAccount as WeChatOAService; use App\Traits\Response as ResponseTrait; /** * @RoutePrefix("/wechat/oa") */ -class WechatOfficialAccountController extends \Phalcon\Mvc\Controller +class WeChatOfficialAccountController extends \Phalcon\Mvc\Controller { use ResponseTrait; @@ -18,7 +18,7 @@ class WechatOfficialAccountController extends \Phalcon\Mvc\Controller */ public function subscribeStatusAction() { - $service = new WechatOAService(); + $service = new WeChatOAService(); $status = $service->getSubscribeStatus(); @@ -30,7 +30,7 @@ class WechatOfficialAccountController extends \Phalcon\Mvc\Controller */ public function subscribeQrCodeAction() { - $service = new WechatOAService(); + $service = new WeChatOAService(); $qrcode = $service->createSubscribeQrCode(); @@ -42,7 +42,7 @@ class WechatOfficialAccountController extends \Phalcon\Mvc\Controller */ public function verifyAction() { - $service = new WechatOAService(); + $service = new WeChatOAService(); $app = $service->getOfficialAccount(); @@ -58,7 +58,7 @@ class WechatOfficialAccountController extends \Phalcon\Mvc\Controller */ public function notifyAction() { - $service = new WechatOAService(); + $service = new WeChatOAService(); $app = $service->getOfficialAccount(); diff --git a/app/Http/Home/Services/Connect.php b/app/Http/Home/Services/Connect.php index 2e3a26f5..360cce00 100644 --- a/app/Http/Home/Services/Connect.php +++ b/app/Http/Home/Services/Connect.php @@ -195,10 +195,6 @@ class Connect extends Service $connect->user_id = $user->id; } - if ($connect->deleted == 1) { - $connect->deleted = 0; - } - $connect->update(); } else { diff --git a/app/Http/Home/Services/ImMessageTrait.php b/app/Http/Home/Services/ImMessageTrait.php index 07b33bd7..aa95dfb4 100644 --- a/app/Http/Home/Services/ImMessageTrait.php +++ b/app/Http/Home/Services/ImMessageTrait.php @@ -11,7 +11,7 @@ use App\Models\ImMessage as ImMessageModel; use App\Repos\ImFriendUser as ImFriendUserRepo; use App\Repos\ImMessage as ImMessageRepo; use App\Repos\ImUser as ImUserRepo; -use App\Services\DingTalk\Notice\CustomService as CustomServiceNotice; +use App\Services\Logic\Notice\DingTalk\CustomService as CustomServiceNotice; use App\Validators\ImFriendUser as ImFriendUserValidator; use App\Validators\ImGroup as ImGroupValidator; use App\Validators\ImGroupUser as ImGroupUserValidator; diff --git a/app/Http/Home/Services/WechatOfficialAccount.php b/app/Http/Home/Services/WeChatOfficialAccount.php similarity index 80% rename from app/Http/Home/Services/WechatOfficialAccount.php rename to app/Http/Home/Services/WeChatOfficialAccount.php index 6fd0e48c..455615ed 100644 --- a/app/Http/Home/Services/WechatOfficialAccount.php +++ b/app/Http/Home/Services/WeChatOfficialAccount.php @@ -2,18 +2,18 @@ namespace App\Http\Home\Services; -use App\Models\WechatSubscribe as WechatSubscribeModel; +use App\Models\WeChatSubscribe as WeChatSubscribeModel; use App\Repos\User as UserRepo; -use App\Repos\WechatSubscribe as WechatSubscribeRepo; -use App\Services\Wechat as WechatService; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; +use App\Services\WeChat as WeChatService; use EasyWeChat\Kernel\Messages\Text as TextMessage; -class WechatOfficialAccount extends Service +class WeChatOfficialAccount extends Service { public function getOfficialAccount() { - $service = new WechatService(); + $service = new WeChatService(); return $service->getOfficialAccount(); } @@ -33,24 +33,18 @@ class WechatOfficialAccount extends Service { $user = $this->getLoginUser(); - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($user->id); - $status = 0; - - if ($subscribe) { - $status = $subscribe->deleted == 0 ? 1 : 0; - } - - return $status; + return $subscribe ? 1 : 0; } public function handleNotify($message) { - $service = new WechatService(); + $service = new WeChatService(); - $service->logger->info('Received Message ' . json_encode($message)); + $service->logger->debug('Received Message ' . json_encode($message)); switch ($message['MsgType']) { case 'event': @@ -107,17 +101,6 @@ class WechatOfficialAccount extends Service protected function handleSubscribeEvent($message) { - $openId = $message['FromUserName'] ?? ''; - - $subscribeRepo = new WechatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByOpenId($openId); - - if ($subscribe && $subscribe->deleted == 1) { - $subscribe->deleted = 0; - $subscribe->update(); - } - return new TextMessage('开心呀,我们又多了一个小伙伴!'); } @@ -125,13 +108,12 @@ class WechatOfficialAccount extends Service { $openId = $message['FromUserName'] ?? ''; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByOpenId($openId); - if ($subscribe && $subscribe->deleted == 0) { - $subscribe->deleted = 1; - $subscribe->update(); + if ($subscribe) { + $subscribe->delete(); } return new TextMessage('伤心呀,我们又少了一个小伙伴!'); @@ -150,7 +132,7 @@ class WechatOfficialAccount extends Service if (!$user) return; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByOpenId($openId); @@ -158,16 +140,15 @@ class WechatOfficialAccount extends Service if ($subscribe->user_id != $userId) { $subscribe->user_id = $userId; } - if ($subscribe->deleted == 1) { - $subscribe->deleted = 0; - } $subscribe->update(); } else { - $subscribe = new WechatSubscribeModel(); + $subscribe = new WeChatSubscribeModel(); $subscribe->user_id = $userId; $subscribe->open_id = $openId; $subscribe->create(); } + + return $this->emptyReply(); } protected function handleClickEvent($message) diff --git a/app/Models/ChapterLike.php b/app/Models/ChapterLike.php index 0421eee1..efae1826 100644 --- a/app/Models/ChapterLike.php +++ b/app/Models/ChapterLike.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class ChapterLike extends Model { @@ -28,13 +26,6 @@ class ChapterLike extends Model */ public $user_id = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -54,18 +45,6 @@ class ChapterLike extends Model return 'kg_chapter_like'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/ChapterUser.php b/app/Models/ChapterUser.php index b3afebe0..7852a6a8 100644 --- a/app/Models/ChapterUser.php +++ b/app/Models/ChapterUser.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class ChapterUser extends Model { @@ -70,13 +68,6 @@ class ChapterUser extends Model */ public $consumed = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -96,18 +87,6 @@ class ChapterUser extends Model return 'kg_chapter_user'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/Connect.php b/app/Models/Connect.php index c5aa5cbd..31e805ed 100644 --- a/app/Models/Connect.php +++ b/app/Models/Connect.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class Connect extends Model { @@ -53,13 +51,6 @@ class Connect extends Model */ public $provider = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -79,18 +70,6 @@ class Connect extends Model return 'kg_connect'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/ConsultLike.php b/app/Models/ConsultLike.php index b88af738..2b4326bb 100644 --- a/app/Models/ConsultLike.php +++ b/app/Models/ConsultLike.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class ConsultLike extends Model { @@ -28,13 +26,6 @@ class ConsultLike extends Model */ public $user_id = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -54,18 +45,6 @@ class ConsultLike extends Model return 'kg_consult_like'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/CourseFavorite.php b/app/Models/CourseFavorite.php index 8801f8f2..1118f382 100644 --- a/app/Models/CourseFavorite.php +++ b/app/Models/CourseFavorite.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class CourseFavorite extends Model { @@ -28,13 +26,6 @@ class CourseFavorite extends Model */ public $user_id = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -54,18 +45,6 @@ class CourseFavorite extends Model return 'kg_course_favorite'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/CourseUser.php b/app/Models/CourseUser.php index f652fa9d..d7b9662c 100644 --- a/app/Models/CourseUser.php +++ b/app/Models/CourseUser.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class CourseUser extends Model { @@ -119,18 +117,6 @@ class CourseUser extends Model return 'kg_course_user'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->plan_id = (int)date('Ymd'); diff --git a/app/Models/Learning.php b/app/Models/Learning.php index a84c32de..2572c288 100644 --- a/app/Models/Learning.php +++ b/app/Models/Learning.php @@ -61,13 +61,6 @@ class Learning extends Model */ public $position = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 客户端类型 * diff --git a/app/Models/PointHistory.php b/app/Models/PointHistory.php index 0b6919c9..1cb0aa91 100644 --- a/app/Models/PointHistory.php +++ b/app/Models/PointHistory.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class PointHistory extends Model { @@ -68,13 +66,6 @@ class PointHistory extends Model */ public $event_point = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -94,18 +85,6 @@ class PointHistory extends Model return 'kg_point_history'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { if (is_array($this->event_info) && !empty($this->event_info)) { diff --git a/app/Models/ReviewLike.php b/app/Models/ReviewLike.php index 96b09b09..8adc8d59 100644 --- a/app/Models/ReviewLike.php +++ b/app/Models/ReviewLike.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class ReviewLike extends Model { @@ -28,13 +26,6 @@ class ReviewLike extends Model */ public $user_id = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -54,18 +45,6 @@ class ReviewLike extends Model return 'kg_review_like'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/Task.php b/app/Models/Task.php index eb63af53..73fb4a75 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -21,6 +21,8 @@ class Task extends Model const TYPE_NOTICE_ORDER_FINISH = 13; // 订单完成通知 const TYPE_NOTICE_REFUND_FINISH = 14; // 退款完成通知 const TYPE_NOTICE_CONSULT_REPLY = 15; // 咨询回复通知 + const TYPE_NOTICE_POINT_GOODS_DELIVER = 16; // 积分商品发货通知 + const TYPE_NOTICE_LUCKY_GOODS_DELIVER = 17; // 中奖商品发货通知 /** * 针对内部人员 diff --git a/app/Models/UserBalance.php b/app/Models/UserBalance.php index 8ab1334f..8f08b5a2 100644 --- a/app/Models/UserBalance.php +++ b/app/Models/UserBalance.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class UserBalance extends Model { @@ -28,13 +26,6 @@ class UserBalance extends Model */ public $point = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -54,18 +45,6 @@ class UserBalance extends Model return 'kg_user_balance'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/UserContact.php b/app/Models/UserContact.php index 790df7ca..a0cf48f1 100644 --- a/app/Models/UserContact.php +++ b/app/Models/UserContact.php @@ -2,9 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - - class UserContact extends Model { @@ -57,13 +54,6 @@ class UserContact extends Model */ public $add_other = ''; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -83,18 +73,6 @@ class UserContact extends Model return 'kg_user_contact'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeSave() { if (empty($this->create_time)) { diff --git a/app/Models/UserSession.php b/app/Models/UserSession.php index 31fd144b..571c8182 100644 --- a/app/Models/UserSession.php +++ b/app/Models/UserSession.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class UserSession extends Model { @@ -43,11 +41,11 @@ class UserSession extends Model public $client_ip = ''; /** - * 删除标识 + * 过期时间 * * @var int */ - public $deleted = 0; + public $expire_time = 0; /** * 创建时间 @@ -68,18 +66,6 @@ class UserSession extends Model return 'kg_user_session'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/UserToken.php b/app/Models/UserToken.php index a3f6f642..1331ee45 100644 --- a/app/Models/UserToken.php +++ b/app/Models/UserToken.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class UserToken extends Model { @@ -43,11 +41,11 @@ class UserToken extends Model public $client_ip = ''; /** - * 删除标识 + * 过期时间 * * @var int */ - public $deleted = 0; + public $expire_time = 0; /** * 创建时间 @@ -68,18 +66,6 @@ class UserToken extends Model return 'kg_user_token'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Models/WechatSubscribe.php b/app/Models/WeChatSubscribe.php similarity index 64% rename from app/Models/WechatSubscribe.php rename to app/Models/WeChatSubscribe.php index 0e2efe98..90a28329 100644 --- a/app/Models/WechatSubscribe.php +++ b/app/Models/WeChatSubscribe.php @@ -2,9 +2,7 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - -class WechatSubscribe extends Model +class WeChatSubscribe extends Model { /** @@ -28,13 +26,6 @@ class WechatSubscribe extends Model */ public $open_id = ''; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -54,18 +45,6 @@ class WechatSubscribe extends Model return 'kg_wechat_subscribe'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { $this->create_time = time(); diff --git a/app/Repos/Chapter.php b/app/Repos/Chapter.php index 3eaf0975..84dd23b0 100644 --- a/app/Repos/Chapter.php +++ b/app/Repos/Chapter.php @@ -150,7 +150,7 @@ class Chapter extends Repository public function countUsers($chapterId) { return (int)ChapterUserModel::count([ - 'conditions' => 'chapter_id = :chapter_id: AND deleted = 0', + 'conditions' => 'chapter_id = :chapter_id:', 'bind' => ['chapter_id' => $chapterId], ]); } @@ -158,7 +158,7 @@ class Chapter extends Repository public function countLikes($chapterId) { return (int)ChapterLikeModel::count([ - 'conditions' => 'chapter_id = :chapter_id: AND deleted = 0', + 'conditions' => 'chapter_id = :chapter_id:', 'bind' => ['chapter_id' => $chapterId], ]); } diff --git a/app/Repos/ChapterUser.php b/app/Repos/ChapterUser.php index 5533b0ef..03bf64ba 100644 --- a/app/Repos/ChapterUser.php +++ b/app/Repos/ChapterUser.php @@ -43,7 +43,7 @@ class ChapterUser extends Repository public function findChapterUser($chapterId, $userId) { return ChapterUserModel::findFirst([ - 'conditions' => 'chapter_id = ?1 AND user_id = ?2 AND deleted = 0', + 'conditions' => 'chapter_id = ?1 AND user_id = ?2', 'bind' => [1 => $chapterId, 2 => $userId], 'order' => 'id DESC', ]); @@ -58,7 +58,7 @@ class ChapterUser extends Repository public function findPlanChapterUser($chapterId, $userId, $planId) { return ChapterUserModel::findFirst([ - 'conditions' => 'chapter_id = ?1 AND user_id = ?2 AND plan_id = ?3 AND deleted = 0', + 'conditions' => 'chapter_id = ?1 AND user_id = ?2 AND plan_id = ?3', 'bind' => [1 => $chapterId, 2 => $userId, 3 => $planId], ]); } diff --git a/app/Repos/Course.php b/app/Repos/Course.php index d4b7cabe..f0ed2533 100644 --- a/app/Repos/Course.php +++ b/app/Repos/Course.php @@ -317,7 +317,7 @@ class Course extends Repository public function countFavorites($courseId) { return (int)CourseFavoriteModel::count([ - 'conditions' => 'course_id = :course_id: AND deleted = 0', + 'conditions' => 'course_id = :course_id:', 'bind' => ['course_id' => $courseId], ]); } diff --git a/app/Repos/WechatSubscribe.php b/app/Repos/WeChatSubscribe.php similarity index 68% rename from app/Repos/WechatSubscribe.php rename to app/Repos/WeChatSubscribe.php index c17d5a70..e4de1c8f 100644 --- a/app/Repos/WechatSubscribe.php +++ b/app/Repos/WeChatSubscribe.php @@ -2,20 +2,20 @@ namespace App\Repos; -use App\Models\WechatSubscribe as WechatSubscribeModel; +use App\Models\WeChatSubscribe as WeChatSubscribeModel; use Phalcon\Mvc\Model; -class WechatSubscribe extends Repository +class WeChatSubscribe extends Repository { /** * @param int $userId * @param string $openId - * @return WechatSubscribeModel|Model|bool + * @return WeChatSubscribeModel|Model|bool */ public function findSubscribe($userId, $openId) { - return WechatSubscribeModel::findFirst([ + return WeChatSubscribeModel::findFirst([ 'conditions' => 'user_id= ?1 AND open_id = ?2', 'bind' => [1 => $userId, 2 => $openId], ]); @@ -23,11 +23,11 @@ class WechatSubscribe extends Repository /** * @param int $id - * @return WechatSubscribeModel|Model|bool + * @return WeChatSubscribeModel|Model|bool */ public function findById($id) { - return WechatSubscribeModel::findFirst([ + return WeChatSubscribeModel::findFirst([ 'conditions' => 'id = :id:', 'bind' => ['id' => $id], ]); @@ -35,7 +35,7 @@ class WechatSubscribe extends Repository /** * @param int $userId - * @return WechatSubscribeModel|Model|bool + * @return WeChatSubscribeModel|Model|bool */ public function findByUserId($userId) { @@ -47,11 +47,11 @@ class WechatSubscribe extends Repository /** * @param string $openId - * @return WechatSubscribeModel|Model|bool + * @return WeChatSubscribeModel|Model|bool */ public function findByOpenId($openId) { - return WechatSubscribeModel::findFirst([ + return WeChatSubscribeModel::findFirst([ 'conditions' => 'open_id = :open_id:', 'bind' => ['open_id' => $openId], ]); diff --git a/app/Services/Auth/Api.php b/app/Services/Auth/Api.php index e1cf4a2c..716b236c 100644 --- a/app/Services/Auth/Api.php +++ b/app/Services/Auth/Api.php @@ -17,9 +17,11 @@ class Api extends AuthService { $token = $this->generateToken($user->id); + $lifetime = $this->getTokenLifetime(); + $this->logoutOtherClients($user->id); - $this->createUserToken($user->id, $token); + $this->createUserToken($user->id, $token, $lifetime); $cache = $this->getCache(); @@ -30,10 +32,6 @@ class Api extends AuthService 'name' => $user->name, ]; - $config = $this->getConfig(); - - $lifetime = $config->path('token.lifetime') ?: 7 * 86400; - $cache->save($key, $authInfo, $lifetime); return $token; @@ -67,7 +65,7 @@ class Api extends AuthService return $authInfo ?: null; } - protected function createUserToken($userId, $token) + protected function createUserToken($userId, $token, $lifetime) { $userToken = new UserTokenModel(); @@ -75,6 +73,7 @@ class Api extends AuthService $userToken->token = $token; $userToken->client_type = $this->getClientType(); $userToken->client_ip = $this->getClientIp(); + $userToken->expire_time = time() + $lifetime; $userToken->create(); } @@ -89,14 +88,11 @@ class Api extends AuthService $clientType = $this->getClientType(); - if ($records->count() == 0) { - return; - } + if ($records->count() == 0) return; foreach ($records as $record) { if ($record->client_type == $clientType) { - $record->deleted = 1; - $record->update(); + $record->delete(); $key = $this->getTokenCacheKey($record->token); $cache->delete($key); } @@ -108,6 +104,13 @@ class Api extends AuthService return md5(uniqid() . time() . $userId); } + protected function getTokenLifetime() + { + $config = $this->getConfig(); + + return $config->path('token.lifetime') ?: 7 * 86400; + } + protected function getTokenCacheKey($token) { return "_PHCR_TOKEN_:{$token}"; diff --git a/app/Services/Auth/Home.php b/app/Services/Auth/Home.php index 6cafc47d..430f4dad 100644 --- a/app/Services/Auth/Home.php +++ b/app/Services/Auth/Home.php @@ -17,9 +17,11 @@ class Home extends AuthService { $sessionId = $this->session->getId(); + $lifetime = $this->getSessionLifetime(); + $this->logoutOtherClients($user->id); - $this->createUserSession($user->id, $sessionId); + $this->createUserSession($user->id, $sessionId, $lifetime); $authKey = $this->getAuthKey(); @@ -52,7 +54,7 @@ class Home extends AuthService return 'home_auth_info'; } - protected function createUserSession($userId, $sessionId) + protected function createUserSession($userId, $sessionId, $lifetime) { $userSession = new UserSessionModel(); @@ -60,6 +62,7 @@ class Home extends AuthService $userSession->session_id = $sessionId; $userSession->client_type = $this->getClientType(); $userSession->client_ip = $this->getClientIp(); + $userSession->expire_time = time() + $lifetime; $userSession->create(); } @@ -72,18 +75,22 @@ class Home extends AuthService $records = $repo->findByUserId($userId); - if ($records->count() == 0) { - return; - } + if ($records->count() == 0) return; foreach ($records as $record) { - $record->deleted = 1; - $record->update(); + $record->delete(); $key = $this->getSessionCacheKey($record->session_id); $cache->delete($key); } } + protected function getSessionLifetime() + { + $config = $this->getConfig(); + + return $config->path('session.lifetime') ?: 24 * 3600; + } + protected function getSessionCacheKey($sessionId) { return "_PHCR_SESSION_:{$sessionId}"; diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php index 75e82832..f9c16ca7 100644 --- a/app/Services/Logic/Chapter/ChapterInfo.php +++ b/app/Services/Logic/Chapter/ChapterInfo.php @@ -6,10 +6,12 @@ use App\Models\Chapter as ChapterModel; use App\Models\ChapterUser as ChapterUserModel; use App\Models\Course as CourseModel; use App\Models\CourseUser as CourseUserModel; +use App\Models\ImGroup as ImGroupModel; use App\Models\ImGroupUser as ImGroupUserModel; use App\Models\User as UserModel; use App\Repos\ChapterLike as ChapterLikeRepo; use App\Repos\ImGroup as ImGroupRepo; +use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Services\Logic\ChapterTrait; use App\Services\Logic\CourseTrait; use App\Services\Logic\Service; @@ -76,7 +78,7 @@ class ChapterInfo extends Service $like = $likeRepo->findChapterLike($chapter->id, $user->id); - if ($like && $like->deleted == 0) { + if ($like) { $me['liked'] = 1; } @@ -104,11 +106,17 @@ class ChapterInfo extends Service $courseUser = new CourseUserModel(); + $roleType = CourseUserModel::ROLE_STUDENT; + $sourceType = CourseUserModel::SOURCE_FREE; + + if ($course->market_price > 0 && $course->vip_price == 0 && $user->vip == 1) { + $sourceType = CourseUserModel::SOURCE_VIP; + } + $courseUser->course_id = $course->id; $courseUser->user_id = $user->id; - $courseUser->source_type = CourseUserModel::SOURCE_FREE; - $courseUser->role_type = CourseUserModel::ROLE_STUDENT; - $courseUser->expiry_time = strtotime('+3 years'); + $courseUser->source_type = $sourceType; + $courseUser->role_type = $roleType; $courseUser->create(); @@ -120,12 +128,21 @@ class ChapterInfo extends Service $group = $groupRepo->findByCourseId($course->id); - $groupUser = new ImGroupUserModel(); + $groupUserRepo = new ImGroupUserRepo(); - $groupUser->group_id = $group->id; - $groupUser->user_id = $user->id; + $groupUser = $groupUserRepo->findGroupUser($group->id, $user->id); - $groupUser->create(); + if (!$groupUser) { + + $groupUser = new ImGroupUserModel(); + + $groupUser->group_id = $group->id; + $groupUser->user_id = $user->id; + + $groupUser->create(); + + $this->incrGroupUserCount($group); + } $this->incrCourseUserCount($course); @@ -179,4 +196,11 @@ class ChapterInfo extends Service $chapter->update(); } + protected function incrGroupUserCount(ImGroupModel $group) + { + $group->user_count += 1; + + $group->update(); + } + } diff --git a/app/Services/Logic/Chapter/ChapterLike.php b/app/Services/Logic/Chapter/ChapterLike.php index d564dd89..6e6c4861 100644 --- a/app/Services/Logic/Chapter/ChapterLike.php +++ b/app/Services/Logic/Chapter/ChapterLike.php @@ -42,18 +42,9 @@ class ChapterLike extends Service } else { - if ($chapterLike->deleted == 0) { + $chapterLike->delete(); - $chapterLike->update(['deleted' => 1]); - - $this->decrLikeCount($chapter); - - } else { - - $chapterLike->update(['deleted' => 0]); - - $this->incrLikeCount($chapter); - } + $this->decrLikeCount($chapter); } $this->incrUserDailyChapterLikeCount($user); diff --git a/app/Services/Logic/ChapterTrait.php b/app/Services/Logic/ChapterTrait.php index 8323437e..775fc22b 100644 --- a/app/Services/Logic/ChapterTrait.php +++ b/app/Services/Logic/ChapterTrait.php @@ -4,6 +4,7 @@ namespace App\Services\Logic; use App\Models\Chapter as ChapterModel; use App\Models\ChapterUser as ChapterUserModel; +use App\Models\CourseUser as CourseUserModel; use App\Models\User as UserModel; use App\Repos\ChapterUser as ChapterUserRepo; use App\Validators\Chapter as ChapterValidator; @@ -65,16 +66,19 @@ trait ChapterTrait { $chapterUser = null; + /** + * @var CourseUserModel $courseUser + */ $courseUser = $this->courseUser; if ($user->id > 0 && $courseUser) { $chapterUserRepo = new ChapterUserRepo(); - $chapterUser = $chapterUserRepo->findChapterUser($chapter->id, $user->id); + $chapterUser = $chapterUserRepo->findPlanChapterUser($chapter->id, $user->id, $courseUser->plan_id); } $this->chapterUser = $chapterUser; - if ($chapterUser && $chapterUser->plan_id == $courseUser->plan_id) { + if ($chapterUser) { $this->joinedChapter = true; } diff --git a/app/Services/Logic/Consult/ConsultCreate.php b/app/Services/Logic/Consult/ConsultCreate.php index 2ec411dd..a1fb5665 100644 --- a/app/Services/Logic/Consult/ConsultCreate.php +++ b/app/Services/Logic/Consult/ConsultCreate.php @@ -6,9 +6,9 @@ use App\Models\Chapter as ChapterModel; use App\Models\Consult as ConsultModel; use App\Models\Course as CourseModel; use App\Models\User as UserModel; -use App\Services\DingTalk\Notice\ConsultCreate as ConsultCreateNotice; use App\Services\Logic\ChapterTrait; use App\Services\Logic\CourseTrait; +use App\Services\Logic\Notice\DingTalk\ConsultCreate as ConsultCreateNotice; use App\Services\Logic\Service; use App\Validators\Consult as ConsultValidator; use App\Validators\UserLimit as UserLimitValidator; diff --git a/app/Services/Logic/Consult/ConsultLike.php b/app/Services/Logic/Consult/ConsultLike.php index e1c06fb8..b674b6a5 100644 --- a/app/Services/Logic/Consult/ConsultLike.php +++ b/app/Services/Logic/Consult/ConsultLike.php @@ -42,18 +42,9 @@ class ConsultLike extends Service } else { - if ($consultLike->deleted == 0) { + $consultLike->delete(); - $consultLike->update(['deleted' => 1]); - - $this->decrLikeCount($consult); - - } else { - - $consultLike->update(['deleted' => 0]); - - $this->incrLikeCount($consult); - } + $this->decrLikeCount($consult); } $this->incrUserDailyConsultLikeCount($user); diff --git a/app/Services/Logic/Course/CourseFavorite.php b/app/Services/Logic/Course/CourseFavorite.php index b6aec553..12da8557 100644 --- a/app/Services/Logic/Course/CourseFavorite.php +++ b/app/Services/Logic/Course/CourseFavorite.php @@ -42,22 +42,11 @@ class CourseFavorite extends Service } else { - if ($favorite->deleted == 0) { + $favorite->delete(); - $favorite->update(['deleted' => 1]); + $this->decrCourseFavoriteCount($course); - $this->decrCourseFavoriteCount($course); - - $this->decrUserFavoriteCount($user); - - } else { - - $favorite->update(['deleted' => 0]); - - $this->incrCourseFavoriteCount($course); - - $this->incrUserFavoriteCount($user); - } + $this->decrUserFavoriteCount($user); } return $favorite; diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php index f51d120a..466404b6 100644 --- a/app/Services/Logic/Course/CourseInfo.php +++ b/app/Services/Logic/Course/CourseInfo.php @@ -48,7 +48,7 @@ class CourseInfo extends Service $favorite = $favoriteRepo->findCourseFavorite($course->id, $user->id); - if ($favorite && $favorite->deleted == 0) { + if ($favorite) { $me['favorited'] = 1; } diff --git a/app/Services/Logic/CourseTrait.php b/app/Services/Logic/CourseTrait.php index 3b8b55fc..0eb83d00 100644 --- a/app/Services/Logic/CourseTrait.php +++ b/app/Services/Logic/CourseTrait.php @@ -59,7 +59,7 @@ trait CourseTrait $this->ownedCourse = true; - } elseif ($course->vip_price == 0 && $user->vip == 1) { + } elseif ($course->market_price > 0 && $course->vip_price == 0 && $user->vip == 1) { $this->ownedCourse = true; @@ -72,14 +72,21 @@ trait CourseTrait $sourceTypes = [ CourseUserModel::SOURCE_CHARGE, CourseUserModel::SOURCE_IMPORT, + CourseUserModel::SOURCE_POINT_REDEEM, + CourseUserModel::SOURCE_LUCKY_REDEEM, ]; $case1 = $courseUser->deleted == 0; $case2 = $courseUser->expiry_time > time(); $case3 = in_array($courseUser->source_type, $sourceTypes); + /** + * 之前参与过课程,但不再满足条件,视为未参与 + */ if ($case1 && $case2 && $case3) { $this->ownedCourse = true; + } else { + $this->joinedCourse = false; } } } diff --git a/app/Services/Logic/Notice/AccountLogin.php b/app/Services/Logic/Notice/AccountLogin.php index 9f4fdd06..e17d3121 100644 --- a/app/Services/Logic/Notice/AccountLogin.php +++ b/app/Services/Logic/Notice/AccountLogin.php @@ -4,9 +4,9 @@ namespace App\Services\Logic\Notice; use App\Models\Task as TaskModel; use App\Models\User as UserModel; -use App\Repos\WechatSubscribe as WechatSubscribeRepo; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; +use App\Services\Logic\Notice\WeChat\AccountLogin as WeChatAccountLoginNotice; use App\Services\Logic\Service as LogicService; -use App\Services\Wechat\Notice\AccountLogin as WechatAccountLoginNotice; use App\Traits\Client as ClientTrait; class AccountLogin extends LogicService @@ -16,17 +16,24 @@ class AccountLogin extends LogicService public function handleTask(TaskModel $task) { + /** + * @todo 鉴于微信消息模板4.30下线,暂时下线登录通知 + */ + $wechatOA = $this->getSettings('wechat.oa'); + + if ($wechatOA['enabled'] == 0) return; + $params = $task->item_info; $userId = $task->item_info['user']['id']; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($userId); if ($subscribe && $subscribe->deleted == 0) { - $notice = new WechatAccountLoginNotice(); + $notice = new WeChatAccountLoginNotice(); return $notice->handle($subscribe, $params); } @@ -34,6 +41,10 @@ class AccountLogin extends LogicService public function createTask(UserModel $user) { + $wechatOA = $this->getSettings('wechat.oa'); + + if ($wechatOA['enabled'] == 0) return; + $task = new TaskModel(); $loginIp = $this->getClientIp(); @@ -59,4 +70,15 @@ class AccountLogin extends LogicService $task->create(); } + public function wechatNoticeEnabled() + { + $oa = $this->getSettings('wechat.oa'); + + if ($oa['enabled'] == 0) return false; + + $template = json_decode($oa['notice_template'], true); + + return $template['account_login']['enabled'] == 1; + } + } diff --git a/app/Services/Logic/Notice/ConsultReply.php b/app/Services/Logic/Notice/ConsultReply.php index 34cfaebc..27bdc5e3 100644 --- a/app/Services/Logic/Notice/ConsultReply.php +++ b/app/Services/Logic/Notice/ConsultReply.php @@ -7,16 +7,21 @@ use App\Models\Task as TaskModel; use App\Repos\Consult as ConsultRepo; use App\Repos\Course as CourseRepo; use App\Repos\User as UserRepo; -use App\Repos\WechatSubscribe as WechatSubscribeRepo; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; +use App\Services\Logic\Notice\Sms\ConsultReply as SmsConsultReplyNotice; +use App\Services\Logic\Notice\WeChat\ConsultReply as WeChatConsultReplyNotice; use App\Services\Logic\Service as LogicService; -use App\Services\Sms\Notice\ConsultReply as SmsConsultReplyNotice; -use App\Services\Wechat\Notice\ConsultReply as WechatConsultReplyNotice; class ConsultReply extends LogicService { public function handleTask(TaskModel $task) { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $consultId = $task->item_info['consult']['id']; $consultRepo = new ConsultRepo(); @@ -55,17 +60,17 @@ class ConsultReply extends LogicService ], ]; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($consult->owner_id); - if ($subscribe && $subscribe->deleted == 0) { + if ($wechatNoticeEnabled && $subscribe) { - $notice = new WechatConsultReplyNotice(); + $notice = new WeChatConsultReplyNotice(); return $notice->handle($subscribe, $params); - } else { + } elseif ($smsNoticeEnabled) { $notice = new SmsConsultReplyNotice(); @@ -75,6 +80,11 @@ class ConsultReply extends LogicService public function createTask(ConsultModel $consult) { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $task = new TaskModel(); $itemInfo = [ @@ -91,4 +101,28 @@ class ConsultReply extends LogicService $task->create(); } + public function wechatNoticeEnabled() + { + $oa = $this->getSettings('wechat.oa'); + + if ($oa['enabled'] == 0) return false; + + $template = json_decode($oa['notice_template'], true); + + $result = $template['consult_reply']['enabled'] ?? 0; + + return $result == 1; + } + + public function smsNoticeEnabled() + { + $sms = $this->getSettings('sms'); + + $template = json_decode($sms['template'], true); + + $result = $template['consult_reply']['enabled'] ?? 0; + + return $result == 1; + } + } diff --git a/app/Services/DingTalk/Notice/ConsultCreate.php b/app/Services/Logic/Notice/DingTalk/ConsultCreate.php similarity index 97% rename from app/Services/DingTalk/Notice/ConsultCreate.php rename to app/Services/Logic/Notice/DingTalk/ConsultCreate.php index 87d7e4c8..3b32f40b 100644 --- a/app/Services/DingTalk/Notice/ConsultCreate.php +++ b/app/Services/Logic/Notice/DingTalk/ConsultCreate.php @@ -1,6 +1,6 @@ wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $courseUser = $task->item_info['course_user']; $chapterId = $task->item_info['chapter']['id']; @@ -53,17 +58,17 @@ class LiveBegin extends LogicService 'course_user' => $courseUser, ]; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($user->id); - if ($subscribe && $subscribe->deleted == 0) { + if ($wechatNoticeEnabled && $subscribe) { - $notice = new WechatLiveBeginNotice(); + $notice = new WeChatLiveBeginNotice(); return $notice->handle($subscribe, $params); - } else { + } elseif ($smsNoticeEnabled) { $notice = new SmsLiveBeginNotice(); @@ -73,6 +78,11 @@ class LiveBegin extends LogicService public function createTask(ChapterModel $chapter, CourseUserModel $courseUser) { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $task = new TaskModel(); $itemInfo = [ @@ -97,4 +107,28 @@ class LiveBegin extends LogicService $task->create(); } + public function wechatNoticeEnabled() + { + $oa = $this->getSettings('wechat.oa'); + + if ($oa['enabled'] == 0) return false; + + $template = json_decode($oa['notice_template'], true); + + $result = $template['live_begin']['enabled'] ?? 0; + + return $result == 1; + } + + public function smsNoticeEnabled() + { + $sms = $this->getSettings('sms'); + + $template = json_decode($sms['template'], true); + + $result = $template['live_begin']['enabled'] ?? 0; + + return $result == 1; + } + } diff --git a/app/Services/Mail/Test.php b/app/Services/Logic/Notice/Mail/Test.php similarity index 94% rename from app/Services/Mail/Test.php rename to app/Services/Logic/Notice/Mail/Test.php index 1e869fe0..a1e2f63f 100644 --- a/app/Services/Mail/Test.php +++ b/app/Services/Logic/Notice/Mail/Test.php @@ -1,6 +1,6 @@ wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $orderId = $task->item_info['order']['id']; $orderRepo = new OrderRepo(); @@ -40,17 +45,17 @@ class OrderFinish extends LogicService ], ]; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($order->owner_id); - if ($subscribe && $subscribe->deleted == 0) { + if ($wechatNoticeEnabled && $subscribe) { - $notice = new WechatOrderFinishNotice(); + $notice = new WeChatOrderFinishNotice(); return $notice->handle($subscribe, $params); - } else { + } elseif ($smsNoticeEnabled) { $notice = new SmsOrderFinishNotice(); @@ -60,6 +65,11 @@ class OrderFinish extends LogicService public function createTask(OrderModel $order) { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $task = new TaskModel(); $itemInfo = [ @@ -75,4 +85,28 @@ class OrderFinish extends LogicService $task->create(); } + public function wechatNoticeEnabled() + { + $oa = $this->getSettings('wechat.oa'); + + if ($oa['enabled'] == 0) return false; + + $template = json_decode($oa['notice_template'], true); + + $result = $template['order_finish']['enabled'] ?? 0; + + return $result == 1; + } + + public function smsNoticeEnabled() + { + $sms = $this->getSettings('sms'); + + $template = json_decode($sms['template'], true); + + $result = $template['order_finish']['enabled'] ?? 0; + + return $result == 1; + } + } diff --git a/app/Services/Logic/Notice/PointGoodsDeliver.php b/app/Services/Logic/Notice/PointGoodsDeliver.php new file mode 100644 index 00000000..fa8ae26b --- /dev/null +++ b/app/Services/Logic/Notice/PointGoodsDeliver.php @@ -0,0 +1,108 @@ +wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + + $redeemId = $task->item_info['point_redeem']['id']; + + $redeemRepo = new PointRedeemRepo(); + + $redeem = $redeemRepo->findById($redeemId); + + $userRepo = new UserRepo(); + + $user = $userRepo->findById($redeem->user_id); + + $params = [ + 'user' => [ + 'id' => $user->id, + 'name' => $user->name, + ], + 'goods_name' => $redeem->gift_name, + 'order_sn' => date('YmdHis') . rand(1000, 9999), + 'deliver_time' => time(), + ]; + + $subscribeRepo = new WeChatSubscribeRepo(); + + $subscribe = $subscribeRepo->findByUserId($user->id); + + if ($wechatNoticeEnabled && $subscribe) { + + $notice = new WeChatGoodsDeliverNotice(); + + return $notice->handle($subscribe, $params); + + } elseif ($smsNoticeEnabled) { + + $notice = new SmsGoodsDeliverNotice(); + + return $notice->handle($user, $params); + } + } + + public function createTask(PointRedeemModel $redeem) + { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + + $task = new TaskModel(); + + $itemInfo = [ + 'point_redeem' => ['id' => $redeem->id], + ]; + + $task->item_id = $redeem->id; + $task->item_info = $itemInfo; + $task->item_type = TaskModel::TYPE_NOTICE_POINT_GOODS_DELIVER; + $task->priority = TaskModel::PRIORITY_MIDDLE; + $task->status = TaskModel::STATUS_PENDING; + + $task->create(); + } + + public function wechatNoticeEnabled() + { + $oa = $this->getSettings('wechat.oa'); + + if ($oa['enabled'] == 0) return false; + + $template = json_decode($oa['notice_template'], true); + + $result = $template['goods_deliver']['enabled'] ?? 0; + + return $result == 1; + } + + public function smsNoticeEnabled() + { + $sms = $this->getSettings('sms'); + + $template = json_decode($sms['template'], true); + + $result = $template['goods_deliver']['enabled'] ?? 0; + + return $result == 1; + } + +} diff --git a/app/Services/Logic/Notice/PointRedeemFinish.php b/app/Services/Logic/Notice/PointRedeemFinish.php deleted file mode 100644 index 2c88e21e..00000000 --- a/app/Services/Logic/Notice/PointRedeemFinish.php +++ /dev/null @@ -1,78 +0,0 @@ -item_info['order']['id']; - - $orderRepo = new OrderRepo(); - - $order = $orderRepo->findById($orderId); - - $userRepo = new UserRepo(); - - $user = $userRepo->findById($order->owner_id); - - $params = [ - 'user' => [ - 'id' => $user->id, - 'name' => $user->name, - ], - 'order' => [ - 'sn' => $order->sn, - 'subject' => $order->subject, - 'amount' => $order->amount, - 'create_time' => $order->create_time, - 'update_time' => $order->update_time, - ], - ]; - - $subscribeRepo = new WechatSubscribeRepo(); - - $subscribe = $subscribeRepo->findByUserId($order->owner_id); - - if ($subscribe && $subscribe->deleted == 0) { - - $notice = new WechatOrderFinishNotice(); - - return $notice->handle($subscribe, $params); - - } else { - - $notice = new SmsOrderFinishNotice(); - - return $notice->handle($user, $params); - } - } - - public function createTask(OrderModel $order) - { - $task = new TaskModel(); - - $itemInfo = [ - 'order' => ['id' => $order->id], - ]; - - $task->item_id = $order->id; - $task->item_info = $itemInfo; - $task->item_type = TaskModel::TYPE_NOTICE_ORDER_FINISH; - $task->priority = TaskModel::PRIORITY_HIGH; - $task->status = TaskModel::STATUS_PENDING; - - $task->create(); - } - -} diff --git a/app/Services/Logic/Notice/RefundFinish.php b/app/Services/Logic/Notice/RefundFinish.php index 833cd6dc..6defe9fb 100644 --- a/app/Services/Logic/Notice/RefundFinish.php +++ b/app/Services/Logic/Notice/RefundFinish.php @@ -6,16 +6,21 @@ use App\Models\Refund as RefundModel; use App\Models\Task as TaskModel; use App\Repos\Refund as RefundRepo; use App\Repos\User as UserRepo; -use App\Repos\WechatSubscribe as WechatSubscribeRepo; +use App\Repos\WeChatSubscribe as WeChatSubscribeRepo; +use App\Services\Logic\Notice\Sms\RefundFinish as SmsRefundFinishNotice; +use App\Services\Logic\Notice\WeChat\OrderFinish as WeChatRefundFinishNotice; use App\Services\Logic\Service as LogicService; -use App\Services\Sms\Notice\RefundFinish as SmsRefundFinishNotice; -use App\Services\Wechat\Notice\RefundFinish as WechatRefundFinishNotice; class RefundFinish extends LogicService { public function handleTask(TaskModel $task) { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $refundId = $task->item_info['refund']['id']; $refundRepo = new RefundRepo(); @@ -40,17 +45,17 @@ class RefundFinish extends LogicService ], ]; - $subscribeRepo = new WechatSubscribeRepo(); + $subscribeRepo = new WeChatSubscribeRepo(); $subscribe = $subscribeRepo->findByUserId($refund->owner_id); - if ($subscribe && $subscribe->deleted == 0) { + if ($wechatNoticeEnabled && $subscribe) { - $notice = new WechatRefundFinishNotice(); + $notice = new WeChatRefundFinishNotice(); return $notice->handle($subscribe, $params); - } else { + } elseif ($smsNoticeEnabled) { $notice = new SmsRefundFinishNotice(); @@ -60,6 +65,11 @@ class RefundFinish extends LogicService public function createTask(RefundModel $refund) { + $wechatNoticeEnabled = $this->wechatNoticeEnabled(); + $smsNoticeEnabled = $this->smsNoticeEnabled(); + + if (!$wechatNoticeEnabled && !$smsNoticeEnabled) return; + $task = new TaskModel(); $itemInfo = [ @@ -75,4 +85,28 @@ class RefundFinish extends LogicService $task->create(); } + public function wechatNoticeEnabled() + { + $oa = $this->getSettings('wechat.oa'); + + if ($oa['enabled'] == 0) return false; + + $template = json_decode($oa['notice_template'], true); + + $result = $template['refund_finish']['enabled'] ?? 0; + + return $result == 1; + } + + public function smsNoticeEnabled() + { + $sms = $this->getSettings('sms'); + + $template = json_decode($sms['template'], true); + + $result = $template['refund_finish']['enabled'] ?? 0; + + return $result == 1; + } + } diff --git a/app/Services/Sms/Notice/ConsultReply.php b/app/Services/Logic/Notice/Sms/ConsultReply.php similarity index 94% rename from app/Services/Sms/Notice/ConsultReply.php rename to app/Services/Logic/Notice/Sms/ConsultReply.php index 85d21f21..0e01bd51 100644 --- a/app/Services/Sms/Notice/ConsultReply.php +++ b/app/Services/Logic/Notice/Sms/ConsultReply.php @@ -1,6 +1,6 @@ findById($user->id); + + if (!$account->phone) return null; + + $templateId = $this->getTemplateId($this->templateCode); + + $params = [ + $params['order_sn'], + $params['goods_name'], + $params['deliver_time'], + ]; + + return $this->send($account->phone, $templateId, $params); + } + +} diff --git a/app/Services/Sms/Notice/LiveBegin.php b/app/Services/Logic/Notice/Sms/LiveBegin.php similarity index 95% rename from app/Services/Sms/Notice/LiveBegin.php rename to app/Services/Logic/Notice/Sms/LiveBegin.php index 104b8f86..6fd3e66a 100644 --- a/app/Services/Sms/Notice/LiveBegin.php +++ b/app/Services/Logic/Notice/Sms/LiveBegin.php @@ -1,6 +1,6 @@ $first, + 'remark' => $remark, + 'keyword1' => $params['goods_name'], + 'keyword2' => $params['order_sn'], + 'keyword3' => date('Y-m-d H:i', $params['deliver_time']), + ]; + + $templateId = $this->getTemplateId($this->templateCode); + + return $this->send($subscribe->open_id, $templateId, $params); + } + +} diff --git a/app/Services/Wechat/Notice/LiveBegin.php b/app/Services/Logic/Notice/WeChat/LiveBegin.php similarity index 72% rename from app/Services/Wechat/Notice/LiveBegin.php rename to app/Services/Logic/Notice/WeChat/LiveBegin.php index 96ab8250..1a7a4255 100644 --- a/app/Services/Wechat/Notice/LiveBegin.php +++ b/app/Services/Logic/Notice/WeChat/LiveBegin.php @@ -1,21 +1,21 @@ deleted == 0) { + $reviewLike->delete(); - $reviewLike->update(['deleted' => 1]); - - $this->decrLikeCount($review); - - } else { - - $reviewLike->update(['deleted' => 0]); - - $this->incrLikeCount($review); - } + $this->decrLikeCount($review); } $this->incrUserDailyReviewLikeCount($user); diff --git a/app/Services/Logic/User/Console/ConnectDelete.php b/app/Services/Logic/User/Console/ConnectDelete.php index 27d60489..28209993 100644 --- a/app/Services/Logic/User/Console/ConnectDelete.php +++ b/app/Services/Logic/User/Console/ConnectDelete.php @@ -18,9 +18,7 @@ class ConnectDelete extends Service $validator->checkOwner($user->id, $connect->user_id); - $connect->deleted = 1; - - $connect->update(); + $connect->delete(); } } diff --git a/app/Services/Logic/Verify/SmsCode.php b/app/Services/Logic/Verify/SmsCode.php index 26e2980e..48c79713 100644 --- a/app/Services/Logic/Verify/SmsCode.php +++ b/app/Services/Logic/Verify/SmsCode.php @@ -2,8 +2,8 @@ namespace App\Services\Logic\Verify; +use App\Services\Logic\Notice\Sms\Verify as SmsVerifyService; use App\Services\Logic\Service; -use App\Services\Sms\Verify as VerifySmsService; use App\Validators\Captcha as CaptchaValidator; use App\Validators\Verify as VerifyValidator; @@ -22,7 +22,7 @@ class SmsCode extends Service $validator->checkCode($post['ticket'], $post['rand']); - $service = new VerifySmsService(); + $service = new SmsVerifyService(); $service->handle($post['phone']); } diff --git a/app/Services/Wechat.php b/app/Services/WeChat.php similarity index 97% rename from app/Services/Wechat.php rename to app/Services/WeChat.php index ed106111..9c0cfb65 100644 --- a/app/Services/Wechat.php +++ b/app/Services/WeChat.php @@ -5,7 +5,7 @@ namespace App\Services; use EasyWeChat\Factory; use Phalcon\Logger\Adapter\File as FileLogger; -class Wechat extends Service +class WeChat extends Service { /** diff --git a/app/Services/WechatNotice.php b/app/Services/WeChatNotice.php similarity index 94% rename from app/Services/WechatNotice.php rename to app/Services/WeChatNotice.php index 18c85ba4..f8d42485 100644 --- a/app/Services/WechatNotice.php +++ b/app/Services/WeChatNotice.php @@ -2,10 +2,10 @@ namespace App\Services; -use App\Services\Wechat as WechatService; +use App\Services\WeChat as WeChatService; use Phalcon\Logger\Adapter\File as FileLogger; -Abstract class WechatNotice extends Service +abstract class WeChatNotice extends Service { /** @@ -37,7 +37,7 @@ Abstract class WechatNotice extends Service */ public function send($openId, $templateId, $params, $url = null, $miniProgram = []) { - $service = new WechatService(); + $service = new WeChatService(); $app = $service->getOfficialAccount(); diff --git a/db/migrations/20200827112717_insert_setting_data.php b/db/migrations/20200827112717_insert_setting_data.php index 70a3607f..fe633e31 100644 --- a/db/migrations/20200827112717_insert_setting_data.php +++ b/db/migrations/20200827112717_insert_setting_data.php @@ -1,7 +1,5 @@ 'sms', 'item_key' => 'template', - 'item_value' => '{"verify":"561282","order":"561954","refund":"561286","live":"561288"}', + 'item_value' => '{"verify":"","order":"","refund":"","live":""}', ], [ 'section' => 'cos', @@ -418,7 +416,7 @@ final class InsertSettingData extends AbstractMigration [ 'section' => 'vod', 'item_key' => 'wmk_tpl_id', - 'item_value' => '462027', + 'item_value' => '', ], [ 'section' => 'vod', diff --git a/db/migrations/20200827113559_insert_user_data.php b/db/migrations/20200827113559_insert_user_data.php index a11ad937..e7492045 100644 --- a/db/migrations/20200827113559_insert_user_data.php +++ b/db/migrations/20200827113559_insert_user_data.php @@ -1,7 +1,5 @@ getQueryBuilder()->delete('kg_setting')->where(['section' => 'wechat.oa'])->execute(); + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'wechat.oa']) + ->execute(); } protected function updateSmsTemplate() @@ -63,7 +64,12 @@ final class Data202012121830 extends AbstractMigration $where = ['section' => 'sms', 'item_key' => 'template']; - $setting = $this->getQueryBuilder()->select('*')->from($table)->where($where)->execute()->fetch('assoc'); + $setting = $this->getQueryBuilder() + ->select('*') + ->from($table) + ->where($where) + ->execute() + ->fetch('assoc'); $itemValue = json_decode($setting['item_value'], true); @@ -75,7 +81,11 @@ final class Data202012121830 extends AbstractMigration 'consult_reply' => '', ]); - $this->getQueryBuilder()->update($table)->where($where)->set('item_value', $newItemValue)->execute(); + $this->getQueryBuilder() + ->update($table) + ->where($where) + ->set('item_value', $newItemValue) + ->execute(); } } \ No newline at end of file diff --git a/db/migrations/20210106112717_data_202101061830.php b/db/migrations/20210106112717_data_202101061830.php index c11aee46..5bdc8ef1 100644 --- a/db/migrations/20210106112717_data_202101061830.php +++ b/db/migrations/20210106112717_data_202101061830.php @@ -1,7 +1,5 @@ getQueryBuilder()->select('*')->from('kg_resource')->execute(); + $resources = $this->getQueryBuilder() + ->select('*') + ->from('kg_resource') + ->execute(); $courseMappings = []; $chapterMappings = []; diff --git a/db/migrations/20210228035113_data_202102280351.php b/db/migrations/20210228035113_data_202102280351.php new file mode 100644 index 00000000..3d1a4968 --- /dev/null +++ b/db/migrations/20210228035113_data_202102280351.php @@ -0,0 +1,92 @@ +updateSmsNoticeTemplate(); + $this->updateWechatNoticeTemplate(); + } + + protected function updateSmsNoticeTemplate() + { + $table = 'kg_setting'; + + $where = [ + 'section' => 'sms', + 'item_key' => 'template', + ]; + + $setting = $this->getQueryBuilder() + ->select('*') + ->from($table) + ->where($where) + ->execute() + ->fetch('assoc'); + + $itemValue = json_decode($setting['item_value'], true); + + $newItemValue = []; + + foreach ($itemValue as $key => $value) { + $newItemValue[$key]['id'] = $value; + $newItemValue[$key]['enabled'] = 1; + } + + /** + * 增加发货通知 + */ + $newItemValue['goods_deliver'] = ['id' => '', 'enabled' => 1]; + + $itemValue = json_encode($newItemValue); + + $this->getQueryBuilder() + ->update($table) + ->where($where) + ->set('item_value', $itemValue) + ->execute(); + } + + protected function updateWechatNoticeTemplate() + { + $table = 'kg_setting'; + + $where = [ + 'section' => 'wechat.oa', + 'item_key' => 'notice_template', + ]; + + $setting = $this->getQueryBuilder() + ->select('*') + ->from($table) + ->where($where) + ->execute() + ->fetch('assoc'); + + $itemValue = json_decode($setting['item_value'], true); + + $newItemValue = []; + + foreach ($itemValue as $key => $value) { + $newItemValue[$key]['id'] = $value; + $newItemValue[$key]['enabled'] = 1; + } + + /** + * 增加发货通知 + */ + $newItemValue['goods_deliver'] = ['id' => '', 'enabled' => 1]; + + $itemValue = json_encode($newItemValue); + + $this->getQueryBuilder() + ->update($table) + ->where($where) + ->set('item_value', $itemValue) + ->execute(); + } + +} diff --git a/db/migrations/20210302021013_schema_202103021010.php b/db/migrations/20210302021013_schema_202103021010.php new file mode 100644 index 00000000..781dba26 --- /dev/null +++ b/db/migrations/20210302021013_schema_202103021010.php @@ -0,0 +1,91 @@ +deleteCourseTeachers(); + + if ($this->table('kg_chapter_like')->hasColumn('deleted')) { + $this->table('kg_chapter_like')->removeColumn('deleted'); + } + + if ($this->table('kg_chapter_user')->hasColumn('deleted')) { + $this->table('kg_chapter_user')->removeColumn('deleted'); + } + + if ($this->table('kg_consult_like')->hasColumn('deleted')) { + $this->table('kg_consult_like')->removeColumn('deleted'); + } + + if ($this->table('kg_course_favorite')->hasColumn('deleted')) { + $this->table('kg_course_favorite')->removeColumn('deleted'); + } + + if ($this->table('kg_learning')->hasColumn('deleted')) { + $this->table('kg_learning')->removeColumn('deleted'); + } + + if ($this->table('kg_point_history')->hasColumn('deleted')) { + $this->table('kg_point_history')->removeColumn('deleted'); + } + + if ($this->table('kg_review_like')->hasColumn('deleted')) { + $this->table('kg_review_like')->removeColumn('deleted'); + } + + if ($this->table('kg_user_balance')->hasColumn('deleted')) { + $this->table('kg_user_balance')->removeColumn('deleted'); + } + + if ($this->table('kg_user_contact')->hasColumn('deleted')) { + $this->table('kg_user_contact')->removeColumn('deleted'); + } + + if ($this->table('kg_user_session')->hasColumn('deleted')) { + $this->table('kg_user_session')->removeColumn('deleted'); + } + + if ($this->table('kg_user_token')->hasColumn('deleted')) { + $this->table('kg_user_token')->removeColumn('deleted'); + } + + if ($this->table('kg_wechat_subscribe')->hasColumn('deleted')) { + $this->table('kg_wechat_subscribe')->removeColumn('deleted'); + } + + if ($this->table('kg_user_session')->hasColumn('expire_time') == false) { + $this->table('kg_user_session')->addColumn('expire_time', 'integer', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'comment' => '过期时间', + 'after' => 'client_ip', + ])->save(); + } + + if ($this->table('kg_user_token')->hasColumn('expire_time') == false) { + $this->table('kg_user_token')->addColumn('expire_time', 'integer', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'comment' => '过期时间', + 'after' => 'client_ip', + ])->save(); + } + } + + protected function deleteCourseTeachers() + { + $this->getQueryBuilder() + ->delete('kg_course_user') + ->where(['role_type' => 2, 'deleted' => 1]) + ->execute(); + } + +} From 3838d95dc4a992fde56780db3edf67edbfc169a9 Mon Sep 17 00:00:00 2001 From: koogua Date: Tue, 2 Mar 2021 20:14:47 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=95=B4=E7=90=86=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BB=A5=E5=8F=8Adeleted=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20210302021013_schema_202103021010.php | 84 ++++++++++++------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/db/migrations/20210302021013_schema_202103021010.php b/db/migrations/20210302021013_schema_202103021010.php index 781dba26..d9418857 100644 --- a/db/migrations/20210302021013_schema_202103021010.php +++ b/db/migrations/20210302021013_schema_202103021010.php @@ -9,56 +9,82 @@ class Schema202103021010 extends Phinx\Migration\AbstractMigration { $this->deleteCourseTeachers(); - if ($this->table('kg_chapter_like')->hasColumn('deleted')) { - $this->table('kg_chapter_like')->removeColumn('deleted'); + $table = $this->table('kg_chapter_like'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_chapter_user')->hasColumn('deleted')) { - $this->table('kg_chapter_user')->removeColumn('deleted'); + $table = $this->table('kg_chapter_user'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_consult_like')->hasColumn('deleted')) { - $this->table('kg_consult_like')->removeColumn('deleted'); + $table = $this->table('kg_consult_like'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_course_favorite')->hasColumn('deleted')) { - $this->table('kg_course_favorite')->removeColumn('deleted'); + $table = $this->table('kg_course_favorite'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_learning')->hasColumn('deleted')) { - $this->table('kg_learning')->removeColumn('deleted'); + $table = $this->table('kg_learning'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_point_history')->hasColumn('deleted')) { - $this->table('kg_point_history')->removeColumn('deleted'); + $table = $this->table('kg_point_history'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_review_like')->hasColumn('deleted')) { - $this->table('kg_review_like')->removeColumn('deleted'); + $table = $this->table('kg_review_like'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_user_balance')->hasColumn('deleted')) { - $this->table('kg_user_balance')->removeColumn('deleted'); + $table = $this->table('kg_user_balance'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_user_contact')->hasColumn('deleted')) { - $this->table('kg_user_contact')->removeColumn('deleted'); + $table = $this->table('kg_user_contact'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_user_session')->hasColumn('deleted')) { - $this->table('kg_user_session')->removeColumn('deleted'); + $table = $this->table('kg_user_session'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_user_token')->hasColumn('deleted')) { - $this->table('kg_user_token')->removeColumn('deleted'); + $table = $this->table('kg_user_token'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_wechat_subscribe')->hasColumn('deleted')) { - $this->table('kg_wechat_subscribe')->removeColumn('deleted'); + $table = $this->table('kg_wechat_subscribe'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); } - if ($this->table('kg_user_session')->hasColumn('expire_time') == false) { - $this->table('kg_user_session')->addColumn('expire_time', 'integer', [ + $table = $this->table('kg_user_session'); + + if ($table->hasColumn('expire_time') == false) { + $table->addColumn('expire_time', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, @@ -68,8 +94,10 @@ class Schema202103021010 extends Phinx\Migration\AbstractMigration ])->save(); } - if ($this->table('kg_user_token')->hasColumn('expire_time') == false) { - $this->table('kg_user_token')->addColumn('expire_time', 'integer', [ + $table = $this->table('kg_user_token'); + + if ($table->hasColumn('expire_time') == false) { + $table->addColumn('expire_time', 'integer', [ 'null' => false, 'default' => '0', 'limit' => MysqlAdapter::INT_REGULAR, From da1d35399db42f1cb280662f2aff243054f94a66 Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 3 Mar 2021 10:25:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=95=B4=E7=90=86=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BB=A5=E5=8F=8Adeleted=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Views/setting/sms.volt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Admin/Views/setting/sms.volt b/app/Http/Admin/Views/setting/sms.volt index 402798f3..046b4a0c 100644 --- a/app/Http/Admin/Views/setting/sms.volt +++ b/app/Http/Admin/Views/setting/sms.volt @@ -57,16 +57,6 @@
复制
商品发货通知 - - - 复制
购买成功通知 @@ -77,6 +67,16 @@ 复制
商品发货通知 + + + 复制
退款成功通知 From 9d4225f6636fb9adb595f36f0fe0a21d66859788 Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 3 Mar 2021 17:29:27 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=95=B4=E7=90=86migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/ImNotice.php | 28 ---------- app/Repos/Connect.php | 4 -- app/Repos/CourseFavorite.php | 4 -- app/Repos/ImFriendUser.php | 4 -- app/Repos/ImNotice.php | 4 -- app/Repos/UserSession.php | 1 - app/Repos/UserToken.php | 1 - .../20201004095647_create_online_table.php | 29 ----------- ...201205112717_insert_oauth_setting_data.php | 17 ++++-- .../20201212112717_data_202012121830.php | 27 +++++----- .../20210228035113_data_202102280351.php | 52 ++++++++----------- .../20210302021013_schema_202103021010.php | 6 +++ 12 files changed, 54 insertions(+), 123 deletions(-) diff --git a/app/Models/ImNotice.php b/app/Models/ImNotice.php index 73fe6bfd..258f77fb 100644 --- a/app/Models/ImNotice.php +++ b/app/Models/ImNotice.php @@ -2,8 +2,6 @@ namespace App\Models; -use Phalcon\Mvc\Model\Behavior\SoftDelete; - class ImNotice extends Model { @@ -59,13 +57,6 @@ class ImNotice extends Model */ public $item_info = ''; - /** - * 优先级 - * - * @var int - */ - public $priority = 0; - /** * 阅读标识 * @@ -73,13 +64,6 @@ class ImNotice extends Model */ public $viewed = 0; - /** - * 删除标识 - * - * @var int - */ - public $deleted = 0; - /** * 创建时间 * @@ -99,18 +83,6 @@ class ImNotice extends Model return 'kg_im_notice'; } - public function initialize() - { - parent::initialize(); - - $this->addBehavior( - new SoftDelete([ - 'field' => 'deleted', - 'value' => 1, - ]) - ); - } - public function beforeCreate() { if (!empty($this->item_info)) { diff --git a/app/Repos/Connect.php b/app/Repos/Connect.php index 49c07865..5337cfac 100644 --- a/app/Repos/Connect.php +++ b/app/Repos/Connect.php @@ -28,10 +28,6 @@ class Connect extends Repository $query->andWhere('provider = :provider:', ['provider' => $where['provider']]); } - if (isset($where['deleted'])) { - $query->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - $query->orderBy('id DESC'); return $query->execute(); diff --git a/app/Repos/CourseFavorite.php b/app/Repos/CourseFavorite.php index 8ea512b9..4fc7ad04 100644 --- a/app/Repos/CourseFavorite.php +++ b/app/Repos/CourseFavorite.php @@ -25,10 +25,6 @@ class CourseFavorite extends Repository $builder->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]); } - if (isset($where['deleted'])) { - $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - switch ($sort) { default: $orderBy = 'id DESC'; diff --git a/app/Repos/ImFriendUser.php b/app/Repos/ImFriendUser.php index 355b1e44..39d0467e 100644 --- a/app/Repos/ImFriendUser.php +++ b/app/Repos/ImFriendUser.php @@ -25,10 +25,6 @@ class ImFriendUser extends Repository $builder->andWhere('friend_id = :friend_id:', ['friend_id' => $where['friend_id']]); } - if (isset($where['blocked'])) { - $builder->andWhere('blocked = :blocked:', ['blocked' => $where['blocked']]); - } - switch ($sort) { case 'oldest': $orderBy = 'id ASC'; diff --git a/app/Repos/ImNotice.php b/app/Repos/ImNotice.php index ee87d26c..e502fd37 100644 --- a/app/Repos/ImNotice.php +++ b/app/Repos/ImNotice.php @@ -27,10 +27,6 @@ class ImNotice extends Repository $builder->andWhere('receiver_id = :receiver_id:', ['receiver_id' => $where['receiver_id']]); } - if (isset($where['deleted'])) { - $builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]); - } - switch ($sort) { case 'oldest': $orderBy = 'id ASC'; diff --git a/app/Repos/UserSession.php b/app/Repos/UserSession.php index be56e73c..d1cd85d5 100644 --- a/app/Repos/UserSession.php +++ b/app/Repos/UserSession.php @@ -17,7 +17,6 @@ class UserSession extends Repository { return UserSessionModel::query() ->where('user_id = :user_id:', ['user_id' => $userId]) - ->andWhere('deleted = 0') ->execute(); } diff --git a/app/Repos/UserToken.php b/app/Repos/UserToken.php index 70da5427..799ddb20 100644 --- a/app/Repos/UserToken.php +++ b/app/Repos/UserToken.php @@ -17,7 +17,6 @@ class UserToken extends Repository { return UserTokenModel::query() ->where('user_id = :user_id:', ['user_id' => $userId]) - ->andWhere('deleted = 0') ->execute(); } diff --git a/db/migrations/20201004095647_create_online_table.php b/db/migrations/20201004095647_create_online_table.php index 9f9438e7..25497498 100644 --- a/db/migrations/20201004095647_create_online_table.php +++ b/db/migrations/20201004095647_create_online_table.php @@ -81,35 +81,6 @@ class CreateOnlineTable extends Phinx\Migration\AbstractMigration 'unique' => false, ]) ->create(); - $this->table('kg_task', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '', - 'row_format' => 'DYNAMIC', - ]) - ->save(); - $this->table('kg_trade', [ - 'id' => false, - 'primary_key' => ['id'], - 'engine' => 'InnoDB', - 'encoding' => 'utf8mb4', - 'collation' => 'utf8mb4_general_ci', - 'comment' => '主键编号', - 'row_format' => 'DYNAMIC', - ]) - ->changeColumn('channel_sn', 'string', [ - 'null' => false, - 'default' => '', - 'limit' => 64, - 'collation' => 'utf8mb4_general_ci', - 'encoding' => 'utf8mb4', - 'comment' => '平台序号', - 'after' => 'channel', - ]) - ->save(); } } diff --git a/db/migrations/20201205112717_insert_oauth_setting_data.php b/db/migrations/20201205112717_insert_oauth_setting_data.php index 0b5643cc..8bde8590 100644 --- a/db/migrations/20201205112717_insert_oauth_setting_data.php +++ b/db/migrations/20201205112717_insert_oauth_setting_data.php @@ -80,9 +80,20 @@ final class InsertOauthSettingData extends AbstractMigration public function down() { - $this->execute("DELETE FROM kg_setting WHERE section = 'oauth.qq'"); - $this->execute("DELETE FROM kg_setting WHERE section = 'oauth.weixin'"); - $this->execute("DELETE FROM kg_setting WHERE section = 'oauth.weibo'"); + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'oauth.qq']) + ->execute(); + + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'oauth.weixin']) + ->execute(); + + $this->getQueryBuilder() + ->delete('kg_setting') + ->where(['section' => 'oauth.weibo']) + ->execute(); } } \ No newline at end of file diff --git a/db/migrations/20201212112717_data_202012121830.php b/db/migrations/20201212112717_data_202012121830.php index ae7c66ba..e73b008e 100644 --- a/db/migrations/20201212112717_data_202012121830.php +++ b/db/migrations/20201212112717_data_202012121830.php @@ -60,30 +60,27 @@ final class Data202012121830 extends AbstractMigration protected function updateSmsTemplate() { - $table = 'kg_setting'; - - $where = ['section' => 'sms', 'item_key' => 'template']; - $setting = $this->getQueryBuilder() ->select('*') - ->from($table) - ->where($where) - ->execute() - ->fetch('assoc'); + ->from('kg_setting') + ->where(['section' => 'sms', 'item_key' => 'template']) + ->execute()->fetch('assoc'); + + if (!$setting) return; $itemValue = json_decode($setting['item_value'], true); $newItemValue = json_encode([ - 'verify' => $itemValue['verify'], - 'order_finish' => $itemValue['order'], - 'refund_finish' => $itemValue['refund'], - 'live_begin' => $itemValue['live'], - 'consult_reply' => '', + 'verify' => $itemValue['verify'] ?? '', + 'order_finish' => $itemValue['order'] ?? '', + 'refund_finish' => $itemValue['refund'] ?? '', + 'live_begin' => $itemValue['live'] ?? '', + 'consult_reply' => $itemValue['consult'] ?? '', ]); $this->getQueryBuilder() - ->update($table) - ->where($where) + ->update('kg_setting') + ->where(['id' => $setting['id']]) ->set('item_value', $newItemValue) ->execute(); } diff --git a/db/migrations/20210228035113_data_202102280351.php b/db/migrations/20210228035113_data_202102280351.php index 3d1a4968..ebb5faab 100644 --- a/db/migrations/20210228035113_data_202102280351.php +++ b/db/migrations/20210228035113_data_202102280351.php @@ -13,27 +13,24 @@ final class Data202102280351 extends AbstractMigration protected function updateSmsNoticeTemplate() { - $table = 'kg_setting'; - - $where = [ - 'section' => 'sms', - 'item_key' => 'template', - ]; - $setting = $this->getQueryBuilder() ->select('*') - ->from($table) - ->where($where) - ->execute() - ->fetch('assoc'); + ->from('kg_setting') + ->where(['section' => 'sms', 'item_key' => 'template']) + ->execute()->fetch('assoc'); + + if (!$setting) return; $itemValue = json_decode($setting['item_value'], true); $newItemValue = []; + /** + * 更改数据结构 + */ foreach ($itemValue as $key => $value) { - $newItemValue[$key]['id'] = $value; - $newItemValue[$key]['enabled'] = 1; + $newItemValue[$key]['id'] = $value['id'] ?? $value; + $newItemValue[$key]['enabled'] = $value['enabled'] ?? 1; } /** @@ -44,35 +41,30 @@ final class Data202102280351 extends AbstractMigration $itemValue = json_encode($newItemValue); $this->getQueryBuilder() - ->update($table) - ->where($where) + ->update('kg_setting') + ->where(['id' => $setting['id']]) ->set('item_value', $itemValue) ->execute(); } protected function updateWechatNoticeTemplate() { - $table = 'kg_setting'; - - $where = [ - 'section' => 'wechat.oa', - 'item_key' => 'notice_template', - ]; - $setting = $this->getQueryBuilder() ->select('*') - ->from($table) - ->where($where) - ->execute() - ->fetch('assoc'); + ->from('kg_setting') + ->where(['section' => 'wechat.oa', 'item_key' => 'notice_template']) + ->execute()->fetch('assoc'); $itemValue = json_decode($setting['item_value'], true); $newItemValue = []; + /** + * 更改数据结构 + */ foreach ($itemValue as $key => $value) { - $newItemValue[$key]['id'] = $value; - $newItemValue[$key]['enabled'] = 1; + $newItemValue[$key]['id'] = $value['id'] ?? $value; + $newItemValue[$key]['enabled'] = $value['enabled'] ?? 1; } /** @@ -83,8 +75,8 @@ final class Data202102280351 extends AbstractMigration $itemValue = json_encode($newItemValue); $this->getQueryBuilder() - ->update($table) - ->where($where) + ->update('kg_setting') + ->where(['id' => $setting['id']]) ->set('item_value', $itemValue) ->execute(); } diff --git a/db/migrations/20210302021013_schema_202103021010.php b/db/migrations/20210302021013_schema_202103021010.php index d9418857..5829d86d 100644 --- a/db/migrations/20210302021013_schema_202103021010.php +++ b/db/migrations/20210302021013_schema_202103021010.php @@ -33,6 +33,12 @@ class Schema202103021010 extends Phinx\Migration\AbstractMigration $table->removeColumn('deleted')->save(); } + $table = $this->table('kg_im_notice'); + + if ($table->hasColumn('deleted')) { + $table->removeColumn('deleted')->save(); + } + $table = $this->table('kg_learning'); if ($table->hasColumn('deleted')) {