request->param(); $template_id = $param['template_id']??''; $ms_activity_id = $param['ms_activity_id']??0; if(empty($template_id)){ return $this->renderError("缺少template_id"); } $user = UserService::getCurrentLoginUser(true); $key = (new WechatSub('miaosha'))->getMiaoShaKey($user->user_id,$template_id,$ms_activity_id); $rds = new Redis(config('cache.stores.redis')); if(!empty($user->open_id)){ $rds->set($key,1,1000000); } $value = $rds->get($key); $ms_id = $param['ms_id']??0; $jobHandlerClassName = 'app\job\MiaoshaPushSubscribe'; $jobQueueName = "orderWaitCommissionsQueue"; //数据 $data = [ 'ms_activity_id'=>$ms_activity_id, 'ms_id' => $ms_id, 'user_id'=> $user->user_id, 'template_id'=>$template_id, ]; $msGood = MsActivityGood::where('id',$ms_id)->find(); if($msGood){ $start = strtotime($msGood->start_time); $dif_second = $start - time() -300; if($dif_second>0){ $isPushed = Queue::later($dif_second, $jobHandlerClassName, $data ,$jobQueueName); } } return $this->renderSuccess(compact('value')); } //取消秒杀活动订阅 public function cancelMiaoshaSubscribe(){ $param = $this->request->param(); $template_id = $param['template_id']??''; $ms_activity_id = $param['ms_activity_id']??0; if(empty($template_id)){ return $this->renderError("缺少template_id"); } $user = UserService::getCurrentLoginUser(true); $key = (new WechatSub('miaosha'))->getMiaoShaKey($user->user_id,$template_id,$ms_activity_id); $rds = new Redis(config('cache.stores.redis')); if(!empty($user->open_id)){ $rds->del($key); } return $this->renderSuccess(); } //检查是否订阅了秒杀消息 public function checkMiaoshaSubscribe(){ $param = $this->request->param(); $template_id = $param['template_id']??''; $ms_activity_id = $param['ms_activity_id']??0; if(empty($template_id)){ return $this->renderError("缺少template_id"); } $user = UserService::getCurrentLoginUser(false); $user_id = $user->user_id??0; if(empty($user_id)){ $flag = false; } else{ $key = (new WechatSub('miaosha'))->getMiaoShaKey($user->user_id,$template_id,$ms_activity_id); $rds = new Redis(config('cache.stores.redis')); $flag = false; if(!empty($user->open_id)){ $v1 = $rds->get($key); if(!empty($v1)){ $flag = true; } } } return $this->renderSuccess(compact('flag')); } //订阅 public function subscribe(){ $param = $this->request->param(); $template_id = $param['template_id']??''; // $ms_activity_id = $param['ms_activity_id']??0; if(empty($template_id)){ return $this->renderError("缺少template_id"); } $user = UserService::getCurrentLoginUser(true); $key ='subscribe:open_id:'.$user->open_id.'template_id:'.$template_id; $key2 ='subscribe:user_id:'.$user->user_id.'template_id:'.$template_id; $rds = new Redis(config('cache.stores.redis')); if(!empty($user->open_id)){ $rds->set($key,1,1000000); $rds->set($key2,1,1000000); } $value1 = $rds->get($key); $value2 = $rds->get($key2); $value = $value1.$value2; return $this->renderSuccess(compact('value')); } //取消订阅 public function cancelSubscribe(){ $param = $this->request->param(); $template_id = $param['template_id']??''; if(empty($template_id)){ return $this->renderError("缺少template_id"); } $user = UserService::getCurrentLoginUser(true); $key ='subscribe:open_id:'.$user->open_id.'template_id:'.$template_id; $key2 ='subscribe:user_id:'.$user->user_id.'template_id:'.$template_id; $rds = new Redis(config('cache.stores.redis')); if(!empty($user->open_id)){ $rds->del($key); $rds->del($key2); } return $this->renderSuccess(); } //检查是否订阅了消息 public function checkSubscribe(){ $param = $this->request->param(); $template_id = $param['template_id']??''; // $ms_activity_id = $param['ms_activity_id']??0; if(empty($template_id)){ return $this->renderError("缺少template_id"); } $user = UserService::getCurrentLoginUser(false); $user_id = $user->user_id??0; if(empty($user_id)){ $flag = false; } else{ $key ='subscribe:open_id:'.$user->open_id.'template_id:'.$template_id; $key2 ='subscribe:user_id:'.$user->user_id.'template_id:'.$template_id; // if($ms_activity_id>0){ // $key.='ms_activity_id:'.$ms_activity_id; // $key2 = 'ms_activity_id:'.$ms_activity_id; // } $rds = new Redis(config('cache.stores.redis')); $flag = false; if(!empty($user->open_id)){ $v1 = $rds->get($key); $v2 = $rds->get($key2); if(!empty($v1)||!empty($v2)){ $flag = true; } } } return $this->renderSuccess(compact('flag')); } public function index() { // 自定义内容区 $model = new CustomBlocks(); $custom_blocks = $model->getList(); return $this->renderSuccess(compact('custom_blocks')); } public function sms($mobile,$type = 0){ $userinfo = UserService::getCurrentLoginUser(false); if($userinfo){ $key = 'sms:user_id:'.$userinfo->user_id; $rds = new Redis(config('cache.stores.redis')); $num = $rds->get($key); if($num==5){ return $this->renderError('你获取短信验证码的次数太多了,请稍后再试'); } if($num==null){ $num = 1; }else{ $num++; } $rds->set($key,$num,300); } $data['mobile'] = $mobile; $data['user_id'] = $userinfo->user_id??0; $code = rand(100000,999999); $data['code'] = $code ; $data['type'] = $type; $content = '验证码:'.$data['code'].',您正在进行身份校验,5分钟内有效,请及时输入。'; $smsCode = new SmsCode; $smsCode->save($data); PushLog::addSmsMon($content,$mobile,1); return $this->renderSuccess(); } }