| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace Modules\Web\Controllers;
- use App\Constants\CommentConstant;
- use App\Model\TurntablePrizeLogModel;
- use App\Model\UserModel;
- use App\Repositories\Service\CommonService;
- use App\Repositories\UserRepository;
- use Carbon\Carbon;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Psr\SimpleCache\CacheInterface;
- class TurntableController extends BaseController
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct()
- {
- if (method_exists(parent::class, '__construct')) {
- parent::__construct(...func_get_args());
- }
- $this->__handlePropertyHandler(__CLASS__);
- }
- 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']];
- private $smsUrl = 'http://101.132.165.21:9198';
- /**
- * 发送短信
- *
- * @return mixed|void
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function sendVerifyCode()
- {
- $inputData = request()->all();
- $rules = ['phone' => 'required|string|max:11', 'user_uid' => 'required'];
- $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return $this->jsonFail($validator->errors()->first());
- }
- $info = TurntablePrizeLogModel::query()->where(['phone' => $inputData['phone'], 'prize_date' => date('m')])->first();
- if (!empty($info)) {
- return $this->jsonFail('该手机号本月已参与过活动,请勿重复绑定');
- }
- $user = UserModel::query()->where('code', $inputData['user_uid'])->first(['id']);
- if (empty($user)) {
- return $this->jsonFail('该用户不存在');
- }
- $url = $this->smsUrl . '/support/sendMsmNew?phone=' . $inputData['phone'] . '&accountId=31';
- $res = make(CommonService::class)->httpGet($url);
- if (empty($res)) {
- return $this->jsonFail('验证码发送失败');
- }
- $res = json_decode($res, true);
- if ($res['code'] == 200) {
- return $this->jsonSuccess([], $res['message']);
- } else {
- return $this->jsonFail($res['message']);
- }
- }
- /**
- * 验证码验证
- *
- * @return mixed
- */
- public function authVerifyCode()
- {
- $inputData = request()->all();
- $rules = ['phone' => 'required|string|max:11', 'code' => 'required'];
- $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return $this->jsonFail($validator->errors()->first());
- }
- $url = $this->smsUrl . '/support/loginSubmitNew?phone=' . $inputData['phone'] . '&accountId=31&code=' . $inputData['code'];
- $res = make(CommonService::class)->httpGet($url);
- if (empty($res)) {
- return $this->jsonFail('验证码异常');
- }
- $res = json_decode($res, true);
- if ($res['code'] == 200) {
- $cache = make(CacheInterface::class);
- $cache->set('phone:code:' . $inputData['phone'], $inputData['code'], 600);
- return $this->jsonSuccess([], $res['message']);
- } else {
- return $this->jsonFail($res['message']);
- }
- }
- /**
- * 抽奖
- *
- * @return mixed|void
- * @throws \Psr\SimpleCache\InvalidArgumentException
- */
- public function lottery()
- {
- $inputData = request()->all();
- $rules = ['user_uid' => 'required', 'phone' => 'required|string|max:11'];
- $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return $this->jsonFail($validator->errors()->first());
- }
- $cache = make(CacheInterface::class);
- $code = $cache->get('phone:code:' . $inputData['phone']);
- if (empty($code)) {
- return $this->jsonFail('改手机号已过期,请重新绑定验证');
- }
- $userInfo = make(UserRepository::class)->getUserInfoFromCache($inputData['user_uid']);
- if (empty($userInfo)) {
- return $this->jsonFail('该用户不存在');
- }
- $info = TurntablePrizeLogModel::query()->where(['phone' => $inputData['phone'], 'prize_date' => date('m')])->first();
- if (!empty($info)) {
- return $this->jsonFail('该手机号本月已参与过活动,请勿重复绑定');
- }
- // 抽奖
- $pricze = countWeight($this->prize);
- //写日志
- $logArray = ['prize_name' => $pricze['name'], 'user_uid' => $userInfo['code'], 'user_name' => $userInfo['nick'], 'prize_date' => date('m'), 'phone' => $inputData['phone']];
- TurntablePrizeLogModel::query()->create($logArray);
- //加会员天数 todo 发奖后期可该异步
- if ($userInfo['is_vip'] == 'y') {
- $vipTime = Carbon::parse($userInfo['vip_expired'])->addDays(1)->toDateTimeString();
- } else {
- $vipTime = Carbon::now()->addDays(1)->toDateTimeString();
- }
- UserModel::query()->where('id', $userInfo['id'])->update(['vip_expired' => $vipTime]);
- //清除用户信息redis缓存
- make(UserRepository::class)->delUserCache($inputData['user_uid']);
- $res = ['uid' => $userInfo['code'], 'key' => $pricze['key'], 'name' => $pricze['name']];
- return $this->jsonSuccess($res);
- }
- /**
- * 中奖记录
- *
- * @return mixed
- */
- public function winRecord()
- {
- // $inputData = request()->all();
- // $rules = [
- // 'page' => 'required|int',
- // 'page_size' => 'required|int',
- // ];
- //
- // $validator = make(ValidatorFactoryInterface::class)->make($inputData, $rules);
- // if ($validator->fails()) {
- // // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- // return $this->jsonFail($validator->errors()->first());
- // }
- //
- // $pageSize = $inputData['page_size'] ?? CommentConstant::PAGE_SIZE;
- // if ($pageSize > 100) {
- // $pageSize = CommentConstant::PAGE_SIZE;
- // }
- // $page = format_page($inputData['page']);
- // $pageSize = intval($pageSize);
- //
- // $result = TurntablePrizeLogModel::query()
- // ->orderByDesc('id')
- // ->paginate((int)$pageSize, ['prize_name', 'user_name', 'phone', 'created_at'], 'page', (int)$page);
- $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' => '雏姬'];
- return $this->jsonSuccess($result);
- }
- }
|