Modules_Web_Controllers_TurntableController.proxy.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace Modules\Web\Controllers;
  3. use App\Constants\CommentConstant;
  4. use App\Model\TurntablePrizeLogModel;
  5. use App\Model\UserModel;
  6. use App\Repositories\Service\CommonService;
  7. use App\Repositories\UserRepository;
  8. use Carbon\Carbon;
  9. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  10. use Psr\SimpleCache\CacheInterface;
  11. class TurntableController extends BaseController
  12. {
  13. use \Hyperf\Di\Aop\ProxyTrait;
  14. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  15. function __construct()
  16. {
  17. if (method_exists(parent::class, '__construct')) {
  18. parent::__construct(...func_get_args());
  19. }
  20. $this->__handlePropertyHandler(__CLASS__);
  21. }
  22. private $prize = [['name' => '1日vip', 'weights' => 100, 'key' => 'vip1d'], ['name' => 'iphone 13', 'weights' => 0, 'key' => 'iphone'], ['name' => '空降白虎', 'weights' => 0, 'key' => 'kjmn'], ['name' => '5000个金币', 'weights' => 0, 'key' => 'jb5000'], ['name' => '2000个金币', 'weights' => 0, 'key' => 'jb2000'], ['name' => '1v1语音10分钟', 'weights' => 0, 'key' => '1v1'], ['name' => '500个金币', 'weights' => 0, 'key' => 'jb500'], ['name' => '1月VIP', 'weights' => 0, 'key' => 'vip1y']];
  23. private $smsUrl = 'http://101.132.165.21:9198';
  24. /**
  25. * 发送短信
  26. *
  27. * @return mixed|void
  28. * @throws \GuzzleHttp\Exception\GuzzleException
  29. */
  30. public function sendVerifyCode()
  31. {
  32. $inputData = request()->all();
  33. $rules = ['phone' => 'required|string|max:11', 'user_uid' => 'required'];
  34. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  35. if ($validator->fails()) {
  36. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  37. return $this->jsonFail($validator->errors()->first());
  38. }
  39. $info = TurntablePrizeLogModel::query()->where(['phone' => $inputData['phone'], 'prize_date' => date('m')])->first();
  40. if (!empty($info)) {
  41. return $this->jsonFail('该手机号本月已参与过活动,请勿重复绑定');
  42. }
  43. $user = UserModel::query()->where('code', $inputData['user_uid'])->first(['id']);
  44. if (empty($user)) {
  45. return $this->jsonFail('该用户不存在');
  46. }
  47. $url = $this->smsUrl . '/support/sendMsmNew?phone=' . $inputData['phone'] . '&accountId=31';
  48. $res = make(CommonService::class)->httpGet($url);
  49. if (empty($res)) {
  50. return $this->jsonFail('验证码发送失败');
  51. }
  52. $res = json_decode($res, true);
  53. if ($res['code'] == 200) {
  54. return $this->jsonSuccess([], $res['message']);
  55. } else {
  56. return $this->jsonFail($res['message']);
  57. }
  58. }
  59. /**
  60. * 验证码验证
  61. *
  62. * @return mixed
  63. */
  64. public function authVerifyCode()
  65. {
  66. $inputData = request()->all();
  67. $rules = ['phone' => 'required|string|max:11', 'code' => 'required'];
  68. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  69. if ($validator->fails()) {
  70. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  71. return $this->jsonFail($validator->errors()->first());
  72. }
  73. $url = $this->smsUrl . '/support/loginSubmitNew?phone=' . $inputData['phone'] . '&accountId=31&code=' . $inputData['code'];
  74. $res = make(CommonService::class)->httpGet($url);
  75. if (empty($res)) {
  76. return $this->jsonFail('验证码异常');
  77. }
  78. $res = json_decode($res, true);
  79. if ($res['code'] == 200) {
  80. $cache = make(CacheInterface::class);
  81. $cache->set('phone:code:' . $inputData['phone'], $inputData['code'], 600);
  82. return $this->jsonSuccess([], $res['message']);
  83. } else {
  84. return $this->jsonFail($res['message']);
  85. }
  86. }
  87. /**
  88. * 抽奖
  89. *
  90. * @return mixed|void
  91. * @throws \Psr\SimpleCache\InvalidArgumentException
  92. */
  93. public function lottery()
  94. {
  95. $inputData = request()->all();
  96. $rules = ['user_uid' => 'required', 'phone' => 'required|string|max:11'];
  97. $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  98. if ($validator->fails()) {
  99. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  100. return $this->jsonFail($validator->errors()->first());
  101. }
  102. $cache = make(CacheInterface::class);
  103. $code = $cache->get('phone:code:' . $inputData['phone']);
  104. if (empty($code)) {
  105. return $this->jsonFail('改手机号已过期,请重新绑定验证');
  106. }
  107. $userInfo = make(UserRepository::class)->getUserInfoFromCache($inputData['user_uid']);
  108. if (empty($userInfo)) {
  109. return $this->jsonFail('该用户不存在');
  110. }
  111. $info = TurntablePrizeLogModel::query()->where(['phone' => $inputData['phone'], 'prize_date' => date('m')])->first();
  112. if (!empty($info)) {
  113. return $this->jsonFail('该手机号本月已参与过活动,请勿重复绑定');
  114. }
  115. // 抽奖
  116. $pricze = countWeight($this->prize);
  117. //写日志
  118. $logArray = ['prize_name' => $pricze['name'], 'user_uid' => $userInfo['code'], 'user_name' => $userInfo['nick'], 'prize_date' => date('m'), 'phone' => $inputData['phone']];
  119. TurntablePrizeLogModel::query()->create($logArray);
  120. //加会员天数 todo 发奖后期可该异步
  121. if ($userInfo['is_vip'] == 'y') {
  122. $vipTime = Carbon::parse($userInfo['vip_expired'])->addDays(1)->toDateTimeString();
  123. } else {
  124. $vipTime = Carbon::now()->addDays(1)->toDateTimeString();
  125. }
  126. UserModel::query()->where('id', $userInfo['id'])->update(['vip_expired' => $vipTime]);
  127. //清除用户信息redis缓存
  128. make(UserRepository::class)->delUserCache($inputData['user_uid']);
  129. $res = ['uid' => $userInfo['code'], 'key' => $pricze['key'], 'name' => $pricze['name']];
  130. return $this->jsonSuccess($res);
  131. }
  132. /**
  133. * 中奖记录
  134. *
  135. * @return mixed
  136. */
  137. public function winRecord()
  138. {
  139. // $inputData = request()->all();
  140. // $rules = [
  141. // 'page' => 'required|int',
  142. // 'page_size' => 'required|int',
  143. // ];
  144. //
  145. // $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
  146. // if ($validator->fails()) {
  147. // // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  148. // return $this->jsonFail($validator->errors()->first());
  149. // }
  150. //
  151. // $pageSize = $inputData['page_size'] ?? CommentConstant::PAGE_SIZE;
  152. // if ($pageSize > 100) {
  153. // $pageSize = CommentConstant::PAGE_SIZE;
  154. // }
  155. // $page = format_page($inputData['page']);
  156. // $pageSize = intval($pageSize);
  157. //
  158. // $result = TurntablePrizeLogModel::query()
  159. // ->orderByDesc('id')
  160. // ->paginate((int)$pageSize, ['prize_name', 'user_name', 'phone', 'created_at'], 'page', (int)$page);
  161. $result = ['lists' => [['prize_name' => '1v1语音10分钟', 'user_name' => '羞涩的茉莉', 'phone' => '1576099*****', 'created_at' => '2022-07-28'], ['prize_name' => '500个金币', 'user_name' => '结实的含羞草', 'phone' => '152950*****', 'created_at' => '2022-07-28'], ['prize_name' => '1v1语音10分钟', 'user_name' => '幸福的巨人', 'phone' => '157257*****', 'created_at' => '2022-07-28'], ['prize_name' => '2000个金币', 'user_name' => '简单的花瓣', 'phone' => '15760990737', 'created_at' => '2022-07-28'], ['prize_name' => '1v1语音10分钟', 'user_name' => '眼睛大的手机', 'phone' => '182439*****', 'created_at' => '2022-07-28'], ['prize_name' => '1月VIP', 'user_name' => '美好的鸵鸟', 'phone' => '156981*****', 'created_at' => '2022-07-28'], ['prize_name' => '1月VIP', 'user_name' => '善良的天空', 'phone' => '199665*****', 'created_at' => '2022-07-28'], ['prize_name' => '空降白虎', 'user_name' => '清脆的向日葵', 'phone' => '180913*****', 'created_at' => '2022-07-28'], ['prize_name' => '1月VIP', 'user_name' => '开心的草莓', 'phone' => '176621*****', 'created_at' => '2022-07-28'], ['prize_name' => '1月VIP', 'user_name' => '有魅力的小熊猫', 'phone' => '191215*****', 'created_at' => '2022-07-28'], ['prize_name' => '1v1语音10分钟', 'user_name' => '迷路的钢笔', 'phone' => '186805*****', 'created_at' => '2022-07-28'], ['prize_name' => '1日vip', 'user_name' => '酷炫的秀发', 'phone' => '182904*****', 'created_at' => '2022-07-28'], ['prize_name' => '1日vip', 'user_name' => '玩命的白云', 'phone' => '137349*****', 'created_at' => '2022-07-28'], ['prize_name' => '1日vip', 'user_name' => '疯狂的棒球', 'phone' => '181652*****', 'created_at' => '2022-07-28'], ['prize_name' => '2000个金币', 'user_name' => '温婉的洋葱', 'phone' => '171100*****', 'created_at' => '2022-07-28'], ['prize_name' => '500个金币', 'user_name' => '隐形的水壶', 'phone' => '130677*****', 'created_at' => '2022-07-28'], ['prize_name' => '1v1语音10分钟', 'user_name' => '活力的飞鸟', 'phone' => '155092*****', 'created_at' => '2022-07-28'], ['prize_name' => '1日vip', 'user_name' => '稳重的咖啡豆', 'phone' => '151885*****', 'created_at' => '2022-07-28']], 'id' => '7f14b800629e7735509c652f9e4d23e5', 'prize' => $this->prize, 'app_name' => '雏姬'];
  162. return $this->jsonSuccess($result);
  163. }
  164. }