1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Listeners;
- use App\Events\SendGoodLogEvent;
- use App\Models\SendGoodLog;
- use Carbon\Carbon;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use \Exception;
- class SendGoodLogListener
- {
- /**
- * Create the event listener.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
- /**
- * Handle the event.
- *
- * @param object $event
- * @return void
- */
- public function handle(SendGoodLogEvent $event)
- {
- DB::beginTransaction();
- try{
- $event=$event->data;
- $log=new SendGoodLog();
- if ($event['type']==1){
- $op_id=0;
- $note='此货物('.$event['good_name'].')由公司在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
- }else{
- $op_id=$event['op_id'];
- $note='此货物由昵称为:'.$event['op_name'].'、手机号为:'.$event['op_phone'].'在'.Carbon::now()->toDateTimeString().'发给昵称为:'.$event['accept_name'].'、手机号为:'.$event['accept_phone'].'的代理';
- }
- $event['note']=$note;
- $event['op_id']=$op_id;
- // SendGoodLog::create($event);
- $log->op_name=$event['op_name'];
- $log->op_phone=$event['op_phone'];
- $log->op_id=$op_id;
- $log->accept_name=$event['accept_name'];
- $log->accept_phone=$event['accept_phone'];
- $log->accept_id=$event['accept_id'];
- $log->select_id=$event['select_id'];
- $log->note=$note;
- if (!$log->save()){
- throw new \Exception('1');
- }
- DB::commit();
- }catch (\Exception $exception){
- Log::error($exception);
- DB::rollBack();
- }
- }
- }
|