From c886434ccc7a3c2f976121c85512f7729c2b530f Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Wed, 23 Sep 2020 21:41:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=AE=9D=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E8=B0=83=E6=95=B4=E6=88=90=E5=85=AC=E9=92=A5=E8=AF=81?= =?UTF-8?q?=E4=B9=A6=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/DeliverTask.php | 81 ++++++++++++++----- app/Http/Admin/Services/PayTest.php | 6 +- app/Http/Admin/Views/setting/pay_alipay.volt | 7 -- .../Admin/Views/setting/pay_wxpay_test.volt | 2 +- app/Http/Home/Services/ImCsTrait.php | 31 +++---- app/Http/Home/Services/ImFriendTrait.php | 25 +++++- app/Http/Home/Services/ImGroupTrait.php | 26 +++++- app/Http/Home/Views/im/group/show.volt | 1 - app/Library/Sitemap.php | 4 +- app/Repos/ImGroup.php | 12 +++ app/Services/LiveNotify.php | 8 +- app/Services/Logic/Chapter/ChapterInfo.php | 13 +++ app/Services/Mail/Verify.php | 2 +- app/Services/MyStorage.php | 2 +- app/Services/Pay/AlipayGateway.php | 5 +- app/Services/Throttle.php | 2 +- app/Services/Verify.php | 12 +-- app/Validators/Account.php | 10 +-- app/Validators/ImGroupUser.php | 41 ++++++++++ app/Validators/Validator.php | 4 +- app/Validators/Verify.php | 10 +-- bootstrap/ConsoleErrorHandler.php | 2 +- bootstrap/ConsoleKernel.php | 4 +- bootstrap/Helper.php | 2 +- bootstrap/HttpKernel.php | 4 +- bootstrap/Kernel.php | 12 +-- config/errors.php | 18 +++-- db/migrations/20200827063842_init_table.php | 2 +- 28 files changed, 243 insertions(+), 105 deletions(-) diff --git a/app/Console/Tasks/DeliverTask.php b/app/Console/Tasks/DeliverTask.php index 9b9ddebd..1895ce26 100644 --- a/app/Console/Tasks/DeliverTask.php +++ b/app/Console/Tasks/DeliverTask.php @@ -3,10 +3,13 @@ namespace App\Console\Tasks; use App\Models\CourseUser as CourseUserModel; +use App\Models\ImGroupUser as ImGroupUserModel; 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\ImGroup as ImGroupRepo; +use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\Order as OrderRepo; use App\Repos\User as UserRepo; use App\Services\Sms\Order as OrderSms; @@ -104,19 +107,36 @@ class DeliverTask extends Task */ $itemInfo = $order->item_info; - $data = [ - 'user_id' => $order->owner_id, - 'course_id' => $order->item_id, - 'expiry_time' => $itemInfo['course']['study_expiry_time'], - 'role_type' => CourseUserModel::ROLE_STUDENT, - 'source_type' => CourseUserModel::SOURCE_CHARGE, - ]; - $courseUser = new CourseUserModel(); - if ($courseUser->create($data) === false) { + $courseUser->user_id = $order->owner_id; + $courseUser->course_id = $order->item_id; + $courseUser->expiry_time = $itemInfo['course']['study_expiry_time']; + $courseUser->role_type = CourseUserModel::ROLE_STUDENT; + $courseUser->source_type = CourseUserModel::SOURCE_CHARGE; + + if ($courseUser->create() === false) { throw new \RuntimeException('Create Course User Failed'); } + + $groupRepo = new ImGroupRepo(); + + $group = $groupRepo->findByCourseId($order->item_id); + + $groupUserRepo = new ImGroupUserRepo(); + + $groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id); + + if ($groupUser) return; + + $groupUser = new ImGroupUserModel(); + + $groupUser->group_id = $group->id; + $groupUser->user_id = $order->owner_id; + + if ($groupUser->create() === false) { + throw new \RuntimeException('Create Group User Failed'); + } } protected function handlePackageOrder(OrderModel $order) @@ -128,33 +148,50 @@ class DeliverTask extends Task foreach ($itemInfo['courses'] as $course) { - $data = [ - 'user_id' => $order->owner_id, - 'course_id' => $course['id'], - 'expiry_time' => $course['study_expiry_time'], - 'role_type' => CourseUserModel::ROLE_STUDENT, - 'source_type' => CourseUserModel::SOURCE_CHARGE, - ]; - $courseUser = new CourseUserModel(); - if ($courseUser->create($data) === false) { + $courseUser->user_id = $order->owner_id; + $courseUser->course_id = $course['id']; + $courseUser->expiry_time = $course['study_expiry_time']; + $courseUser->role_type = CourseUserModel::ROLE_STUDENT; + $courseUser->source_type = CourseUserModel::SOURCE_CHARGE; + + if ($courseUser->create() === false) { throw new \RuntimeException('Create Course User Failed'); } + + $groupRepo = new ImGroupRepo(); + + $group = $groupRepo->findByCourseId($course['id']); + + $groupUserRepo = new ImGroupUserRepo(); + + $groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id); + + if ($groupUser) continue; + + $groupUser = new ImGroupUserModel(); + + $groupUser->group_id = $group->id; + $groupUser->user_id = $order->owner_id; + + if ($groupUser->create() === false) { + throw new \RuntimeException('Create Group User Failed'); + } } } protected function handleVipOrder(OrderModel $order) { - $userRepo = new UserRepo(); - - $user = $userRepo->findById($order->owner_id); - /** * @var array $itemInfo */ $itemInfo = $order->item_info; + $userRepo = new UserRepo(); + + $user = $userRepo->findById($order->owner_id); + $user->vip_expiry_time = $itemInfo['vip']['expiry_time']; if ($user->update() === false) { diff --git a/app/Http/Admin/Services/PayTest.php b/app/Http/Admin/Services/PayTest.php index ea563b0c..dc028bea 100644 --- a/app/Http/Admin/Services/PayTest.php +++ b/app/Http/Admin/Services/PayTest.php @@ -30,8 +30,8 @@ abstract class PayTest extends Service $order = new OrderModel(); - $order->subject = '测试 - 支付测试3.01元'; - $order->amount = 3.01; + $order->subject = '测试 - 支付测试0.01元'; + $order->amount = 0.01; $order->owner_id = $authUser['id']; $order->item_type = OrderModel::ITEM_TEST; @@ -59,7 +59,7 @@ abstract class PayTest extends Service $order = new OrderModel(); /** - * 微信沙箱环境金额不能自定义,只能是测试用例值(沙吊的不行) + * 微信沙箱环境金额不能自定义,只能是固定测试用例值(SB的不行) */ if ($config->get('env') == ENV_DEV) { $order->subject = '测试 - 支付测试3.01元'; diff --git a/app/Http/Admin/Views/setting/pay_alipay.volt b/app/Http/Admin/Views/setting/pay_alipay.volt index 3a773750..aa060e5d 100644 --- a/app/Http/Admin/Views/setting/pay_alipay.volt +++ b/app/Http/Admin/Views/setting/pay_alipay.volt @@ -12,13 +12,6 @@ -
- -
- -
-
-
diff --git a/app/Http/Admin/Views/setting/pay_wxpay_test.volt b/app/Http/Admin/Views/setting/pay_wxpay_test.volt index 3c57f314..518d4517 100644 --- a/app/Http/Admin/Views/setting/pay_wxpay_test.volt +++ b/app/Http/Admin/Views/setting/pay_wxpay_test.volt @@ -1,6 +1,6 @@ {% extends 'templates/main.volt' %} -{% block contnet %} +{% block content %}
{% if qrcode %} diff --git a/app/Http/Home/Services/ImCsTrait.php b/app/Http/Home/Services/ImCsTrait.php index a86a3dc5..c3a816c1 100644 --- a/app/Http/Home/Services/ImCsTrait.php +++ b/app/Http/Home/Services/ImCsTrait.php @@ -2,7 +2,7 @@ namespace App\Http\Home\Services; -use App\Caches\Setting as SettingCache; +use App\Services\Service as AppService; use GatewayClient\Gateway; trait ImCsTrait @@ -11,32 +11,33 @@ trait ImCsTrait public function getCsUser() { $csUserIds = []; + $onlineUserIds = []; - $cache = new SettingCache(); + $appService = new AppService(); - $imInfo = $cache->get('im'); + $csInfo = $appService->getSettings('im.cs'); Gateway::$registerAddress = $this->getRegisterAddress(); - if (!empty($imInfo['cs_user1_id'])) { - $csUserIds[] = $imInfo['cs_user1_id']; - if (Gateway::isUidOnline($imInfo['cs_user1_id'])) { - $onlineUserIds[] = $imInfo['cs_user1_id']; + if (!empty($csInfo['user1_id'])) { + $csUserIds[] = $csInfo['user1_id']; + if (Gateway::isUidOnline($csInfo['user1_id'])) { + $onlineUserIds[] = $csInfo['user1_id']; } } - if (!empty($imInfo['cs_user2_id'])) { - $csUserIds[] = $imInfo['cs_user2_id']; - if (Gateway::isUidOnline($imInfo['cs_user2_id'])) { - $onlineUserIds[] = $imInfo['cs_user2_id']; + if (!empty($csInfo['user2_id'])) { + $csUserIds[] = $csInfo['user2_id']; + if (Gateway::isUidOnline($csInfo['user2_id'])) { + $onlineUserIds[] = $csInfo['user2_id']; } } - if (!empty($imInfo['cs_user3_id'])) { - $csUserIds[] = $imInfo['cs_user3_id']; - if (Gateway::isUidOnline($imInfo['cs_user3_id'])) { - $onlineUserIds[] = $imInfo['cs_user3_id']; + if (!empty($csInfo['user3_id'])) { + $csUserIds[] = $csInfo['user3_id']; + if (Gateway::isUidOnline($csInfo['user3_id'])) { + $onlineUserIds[] = $csInfo['user3_id']; } } diff --git a/app/Http/Home/Services/ImFriendTrait.php b/app/Http/Home/Services/ImFriendTrait.php index 1e807383..5731397b 100644 --- a/app/Http/Home/Services/ImFriendTrait.php +++ b/app/Http/Home/Services/ImFriendTrait.php @@ -11,17 +11,24 @@ use App\Repos\ImUser as ImUserRepo; use App\Validators\ImFriendUser as ImFriendUserValidator; use App\Validators\ImNotice as ImNoticeValidator; use GatewayClient\Gateway; +use Phalcon\Di; +use Phalcon\Http\Request; Trait ImFriendTrait { public function applyFriend() { + /** + * @var Request $request + */ + $request = Di::getDefault()->get('request'); + $loginUser = $this->getLoginUser(); $user = $this->getImUser($loginUser->id); - $post = $this->request->getPost(); + $post = $request->getPost(); $validator = new ImFriendUserValidator(); @@ -37,12 +44,17 @@ Trait ImFriendTrait public function acceptFriend() { + /** + * @var Request $request + */ + $request = Di::getDefault()->get('request'); + $loginUser = $this->getLoginUser(); $user = $this->getImUser($loginUser->id); - $noticeId = $this->request->getPost('notice_id'); - $groupId = $this->request->getPost('group_id'); + $noticeId = $request->getPost('notice_id'); + $groupId = $request->getPost('group_id'); $validator = new ImFriendUserValidator(); @@ -103,11 +115,16 @@ Trait ImFriendTrait public function refuseFriend() { + /** + * @var Request $request + */ + $request = Di::getDefault()->get('request'); + $loginUser = $this->getLoginUser(); $user = $this->getImUser($loginUser->id); - $noticeId = $this->request->getPost('notice_id'); + $noticeId = $request->getPost('notice_id'); $validator = new ImNoticeValidator(); diff --git a/app/Http/Home/Services/ImGroupTrait.php b/app/Http/Home/Services/ImGroupTrait.php index 7cdf1a93..d411e4d6 100644 --- a/app/Http/Home/Services/ImGroupTrait.php +++ b/app/Http/Home/Services/ImGroupTrait.php @@ -13,35 +13,48 @@ use App\Validators\ImGroup as ImGroupValidator; use App\Validators\ImGroupUser as ImGroupUserValidator; use App\Validators\ImNotice as ImNoticeValidator; use GatewayClient\Gateway; +use Phalcon\Di; +use Phalcon\Http\Request; Trait ImGroupTrait { public function applyGroup() { + /** + * @var Request $request + */ + $request = Di::getDefault()->get('request'); + $loginUser = $this->getLoginUser(); $user = $this->getImUser($loginUser->id); - $post = $this->request->getPost(); - $validator = new ImGroupUserValidator(); + $post = $request->getPost(); + $group = $validator->checkGroup($post['group_id']); $remark = $validator->checkRemark($post['remark']); $validator->checkIfJoined($group->id, $user->id); + $validator->checkIfAllowJoin($group->id, $user->id); $this->handleApplyGroupNotice($user, $group, $remark); } public function acceptGroup() { + /** + * @var Request $request + */ + $request = Di::getDefault()->get('request'); + $loginUser = $this->getLoginUser(); $user = $this->getImUser($loginUser->id); - $noticeId = $this->request->getPost('notice_id', 'int'); + $noticeId = $request->getPost('notice_id', 'int'); $validator = new ImNoticeValidator(); @@ -92,11 +105,16 @@ Trait ImGroupTrait public function refuseGroup() { + /** + * @var Request $request + */ + $request = Di::getDefault()->get('request'); + $loginUser = $this->getLoginUser(); $user = $this->getImUser($loginUser->id); - $noticeId = $this->request->getPost('notice_id', 'int'); + $noticeId = $request->getPost('notice_id', 'int'); $validator = new ImNoticeValidator(); diff --git a/app/Http/Home/Views/im/group/show.volt b/app/Http/Home/Views/im/group/show.volt index 9b87b338..885f6451 100644 --- a/app/Http/Home/Views/im/group/show.volt +++ b/app/Http/Home/Views/im/group/show.volt @@ -3,7 +3,6 @@ {% block content %} {% set group.about = group.about ? group.about : '这个家伙真懒,什么都没有留下~' %} - {% set apply_group_url = '' %} {% set users_url = url({'for':'home.group.users','id':group.id}) %} {% set active_users_url = url({'for':'home.group.active_users','id':group.id}) %} diff --git a/app/Library/Sitemap.php b/app/Library/Sitemap.php index 26dd7728..02e7fdd9 100644 --- a/app/Library/Sitemap.php +++ b/app/Library/Sitemap.php @@ -24,7 +24,7 @@ class Sitemap * @param string $changefreq 更新频率的单位 * @param string $lastmod 日期格式 YYYY-MM-DD */ - function addItem($loc, $priority = null, $changefreq = null, $lastmod = null) + public function addItem($loc, $priority = null, $changefreq = null, $lastmod = null) { $this->items[] = array( 'loc' => $loc, @@ -38,7 +38,7 @@ class Sitemap * @param string $filename * @return mixed */ - function build($filename = null) + public function build($filename = null) { $xml = '' . "\n"; $xml .= '' . "\n"; diff --git a/app/Repos/ImGroup.php b/app/Repos/ImGroup.php index 1f8b05b0..7265b426 100644 --- a/app/Repos/ImGroup.php +++ b/app/Repos/ImGroup.php @@ -79,6 +79,18 @@ class ImGroup extends Repository return ImGroupModel::findFirst($id); } + /** + * @param int $courseId + * @return ImGroupModel|Model|bool + */ + public function findByCourseId($courseId) + { + return ImGroupModel::findFirst([ + 'conditions' => 'course_id = :course_id:', + 'bind' => ['course_id' => $courseId], + ]); + } + /** * @param array $ids * @param string|array $columns diff --git a/app/Services/LiveNotify.php b/app/Services/LiveNotify.php index c2c8daee..051172d4 100644 --- a/app/Services/LiveNotify.php +++ b/app/Services/LiveNotify.php @@ -162,9 +162,13 @@ class LiveNotify extends Service */ protected function checkSign($sign, $time) { - if (!$sign || !$time) return false; + if (!$sign || !$time) { + return false; + } - if ($time < time()) return false; + if ($time < time()) { + return false; + } $notify = $this->getSettings('live.notify'); diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php index 31245ba5..fe8cd5d8 100644 --- a/app/Services/Logic/Chapter/ChapterInfo.php +++ b/app/Services/Logic/Chapter/ChapterInfo.php @@ -6,8 +6,10 @@ 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\ImGroupUser as ImGroupUserModel; use App\Models\User as UserModel; use App\Repos\ChapterLike as ChapterLikeRepo; +use App\Repos\ImGroup as ImGroupRepo; use App\Services\Logic\ChapterTrait; use App\Services\Logic\CourseTrait; use App\Services\Logic\Service; @@ -114,6 +116,17 @@ class ChapterInfo extends Service $this->joinedCourse = true; + $groupRepo = new ImGroupRepo(); + + $group = $groupRepo->findByCourseId($course->id); + + $groupUser = new ImGroupUserModel(); + + $groupUser->group_id = $group->id; + $groupUser->user_id = $user->id; + + $groupUser->create(); + $this->incrCourseUserCount($course); $this->incrUserCourseCount($user); diff --git a/app/Services/Mail/Verify.php b/app/Services/Mail/Verify.php index 199183bb..6709a1ca 100644 --- a/app/Services/Mail/Verify.php +++ b/app/Services/Mail/Verify.php @@ -22,7 +22,7 @@ class Verify extends MailerService $minutes = 5; - $code = $verify->getEmailCode($email, 60 * $minutes); + $code = $verify->getMailCode($email, 60 * $minutes); $subject = '邮件验证码'; diff --git a/app/Services/MyStorage.php b/app/Services/MyStorage.php index 7ac2c478..e6d6ca74 100644 --- a/app/Services/MyStorage.php +++ b/app/Services/MyStorage.php @@ -106,7 +106,7 @@ class MyStorage extends Storage * * @param string $prefix * @param string $mimeType - * @param string $uploadType + * @param int $uploadType * @return UploadModel|bool */ protected function upload($prefix, $mimeType, $uploadType) diff --git a/app/Services/Pay/AlipayGateway.php b/app/Services/Pay/AlipayGateway.php index 40fa26e1..e686be2f 100644 --- a/app/Services/Pay/AlipayGateway.php +++ b/app/Services/Pay/AlipayGateway.php @@ -42,9 +42,10 @@ class AlipayGateway extends Service $options = [ 'app_id' => $this->settings['app_id'], - 'ali_public_key' => $this->settings['public_key'], 'private_key' => $this->settings['private_key'], - 'return_url' => $this->settings['return_url'], + 'ali_public_key' => config_path('alipay/alipayCertPublicKey.crt'), // 支付宝公钥证书 + 'alipay_root_cert' => config_path('alipay/alipayRootCert.crt'), // 支付宝根证书 + 'app_cert_public_key' => config_path('alipay/appCertPublicKey.crt'), // 应用公钥证书 'notify_url' => $this->settings['notify_url'], 'log' => [ 'file' => log_path('alipay.log'), diff --git a/app/Services/Throttle.php b/app/Services/Throttle.php index 1d0d0e33..7a5f4140 100644 --- a/app/Services/Throttle.php +++ b/app/Services/Throttle.php @@ -49,7 +49,7 @@ class Throttle extends Service return md5($httpHost . '|' . $clientAddress); } - throw new \RuntimeException('Unable to generate the request signature.'); + throw new \RuntimeException('Unable to generate request signature'); } protected function getCacheKey($sign) diff --git a/app/Services/Verify.php b/app/Services/Verify.php index 171e636b..da1afe8e 100644 --- a/app/Services/Verify.php +++ b/app/Services/Verify.php @@ -29,9 +29,9 @@ class Verify extends Service return $code; } - public function getEmailCode($email, $lifetime = 300) + public function getMailCode($email, $lifetime = 300) { - $key = $this->getEmailCacheKey($email); + $key = $this->getMailCacheKey($email); $code = Text::random(Text::RANDOM_NUMERIC, 6); @@ -49,18 +49,18 @@ class Verify extends Service return $code == $value; } - public function checkEmailCode($email, $code) + public function checkMailCode($email, $code) { - $key = $this->getEmailCacheKey($email); + $key = $this->getMailCacheKey($email); $value = $this->cache->get($key); return $code == $value; } - protected function getEmailCacheKey($email) + protected function getMailCacheKey($email) { - return "verify:email:{$email}"; + return "verify:mail:{$email}"; } protected function getSmsCacheKey($phone) diff --git a/app/Validators/Account.php b/app/Validators/Account.php index 08afc337..0bc8e8e7 100644 --- a/app/Validators/Account.php +++ b/app/Validators/Account.php @@ -67,7 +67,7 @@ class Account extends Validator public function checkPassword($password) { if (!CommonValidator::password($password)) { - throw new BadRequestException('account.invalid_password'); + throw new BadRequestException('account.invalid_pwd'); } return $password; @@ -76,7 +76,7 @@ class Account extends Validator public function checkConfirmPassword($newPassword, $confirmPassword) { if ($newPassword != $confirmPassword) { - throw new BadRequestException('account.password_not_match'); + throw new BadRequestException('account.pwd_not_match'); } } @@ -85,7 +85,7 @@ class Account extends Validator $hash = PasswordUtil::hash($password, $account->salt); if ($hash != $account->password) { - throw new BadRequestException('account.origin_password_incorrect'); + throw new BadRequestException('account.origin_pwd_incorrect'); } } @@ -94,7 +94,7 @@ class Account extends Validator $hash = PasswordUtil::hash($password, $account->salt); if ($hash != $account->password) { - throw new BadRequestException('account.login_password_incorrect'); + throw new BadRequestException('account.login_pwd_incorrect'); } } @@ -140,7 +140,7 @@ class Account extends Validator $hash = PasswordUtil::hash($password, $account->salt); if ($hash != $account->password) { - throw new BadRequestException('account.login_password_incorrect'); + throw new BadRequestException('account.login_pwd_incorrect'); } $userRepo = new UserRepo(); diff --git a/app/Validators/ImGroupUser.php b/app/Validators/ImGroupUser.php index e262aa3e..676e0633 100644 --- a/app/Validators/ImGroupUser.php +++ b/app/Validators/ImGroupUser.php @@ -3,7 +3,13 @@ namespace App\Validators; use App\Exceptions\BadRequest as BadRequestException; +use App\Models\ImGroup as ImGroupModel; +use App\Models\User as UserModel; +use App\Repos\Course as CourseRepo; +use App\Repos\CourseUser as CourseUserRepo; +use App\Repos\ImGroup as ImGroupRepo; use App\Repos\ImGroupUser as ImGroupUserRepo; +use App\Repos\User as UserRepo; class ImGroupUser extends Validator { @@ -59,4 +65,39 @@ class ImGroupUser extends Validator } } + public function checkIfAllowJoin($groupId, $userId) + { + $message = 'im_group_user.join_not_allowed'; + + $groupRepo = new ImGroupRepo(); + $group = $groupRepo->findById($groupId); + + $userRepo = new UserRepo(); + $user = $userRepo->findById($userId); + + $staff = $user->admin_role > 0 || $user->edu_role == UserModel::EDU_ROLE_TEACHER; + + if ($group->type == ImGroupModel::TYPE_STAFF && !$staff) { + throw new BadRequestException($message); + } + + if ($group->course_id > 0) { + + $courseRepo = new CourseRepo(); + $course = $courseRepo->findById($group->course_id); + + $courseUserRepo = new CourseUserRepo(); + $courseUser = $courseUserRepo->findCourseUser($course->id, $user->id); + + if ($course->market_price > 0) { + if ($course->vip_price > 0 && !$courseUser) { + throw new BadRequestException($message); + } + if ($course->vip_price == 0 && $user->vip == 0) { + throw new BadRequestException($message); + } + } + } + } + } diff --git a/app/Validators/Validator.php b/app/Validators/Validator.php index 99f95dba..2f3a8091 100644 --- a/app/Validators/Validator.php +++ b/app/Validators/Validator.php @@ -9,9 +9,9 @@ use Phalcon\Mvc\User\Component; class Validator extends Component { - public function checkAuthUser($authUser) + public function checkAuthUser($authInfo) { - if (empty($authUser['id'])) { + if (empty($authInfo['id'])) { throw new UnauthorizedException('sys.unauthorized'); } } diff --git a/app/Validators/Verify.php b/app/Validators/Verify.php index 9c8e4e78..360616f8 100644 --- a/app/Validators/Verify.php +++ b/app/Validators/Verify.php @@ -30,11 +30,11 @@ class Verify extends Validator public function checkCode($identity, $code) { if (CommonValidator::email($identity)) { - $this->checkEmailCode($identity, $code); + $this->checkMailCode($identity, $code); } elseif (CommonValidator::phone($identity)) { $this->checkSmsCode($identity, $code); } else { - throw new BadRequestException('verify.unsupported_identity'); + throw new BadRequestException('verify.invalid_code'); } } @@ -49,14 +49,14 @@ class Verify extends Validator } } - public function checkEmailCode($email, $code) + public function checkMailCode($email, $code) { $service = new VerifyService(); - $result = $service->checkEmailCode($email, $code); + $result = $service->checkMailCode($email, $code); if (!$result) { - throw new BadRequestException('verify.invalid_email_code'); + throw new BadRequestException('verify.invalid_mail_code'); } } diff --git a/bootstrap/ConsoleErrorHandler.php b/bootstrap/ConsoleErrorHandler.php index c6a25826..3ad28acd 100644 --- a/bootstrap/ConsoleErrorHandler.php +++ b/bootstrap/ConsoleErrorHandler.php @@ -45,7 +45,7 @@ class ConsoleErrorHandler extends Component */ protected function getConfig() { - return $this->getDI()->get('config'); + return $this->getDI()->getShared('config'); } /** diff --git a/bootstrap/ConsoleKernel.php b/bootstrap/ConsoleKernel.php index b531a253..9bb01233 100644 --- a/bootstrap/ConsoleKernel.php +++ b/bootstrap/ConsoleKernel.php @@ -26,8 +26,8 @@ class ConsoleKernel extends Kernel $this->loader = new Loader(); $this->initAppEnv(); - $this->initAppConfigs(); - $this->initAppSettings(); + $this->initAppConfig(); + $this->initAppSetting(); $this->registerLoaders(); $this->registerServices(); $this->registerErrorHandler(); diff --git a/bootstrap/Helper.php b/bootstrap/Helper.php index 42b8fdde..240acb1c 100644 --- a/bootstrap/Helper.php +++ b/bootstrap/Helper.php @@ -115,7 +115,7 @@ function tmp_path($path = '') } /** - * Rtrim slash + * Trim path slash * * @param string $path * @return string diff --git a/bootstrap/HttpKernel.php b/bootstrap/HttpKernel.php index 5598eb84..648c905b 100644 --- a/bootstrap/HttpKernel.php +++ b/bootstrap/HttpKernel.php @@ -35,8 +35,8 @@ class HttpKernel extends Kernel $this->loader = new Loader(); $this->initAppEnv(); - $this->initAppConfigs(); - $this->initAppSettings(); + $this->initAppConfig(); + $this->initAppSetting(); $this->registerLoaders(); $this->registerServices(); $this->registerModules(); diff --git a/bootstrap/Kernel.php b/bootstrap/Kernel.php index 5e1bea07..5cb8c9db 100644 --- a/bootstrap/Kernel.php +++ b/bootstrap/Kernel.php @@ -27,7 +27,7 @@ abstract class Kernel /** * @var array */ - protected $configs = []; + protected $config = []; public function getApp() { @@ -44,16 +44,16 @@ abstract class Kernel require __DIR__ . '/Helper.php'; } - protected function initAppConfigs() + protected function initAppConfig() { - $this->configs = require config_path('config.php'); + $this->config = require config_path('config.php'); } - protected function initAppSettings() + protected function initAppSetting() { - ini_set('date.timezone', $this->configs['timezone']); + ini_set('date.timezone', $this->config['timezone']); - if ($this->configs['env'] == ENV_DEV) { + if ($this->config['env'] == ENV_DEV) { ini_set('display_errors', 1); error_reporting(E_ALL); } else { diff --git a/config/errors.php b/config/errors.php index 3a80b3f5..94e90723 100644 --- a/config/errors.php +++ b/config/errors.php @@ -26,10 +26,11 @@ $error['security.invalid_http_referer'] = '无效请求来源'; */ $error['verify.invalid_phone'] = '无效手机号'; $error['verify.invalid_email'] = '无效的邮箱'; +$error['verify.invalid_code'] = '无效的验证码'; $error['verify.invalid_sms_code'] = '无效的短信验证码'; -$error['verify.invalid_email_code'] = '无效的邮件验证码'; -$error['verify.send_sms_failed'] = '发送短信验证码失败'; -$error['verify.send_email_failed'] = '发送邮件验证码失败'; +$error['verify.invalid_mail_code'] = '无效的邮件验证码'; +$error['verify.send_sms_failed'] = '发送短信失败'; +$error['verify.send_mail_failed'] = '发送邮件失败'; /** * captcha相关 @@ -41,16 +42,16 @@ $error['captcha.invalid_code'] = '无效的验证码'; */ $error['account.not_found'] = '账号不存在'; $error['account.login_block'] = '账号被锁定,无法登录'; -$error['account.login_password_incorrect'] = '登录密码不正确'; +$error['account.login_pwd_incorrect'] = '登录密码不正确'; $error['account.invalid_login_name'] = '无效的登录名'; $error['account.invalid_email'] = '无效的电子邮箱'; $error['account.invalid_phone'] = '无效的手机号'; -$error['account.invalid_password'] = '无效的密码(字母或数字6-16位)'; +$error['account.invalid_pwd'] = '无效的密码(字母或数字6-16位)'; $error['account.email_taken'] = '邮箱被占用'; $error['account.phone_taken'] = '手机号被占用'; -$error['account.password_not_match'] = '密码不匹配'; -$error['account.origin_password_incorrect'] = '原有密码不正确'; -$error['account.login_password_incorrect'] = '登录密码不正确'; +$error['account.pwd_not_match'] = '密码不匹配'; +$error['account.origin_pwd_incorrect'] = '原有密码不正确'; +$error['account.login_pwd_incorrect'] = '登录密码不正确'; /** * 用户相关 @@ -341,6 +342,7 @@ $error['im_group.invalid_publish_status'] = '无效的发布状态'; $error['im_group_user.not_found'] = '群组关系不存在'; $error['im_group_user.remark_too_long'] = '验证信息太长(超过30字符)'; $error['im_group_user.has_joined'] = '已经加入过群组'; +$error['im_group_user.join_not_allowed'] = '当前不允许加入群组'; $error['im_friend_user.not_found'] = '好友关系不存在'; $error['im_friend_user.remark_too_long'] = '验证信息太长(超过30字符)'; diff --git a/db/migrations/20200827063842_init_table.php b/db/migrations/20200827063842_init_table.php index e202ca88..5547e5b3 100644 --- a/db/migrations/20200827063842_init_table.php +++ b/db/migrations/20200827063842_init_table.php @@ -3816,7 +3816,7 @@ class InitTable extends Phinx\Migration\AbstractMigration ->addColumn('channel_sn', 'string', [ 'null' => false, 'default' => '', - 'limit' => 32, + 'limit' => 64, 'collation' => 'utf8mb4_general_ci', 'encoding' => 'utf8mb4', 'comment' => '平台序号', From 5e5fbedea9567ac0cc56a8ca98782eb6a568a91b Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 24 Sep 2020 20:06:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=80=80=E6=AC=BE?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=8B=A5=E5=B9=B2=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E5=BF=AB=E6=8D=B7=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/MaintainTask.php | 68 +++++++++++++++++++++ app/Console/Tasks/VodEventTask.php | 7 +++ app/Http/Admin/Services/ChapterContent.php | 41 ++++++++++--- app/Http/Admin/Views/public/login.volt | 7 ++- app/Http/Admin/Views/setting/vod.volt | 2 +- app/Services/Live.php | 2 +- app/Services/Smser.php | 13 ++++ app/Services/Storage.php | 2 +- app/Services/Vod.php | 51 ++++++++++++++-- bootstrap/ConsoleErrorHandler.php | 6 +- db/migrations/20200827063842_init_table.php | 4 -- db/migrations/schema.php | 33 ---------- 12 files changed, 176 insertions(+), 60 deletions(-) diff --git a/app/Console/Tasks/MaintainTask.php b/app/Console/Tasks/MaintainTask.php index 4b526448..f360db8f 100644 --- a/app/Console/Tasks/MaintainTask.php +++ b/app/Console/Tasks/MaintainTask.php @@ -5,10 +5,19 @@ namespace App\Console\Tasks; use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache; use App\Caches\IndexNewCourseList as IndexNewCourseListCache; use App\Caches\IndexVipCourseList as IndexVipCourseListCache; +use App\Http\Admin\Services\Setting as SettingService; +use App\Library\Utils\Password as PasswordUtil; +use App\Validators\Account as AccountValidator; class MaintainTask extends Task { + /** + * 重建首页课程缓存 + * + * @param array $params + * @command: php console.php maintain reset_index_course_cache + */ public function rebuildIndexCourseCacheAction($params) { $section = $params[0] ?? null; @@ -29,4 +38,63 @@ class MaintainTask extends Task } } + /** + * 修改密码 + * + * @param array $params + * @command: php console.php maintain reset_password 13507083515 123456 + */ + public function resetPasswordAction($params) + { + if (empty($params[0])) { + echo 'account is required' . PHP_EOL; + } + + if (empty($params[1])) { + echo 'password is required' . PHP_EOL; + } + + $validator = new AccountValidator(); + + $account = $validator->checkAccount($params[0]); + + $salt = PasswordUtil::salt(); + $hash = PasswordUtil::hash($params[1], $salt); + + $account->salt = $salt; + $account->password = $hash; + + $account->update(); + + echo 'reset password success' . PHP_EOL; + } + + /** + * 关闭验证码 + * + * @command: php console.php maintain disable_captcha + */ + public function disableCaptchaAction() + { + $service = new SettingService(); + + $service->updateSettings('captcha', ['enabled' => 0]); + + echo 'disable captcha success' . PHP_EOL; + } + + /** + * 启用验证码 + * + * @command: php console.php maintain enable_captcha + */ + public function enableCaptchaAction() + { + $service = new SettingService(); + + $service->updateSettings('captcha', ['enabled' => 1]); + + echo 'enable captcha success' . PHP_EOL; + } + } diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index c51e0c1d..0189960b 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -28,6 +28,8 @@ class VodEventTask extends Task $this->handleNewFileUploadEvent($event); } elseif ($event['EventType'] == 'ProcedureStateChanged') { $this->handleProcedureStateChangedEvent($event); + } elseif ($event['EventType'] == 'FileDeleted') { + $this->handleFileDeletedEvent($event); } $count++; @@ -123,6 +125,11 @@ class VodEventTask extends Task $chapter->update(['attrs' => $attrs]); } + protected function handleFileDeletedEvent($event) + { + + } + protected function pullEvents() { $vodService = new VodService(); diff --git a/app/Http/Admin/Services/ChapterContent.php b/app/Http/Admin/Services/ChapterContent.php index 665992bf..f02962d1 100644 --- a/app/Http/Admin/Services/ChapterContent.php +++ b/app/Http/Admin/Services/ChapterContent.php @@ -10,6 +10,7 @@ use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; use App\Services\ChapterVod as ChapterVodService; use App\Services\CourseStat as CourseStatService; +use App\Services\Vod as VodService; use App\Validators\ChapterLive as ChapterLiveValidator; use App\Validators\ChapterRead as ChapterReadValidator; use App\Validators\ChapterVod as ChapterVodValidator; @@ -100,9 +101,11 @@ class ChapterContent extends Service $chapter->update(['attrs' => $attrs]); - $courseStats = new CourseStatService(); + $this->updateCourseVodAttrs($vod->course_id); - $courseStats->updateVodAttrs($chapter->course_id); + if (!empty($vod->file_id)) { + $this->deleteVodFile($vod->file_id); + } } protected function updateChapterLive(ChapterModel $chapter) @@ -135,9 +138,7 @@ class ChapterContent extends Service $chapter->update(['attrs' => $attrs]); - $courseStats = new CourseStatService(); - - $courseStats->updateLiveAttrs($chapter->course_id); + $this->updateCourseLiveAttrs($live->course_id); } protected function updateChapterRead(ChapterModel $chapter) @@ -164,9 +165,35 @@ class ChapterContent extends Service $chapter->update(['attrs' => $attrs]); - $courseStats = new CourseStatService(); + $this->updateCourseReadAttrs($read->course_id); + } - $courseStats->updateReadAttrs($chapter->course_id); + protected function updateCourseVodAttrs($courseId) + { + $statService = new CourseStatService(); + + $statService->updateVodAttrs($courseId); + } + + protected function updateCourseLiveAttrs($courseId) + { + $statService = new CourseStatService(); + + $statService->updateLiveAttrs($courseId); + } + + protected function updateCourseReadAttrs($courseId) + { + $statService = new CourseStatService(); + + $statService->updateReadAttrs($courseId); + } + + protected function deleteVodFile($fileId) + { + $vodService = new VodService(); + + $vodService->deleteMedia($fileId); } protected function rebuildCatalogCache(ChapterModel $chapter) diff --git a/app/Http/Admin/Views/public/login.volt b/app/Http/Admin/Views/public/login.volt index d2afecea..9b51cbd7 100644 --- a/app/Http/Admin/Views/public/login.volt +++ b/app/Http/Admin/Views/public/login.volt @@ -2,6 +2,9 @@ {% block content %} + {% set disabled_submit = captcha.enabled == 1 ? 'disabled="disabled"' : '' %} + {% set disabled_class = captcha.enabled == 1 ? 'layui-btn-disabled' : '' %} +