123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace App\Console\Commands;
- use App\Models\AccountLog;
- use App\Models\DreamInfoModel;
- use App\Models\SupportDreamModel;
- use App\Models\SystemInfoModel;
- use App\Models\UserCareDream;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Auth;
- use App\Helper\JpushHelper;
- use Illuminate\Support\Facades\Log;
- use App\Helper\LogHelper;
- class DreamDJS extends Command
- {
- use JpushHelper,LogHelper;
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'DreamDJS';
- /**
- * 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()
- {
- //执行逻辑
- Log::info('------------定时任务begin-----------');
- $end_dream_info = DreamInfoModel::with('user')->where('end_time','<',date('Y-m-d H:i:s'))->get();
- if (count($end_dream_info)>0) {
- foreach ($end_dream_info as $item){
- // (1)给梦想者发消息 梦想结束记录日志account_logs 梦想结束创建二维码
- if (empty($item->code)) {
- // 生成二维码
- $info = [];
- $info['transaction_id'] = date('YmdHis') . mt_rand(1000, 9999);
- $info['code'] = 'WECHATPAY_' . $info['transaction_id'];
- $code_url = env('APP_URL').'/api/user/meet?dream_id='.$item->id;
- $code_path = public_path('qrcodes/'.$info['code'].'.png');
- \QrCode::format('png')->size(500)->generate($code_url,$code_path);
- $code = env('APP_URL').'/qrcodes/'.$info['code'].'.png';
- $item->code = $code;
- $item->save();
- }
- $dream_user = $item->user;
- if (!empty($dream_user)) {
- /* $img = $item->img; //梦想图片
- $arr = [
- 'from_type'=>'梦想币',
- 'from_id'=>$dream_user->id,
- 'from_name'=>$dream_user->nickname,
- 'op'=>'梦想结束',
- 'from_amount'=>$item->get_coin,
- 'to_type'=>'梦想币',
- 'to_id'=>$dream_user->id,
- 'to_name'=>$dream_user->nickname,
- 'to_amount'=>$item->get_coin,
- 'channel'=>'平台内',
- 'avatar'=>empty($img) ? '' : $img->pic,
- 'title'=>$item->name,
- 'dream_id'=>$item->id,
- ];
- $exist = AccountLog::where('dream_id',$item->id)->first();
- if (empty($exist)) {
- // AccountLog::firstOrCreate($arr);
- AccountLog::create($arr);
- }*/
- $message = "你的梦想《".$item->name."》已结束,点击了解接下来的步骤";
- $info = $dream_user->nickname.'会以你提供的微信/电话联系你约好时间地点亲自感谢你给予的支持和鼓励。如果你不希望见面或
- 不想要梦想者拥有你的联系方式,请按《不需要见面》的按钮或联系客服。';
- $arr = [
- 'user_id'=>0,
- 'message'=>$message,
- 'info'=>$info,
- 'to_user_id'=>$item->user_id,
- 'dream_id'=>$item->id,
- 'is_end'=>1,
- 'type_id'=>1,
- 'attr_id'=>6,
- ];
- SystemInfoModel::firstOrCreate($arr);
- // (2) 给支持者发送消息
- $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
- $top = [] ;
- foreach ($support_dream as $item2) {
- if (!array_key_exists($item2->user_id,$top)) {
- $top[$item2->user_id] = $item2->score;
- }else{
- $top[$item2->user_id] += $item2->score;
- }
- }
- arsort($top);
- $new_arr = array_values($top);
- if (!empty($top)) {
- foreach ($top as $k => $v) {
- $key = array_search($v,$new_arr); //排名
- $message = '《'.$item->name."》已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
- if (empty($key)) { //最大支持者
- $message = "恭喜你成为《".$item->name."》的《梦主》! ";
- $info = $dream_user->nickname."会以你提供的微信/电话联系你约好时间地点亲自感谢你给予的支持和鼓励。如果你不希望见面或不想要梦想者拥有你的联系方式,请按《不需要见面》的按钮或联系客服。";
- $arr2 = [
- 'user_id'=>$item->user_id,
- 'info'=>$info,
- 'message'=>$message,
- 'to_user_id'=>$k,
- 'dream_id'=>$item->id,
- 'is_end'=>1,
- 'is_url'=>1,
- 'type_id'=>2,
- 'is_max'=>1,
- ];
- }else{
- $arr2 = [
- 'user_id'=>0,
- 'message'=>$message,
- 'to_user_id'=>$k,
- 'dream_id'=>$item->id,
- 'is_end'=>1,
- 'is_url'=>1,
- 'type_id'=>2,
- ];
- }
- SystemInfoModel::firstOrCreate($arr2);
- }
- }
- }
- }
- }
- // 2 我关注的梦想倒计时 通知消息
- $dreams =DreamInfoModel::with('user')->where('end_time','>',date('Y-m-d H:i:s'))->get();
- if (count($dreams) > 0) {
- foreach ($dreams as $item) {
- if (date('Y-m-d',strtotime($item->end_time)) == date('Y-m-d',time()+1*24*3600)) {
- $message = "《".$item->name.'》过1天就要结束啦!';
- }elseif(date('Y-m-d H:i',strtotime($item->end_time)) == date('Y-m-d H:i',time()+3600)){
- $message = "《".$item->name.'》过1小时就要结束啦!';
- }else{
- $message = '';
- }
- if (!empty($message)) {
- $user_ids = UserCareDream::where('dream_id',$item->id)->select('id','user_id')->get()->toArray();
- $arr_ids = array_column($user_ids,'user_id');
- if (!empty($arr_ids)) {
- foreach ($arr_ids as $u_id) {
- $arr3 = [
- 'user_id'=>0,
- 'message'=>$message,
- 'to_user_id'=>$u_id,
- 'dream_id'=>$item->id,
- 'is_url'=>1,
- 'type_id'=>2,
- 'attr_id'=>9,
- ];
- SystemInfoModel::firstOrCreate($arr3);
- }
- }
- }
- }
- }
- }
- }
|