| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 | 
							- <?php
 
- namespace App\Http\Controllers\Api;
 
- use App\Model\BigKingTbj;
 
- use App\Service\EmployeeService;
 
- use App\Service\SysMenuService;
 
- use Illuminate\Http\Request;
 
- use Illuminate\Support\Facades\Redis;
 
- use Illuminate\Support\Str;
 
- class DwyController extends BaseController
 
- {
 
-     public function advertisement()
 
-     {
 
-         return ['status' => 200, 'data' => [
 
-             'video' => ['https://clouddevice.qingyaokeji.com/1.mp4',
 
-                 'https://clouddevice.qingyaokeji.com/2.mp4'],
 
-             'img' => [
 
-                 'https://clouddevice.qingyaokeji.com/3.jpeg',
 
-                 'https://clouddevice.qingyaokeji.com/3.jpeg',
 
-             ],
 
-             'limit_time' => 10
 
-         ]];
 
-     }
 
-     public function openCommand(Request $request)
 
-     {
 
-         $data = $request->all();
 
-         file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8);
 
-         $device_id = $data['device_code'];
 
-         $box_code = $data['box_code'];
 
-         $key = $data['type'];
 
-         if ($key === 'UP') {
 
-             $num = Redis::get($device_id . 'status_num');
 
-             if (empty($num)) $num = 0;
 
-             $num++;
 
-             if ($num === 1) {
 
-                 Redis::set($device_id . 'status_num', $num);
 
-                 Redis::expire($device_id . 'status_num', 300);
 
-                 Redis::set($device_id . 'status', 201);
 
-                 Redis::expire($device_id . 'status', 300);
 
-                 Redis::set($device_id, json_encode([$box_code]));
 
-                 Redis::expire($device_id, 300);
 
-             } else {
 
-                 $old = Redis::get($device_id);
 
-                 if (empty($old)) $old = [];
 
-                 else $old = json_decode($old, true);
 
-                 $data = array_merge($old, [$box_code]);
 
-                 Redis::set($device_id, json_encode($data));
 
-                 Redis::expire($device_id, 300);
 
-                 Redis::del($device_id . 'status');
 
-                 Redis::del($device_id . 'status_num');
 
-             }
 
-         } else {
 
-             Redis::set($device_id, json_encode([$box_code]));
 
-             Redis::expire($device_id, 300);
 
-         }
 
-         return ['status' => 200];
 
-     }
 
-     public function openDoor(Request $request)
 
-     {
 
-         $data = $request->all();
 
-         file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8);
 
-         $data = $data['device_code'];
 
-         $code = Redis::get($data);
 
-         Redis::del($data);
 
- //        return ['data'=>['CK00001','CK00018'],'status'=>200];
 
-         if (empty($code)) return ['data' => [], 'status' => 201];
 
-         $status = Redis::get($data . 'status');
 
-         if (empty($status)) $status = 200;
 
-         return ['data' => json_decode($code, true), 'status' => $status];
 
-     }
 
-     public function getOpenCommand(Request $request)
 
-     {
 
-         $data = $request->all();
 
-         file_put_contents('dwy1.txt', json_encode($data) . PHP_EOL, 8);
 
-         $device_id = $data['device_code'];
 
-         $box_code = $data['box_code'];
 
-         $key = $device_id . '_' . $box_code;
 
-         $return = 201;
 
-         $status = Redis::get($key);
 
-         if ($status) {
 
-             $return = 200;
 
-             Redis::del($key);
 
-         }
 
-         return ['status' => $return];
 
-     }
 
-     public function boxList(Request $request)
 
-     {
 
-         $param = $request->all();
 
-         $token = $param['token'];
 
-         $device_code = $param['device_code'];
 
-         //商标仓列表
 
-         $url = 'https://tm.dwycloud.com/jbl/api/module-data/device/device/diy/device_code';
 
-         $header = [
 
-             'Content-Type:application/json',
 
-             'Authorization: ' . $token,
 
-         ];
 
-         $box_data = $this->post_helper($url, '{"device_code":"' . $device_code . '"}', $header);
 
-         $box_data = json_decode($box_data, true);
 
-         if (isset($box_data['status']) && $box_data['status'] === 'success') {
 
-             //库存查询
 
-             $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
 
-             $stock_data = $this->post_helper($url, '{"device_code":"' . $device_code . '"}', $header);
 
-             $stock_data = json_decode($stock_data, true);
 
-             if ($stock_data) {
 
-                 $list = [];
 
-                 $material_list = [];
 
-                 foreach ($box_data['data'] as $v) {
 
-                     $list[$v['box_code']] = [
 
-                         'material_code' => $v['material_code'],
 
-                         'material_code_show' => $v['material_code_show'],
 
-                         'box_code' => $v['box_code'],
 
-                         'box_code_show' => $v['box_code_show'],
 
-                         'min_stock_qty' => $v['min_stock_qty'] ?? 0,
 
-                         'safe_stock_qty' => $v['safe_stock_qty'] ?? 0,
 
-                         'status' => 1, //0设备仓中没有对应库存,1有对应库存,2对应商标仓中还有数量不允许上标
 
-                         'qty' => 0,
 
-                     ];
 
-                     $material_list[$v['material_code']][] = $v['box_code'];
 
-                 }
 
-                 $return = [];
 
-                 foreach ($stock_data as $v) {
 
-                     if (isset($material_list[$v['material_code']]) && $v['box_code'] == 'CK00001' && $v['qty'] > 0) {
 
-                         foreach ($material_list[$v['material_code']] as $vv) {
 
-                             $list[$vv]['status'] = 1;
 
-                         }
 
-                     }
 
-                     if (isset($list[$v['box_code']]) && $v['qty'] > 0) {
 
-                         $list[$v['box_code']]['qty'] = $v['qty'];
 
-                     }
 
-                 }
 
-                 foreach ($list as $v) {
 
-                     if ($v['qty'] > 0) {
 
-                         $v['status'] = 2;
 
-                     }
 
-                     $return[] = $v;
 
-                 }
 
-                 return ['status' => 'success', 'data' => $return];
 
-             }
 
-         }
 
-         return $box_data;
 
-     }
 
-     public function setLb(Request $request)
 
-     {
 
-         $param = $request->all();
 
-         file_put_contents('dwy.txt', json_encode($param) . PHP_EOL, 8);
 
- //        $param = [
 
- //            'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
 
- //            'list'=>[
 
- //                [
 
- //                    'title'=>'优选A7家具板ENF小标',
 
- //                    'num'=>'20',
 
- //                ],[
 
- //                    'title'=>'植萃除醛圆标',
 
- //                    'num'=>'10',
 
- //                ],
 
- //            ],
 
- //        ];
 
- //        dd(json_encode($param));
 
-         $token = $param['token'];
 
-         $list = $param['list'];
 
-         $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
 
-         $header = [
 
-             'Content-Type:application/json',
 
-             'Authorization: ' . $token,
 
-         ];
 
-         $data = $this->post_helper($url, '{"device_code":"DV00001"}', $header);
 
-         $data = json_decode($data, true);
 
-         foreach ($data as $k => &$v) {
 
-             if (!isset($v['product_list'])) $v['product_list'] = [];
 
-             if (!isset($v['box_code_show']) || $v['box_code_show'] == '设备仓') {
 
-                 unset($data[$k]);
 
-                 continue;
 
-             }
 
-             $v['use_qty'] = $v['qty'];
 
-             if ($v['qty'] <= 0) {
 
-                 unset($data[$k]);
 
-                 continue;
 
-             }
 
- //            $key_list = [];
 
-             if (!isset($v['send_qty'])) $v['send_qty'] = 0;
 
-             foreach ($list as $kk => $vv) {
 
-                 if ($vv['num'] == 0) continue;
 
-                 if ($v['material_code_show'] === $vv['title']) {
 
-                     $v['restore_qty'] = isset($vv['restock_qty']) && $vv['restock_qty'] > 0 ? $vv['restock_qty'] : 0;
 
-                     if (($v['qty'] - $v['send_qty']) > $vv['num']) {
 
-                         $list[$kk]['num'] -= $vv['num'];
 
-                         $v['send_qty'] += $vv['num'];
 
-                     } else {
 
-                         $list[$kk]['num'] -= ($v['qty'] - $v['send_qty']);
 
-                         $v['send_qty'] += ($v['qty'] - $v['send_qty']);
 
-                     }
 
-                     //把产品相关参数进行封装
 
-                     $key_arr = [
 
-                         'product_code' => $vv['product_code'] ?? '',
 
-                         'product_code_show' => $vv['product_code_show'] ?? '',
 
-                         'order_item_id' => $vv['order_item_id'] ?? '',
 
-                         'order_item_id_show' => $vv['order_item_id_show'] ?? '',
 
-                         'send_qty' => $vv['num'],
 
-                         'restock_qty' => $vv['restock_qty'] ?? 0,
 
-                     ];
 
-                     $v['product_list'][] = $key_arr;
 
-                 }
 
-             }
 
-         }
 
-         sort($data);
 
-         return ['status' => 200, 'data' => $data];
 
-     }
 
