| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | 
							- <?php
 
- namespace App\Jobs;
 
- use App\Model\ErrorTable;
 
- use App\Service\Box\BoxService;
 
- 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\Log;
 
- use Symfony\Component\Console\Output\ConsoleOutput;
 
- use Symfony\Component\Console\Output\OutputInterface;
 
- class BoxAddJob implements ShouldQueue
 
- {
 
-     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
-     //队列名称
 
-     const job = 'hc_box';// 包装 =》 用友产成品入库
 
-     protected $data;
 
-     protected $user;
 
-     public $tries = 0;
 
-     public function __construct($data, $user = [])
 
-     {
 
-         $this->data = $data ?? [];
 
-         $this->user = $user ?? [];
 
-     }
 
-     /**
 
-      *
 
-      * file_put_contents('charge.txt',"标记位置退出".PHP_EOL,8);
 
-      * Execute the job.
 
-      *
 
-      * @return void
 
-      */
 
-     public function handle()
 
-     {
 
-         $service = new BoxService();
 
-         $currentAttempt = $this->attempts();
 
-         try {
 
-             Log::info("任务开始执行", [
 
-                 'job_id' => $this->job->getJobId(),
 
-                 'attempt' => $currentAttempt,
 
-                 'data' => $this->data
 
-             ]);
 
-             list($status,$msg) = $service->boxInSettle($this->data, $this->user);
 
-             if(! $status) {
 
-                 Log::info("业务逻辑执行失败", [
 
-                     'job_id' => $this->job->getJobId(),
 
-                     'attempt' => $currentAttempt,
 
-                     'error' => $msg
 
-                 ]);
 
-                 $service->dellimitingSendRequestBackgNeed($service->lock_key); //删除锁
 
-                 $this->recordErrorTable($msg);
 
-             }else {
 
-                 Log::info("任务执行成功", [
 
-                     'job_id' => $this->job->getJobId(),
 
-                     'attempt' => $currentAttempt
 
-                 ]);
 
-             }
 
-         } catch (\Throwable $e) {
 
-             Log::error("任务执行异常", [
 
-                 'job_id' => $this->job->getJobId(),
 
-                 'attempt' => $currentAttempt,
 
-                 'exception' => $e->getMessage(),
 
-             ]);
 
-             $service->dellimitingSendRequestBackgNeed($service->lock_key);//删除锁
 
-             $this->delete();
 
-             $this->recordErrorTable($e->getFile() . $e->getMessage() . $e->getLine());
 
-         }
 
-         //输出信息
 
-         $this->echoMessage(new ConsoleOutput());
 
-     }
 
-     protected function echoMessage(OutputInterface $output)
 
-     {
 
-         //输出消息
 
-         $output->writeln(json_encode($this->data));
 
-     }
 
-     private function recordErrorTable($msg){
 
-         // 连接到指定数据库连接
 
-         ErrorTable::insert([
 
-             'msg' => $msg,
 
-             'data' => json_encode($this->data),
 
-             'user_id' => $this->user['id'] ?? 0,
 
-             'user_operation_time' => time(),
 
-             'type' => 1,
 
-             'order_no' => $data['order_no'] ?? ""
 
-         ]);
 
-     }
 
- }
 
 
  |