cqp 5 дней назад
Родитель
Сommit
5d3a17f778
1 измененных файлов с 67 добавлено и 0 удалено
  1. 67 0
      app/Jobs/WxProcessDataJob.php

+ 67 - 0
app/Jobs/WxProcessDataJob.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Model\EnterpriseRecord;
+use App\Model\Record;
+use App\Service\EnterpriseWechatService;
+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 WxProcessDataJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    protected $data;
+    public $timeout = 30;
+
+    public function __construct($data)
+    {
+        $this->data = $data;
+    }
+
+    public function handle()
+    {
+        try {
+            list($bool, $msg) = $this->settle();
+            if(! $bool) $this->finalDo($msg);
+        } catch (\Throwable $e) {
+            $this->finalDo("异常:" . $e->getMessage());
+            $this->delete();
+        }
+    }
+
+    private function finalDo($msg){
+        $data = $this->data;
+        EnterpriseRecord::where('sp_no', $data['sp_no'])
+            ->update(['result' => $msg]);
+    }
+
+    private function settle()
+    {
+        $data = $this->data;
+        try {
+            $no = $data['sp_no'];
+            $template_id = $data['template_id'];
+            $service = new EnterpriseWechatService();
+
+            $detail = $service->getOA()->approvalDetail($no);
+            //todo
+        } catch (\Throwable $e) {
+            return [false, $e->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    protected function echoMessage(OutputInterface $output)
+    {
+        //输出消息
+        $output->writeln(json_encode($this->data));
+    }
+}