BirthdayGiftController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\birthday\classes\BirthdayGiftClass;
  4. use common\components\util;
  5. use Yii;
  6. class BirthdayGiftController extends BaseController
  7. {
  8. public $guestAccess = ['info', 'claim'];
  9. public function actionInfo()
  10. {
  11. $get = Yii::$app->request->get();
  12. $token = trim($get['token'] ?? '');
  13. $account = intval($get['account'] ?? 0);
  14. if (empty($token) || $account <= 0) {
  15. util::fail('参数错误');
  16. }
  17. $data = BirthdayGiftClass::getInfoByToken($account, $token);
  18. util::success($data);
  19. }
  20. public function actionClaim()
  21. {
  22. $post = Yii::$app->request->post();
  23. if (empty($post)) {
  24. $post = Yii::$app->request->get();
  25. }
  26. if (BirthdayGiftClass::isSmsClaimPush($post)) {
  27. Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  28. try {
  29. BirthdayGiftClass::claimBySmsPush($post);
  30. return ['clcode' => '000000'];
  31. } catch (\Throwable $e) {
  32. Yii::error('birthday gift sms claim failed: ' . $e->getMessage() . ' params=' . json_encode($post, JSON_UNESCAPED_UNICODE), __METHOD__);
  33. return ['clcode' => '111111'];
  34. }
  35. }
  36. $token = trim($post['token'] ?? '');
  37. $account = intval($post['account'] ?? 0);
  38. $pickupTime = trim($post['pickupTime'] ?? '');
  39. if (empty($token) || $account <= 0) {
  40. util::fail('参数错误');
  41. }
  42. BirthdayGiftClass::claimByToken($account, $token, $pickupTime);
  43. util::complete('领取成功');
  44. }
  45. }