|
@@ -0,0 +1,78 @@
|
|
|
|
+<?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 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();
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ list($status,$msg) = $service->boxInSettle($this->data, $this->user);
|
|
|
|
+ if(! $status) {
|
|
|
|
+ $service->dellimitingSendRequestBackgNeed($service->lock_key); //删除锁
|
|
|
|
+ $this->recordErrorTable($msg);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (\Throwable $e) {
|
|
|
|
+ $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'] ?? ""
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+}
|