123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace App\Console\Commands;
- use App\Events\SuccessSignMessageEvent;
- use App\Events\SuccessSignSureEvent;
- use App\Models\AuthManage;
- use App\Models\Basic;
- use App\Models\Code;
- use App\Models\User;
- use GuzzleHttp\Client;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Log;
- use Overtrue\EasySms\EasySms;
- class SendMessageCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'SendMessageCommand';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $basic=Basic::all();
- foreach ($basic as $k=>$v){
- $season[$v->keys]=$v->value;
- }
- $code=Code::where('season',$season['season'])->where('type',$season['type'])->with(['get_user'])->get();
- if ($code){
- foreach ($code as $k=>$v){
- $re=Code::find($v->id);
- if ($v->mini_message_num==0){
- $easySms=new EasySms(config('easysms'));
- $year=date('Y',$season['time_start']);
- $month=date('m',$season['time_start']);
- $day=date('d',$season['time_start']);
- if ($v->type==0){
- $mean='实战营';
- }elseif ($v->type==1){
- $mean='密训营';
- }
- try{
- $data=AuthManage::where('season',$v->season)->where('type',$v->type)->pluck('phone')->toArray();
- $phone=User::where('id',$v->user_id)->value('phone');
- $client=new Client();
- $url='http://api.admin.app.jiuweiyun.cn/api/sign_message';
- $array=[
- 'form_params'=>[
- 'data'=>$data,
- 'mobile'=>$phone,
- 'season'=>$v->season,
- 'type'=>$v->type,
- 'appids'=>'daweiboshi_szy',
- 'secret'=>'daweiboshi_szy_secret'
- ]
- ];
- $client->request('post',$url,$array);
- }catch (\Exception $exception){
- Log::error($exception);
- }
- }
- if ($v->account_message_num==0){
- try{
- $data=[
- 'template_id'=>'BTmiw1Lr630I5ADYVX8Pzy75e4M7OmtgUBcCPVj7CKo',
- 'touser'=>$v->get_user->openid,
- 'page'=>'',
- 'data'=>[
- 'thing5'=>[
- 'value'=>'第'.$v->season.'届大卫博士创业'.$mean,
- ],
- 'thing7'=>[
- 'value'=>$season['province'].'-'.$season['city']
- ],
- 'time6'=>[
- 'value'=>date('Y年m月d日',$season['time_start'])
- ],
- 'thing4'=>[
- 'value'=>'请提前一天前往举办地签到'
- ]
- ]
- ];
- event(new SuccessSignMessageEvent($data));
- }catch (\Exception $exception){
- Log::error('订阅消息发送失败'.$exception);
- }
- }
- if ($v->sms_message_num==0){
- try {
- $content="【大卫博士】恭喜你,成功报名第".$v->season.'届大卫博士创业'.$mean.'。活动将于'.$year.'年'.$month.'月'.$day.'日开始,请提前一天前往举办地签到。';
- $easySms->send($v->get_user->phone, ['content' =>$content]);
- } catch (\Overtrue\EasySms\Exceptions\NoGatewayAvailableException $exception) {
- $message = $exception->getException('qcloud')->getMessage();
- Log::error($message);
- }
- }
- $re->sms_message_num=1;
- $re->account_message_num=1;
- $re->mini_message_num=1;
- $re->save();
- }
- }
- }
- }
|