DreamDJS.php 6.7 KB

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