DreamDJS.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. $dream_user = $item->user;
  51. $img = $item->img; //梦想图片
  52. $arr = [
  53. 'from_type'=>'梦想币',
  54. 'from_id'=>$dream_user->id,
  55. 'from_name'=>$dream_user->nickname,
  56. 'op'=>'梦想结束',
  57. 'from_amount'=>$item->get_coin,
  58. 'to_type'=>'梦想币',
  59. ];
  60. if (!empty($dream_user)) {
  61. $message = "你的梦想《".$item->name."》已结束,点击了解接下来的步骤";
  62. $info = $dream_user->nickname.'会以你提供的微信/电话联系你约好时间地点亲自感谢你给予的支持和鼓励。如果你不希望见面或
  63. 不想要梦想者拥有你的联系方式,请按《不需要见面》的按钮或联系客服。';
  64. $arr = [
  65. 'user_id'=>0,
  66. 'message'=>$message,
  67. 'info'=>$info,
  68. 'to_user_id'=>$item->user_id,
  69. 'dream_id'=>$item->id,
  70. 'is_end'=>1,
  71. 'type_id'=>1,
  72. 'attr_id'=>6,
  73. ];
  74. SystemInfoModel::firstOrCreate($arr);
  75. // (2) 给支持者发送消息
  76. $support_dream = SupportDreamModel::where('dream_id',$item->id)->get();
  77. $top = [] ;
  78. foreach ($support_dream as $item2) {
  79. if (!array_key_exists($item2->user_id,$top)) {
  80. $top[$item2->user_id] = $item2->score;
  81. }else{
  82. $top[$item2->user_id] += $item2->score;
  83. }
  84. }
  85. arsort($top);
  86. $new_arr = array_values($top);
  87. if (!empty($top)) {
  88. foreach ($top as $k => $v) {
  89. $key = array_search($v,$new_arr); //排名
  90. $message = $item->name."已经结束啦!谢谢你的支持,你可是他的第".($key+1)."支持者哦!";
  91. if (empty($key)) { //最大支持者
  92. $message = "恭喜你成为《".$item->name."》的《梦主》! ";
  93. $info = $dream_user->nickname."会以你提供的微信/电话联系你约好时间地点亲自感谢你给予的支持和鼓励。如果你不希望见面或不想要梦想者拥有你的联系方式,请按《不需要见面》的按钮或联系客服。";
  94. $arr2 = [
  95. 'user_id'=>$item->user_id,
  96. 'info'=>$info,
  97. 'message'=>$message,
  98. 'to_user_id'=>$k,
  99. 'dream_id'=>$item->id,
  100. 'is_end'=>1,
  101. 'is_url'=>1,
  102. 'type_id'=>2,
  103. 'is_max'=>1,
  104. ];
  105. }else{
  106. $arr2 = [
  107. 'user_id'=>0,
  108. 'message'=>$message,
  109. 'to_user_id'=>$k,
  110. 'dream_id'=>$item->id,
  111. 'is_end'=>1,
  112. 'is_url'=>1,
  113. 'type_id'=>2,
  114. ];
  115. }
  116. SystemInfoModel::firstOrCreate($arr2);
  117. }
  118. }
  119. }
  120. }
  121. }
  122. // 2 我关注的梦想倒计时 通知消息
  123. $dreams =DreamInfoModel::with('user')->where('end_time','>',date('Y-m-d H:i:s'))->get();
  124. if (count($dreams) > 0) {
  125. foreach ($dreams as $item) {
  126. if (date('Y-m-d',strtotime($item->end_time)) == date('Y-m-d',time()+1*24*3600)) {
  127. $message = $item->name.'过1天就要结束啦!';
  128. }elseif(date('Y-m-d H:i',strtotime($item->end_time)) == date('Y-m-d H:i',time()+3600)){
  129. $message = $item->name.'过1小时就要结束啦!';
  130. }else{
  131. $message = '';
  132. }
  133. if (!empty($message)) {
  134. $user_ids = UserCareDream::where('dream_id',$item->id)->select('id','user_id')->get()->toArray();
  135. $arr_ids = array_column($user_ids,'user_id');
  136. if (!empty($arr_ids)) {
  137. foreach ($arr_ids as $u_id) {
  138. $arr3 = [
  139. 'user_id'=>0,
  140. 'message'=>$message,
  141. 'to_user_id'=>$u_id,
  142. 'dream_id'=>$item->id,
  143. 'is_url'=>1,
  144. 'type_id'=>2,
  145. 'attr_id'=>9,
  146. ];
  147. SystemInfoModel::firstOrCreate($arr3);
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }