TSpaceService.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Construction;
  5. use App\Model\ConstructionProductInfo;
  6. use App\Model\Customer;
  7. use App\Model\CustomerInfo;
  8. use App\Model\Product;
  9. use App\Model\ProductCategory;
  10. use App\Model\ProductSnInfo;
  11. use App\Model\ReturnExchangeOrder;
  12. use App\Model\ReturnExchangeOrderProductInfo;
  13. use App\Model\SalesOrder;
  14. use App\Model\SalesOrderProductInfo;
  15. use App\Model\TSpaceSet;
  16. use App\Model\Warranty;
  17. use Illuminate\Support\Facades\DB;
  18. class TSpaceService extends Service
  19. {
  20. public function add($data, $user){
  21. return [true, ''];
  22. }
  23. public function edit($data, $user){
  24. list($status, $msg) = $this->constructionEditOtherRule($data, $user);
  25. if(! $status) return [false, $msg];
  26. DB::beginTransaction();
  27. try{
  28. $set = TSpaceSet::where('del_time',0)
  29. ->where('type', $data['type'])
  30. ->select('file', 'id')
  31. ->get()->toArray();
  32. $set_map = array_column($set,'file','id');
  33. $time = time();
  34. $insert = $update = $new = $old = $id = [];
  35. foreach ($data['data'] as $value){
  36. $text = "";
  37. if(! empty($value['text'])) $text = json_encode($value['text']);
  38. if(! empty($value['id'])){
  39. $file = $set_map[$value['id']] ?? "";
  40. if($value['file'] != $file){
  41. $old[] = $file;
  42. $new[] = $value['file'];
  43. }
  44. $update[] = [
  45. 'id' => $value['id'],
  46. 'type' => $data['type'],
  47. 'text' => $text,
  48. 'file' => $value['file'],
  49. 'crt_time' => $time,
  50. ];
  51. $id[] = $value['id'];
  52. }else{
  53. $new[] = $value['file'];
  54. $insert[] = [
  55. 'type' => $data['type'],
  56. 'text' => $text,
  57. 'file' => $value['file'],
  58. 'crt_time' => $time,
  59. ];
  60. }
  61. }
  62. foreach ($set as $value){
  63. if(! in_array($value['id'], $id)){
  64. $update[] = [
  65. 'id' => $value['id'],
  66. 'del_time' => $time,
  67. ];
  68. $old[] = $value['file'];
  69. }
  70. }
  71. if(! empty($update)){
  72. foreach ($update as $value){
  73. TSpaceSet::where('id',$value['id'])
  74. ->update($value);
  75. }
  76. }
  77. if(! empty($insert)) TSpaceSet::insert($insert);
  78. DB::commit();
  79. }catch (\Exception $exception){
  80. DB::rollBack();
  81. return [false, $exception->getMessage()];
  82. }
  83. return [true, ['file' => ['new' => $new, 'old' => $old]]];
  84. }
  85. public function constructionEditOtherRule($data,$user){
  86. if(empty($data['type'])) return [false,'TSpace首页设置类型不能为空'];
  87. if(! isset(TSpaceSet::$model_type_title[$data['type']])) return [false,'TSpace首页设置类型错误'];
  88. if(empty($data['data'])) return [false, '设置内容不能为空'];
  89. foreach ($data['data'] as $value){
  90. if(empty($value['file'])) return [false, '文件不能为空'];
  91. }
  92. return [true, ''];
  93. }
  94. public function detail($data, $user){
  95. if(empty($data['type'])) return [false,'TSpace首页设置类型不能为空'];
  96. if(! isset(TSpaceSet::$model_type_title[$data['type']])) return [false,'TSpace首页设置类型错误'];
  97. $set = TSpaceSet::where('del_time',0)
  98. ->where('type', $data['type'])
  99. ->select('file', 'id', 'text')
  100. ->get()->toArray();
  101. $fileUploadService = new FileUploadService();
  102. foreach ($set as $key => $value){
  103. if(! empty($value['text'])) $set[$key]['text'] = json_decode($value['text'], true);
  104. $url = "";
  105. if(! empty($value['file'])) $url = $fileUploadService->getFileShow($value['file']);
  106. $set[$key]['file_url'] = $url;
  107. }
  108. return [true, $set];
  109. }
  110. public function tSpacelist($data){
  111. if(empty($data['type'])){
  112. $type = [];
  113. }else{
  114. if(! is_array($data['type'])){
  115. $type = [$data['type']];
  116. }else{
  117. $type = $data['type'];
  118. }
  119. }
  120. $set = TSpaceSet::where('del_time',0)
  121. ->when(! empty($type), function ($query) use ($type) {
  122. return $query->whereIn('type',$type);
  123. })
  124. ->select('file', 'id', 'text', 'type')
  125. ->get()->toArray();
  126. $fileUploadService = new FileUploadService();
  127. foreach ($set as $key => $value){
  128. if(! empty($value['text'])) $set[$key]['text'] = json_decode($value['text'], true);
  129. $url = "";
  130. if(! empty($value['file'])) $url = $fileUploadService->getFileShow($value['file']);
  131. $set[$key]['file_url'] = $url;
  132. }
  133. return [true, $set];
  134. }
  135. public function warrantyGetProduct($data, $user){
  136. if(empty($data['sale_order_id'])) return [false, '合同ID不能为空'];
  137. $return = $this->warrantyGetProductList($data, $user);
  138. return [true, $return];
  139. }
  140. public function warrantyGetProductList($data, $user){
  141. $return = [];
  142. $data_id = $data['sale_order_id'];
  143. //销售订单对应产品总数
  144. $product = SalesOrderProductInfo::from('sales_order_product_info as a')
  145. ->join('product as b','a.product_id','b.id')
  146. ->where('a.del_time',0)
  147. ->where('a.sales_order_id', $data_id)
  148. ->where('b.warranty_time', '>', 0)
  149. ->select('a.number','a.product_id','b.product_category')
  150. ->get()->toArray();
  151. if(empty($product)) return $return;
  152. $product_id = array_column($product,'product_id');
  153. $map = (new ProductService())->getProductDetail($product_id);
  154. //合同质保产品
  155. $sn_product = ProductSnInfo::where("del_time",0)
  156. ->where('data_id', $data_id)
  157. ->where('type',ProductSnInfo::type_two)
  158. ->whereIn('product_id',$product_id)
  159. ->select('product_id')
  160. ->get()->toArray();
  161. $product_map1 = [];
  162. foreach ($sn_product as $value){
  163. $key = $value['product_id'];
  164. if(isset($product_map1[$key])){
  165. $number = bcadd(1, $product_map1[$key],2);
  166. $product_map1[$key] = $number;
  167. }else{
  168. $product_map1[$key] = 1;
  169. }
  170. }
  171. //合同退货产品
  172. $product_map2 = [];
  173. $return_id = ReturnExchangeOrder::where('del_time',0)
  174. ->where('type', ReturnExchangeOrder::Order_type)
  175. ->where('model_type', ReturnExchangeOrder::Model_type_one)
  176. ->where('data_id', $data_id)
  177. ->select('id')
  178. ->get()->toArray();
  179. $save2 = ReturnExchangeOrderProductInfo::where('del_time',0)
  180. ->whereIn('return_exchange_id', array_column($return_id,'id'))
  181. ->where('return_or_exchange',ReturnExchangeOrderProductInfo::type_one)
  182. ->select('number', 'return_exchange_id','product_id')
  183. ->get()->toArray();
  184. foreach ($save2 as $value){
  185. $key = $value['product_id'];
  186. if(isset($product_map2[$key])){
  187. $number = bcadd($value['number'], $product_map2[$key],2);
  188. $product_map2[$key] = $number;
  189. }else{
  190. $product_map2[$key] = $value['number'];
  191. }
  192. }
  193. $service = new DataSyncToU8Service();
  194. foreach ($product as $value){
  195. $bool = $service->forCheck($value['product_category']);
  196. //车窗膜不管数量算一个
  197. if($bool) $value['number'] = 1;
  198. //合同质保产品
  199. $p1 = $product_map1[$value['product_id']] ?? 0;
  200. //合同退货产品
  201. $p2 = $product_map2[$value['product_id']] ?? 0;
  202. $number = bcsub($value['number'], $p1,2);
  203. $number = bcsub($number, $p2,2);
  204. if($number <= 0) continue;
  205. $tmp = $map[$value['product_id']] ?? [];
  206. $return[] = [
  207. 'number' => $number, //可出数量
  208. 'product_id' => $value['product_id'],
  209. 'title' => $tmp['title'] ?? "",
  210. 'code' => $tmp['code'] ?? "",
  211. 'size' => $tmp['size'] ?? "",
  212. 'unit' => $tmp['unit'] ?? "",
  213. ];
  214. }
  215. return $return;
  216. }
  217. public function needSnFix($data, $user){
  218. if(empty($data['id'])) return [false, '施工单id不能为空'];
  219. //产品
  220. $p_info = ConstructionProductInfo::where('del_time',0)
  221. ->where('construction_id',$data['id'])
  222. ->get()->toArray();
  223. $basic_price = BasicType::whereIn('id',array_unique(array_column($p_info,'basic_type_id')))->pluck('title','id')->toArray();
  224. $map = (new ProductService())->getProductDetail(array_column($p_info,'product_id'));
  225. $product = [];
  226. //sn码信息
  227. $sn_map = (new DataSyncToU8Service())->getSn($data, ProductSnInfo::type_one);
  228. $service = new DataSyncToU8Service();
  229. $needSnFix = false;
  230. foreach ($p_info as $value){
  231. $tmp = $map[$value['product_id']] ?? [];
  232. $value['title'] = $tmp['title'] ?? "";
  233. $value['code'] = $tmp['code'] ?? "";
  234. $value['size'] = $tmp['size'] ?? "";
  235. $value['unit'] = $tmp['unit'] ?? "";
  236. $value['bar_code'] = $tmp['bar_code'] ?? "";
  237. $value['basic_type_title'] = $basic_price[$value['basic_type_id']] ?? "";
  238. $s_t = $sn_map[$value['code']] ?? [];
  239. $sn = array_column($s_t,'sn');
  240. $value['product_sn_info'] = $sn;
  241. $bool = $service->forCheck($tmp['product_category']);
  242. $count = count($sn);
  243. if($bool){
  244. //如果车窗膜已经有sn码 则跳过
  245. if($count > 0) {
  246. $product_type_for_sn = 0;
  247. }else{
  248. if(! $needSnFix) $needSnFix = true;
  249. $product_type_for_sn = 1;
  250. }
  251. }else{
  252. $bool = $service->forCheck2($tmp['product_category']);
  253. if($bool){
  254. //如果除车窗膜外已经有sn码 则跳过
  255. if($count > 0) {
  256. $product_type_for_sn = 0;
  257. }else{
  258. if(! $needSnFix) $needSnFix = true;
  259. $product_type_for_sn = 1;
  260. }
  261. }else{
  262. //其它产品数量达到 则跳过
  263. if($count >= $p_info['number']) {
  264. $product_type_for_sn = 0;
  265. }else{
  266. if(! $needSnFix) $needSnFix = true;
  267. $product_type_for_sn = 2;
  268. }
  269. }
  270. }
  271. $value['product_type_for_sn'] = $product_type_for_sn;
  272. $product[] = $value;
  273. }
  274. if(empty($needSnFix)) return [true, ['needSnFix' => $needSnFix, 'product' => $product]];
  275. return [true, ['needSnFix' => $needSnFix, 'product' => $product]];
  276. }
  277. public function warrantyAdd($data, $user){
  278. list($status, $msg) = $this->warrantyAddRule($data,$user);
  279. if(! $status) return [false, $msg];
  280. list($warranty, $sn) = $msg;
  281. try {
  282. DB::beginTransaction();
  283. Warranty::insert($warranty);
  284. if(! empty($sn)){
  285. $warranty_list = Warranty::where('del_time',0)
  286. ->whereIn("sn",$sn)
  287. ->select('id','sn')
  288. ->get()->toArray();
  289. foreach ($warranty_list as $value){
  290. ProductSnInfo::where('del_time',0)
  291. ->where('sn', $value['sn'])
  292. ->update(['warranty_id' => $value['id']]);
  293. }
  294. }
  295. // if($data['type'] == ProductSnInfo::type_two){
  296. // //同一个合同,多次填写的客户基本信息按最后一次更新为主
  297. // Warranty::where('del_time',0)
  298. // ->where('data_id',$data['data_id'])
  299. // ->where('type', $data['type'])
  300. // ->update(['customer_name' => $data['customer_name'], 'customer_contact' => $data['customer_contact']]);
  301. // }
  302. DB::commit();
  303. }catch (\Throwable $exception){
  304. DB::rollBack();
  305. return [false, $exception->getMessage()];
  306. }
  307. return [true, ''];
  308. }
  309. private function warrantyAddRule($data, $user){
  310. if(empty($data['type'])) return [false, 'type不能为空'];
  311. if(! isset(ProductSnInfo::$type_name[$data['type']])) return [false,'type不存在'];
  312. if(empty($data['data_id'])) return [false, 'data_id不能为空'];
  313. $time = time();
  314. $warranty = $sn_update = [];
  315. if($data['type'] == ProductSnInfo::type_one){
  316. $order = Construction::where('del_time',0)->where('id',$data['data_id'])->first();
  317. if(empty($order)) return [false, '施工单不存在或已被删除'];
  318. $order = $order->toArray();
  319. if($order['state'] != Construction::STATE_FOUR) return [false, '施工单暂未完结,生成质保信息失败'];
  320. if(empty($order['vin_no'])) return [false, '车架号不能为空'];
  321. $bool = $this->isValidVin($order['vin_no']);
  322. if(! $bool) return [false, '车架号错误,请查看原施工单车架号,编辑输入完整车架号'];
  323. if(empty($order['customer_id'])) return [false, '客户信息不存在'];
  324. $customer = Customer::where('del_time', 0)->where('id',$order['customer_id'])->first();
  325. if(empty($customer)) return [false, '客户不存在或已被删除'];
  326. $customer = $customer->toArray();
  327. $info = CustomerInfo::where('del_time',0)
  328. ->where('type',CustomerInfo::type_one)
  329. ->where('customer_id', $customer['id'])
  330. ->where('contact_info', "<>", "")
  331. ->select('contact_info')
  332. ->first();
  333. if(empty($info)) return [false, "客户的联系方式不能为空"];
  334. $info = $info->toArray();
  335. $customer_info = $info['contact_info'];
  336. $product_sn = ProductSnInfo::from('product_sn_info as a')
  337. ->leftJoin('product as b','b.id','a.product_id')
  338. ->select('a.*','b.title','b.warranty_time')
  339. ->where('a.del_time',0)
  340. ->where('a.data_id',$data['data_id'])
  341. ->where('a.type', ProductSnInfo::type_one)
  342. ->where('a.warranty_id', 0)
  343. ->get()->toArray();
  344. if(empty($product_sn)) return [false, '施工单暂无未生成质保信息的sn码'];
  345. $construction_site = BasicType::where('id',$order['install_position'])->value('title') ?? "";
  346. //质保单数据 需要更新的sn码信息
  347. foreach ($product_sn as $value){
  348. $warranty[] = [
  349. 'data_id' => $order['id'],
  350. 'data_title' => $order['order_number'],
  351. 'type' => ProductSnInfo::type_one,
  352. 'product_id' => $value['product_id'],
  353. 'code' => $value['code'],
  354. 'title' => $value['title'],
  355. 'sn' => $value['sn'],
  356. 'customer_id' => $order['customer_id'],
  357. 'customer_name' => $customer['title'],
  358. 'customer_contact' => $customer_info,
  359. 'vin_no' => $order['vin_no'],
  360. 'warranty_time' => $value['warranty_time'],
  361. 'construction_site_title' => $construction_site,
  362. 'start_time' => $order['end_time'],
  363. 'crt_time' => $time,
  364. 'crt_id' => $user['id'],
  365. ];
  366. $sn_update[] = $value['sn'];
  367. }
  368. }elseif($data['type'] == ProductSnInfo::type_two){
  369. $order = SalesOrder::where('del_time',0)->where('id',$data['data_id'])->first();
  370. if(empty($order)) return [false, '合同不存在或已被删除'];
  371. $order = $order->toArray();
  372. if(empty($order['customer_id'])) return [false, '客户不能为空'];
  373. $customer_name = Customer::where('id', $order['customer_id'])->value('title');
  374. if(empty($order['customer_contact'])) return [false, '客户联系方式不能为空'];
  375. $product = (new SalesOrderService())->getSalesProductForWarranty($data['data_id']);
  376. if(empty($product)) return [false, '合同已全部或暂无可生成质保信息的产品'];
  377. foreach ($product as $value){
  378. for($i = 0 ;$i < $value['number']; $i++){
  379. $warranty[] = [
  380. 'data_id' => $order['id'],
  381. 'data_title' => $order['order_number'],
  382. 'type' => ProductSnInfo::type_two,
  383. 'product_id' => $value['product_id'],
  384. 'code' => $value['code'],
  385. 'title' => $value['title'],
  386. 'sn' => "",
  387. 'customer_id' => $order['customer_id'],
  388. 'customer_name' => $customer_name,
  389. 'customer_contact' => $order['customer_contact'],
  390. 'vin_no' => "",
  391. 'warranty_time' => $value['warranty_time'],
  392. 'construction_site_title' => "",
  393. 'start_time' => $time,
  394. 'crt_time' => $time,
  395. 'crt_id' => $user['id'],
  396. ];
  397. }
  398. }
  399. }else{
  400. return [false, '质保生成类型错误'];
  401. }
  402. return [true, [$warranty, $sn_update]];
  403. }
  404. public function ori()
  405. {//生成质保 合同原来的代码
  406. $order = SalesOrder::where('del_time', 0)->where('id', $data['data_id'])->first();
  407. if (empty($order)) return [false, '合同不存在或已被删除'];
  408. $order = $order->toArray();
  409. if (empty($data['customer_name'])) return [false, '客户名称不能为空'];
  410. if (empty($data['customer_contact'])) return [false, '客户联系方式不能为空'];
  411. $bool = $this->isValidMobile($data['customer_contact']);
  412. if (!$bool) return [false, '手机号错误,请输入完整的手机号'];
  413. $vin_no = "";
  414. if (!empty($data['vin_no'])) {
  415. $bool = $this->isValidVin($data['vin_no']);
  416. if (!$bool) return [false, '车架号错误,请填写完整车架号'];
  417. $vin_no = $data['vin_no'];
  418. }
  419. if (empty($data['product'])) return [false, '合同无生成质保的产品信息'];
  420. $product = (new SalesOrderService())->getSalesProductForWarranty($data['data_id']);
  421. if (empty($product)) return [false, '合同暂无能生成质保信息的产品'];
  422. foreach ($data['product'] as $value) {
  423. $tmp = $product[$value['product_id']] ?? [];
  424. if (empty($tmp)) return [false, '存在不能生成质保的产品'];
  425. if ($tmp['number'] > $value['number']) return [false, '产品编码:' . $tmp['code'] . '本次可生成质保信息的产品最多' . $tmp['number']];
  426. $warranty[] = [
  427. 'data_id' => $order['id'],
  428. 'data_title' => $order['order_number'],
  429. 'type' => ProductSnInfo::type_two,
  430. 'product_id' => $tmp['product_id'],
  431. 'code' => $tmp['code'],
  432. 'title' => $tmp['title'],
  433. 'sn' => "",
  434. 'customer_id' => $order['customer_id'],
  435. 'customer_name' => $data['customer_name'],
  436. 'customer_contact' => $data['customer_contact'],
  437. 'vin_no' => $vin_no,
  438. 'warranty_time' => $tmp['warranty_time'],
  439. 'construction_site_title' => "",
  440. 'start_time' => $time,
  441. 'crt_time' => $time,
  442. 'crt_id' => $user['id'],
  443. ];
  444. }
  445. }
  446. public function saveWarrantyByMyself($data){
  447. list($status, $msg) = $this->saveWarrantyByMyselfRule($data);
  448. if(! $status) return [false, $msg];
  449. list($warranty, $sn) = $msg;
  450. try {
  451. DB::beginTransaction();
  452. $warranty_id = DB::table('warranty')->insertGetId($warranty);
  453. $sn['warranty_id'] = $warranty_id;
  454. ProductSnInfo::insert($sn);
  455. (new DataSyncToU8Service())->updateByVinNo($data);
  456. if(! empty($data['auto_id'])) (new DataSyncToU8Service())->updateSnInfo(1, [$data['auto_id']], 1);
  457. DB::commit();
  458. }catch (\Throwable $exception){
  459. DB::rollBack();
  460. return [false, $exception->getMessage()];
  461. }
  462. return [true, ''];
  463. }
  464. private function saveWarrantyByMyselfRule($data){
  465. if(empty($data['product_id'])) return [false, '产品ID不能为空'];
  466. $product = Product::where('del_time',0)
  467. ->where('id',$data['product_id'])
  468. ->first();
  469. if(empty($product)) return [false, '产品不存在或已被删除'];
  470. $product = $product->toArray();
  471. if(empty($data['start_time'])) return [false, '施工日期不能为空'];
  472. if(empty($product['warranty_time'])) return [false, '质保时长不能为空'];
  473. if(empty($data['sn'])) return [false, '产品序列号不能为空'];
  474. list($status, $msg) = (new DataSyncToU8Service())->snForWarranty($data);
  475. if(! $status) return [false, $msg];
  476. //校验sn是否被占用
  477. $submit_info[] = $product['code'] . $data['sn'];
  478. list($status, $msg) = (new DataSyncToU8Service())->snForCheck([$product['code']], [$data['sn']], $submit_info);
  479. if(! $status) return [false, "产品序列号:" . $data['sn'] . "已存在于门店系统"];
  480. if(empty($data['customer_name'])) return [false, '客户名称不能为空'];
  481. if(empty($data['customer_contact'])) return [false, '客户联系方式不能为空'];
  482. $bool = $this->isValidMobile($data['customer_contact']);
  483. // if(! $bool) return [false, '手机号错误,请填写完整的11位手机号'];
  484. if(empty($data['vin_no'])) return [false, '车架号不能为空'];
  485. $bool = $this->isValidVin($data['vin_no']);
  486. if(! $bool) return [false, '车架号错误,请填写完整的17位车架号'];
  487. $time = time();
  488. //质保单数据 sn码数据
  489. $warranty = [
  490. 'data_id' => 0,
  491. 'data_title' => '',
  492. 'type' => ProductSnInfo::type_three,
  493. 'product_id' => $product['id'],
  494. 'code' => $product['code'],
  495. 'title' => $product['title'],
  496. 'sn' => $data['sn'],
  497. 'customer_id' => 0,
  498. 'customer_name' => $data['customer_name'],
  499. 'customer_contact' => $data['customer_contact'],
  500. 'vin_no' => $data['vin_no'],
  501. 'warranty_time' => $product['warranty_time'],
  502. 'construction_site_title' => $data['construction_site_title'] ?? "",
  503. 'start_time' => $data['start_time'],
  504. 'crt_time' => $time,
  505. 'crt_id' => 0,
  506. 'is_active' => Warranty::type_one,
  507. 'sn_type' => 1,
  508. ];
  509. $sn_update = [
  510. 'data_id' => 0,
  511. 'type' => ProductSnInfo::type_three,
  512. 'product_id' => $product['id'],
  513. 'code' => $product['code'],
  514. 'sn' => $data['sn'],
  515. 'crt_time' => $time,
  516. 'warranty_id' => 0,
  517. 'auto_id' => $data['auto_id'] ?? 0,
  518. ];
  519. return [true, [$warranty, $sn_update]];
  520. }
  521. //获取未激活列表
  522. public function getWarrantyNotActiveList($data){
  523. if(empty($data['customer_contact'])) return [false, '手机号不能为空'];
  524. $model = Warranty::where('del_time',0)
  525. ->where('customer_contact',$data['customer_contact'])
  526. ->where('is_active',Warranty::type_zero)
  527. ->whereIn('type',[ProductSnInfo::type_one, ProductSnInfo::type_two])
  528. ->where(function ($query) {
  529. $query->where('type', '!=', ProductSnInfo::type_one)
  530. ->orWhere(function ($q) {
  531. $q->where('type', ProductSnInfo::type_one)
  532. ->where('sn', '<>', '');
  533. });
  534. })//sn限制
  535. ->select('id','data_id','data_title','type','product_id','title','sn','customer_name','customer_contact','vin_no','warranty_time','construction_site_title','start_time');
  536. $list = $this->limit($model,'', $data);
  537. $list = $this->fillGetWarrantyNotActiveList($list);
  538. return [true, $list];
  539. }
  540. public function fillGetWarrantyNotActiveList($data){
  541. if(empty($data['data'])) return $data;
  542. foreach ($data['data'] as $key => $value){
  543. $data['data'][$key]['start_time'] = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
  544. }
  545. return $data;
  546. }
  547. //质保激活
  548. public function warrantyActivationCustomer($data){
  549. list($status, $msg) = $this->warrantyActivationCustomerRule($data);
  550. if(! $status) return [false, $msg];
  551. $order = $msg;
  552. try {
  553. DB::beginTransaction();
  554. if($order['type'] == ProductSnInfo::type_two){
  555. $update = [
  556. 'sn' => $data['sn'] ?? '',
  557. 'construction_site_title' => $data['construction_site_title'] ?? '',
  558. 'vin_no' => $data['vin_no'],
  559. 'is_active' => Warranty::type_one
  560. ];
  561. Warranty::where('id',$data['id'])->update($update);
  562. if(! empty($data['sn'])){
  563. $order = Warranty::where('id',$data['id'])->first()->toArray();
  564. $sn_update = [
  565. 'data_id' => $order['data_id'],
  566. 'type' => $order['type'],
  567. 'product_id' => $order['product_id'],
  568. 'code' => $order['code'],
  569. 'sn' => $order['sn'],
  570. 'crt_time' => time(),
  571. 'warranty_id' => $order['id'],
  572. ];
  573. ProductSnInfo::insert($sn_update);
  574. }
  575. }elseif($order['type'] == ProductSnInfo::type_one){
  576. $update = [
  577. 'construction_site_title' => $data['construction_site_title'] ?? '',
  578. 'is_active' => Warranty::type_one
  579. ];
  580. Warranty::where('id',$data['id'])->update($update);
  581. }
  582. (new DataSyncToU8Service())->updateByVinNo($data);
  583. DB::commit();
  584. }catch (\Throwable $exception){
  585. DB::rollBack();
  586. return [false, $exception->getMessage()];
  587. }
  588. return [true, ''];
  589. }
  590. public function warrantyActivationCustomerRule($data){
  591. if(empty($data['id'])) return [false, '质保ID不能为空'];
  592. $order = Warranty::where('del_time',0)
  593. ->where('id', $data['id'])
  594. ->first();
  595. if(empty($order)) return [false, '质保卡不存在或已被删除'];
  596. $order = $order->toArray();
  597. if($order['is_active'] > Warranty::type_zero) return [false, '质保卡已激活,请勿重复操作'];
  598. if(empty($data['customer_name'])) return [false, '车主姓名不能为空'];
  599. if(empty($data['customer_contact'])) return [false, '联系方式不能为空'];
  600. if(empty($data['vin_no'])) return [false, '车架号不能为空'];
  601. if($order['type'] == ProductSnInfo::type_one){
  602. }else{
  603. if(! empty($data['sn'])){
  604. list($status, $msg) = (new DataSyncToU8Service())->snForWarranty($data);
  605. if(! $status) return [false, $msg];
  606. $submit_info[] = $order['code'] . $data['sn'];
  607. list($status, $msg) = (new DataSyncToU8Service())->snForCheck([$order['code']], [$data['sn']], $submit_info);
  608. if(! $status) return [false, "产品序列号:" . $data['sn'] . "已存在于门店系统"];
  609. }
  610. $bool = $this->isValidVin($data['vin_no']);
  611. if(! $bool) return [false, '车架号错误,请填写完整车架号'];
  612. }
  613. return [true, $order];
  614. }
  615. //后台列表
  616. public function warrantyList($data,$user){
  617. $model = Warranty::where('del_time',0)
  618. ->select('id','data_id','data_title','code','type','product_id','title','sn','customer_name','customer_contact','vin_no','warranty_time','construction_site_title','start_time','crt_id','is_active','active_id','sy_code')
  619. ->orderBy('id','desc');
  620. if(! empty($data['type'])) $model->where('type', $data['type']);
  621. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  622. if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
  623. if(! empty($data['data_title'])) $model->where('data_title', 'LIKE', '%'.$data['data_title'].'%');
  624. if(! empty($data['sn'])) $model->where('sn', 'LIKE', '%'.$data['sn'].'%');
  625. if(! empty($data['customer_name'])) $model->where('customer_name', 'LIKE', '%'.$data['customer_name'].'%');
  626. if(! empty($data['customer_contact'])) $model->where('customer_contact', 'LIKE', '%'.$data['customer_contact'].'%');
  627. if(! empty($data['vin_no'])) $model->where('vin_no', 'LIKE', '%'.$data['vin_no'].'%');
  628. if(! empty($data['construction_site_title'])) $model->where('construction_site_title', 'LIKE', '%'.$data['construction_site_title'].'%');
  629. if(! empty($data['warranty_time'])) $model->where('warranty_time', $data['warranty_time']);
  630. if(isset($data['is_active'])) $model->where('is_active', $data['is_active']);
  631. if(! empty($data['crt_id'])) $model->where('crt_id', $data['crt_id']);
  632. if(! empty($data['id'])) $model->where('id', $data['id']);
  633. if(! empty($data['sy_code'])) $model->where('sy_code', 'LIKE', '%'.$data['sy_code'].'%');
  634. $list = $this->limit($model,'', $data);
  635. $list = $this->fillWarrantyList($list);
  636. return [true, $list];
  637. }
  638. public function fillWarrantyList($data){
  639. if(empty($data['data'])) return $data;
  640. foreach ($data['data'] as $key => $value){
  641. $data['data'][$key]['start_time'] = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
  642. $data['data'][$key]['type_title'] = ProductSnInfo::$type_name[$value['type']] ?? "";
  643. }
  644. return $data;
  645. }
  646. //后台质保编辑以及激活
  647. public function warrantyEditAndActivation($data,$user){
  648. list($status, $msg) = $this->warrantyEditAndActivationRule($data);
  649. if(! $status) return [false, $msg];
  650. $order = $msg;
  651. try {
  652. DB::beginTransaction();
  653. $time = time();
  654. $sn = $data['sn'] ?? "";
  655. $order_sn = $order['sn'];
  656. if(! empty($order_sn) && ! empty($sn) && $order_sn != $sn){
  657. ProductSnInfo::where('del_time',0)
  658. ->where('data_id', $order['data_id'])
  659. ->where('type', $order['type'])
  660. ->where('sn', $order_sn)
  661. ->update(['del_time' => $time]);
  662. $sn_update = [
  663. 'data_id' => $order['data_id'],
  664. 'type' => $order['type'],
  665. 'product_id' => $order['product_id'],
  666. 'code' => $order['code'],
  667. 'sn' => $order['sn'],
  668. 'crt_time' => time(),
  669. 'warranty_id' => $order['id'],
  670. ];
  671. ProductSnInfo::insert($sn_update);
  672. }
  673. $update = [
  674. 'sn' => $sn,
  675. 'construction_site_title' => $data['construction_site_title'] ?? '',
  676. 'vin_no' => $data['vin_no'],
  677. 'start_time' => $data['start_time'],
  678. 'customer_name' => $data['customer_name'],
  679. 'customer_contact' => $data['customer_contact'],
  680. 'warranty_time' => $data['warranty_time'],
  681. ];
  682. if(empty($data['is_active'])) {
  683. $update['is_active'] = Warranty::type_one;
  684. $update['active_id'] = $user['id'];
  685. }
  686. Warranty::where('id',$data['id'])->update($update);
  687. (new DataSyncToU8Service())->updateByVinNo($data);
  688. DB::commit();
  689. }catch (\Throwable $exception){
  690. DB::rollBack();
  691. return [false, $exception->getMessage()];
  692. }
  693. return [true, ''];
  694. }
  695. public function warrantyEditAndActivationRule(&$data){
  696. if(empty($data['id'])) return [false, '质保ID不能为空'];
  697. $order = Warranty::where('del_time',0)
  698. ->where('id', $data['id'])
  699. ->first();
  700. if(empty($order)) return [false, '质保卡不存在或已被删除'];
  701. $order = $order->toArray();
  702. // if(! empty($data['is_active']) && $order['is_active'] > Warranty::type_zero) return [false, '质保卡已激活,请勿重复操作'];
  703. if(empty($data['start_time'])) return [false, '请填写施工日期/生效日期'];
  704. $data['start_time'] = $this->changeDateToDateMin($data['start_time']);
  705. if(empty($data['customer_name'])) return [false, '车主姓名不能为空'];
  706. if(empty($data['customer_contact'])) return [false, '联系方式不能为空'];
  707. if(empty($data['warranty_time'])) return [false, '质保时长(月)不能为空'];
  708. if(empty($data['vin_no'])) return [false, '车架号不能为空'];
  709. $bool = $this->isValidVin($data['vin_no']);
  710. if(! $bool) return [false, '车架号错误,请填写完整车架号'];
  711. if(! empty($data['sn'])){
  712. // list($status, $msg) = (new DataSyncToU8Service())->snForWarranty($data);
  713. // if(! $status) return [false, $msg];
  714. $submit_info[] = $order['code'] . $data['sn'];
  715. $data_id = $order['data_id'];
  716. if($order['type'] == ProductSnInfo::type_three) $data_id = $order['id'];
  717. $message = [
  718. 'id' => $data_id,
  719. 'data_type' => $order['type']
  720. ];
  721. list($status, $msg) = (new DataSyncToU8Service())->snForCheck([$order['code']], [$data['sn']], $submit_info, $message);
  722. if(! $status) return [false, "产品序列号:" . $data['sn'] . "已存在于门店系统"];
  723. }
  724. return [true, $order];
  725. }
  726. //后台质保激活
  727. public function warrantyActivation($data,$user){
  728. list($status, $msg) = $this->warrantyActivationRule($data);
  729. if(! $status) return [false, $msg];
  730. $order = $msg;
  731. try {
  732. DB::beginTransaction();
  733. $update['is_active'] = Warranty::type_one;
  734. $update['active_id'] = $user['id'];
  735. Warranty::where('id', $data['id'])->update($update);
  736. (new DataSyncToU8Service())->updateByVinNo($order);
  737. DB::commit();
  738. }catch (\Throwable $exception){
  739. DB::rollBack();
  740. return [false, $exception->getMessage()];
  741. }
  742. return [true, ''];
  743. }
  744. public function warrantyActivationRule($data){
  745. if(empty($data['id'])) return [false, '质保ID不能为空'];
  746. $order = Warranty::where('del_time',0)
  747. ->where('id', $data['id'])
  748. ->first();
  749. if(empty($order)) return [false, '质保卡不存在或已被删除'];
  750. $order = $order->toArray();
  751. if(! empty($data['is_active']) && $order['is_active'] > Warranty::type_zero) return [false, '质保卡已激活,请勿重复操作'];
  752. if(empty($order['start_time'])) return [false, '施工日期/生效日期不能为空'];
  753. if(empty($order['customer_name'])) return [false, '车主姓名不能为空'];
  754. if(empty($order['customer_contact'])) return [false, '联系方式不能为空'];
  755. if(empty($order['warranty_time'])) return [false, '质保时长(月)不能为空'];
  756. if(empty($order['vin_no'])) return [false, '车架号不能为空'];
  757. $bool = $this->isValidVin($order['vin_no']);
  758. if(! $bool) return [false, '车架号错误,请填写完整车架号'];
  759. return [true, $order];
  760. }
  761. //质保卡作废
  762. public function warrantyDel($data,$user){
  763. list($status, $msg) = $this->warrantyDelRule($data);
  764. if(! $status) return [false, $msg];
  765. $order = $msg;
  766. $time = time();
  767. try {
  768. DB::beginTransaction();
  769. Warranty::where('id', $data['id'])->update(['del_time' => $time]);
  770. if(! empty($order['sn'])) ProductSnInfo::where('del_time',0)->where('sn', $order['sn'])->update(['del_time' => $time]);
  771. DB::commit();
  772. }catch (\Throwable $exception){
  773. DB::rollBack();
  774. return [false, $exception->getMessage()];
  775. }
  776. return [true, ''];
  777. }
  778. public function warrantyDelRule($data){
  779. if(empty($data['id'])) return [false, '质保ID不能为空'];
  780. $order = Warranty::where('del_time',0)
  781. ->where('id', $data['id'])
  782. ->first();
  783. if(empty($order)) return [false, '质保卡不存在或已被删除'];
  784. $order = $order->toArray();
  785. return [true, $order];
  786. }
  787. public function searchWarranty($data){
  788. list($status, $msg) = $this->searchWarrantyRule($data);
  789. if(! $status) return [false, $msg];
  790. list($search_field, $search) = $msg;
  791. $order_list = Warranty::where('del_time',0)
  792. ->when($search_field == 1, function ($query) use ($search) {
  793. return $query->where("customer_contact", $search);
  794. })
  795. ->when($search_field == 2, function ($query) use ($search) {
  796. return $query->where("vin_no", $search);
  797. })
  798. ->where(function ($query) {
  799. $query->where('type', '!=', ProductSnInfo::type_one)
  800. ->orWhere(function ($q) {
  801. $q->where('type', ProductSnInfo::type_one)
  802. ->where('sn', '<>', '');
  803. });
  804. })//sn限制
  805. ->orderBy('id','desc')
  806. ->get()->toArray();
  807. if(empty($order_list)) return [false , "暂无质保信息"];
  808. $first = $order_list[0];
  809. $order['main'] = [
  810. 'customer_name' => $first['customer_name'],
  811. 'customer_contact' => $first['customer_contact'],
  812. 'vin_no' => $first['vin_no'],
  813. ];
  814. foreach ($order_list as $key => $value){
  815. $order_list[$key]['start_time'] = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
  816. }
  817. $order['list'] = $order_list;
  818. return [true, $order];
  819. }
  820. public function searchWarrantyRule($data){
  821. if(empty($data['from'])) return [false, '查询来源不能为空'];
  822. $search = $data['customer_contact_or_vin_no'];
  823. if($data['from'] == 1){
  824. if(empty($data['customer_contact_or_vin_no'])) return [false, '手机号不能为空'];
  825. $length = strlen($data['customer_contact_or_vin_no']);
  826. if($length != 11) return [false, '请输入完整的11位手机号'];
  827. list($status,$msg) = $this->searchWarrantyCommon($data['customer_contact_or_vin_no']);
  828. if(! $status) return [false, $msg];
  829. $search_field = 1;
  830. }elseif($data['from'] == 2){
  831. if(empty($data['customer_contact_or_vin_no'])) return [false, '手机号或车架号不能为空'];
  832. $length = strlen($data['customer_contact_or_vin_no']);
  833. if($length != 11 && $length != 17) return [false, '请输入完整的11位手机号或完整的17位车架号'];
  834. if($length == 11){
  835. list($status,$msg) = $this->searchWarrantyCommon($data['customer_contact_or_vin_no']);
  836. if(! $status) return [false, $msg];
  837. $search_field = 1;
  838. }else{
  839. $search_field = 2;
  840. }
  841. }else{
  842. return [false, '查询来源错误'];
  843. }
  844. return [true, [$search_field, $search]];
  845. }
  846. public function searchWarrantyCommon($customer_contact){
  847. $vinCount = Warranty::where('del_time', 0)
  848. ->where('customer_contact', $customer_contact)
  849. ->where('vin_no', '<>', '')
  850. ->distinct()
  851. ->count('vin_no');
  852. if($vinCount > 1) return [false, '手机号:' . $customer_contact . '下有个多个车架号,请去质保查询功能按需查询质保信息'];
  853. return [true, ''];
  854. }
  855. public function warrantyAddNew($order, $data, $user){
  856. if(empty($data['product'])) return [true, ''];
  857. try {
  858. DB::beginTransaction();
  859. $data['id'] = $order['id'];
  860. $time = time();
  861. //保存sn关联关系
  862. (new DataSyncToU8Service())->saveSn($data, ProductSnInfo::type_one, $time);
  863. $product_sn = ProductSnInfo::from('product_sn_info as a')
  864. ->leftJoin('product as b','b.id','a.product_id')
  865. ->select('a.*','b.title','b.warranty_time')
  866. ->where('a.del_time',0)
  867. ->where('a.data_id',$data['id'])
  868. ->where('a.type', ProductSnInfo::type_one)
  869. ->where('a.warranty_id', 0)
  870. ->get()->toArray();
  871. $construction_site = BasicType::where('id',$order['install_position'])->value('title') ?? "";
  872. //生成质保单数据 需要更新的sn码信息
  873. if(! empty($product_sn)){
  874. $warranty = $sn_update = [];
  875. foreach ($product_sn as $value){
  876. $warranty[] = [
  877. 'data_id' => $order['id'],
  878. 'data_title' => $order['order_number'],
  879. 'type' => ProductSnInfo::type_one,
  880. 'product_id' => $value['product_id'],
  881. 'code' => $value['code'],
  882. 'title' => $value['title'],
  883. 'sn' => $value['sn'],
  884. 'customer_id' => $order['customer_id'],
  885. 'customer_name' => $order['customer_title'],
  886. 'customer_contact' => $order['customer_info'],
  887. 'vin_no' => $order['vin_no'],
  888. 'warranty_time' => $value['warranty_time'],
  889. 'construction_site_title' => $construction_site,
  890. 'start_time' => $order['end_time'],
  891. 'crt_time' => $time,
  892. 'crt_id' => $user['id'],
  893. 'sn_type' => $value['sn_type'],
  894. 'sy_code' => ""
  895. ];
  896. $sn_update[] = $value['sn'];
  897. }
  898. if(! empty($warranty)) Warranty::insert($warranty);
  899. if(! empty($sn_update)){
  900. $warranty_list = Warranty::where('del_time',0)
  901. ->whereIn("sn",$sn_update)
  902. ->select('id','sn')
  903. ->get()->toArray();
  904. foreach ($warranty_list as $value){
  905. ProductSnInfo::where('del_time',0)
  906. ->where('sn', $value['sn'])
  907. ->update(['warranty_id' => $value['id']]);
  908. }
  909. }
  910. }
  911. //生成溯源码质保卡
  912. $insert2 = $this->getInsert($data,$order,$construction_site,$time,$user);
  913. if(! empty($insert2)) Warranty::insert($insert2);
  914. DB::commit();
  915. }catch (\Throwable $exception){
  916. DB::rollBack();
  917. return [false, $exception->getMessage()];
  918. }
  919. return [true, ''];
  920. }
  921. public function getInsert($data,$order,$construction_site,$time,$user){
  922. $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id'));
  923. $service = new DataSyncToU8Service();
  924. $insert2 = [];
  925. foreach ($data['product'] as $value){
  926. $tmp = $map[$value['product_id']] ?? [];
  927. $bool = $service->forCheck($tmp['product_category']);
  928. $value['warranty_time'] = $tmp['warranty_time'];
  929. //没有sn码信息直接返回
  930. if(empty($value['product_sn_info'])) {
  931. if($bool){
  932. $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
  933. }else{
  934. $bool = $service->forCheck2($tmp['product_category']);
  935. if($bool){
  936. $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
  937. }else{
  938. for ($i = 0; $i < intval($value['number']); $i++){
  939. $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
  940. }
  941. }
  942. }
  943. }else{
  944. $num = count(array_column($value['product_sn_info'],'sn'));
  945. if($bool){
  946. if($num < 1){
  947. $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
  948. }
  949. }else{
  950. $bool = $service->forCheck2($tmp['product_category']);
  951. if($bool){
  952. if($num < 1){
  953. $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
  954. }
  955. }else{
  956. $n = bcsub($value['number'], $num,2);
  957. if(intval($n) > 0){
  958. for ($i = 0; $i < intval($value['number']); $i++){
  959. $this->fillInsert($insert2,$order,$value,$construction_site,$time,$user);
  960. }
  961. }
  962. }
  963. }
  964. }
  965. }
  966. return $insert2;
  967. }
  968. public function fillInsert(&$insert2, $order, $value, $construction_site,$time,$user){
  969. $insert2[] = [
  970. 'data_id' => $order['id'],
  971. 'data_title' => $order['order_number'],
  972. 'type' => ProductSnInfo::type_one,
  973. 'product_id' => $value['product_id'],
  974. 'code' => $value['code'],
  975. 'title' => $value['title'],
  976. 'sn' => "",
  977. 'customer_id' => $order['customer_id'],
  978. 'customer_name' => $order['customer_title'],
  979. 'customer_contact' => $order['customer_info'],
  980. 'vin_no' => $order['vin_no'],
  981. 'warranty_time' => $value['warranty_time'],
  982. 'construction_site_title' => $construction_site,
  983. 'start_time' => $order['end_time'],
  984. 'crt_time' => $time,
  985. 'crt_id' => $user['id'],
  986. // 'sn_type' => $value['sn_type'] ?? 0,
  987. 'sy_code' => $value['sy_code'] ?? "",
  988. ];
  989. }
  990. public function StoreSearch($data){
  991. $keyword = $data['keyword'] ?? "";
  992. $page = $data['page'] ?? 1;
  993. $pageSize = $data['pageSize'] ?? 30;
  994. $return = $this->getForSearch($keyword, $page, $pageSize);
  995. return [true, $return];
  996. }
  997. private function getForSearch($keyword, $page, $pageSize){
  998. $curl = curl_init();
  999. curl_setopt_array($curl, [
  1000. CURLOPT_PORT => "3999",
  1001. CURLOPT_URL => "http://146.56.217.228:3999/store/search?keyword=$keyword&page=$page&pageSize=$pageSize",
  1002. CURLOPT_RETURNTRANSFER => true,
  1003. CURLOPT_ENCODING => "",
  1004. CURLOPT_MAXREDIRS => 10,
  1005. CURLOPT_TIMEOUT => 10,
  1006. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1007. CURLOPT_CUSTOMREQUEST => "GET",
  1008. CURLOPT_POSTFIELDS => "",
  1009. CURLOPT_HTTPHEADER => [
  1010. "Accept: */*",
  1011. "Accept-Encoding: gzip, deflate, br",
  1012. "Connection: keep-alive",
  1013. "User-Agent: PostmanRuntime-ApipostRuntime/1.1.0"
  1014. ],
  1015. ]);
  1016. $response = curl_exec($curl);
  1017. $err = curl_error($curl);
  1018. curl_close($curl);
  1019. if ($err) return [];
  1020. return json_decode($response, true);
  1021. }
  1022. }