| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | <?phpnamespace App\Jobs;use App\Model\ErrorTable;use App\Model\U8Job;use App\Service\U8ServerService;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Redis;use MongoDB\Driver\Exception\Exception;use Symfony\Component\Console\Output\ConsoleOutput;use Symfony\Component\Console\Output\OutputInterface;class ProcessDataJob implements ShouldQueue{    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;    protected $data;    public $tries = 0;    public $timeout = 60;    //1 采购  2 销售(合同)    protected $function = [        1 => 'U8PO_PomainSave',        2 => 'U8SaleOrderSave',    ];    public function __construct($data)    {        $this->data = $data;    }    public function handle()    {        try {            $function = $this->function[$this->data['type']] ?? '';            if(empty($function)) return;            //调用同步方法            $this->$function();        } catch (\Throwable $e) {            $this->delete();        }    }    //采购    private function U8PO_PomainSave(){        $service = new U8ServerService();        if(! empty($service->error)) {            $service->finalSettle($this->data['id'], U8Job::one, $service->error);            return;        }        $service->U8PO_PomainSave($this->data['id'], $this->data['user_name']);    }    //销售(合同)    private function U8SaleOrderSave(){        $service = new U8ServerService();        if(! empty($service->error)) {            $service->finalSettle($this->data['id'], U8Job::two, $service->error);            return;        }        $service->U8SaleOrderSave($this->data['id'], $this->data['user_name']);    }//    public function failed($exception)//    {//        // 记录失败错误信息到日志或其他媒介//        $errorMessage = $exception->getFile() . $exception->getMessage() . $exception->getLine();//        $this->recordErrorTable($errorMessage);//    }    private function recordErrorTable($msg){        $data = $this->data;        ErrorTable::insert([            'msg' => $msg,            'data' => json_encode($this->data),            'user_id' => $data['user']['id'],            'user_operation_time' => $data['user']['operate_time'],            'type' => $data['type']        ]);    }    protected function echoMessage(OutputInterface $output)    {        //输出消息        $output->writeln(json_encode($this->data));    }}
 |