SendGoodLogListener.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\SendGoodLogEvent;
  4. use App\Models\SendGoodLog;
  5. use Carbon\Carbon;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. use \Exception;
  11. class SendGoodLogListener
  12. {
  13. /**
  14. * Create the event listener.
  15. *
  16. * @return void
  17. */
  18. public function __construct()
  19. {
  20. //
  21. }
  22. /**
  23. * Handle the event.
  24. *
  25. * @param object $event
  26. * @return void
  27. */
  28. public function handle(SendGoodLogEvent $event)
  29. {
  30. DB::beginTransaction();
  31. try{
  32. $event=$event->data;
  33. $log=new SendGoodLog();
  34. if ($event['type']==1){
  35. $op_id=0;
  36. $note='此货物('.$event['good_name'].')由公司在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
  37. }else{
  38. $op_id=$event['op_id'];
  39. $note='此货物由昵称为:'.$event['op_name'].'、手机号为:'.$event['op_phone'].'在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
  40. }
  41. $event['note']=$note;
  42. $event['op_id']=$op_id;
  43. // SendGoodLog::create($event);
  44. $log->op_name=$event['op_name'];
  45. $log->op_phone=$event['op_phone'];
  46. $log->op_id=$op_id;
  47. $log->accept_name=$event['accept_name'];
  48. $log->accept_phone=$event['accept_phone'];
  49. $log->accept_id=$event['accept_id'];
  50. $log->select_id=$event['select_id'];
  51. $log->before_id=$event['before_id'];
  52. $log->scan_type=$event['scan_type'];
  53. $log->scan_info=$event['scan_info'];
  54. $log->note=$note;
  55. if (!$log->save()){
  56. throw new \Exception('1');
  57. }
  58. DB::commit();
  59. }catch (\Exception $exception){
  60. Log::error($exception);
  61. DB::rollBack();
  62. }
  63. }
  64. }