EnoughFiveListeners.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\EnoughFive;
  4. use App\Models\OrderW;
  5. use App\Models\UserW;
  6. use App\Models\User;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Support\Facades\Auth;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Log;
  13. use Overtrue\EasySms\EasySms;
  14. class EnoughFiveListeners
  15. {
  16. /**
  17. * Create the event listener.
  18. *
  19. * @return void
  20. */
  21. public function __construct()
  22. {
  23. }
  24. /**
  25. * Handle the event.
  26. *
  27. * @param EnoughFive $event
  28. * @return void
  29. */
  30. public function handle(EnoughFive $event)
  31. {
  32. $order_id=$event->data;
  33. $order=OrderW::where('id',$order_id)->first();
  34. // 1.计算客户
  35. $self_phone=UserW::where('id',$order->user_id)->value('phone');
  36. $self_user=User::where('mobile',$self_phone)->first();
  37. if(empty($self_user)){
  38. $self_total=OrderW::query()->where('store_id',$order->store_id)
  39. ->where(function($query)use($order){
  40. $query->where(function($que)use($order){
  41. $que->where('user_id',$order->user_id)->where(function($q){$q->whereNull('recomer_status')->orWhereIn('recomer_status',[0,2]);});
  42. })->orWhere(function($que)use($order){
  43. $que->where('recomer_id',$order->user_id)->where(function($q){$q->whereNull('recomer_status')->orWhereIn('recomer_status',[0,1]);});
  44. });
  45. })
  46. ->whereIn('status',[2,3])
  47. ->sum('total');
  48. Log::info( $self_total);
  49. if($self_total>=5){
  50. Log::info('客户手机号---'.$self_phone);
  51. $this->sendSMs($self_phone,$self_total,$order->id);
  52. }
  53. }
  54. }
  55. public function sendSMs($phone,$num,$order_id){
  56. }
  57. }