DreamDJS.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\AccountLog;
  4. use App\Models\DreamInfoModel;
  5. use App\Models\SupportDreamModel;
  6. use App\Models\SystemInfoModel;
  7. use App\Models\UserCareDream;
  8. use Illuminate\Console\Command;
  9. use Illuminate\Support\Facades\Auth;
  10. use App\Helper\JpushHelper;
  11. use Illuminate\Support\Facades\Log;
  12. use App\Helper\LogHelper;
  13. class DreamDJS extends Command
  14. {
  15. use JpushHelper,LogHelper;
  16. /**
  17. * The name and signature of the console command.
  18. *
  19. * @var string
  20. */
  21. protected $signature = 'DreamDJS';
  22. /**
  23. * The console command description.
  24. *
  25. * @var string
  26. */
  27. protected $description = 'Command description';
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. }
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return mixed
  41. */
  42. public function handle()
  43. {
  44. //执行逻辑
  45. Log::info('------------定时任务begin-----------');
  46. $end_dream_info = DreamInfoModel::with('user')->where('end_time','<',date('Y-m-d H:i:s'))->get();
  47. if (count($end_dream_info)>0) {
  48. foreach ($end_dream_info as $item){
  49. // (1)给梦想者发消息 梦想结束记录日志account_logs 梦想结束创建二维码
  50. if (empty($item->code)) {
  51. // 生成二维码
  52. $info = [];
  53. $info['transaction_id'] = date('YmdHis') . mt_rand(1000, 9999);
  54. $info['code'] = 'WECHATPAY_' . $info['transaction_id'];
  55. $code_url = env('APP_URL').'/api/user/meet?dream_id='.$item->id;
  56. $code_path = public_path('qrcodes/'.$info['code'].'.png');
  57. \QrCode::format('png')->size(500)->generate($code_url,$code_path);
  58. $code = env('APP_URL').'/qrcodes/'.$info['code'].'.png';
  59. $item->code = $code;
  60. $item->save();
  61. }
  62. $dream_user = $item->user;
  63. if (!empty($dream_user)) {
  64. /* $img = $item->img; //梦想图片
  65. $arr = [
  66. 'from_type'=>'梦想币',
  67. 'from_id'=>$dream_user->id,
  68. 'from_name'=>$dream_user->nickname,
  69. 'op'=>'梦想结束',
  70. 'from_amount'=>$item->get_coin,
  71. 'to_type'=>'梦想币',
  72. 'to_id'=>$dream_user->id,
  73. 'to_name'=>$dream_user->nickname,
  74. 'to_amount'=>$item->get_coin,
  75. 'channel'=>'平台内',
  76. 'avatar'=>empty($img) ? '' : $img->pic,
  77. 'title'=>$item->name,
  78. 'dream_id'=>$item->id,
  79. ];
  80. $exist = AccountLog::where('dream_id',$item->id)->first();
  81. if (empty($exist)) {
  82. // AccountLog::firstOrCreate($arr);
  83. AccountLog::create($arr);
  84. }*/
  85. $message = "你的梦想《".$item->name."》已结束,点击了解接下来的步骤";
  86. $info = $dream_user->nickname.'会以你提供的微信/电话联系你约好时间地点亲自感谢你给予的支持和鼓励。如果你不希望见面或
  87. 不想要梦想者拥有你的联系方式,请按《不需要见面》的按钮或联系客服。';
  88. $arr = [
  89. 'user_id'=>0,
  90. 'message'=>$message,
  91. 'info'=>$info,
  92. 'to_user_id'=>$item->user_id,
  93. 'dream_id'=>$item->id,
  94. 'is_end'=>1,
  95. 'type_id'=>1,
  96. 'attr_id'=>6,
  97. ];
  98. SystemInfoModel::firstOrCreate($arr);
  99. // (2) 给支持者发送消息
  100. $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
  101. $top = [] ;
  102. foreach ($support_dream as $item2) {
  103. if (!array_key_exists($item2->user_id,$top)) {
  104. $top[$item2->user_id] = $item2->score;
  105. }else{
  106. $top[$item2->user_id] += $item2->score;
  107. }
  108. }
  109. arsort($top);
  110. $new_arr = array_values($top);
  111. if (!empty($top)) {
  112. foreach ($top as $k => $v) {
  113. $key = array_search($v,$new_arr); //排名
  114. $message = '《'.$item->name."》已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
  115. if (empty($key)) { //最大支持者
  116. $message = "恭喜你成为《".$item->name."》的《梦主》! ";
  117. $info = $dream_user->nickname."会以你提供的微信/电话联系你约好时间地点亲自感谢你给予的支持和鼓励。如果你不希望见面或不想要梦想者拥有你的联系方式,请按《不需要见面》的按钮或联系客服。";
  118. $arr2 = [
  119. 'user_id'=>$item->user_id,
  120. 'info'=>$info,
  121. 'message'=>$message,
  122. 'to_user_id'=>$k,
  123. 'dream_id'=>$item->id,
  124. 'is_end'=>1,
  125. 'is_url'=>1,
  126. 'type_id'=>2,
  127. 'is_max'=>1,
  128. ];
  129. }else{
  130. $arr2 = [
  131. 'user_id'=>0,
  132. 'message'=>$message,
  133. 'to_user_id'=>$k,
  134. 'dream_id'=>$item->id,
  135. 'is_end'=>1,
  136. 'is_url'=>1,
  137. 'type_id'=>2,
  138. ];
  139. }
  140. SystemInfoModel::firstOrCreate($arr2);
  141. }
  142. }
  143. }
  144. }
  145. }
  146. // 2 我关注的梦想倒计时 通知消息
  147. $dreams =DreamInfoModel::with('user')->where('end_time','>',date('Y-m-d H:i:s'))->get();
  148. if (count($dreams) > 0) {
  149. foreach ($dreams as $item) {
  150. if (date('Y-m-d',strtotime($item->end_time)) == date('Y-m-d',time()+1*24*3600)) {
  151. $message = "《".$item->name.'》过1天就要结束啦!';
  152. }elseif(date('Y-m-d H:i',strtotime($item->end_time)) == date('Y-m-d H:i',time()+3600)){
  153. $message = "《".$item->name.'》过1小时就要结束啦!';
  154. }else{
  155. $message = '';
  156. }
  157. if (!empty($message)) {
  158. $user_ids = UserCareDream::where('dream_id',$item->id)->select('id','user_id')->get()->toArray();
  159. $arr_ids = array_column($user_ids,'user_id');
  160. if (!empty($arr_ids)) {
  161. foreach ($arr_ids as $u_id) {
  162. $arr3 = [
  163. 'user_id'=>0,
  164. 'message'=>$message,
  165. 'to_user_id'=>$u_id,
  166. 'dream_id'=>$item->id,
  167. 'is_url'=>1,
  168. 'type_id'=>2,
  169. 'attr_id'=>9,
  170. ];
  171. SystemInfoModel::firstOrCreate($arr3);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }