Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

gogs 11 mesi fa
parent
commit
54ca3eddab

+ 10 - 0
app/Http/Controllers/Api/JobController.php

@@ -4,8 +4,10 @@ namespace App\Http\Controllers\Api;
 
 
 use App\Jobs\DesktopDeviceJob;
+use App\Jobs\LabelDealJob;
 use App\Jobs\ManDeviceJob;
 use App\Jobs\ProcessDataJob;
+use App\Model\BigKingCbj;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Redis;
 
@@ -37,4 +39,12 @@ class JobController extends BaseController
 //        $token = Redis::get($token_key);
         Redis::del($token_key);
     }
+
+    public function labelDeal(Request $request){
+        $id = BigKingCbj::insert(['data'=> json_encode($request->all()), 'crt_time' => time()]);
+        $header = $request->header('Authorization');
+        dispatch(new LabelDealJob($request->all(), $header, $id))->onQueue('label_deal');
+
+        echo 'ok';die;
+    }
 }

+ 59 - 0
app/Jobs/LabelDealJob.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Service\DwyService;
+use App\Service\LabelDealService;
+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 LabelDealJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    protected $data;
+    protected $header;
+    protected $id;
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct($data,$header,$id)
+    {
+        $this->data = $data;
+        $this->header = $header;
+        $this->id = $id;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $data = $this->data;
+        $dv = $data['key'];
+        $return = $box_list = [];
+        //处理数据
+        LabelDealService::getInstance()->clearData($data,$return,$box_list);
+
+        //调用外部方法
+        $result = DwyService::getInstance()->setBoxData($this->header,$dv,$return,$box_list);
+
+        //调用保存接口
+        LabelDealService::getInstance()->boxOut($data,$this->header,$result,$this->id);
+    }
+
+    protected function echoMessage(OutputInterface $output)
+    {
+        $output->writeln($this->data);
+    }
+}

+ 14 - 0
app/Model/BigKingCbj.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BigKingCbj extends Model
+{
+    protected $table = "big_king_cbj"; //指定表
+    const CREATED_AT = null;
+    const UPDATED_AT = null;
+    protected $dateFormat = 'U';
+    protected $guarded = [];
+}

+ 75 - 0
app/Service/LabelDealService.php

@@ -0,0 +1,75 @@
+<?php
+
+namespace App\Service;
+
+
+use App\Model\BigKingCbj;
+
+class LabelDealService extends Service
+{
+    protected static $instance;
+
+    public static function getInstance(): self
+    {
+        if (self::$instance == null) self::$instance = new LabelDealService();
+        return self::$instance;
+    }
+
+    public function clearData($data,&$return,&$box_list){
+        if( empty($data['lead_out']) || empty($data['lead_out']['brand_out_stock_list'])) return;
+
+        foreach ($data['lead_out']['brand_out_stock_list'] as $value){
+            $tmp = $value['brand_out_stock_dtl'];
+            $return[$value['send_box_code']] = [
+                'fake_qty' => $tmp['fake_qty'],
+                'detail' => explode(',',$tmp['brand_qr_code_list'])
+            ];
+            $box_list[] = $value['send_box_code'];
+        }
+    }
+
+    public function boxOut($data,$token,$result,$id)
+    {
+        //商标绑定
+        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/1';
+//        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
+        $header = [
+            'Content-Type:application/json',
+            'Authorization: ' . $token,
+        ];
+        $lead_bind = $data['lead_bind'];
+        $return_bind = $this->post_helper($url, json_encode($lead_bind), $header);
+        $return_bind = json_decode($return_bind, true);
+
+        //商标出库
+//        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
+        $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/11';
+        $lead_out = $result;
+        $return_out = $this->post_helper($url, json_encode($lead_out), $header);
+        $return_out = json_decode($return_out, true);
+
+        //toDo
+        BigKingCbj::where('id',$id)->update(['is_successful' => 1]);
+    }
+
+    public function post_helper($url, $data, $auth)
+    {
+        $header = [
+            'Content-Type:application/json',
+            'Authorization: ' . $auth,
+        ];
+        $ch = curl_init();
+
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+        if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
+        $r = curl_exec($ch);
+        curl_close($ch);
+        return $r;
+
+    }
+}

+ 1 - 0
routes/api.php

@@ -57,6 +57,7 @@ Route::any('zjlb', 'Api\DwyController@zjlb');
 Route::any('tttt', 'Api\DwyController@tttt');
 Route::any('getBoxTrademark', 'Api\DwyController@getBoxTrademark');
 Route::any('aaaa', 'Api\DwyController@setBoxTrademark');
+Route::any('labelDeal', 'Api\JobController@labelDeal');
 
 Route::group(['middleware'=> []],function ($route){
     $route->any('menuAdd', 'Api\SysMenuController@add');