-     public function zjlb(Request $request)
 
-     {
 
-         $param = $request->all();
 
-         file_put_contents('dwy1.txt', json_encode($param) . PHP_EOL, 8);
 
- //        $param = [
 
- //            'token'=>'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIyNzM2OTUyNTA3NTI5NTQzNzMiLCJhdXRoIjoiUk9MRV9JTk5FUl9VU0VSLFJPTEVfQlJBTkRfQVJSRVNULFJPTEVfQURNSU4iLCJ0b2tlbklkIjoiOTUwIiwiZXhwIjoxNzA3OTcxMTcxfQ.2VQ9Wqmk4rvKAcTsQPw59llBbeXjalKDGIZA4kesnuOJ0POmPVOVlRLbTtUDxl0XiFdPDUrKzuEFl2DXSgQdJg',
 
- //            'list'=>[
 
- //                [
 
- //                    'title'=>'优选A7家具板ENF小标',
 
- //                    'num'=>'20',
 
- //                ],[
 
- //                    'title'=>'植萃除醛圆标',
 
- //                    'num'=>'10',
 
- //                ],
 
- //            ],
 
- //        ];
 
- //        dd(json_encode($param));
 
-         $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/box_inventory';
 
-         $header = [
 
-             'Content-Type:application/json',
 
-             'Authorization: ' . $request->header('Authorization'),
 
-         ];
 
-         $data = $this->post_helper($url, json_encode($param), $header);
 
-         $data = json_decode($data, true);
 
-         foreach ($data as $k => $v) {
 
-             if($v['box_code'] !== 'CK00001') unset($data[$k]);
 
-             if($v['qty'] == 0) unset($data[$k]);
 
-         }
 
-         sort($data);
 
-         return json_encode($data);
 
-     }
 
-     public function boxOut(Request $request)
 
-     {
 
-         $param = $request->all();
 
-         //商标绑定
 
-         $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind';
 
-         $header = [
 
-             'Content-Type:application/json',
 
-             'Authorization: ' . $request->header('Authorization'),
 
-         ];
 
-         $lead_bind = $param['lead_bind'];
 
-         $this->post_helper($url, json_encode($lead_bind), $header);
 
-         //商标出库
 
-         $url = 'https://tm.dwycloud.com/jbl/api/module-data/brand_in_stock/brand_in_stock/diy/lead_bind_out_stock';
 
-         $lead_bind = $param['lead_out'];
 
-         $this->post_helper($url, json_encode($lead_bind), $header);
 
-         return ['status'=>200,'success'];
 
-     }
 
-     public function post_helper($url, $data, $header)
 
-     {
 
-         $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, $data);
 
-         $r = curl_exec($ch);
 
-         curl_close($ch);
 
-         return $r;
 
-     }
 
-     public function setTbData(Request $request){
 
-         $data = $request->all();
 
-         if(empty($data['id']) && empty($data['data'])) return [201, ''];
 
-         BigKingTbj::updateOrCreate(
 
-             ['id' => $data['id']], //查询条件
 
-             [
 
-                 "id" => $data['id'],
 
-                 "data" => json_encode($data['data'])
 
-             ]  //添加或者修改的数据
 
-         );
 
-         return [200, ''];
 
-     }
 
-     public function getTbData(Request $request){
 
-         $data = $request->all();
 
-         if(empty($data['id'])) return [201, ''];
 
-         $result = BigKingTbj::where('id',$data['id'])->first();
 
-         if(empty($result)) return [200,'data' => []];
 
-         $result = $result->toArray();
 
-         return [200, 'data' => json_decode($result['data'],true)];
 
-     }
 
- }
 
 
  |