U8ServerService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Customer;
  5. use App\Model\Depart;
  6. use App\Model\Employee;
  7. use App\Model\Product;
  8. use App\Model\PurchaseOrder;
  9. use App\Model\PurchaseOrderInfo;
  10. use App\Model\SalesOrder;
  11. use App\Model\SalesOrderProductInfo;
  12. use App\Model\SeeRange;
  13. use App\Model\Setting;
  14. use App\Model\Supplier;
  15. use App\Model\U8Job;
  16. use Illuminate\Support\Facades\Config;
  17. use Illuminate\Support\Facades\DB;
  18. use Illuminate\Support\Facades\Log;
  19. use Illuminate\Support\Facades\Redis;
  20. class U8ServerService extends Service
  21. {
  22. public $db = null;
  23. public $error = null; // 错误信息
  24. public $u8 = []; //u8 配置连接参数
  25. public $u8_api = ""; //u8接口请求地址
  26. public $post_common = [];//u8接口公用参数
  27. public function __construct($is_need_connect = 0)
  28. {
  29. //u8 配置连接参数 u8_api设置
  30. list($status,$msg) = $this->settingConnection();
  31. if(! $status) {
  32. $this->error = $msg;
  33. return;
  34. }
  35. //是否需要连接u8数据库
  36. if($is_need_connect){
  37. //构建数据库连接对象
  38. list($status,$msg) = $this->settingDb();
  39. if(! $status) {
  40. $this->error = $msg;
  41. }
  42. }
  43. }
  44. //设置u8连接参数
  45. private function settingConnection(){
  46. $u8 = Setting::where('setting_name','u8')->where('setting_value','<>','')->first();
  47. if(empty($u8)) return [false, 'u8配置参数不存在!'];
  48. $u8 = $u8->toArray();
  49. // 使用 eval() 函数执行字符串并转换为数组
  50. $u8 = eval("return {$u8['setting_value']};");
  51. if(empty($u8['domain'])) return [false, '外部域名不能为空!'];
  52. if(empty($u8['u8_api_port'])) return [false, 'u8程序API端口不能为空!'];
  53. if(empty($u8['u8_database_port'])) return [false, 'u8程序数据库端口不能为空!'];
  54. if(empty($u8['database'])) return [false, 'u8程序数据库不能为空!'];
  55. if(empty($u8['database_account'])) return [false, 'u8程序数据库登录账号不能为空!'];
  56. if(empty($u8['database_password'])) return [false, 'u8程序数据库登录密码不能为空!'];
  57. if(empty($u8['sAccID'])) return [false, 'u8程序sAccID不能为空!'];
  58. if(empty($u8['sServer'])) return [false, 'u8程序sServer不能为空!'];
  59. if(empty($u8['sUserID'])) return [false, 'u8程序sUserID不能为空!'];
  60. if(empty($u8['sPassword'])) return [false, 'u8程序sPassword不能为空!'];
  61. $this->u8 = $u8;
  62. $this->u8_api = "https://" . $u8['domain'] . ":" . $u8['u8_api_port'] . "/U8Sys/U8API";
  63. $this->post_common = [
  64. "password"=>"cloud@123456",
  65. "entity"=>"", //调用方法
  66. "login"=>[
  67. "sAccID"=> $u8['sAccID'],
  68. "sDate"=> date("Y-m-d"),
  69. "sServer"=> $u8['sServer'],
  70. "sUserID"=> $u8['sUserID'],
  71. "sSerial"=> "",
  72. "sPassword"=> $u8['sPassword']
  73. ]
  74. ];
  75. return [true, ''];
  76. }
  77. //设置u8数据库连接
  78. private function settingDb(){
  79. if(empty($this->db)){
  80. $u8 = $this->u8;
  81. $config = [
  82. 'driver' => 'sqlsrv',
  83. 'host' => $u8['domain'],
  84. 'port' => $u8['u8_database_port'],
  85. 'database' => $u8['database'],
  86. 'username' => $u8['database_account'],
  87. 'password' => $u8['database_password'],
  88. ];
  89. // 数据库配置设置
  90. Config::set('database.connections.sqlsrvs', $config);
  91. // 连接
  92. try {
  93. $pdo = DB::connection('sqlsrvs')->getPdo();
  94. if ($pdo instanceof \PDO) {
  95. // 连接成功的逻辑代码
  96. $this->db = DB::connection('sqlsrvs');
  97. } else {
  98. return [false, '连接失败!'];
  99. }
  100. } catch (\Throwable $e) {
  101. return [false, $e->getMessage()];
  102. }
  103. }
  104. return [true, ''];
  105. }
  106. //采购订单保存
  107. public function U8PO_PomainSave($data){
  108. $id = $data;
  109. //映射ip是否通畅
  110. $bool = $this->isDomainAvailable($this->u8['domain']);
  111. if(! $bool) {
  112. $msg = 'U8程序外部域名不可达';
  113. $this->finalSettle($id, U8Job::one,$msg);
  114. return;
  115. }
  116. //获取数据
  117. $result = $this->getPurchaseData($id);
  118. if(empty($result)) {
  119. $msg = "同步数据获取失败";
  120. $this->finalSettle($id, U8Job::one, $msg);
  121. return;
  122. }
  123. //u8接口参数组织
  124. $post = $this->post_common;
  125. $post['entity'] = "U8PO_PomainSave";
  126. $time = date("Y-m-d");
  127. foreach ($result as $value){
  128. $bodys = [];
  129. foreach ($value['product'] as $son){
  130. //子表数据
  131. $bodys[] = [
  132. "iappids"=>"", //子表id
  133. "cinvcode"=>$son['code'], //存货编码
  134. "iquantity"=>$son['number'], //数量
  135. "inum"=>$son['number'], //件数
  136. "ipertaxrate"=>$son['ipertaxrate'], //税率
  137. "iunitprice"=>$son['iunitprice'], //原币单价
  138. "itaxprice"=>$son['itaxprice'], //原币含税单价
  139. "isum"=>$son['isum'], //原币价税合计
  140. "imoney"=>$son['imoney'], //原币无税金额
  141. "itax"=>$son['itax'],//原币税额
  142. "cbmemo"=>$son['mark'], //表体备注
  143. "cdefine22"=>"",
  144. "cdefine23"=>"",
  145. "cdefine24"=>"",
  146. "cdefine25"=>"",
  147. "cdefine26"=>"",
  148. "cdefine27"=>"",
  149. "cdefine28"=>"",
  150. "cdefine29"=>"",
  151. "cdefine30"=>"",
  152. "cdefine31"=>"",
  153. "cdefine32"=>"",
  154. "cdefine33"=>"",
  155. "cdefine34"=>"",
  156. "cdefine35"=>"",
  157. "cdefine36"=>"",
  158. "cdefine37"=>"",
  159. "cfree1"=>"",
  160. "cfree2"=>"",
  161. "cfree3"=>"",
  162. "cfree4"=>"",
  163. "cfree5"=>"",
  164. "cfree6"=>"",
  165. "cfree7"=>"",
  166. "cfree8"=>"",
  167. "cfree9"=>"",
  168. "cfree10"=>""
  169. ];
  170. }
  171. //最终数据
  172. $post['data'] = [
  173. "cpoid"=>"",
  174. "dpodate"=>date("Y-m-d",$value['crt_time']),
  175. "cmemo"=>"T9采购单:" . $value['order_number'],
  176. "cmaker"=>"admin",
  177. "cmaketime"=>$time,
  178. "IsExamine"=>false,
  179. "cvencode"=>"", //供应商编码
  180. "cvenname"=>$value['cvenname'], //供应商名称
  181. "cdepcode"=>"", //部门编号
  182. "cdepname"=>$value['cdepname'], //部门名称
  183. "cpersoncode"=>"", //业务员编码jobnumber
  184. "jobnumber"=>$value['jobnumber'], //业务员编码
  185. "cdefine1"=>"",
  186. "cdefine2"=>"",
  187. "cdefine3"=>"",
  188. "cdefine4"=>"",
  189. "cdefine5"=>"",
  190. "cdefine6"=>"",
  191. "cdefine7"=>"",
  192. "cdefine8"=>"",
  193. "cdefine9"=>"",
  194. "cdefine10"=>"",
  195. "cdefine11"=>"",
  196. "cdefine12"=>"",
  197. "cdefine13"=>"",
  198. "cdefine14"=>"",
  199. "cdefine15"=>"",
  200. "cdefine16"=>"",
  201. "bodys"=>$bodys
  202. ];
  203. file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
  204. $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
  205. file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
  206. //剔除数据
  207. $id = array_diff($id, [$value['id']]);
  208. if(empty($return)) {
  209. $msg = '异常错误,请确认请求接口地址或地址不可达';
  210. $this->finalSettle($value['id'], U8Job::one, $msg);
  211. }else{
  212. if( ! empty($return['flag'])){
  213. $this->finalSettle($value['id'], U8Job::one);
  214. }else{
  215. $this->finalSettle($value['id'], U8Job::one, $return['msg']);
  216. }
  217. }
  218. }
  219. if(! empty($id)){
  220. $msg = "未找到同步数据";
  221. $this->finalSettle($id, U8Job::one, $msg);
  222. }
  223. }
  224. //销售订单(合同)保存
  225. public function U8SaleOrderSave($data){
  226. $id = $data;
  227. //映射ip是否通畅
  228. $bool = $this->isDomainAvailable($this->u8['domain']);
  229. if(! $bool) {
  230. $msg = 'U8程序外部域名不可达';
  231. $this->finalSettle($id, U8Job::two, $msg);
  232. return;
  233. }
  234. //获取数据
  235. $result = $this->getSaleOrderData($id);
  236. if(empty($result)) {
  237. $msg = "同步数据获取失败";
  238. $this->finalSettle($id, U8Job::two, $msg);
  239. return;
  240. }
  241. //u8接口参数组织
  242. $post = $this->post_common;
  243. $post['entity'] = "U8SaleOrderSave";
  244. $time = date("Y-m-d");
  245. $time1 = date("Y-m-d H:i:s");
  246. foreach ($result as $value){
  247. $bodys = [];
  248. $cdefine31 = "";
  249. if(! empty($value['cstname']) && $value['cstname'] == "线下销售") $cdefine31 = $value['cstname'];
  250. foreach ($value['product'] as $son){
  251. //子表数据
  252. $bodys[] = [
  253. "cinvcode"=>$son['code'], //存货编码
  254. "iquantity"=>$son['number'], //数量
  255. "inum"=>$son['number'], //件数
  256. "itaxrate"=>$son['itaxrate'], //税率
  257. "iunitprice"=>$son['iunitprice'],//原币单价
  258. "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
  259. "isum"=>$son['isum'], //原币价税合计
  260. "imoney"=>$son['imoney'], //原币无税金额
  261. "itax"=>$son['itax'],//原币税额
  262. "cbmemo"=>$son['mark'], //表体备注
  263. // "iappids"=>"", //子表id
  264. // "cinvcode"=>$son['code'], //存货编码
  265. // "iquantity"=>$son['number'], //数量
  266. // "inum"=>$son['number'], //件数
  267. // "ipertaxrate"=>$son['ipertaxrate'], //税率
  268. // "iunitprice"=>$son['iunitprice'], //原币单价
  269. // "itaxprice"=>$son['itaxprice'], //原币含税单价
  270. // "isum"=>$son['isum'], //原币价税合计
  271. // "imoney"=>$son['imoney'], //原币无税金额
  272. // "itax"=>$son['itax'],//原币税额
  273. // "cbmemo"=>$son['mark'], //表体备注
  274. "cdefine22"=>$son['cdefine22'], //手机号码
  275. "cdefine23"=>"",
  276. "cdefine24"=>"",
  277. "cdefine25"=>$son['cdefine25'], //平台类型
  278. "cdefine26"=>"",
  279. "cdefine27"=>"",
  280. "cdefine28"=>$son['cdefine28'], //平台单号
  281. "cdefine29"=>$son['cdefine29'], //分社施工
  282. "cdefine30"=>$son['cdefine30'], //业务员
  283. "cdefine31"=>$cdefine31, //客户名称
  284. "cdefine32"=>$son['cdefine32'], //直播销售
  285. "cdefine33"=>"",
  286. "cdefine34"=>"",
  287. "cdefine35"=>"",
  288. "cdefine36"=>"",
  289. "cdefine37"=>"",
  290. "cfree1"=>"",
  291. "cfree2"=>"",
  292. "cfree3"=>"",
  293. "cfree4"=>"",
  294. "cfree5"=>"",
  295. "cfree6"=>"",
  296. "cfree7"=>"",
  297. "cfree8"=>"",
  298. "cfree9"=>"",
  299. "cfree10"=>""
  300. ];
  301. }
  302. //最终数据
  303. $post['data'] = [
  304. "csocode"=>'',
  305. "ddate"=> $time,
  306. "cmaker"=>"admin",
  307. "dcreatesystime"=>$time1,
  308. "cstcode"=>"",
  309. "cbustype" => $value['cbustype'], //业务类型
  310. "cstname"=>$value['cstname'], //销售类型
  311. "ccuscode"=>"",
  312. "ccusabbname"=>$value['ccusabbname'], //客户简称
  313. "cdepcode"=>"",
  314. "cdepname"=>$value['cdepname'], // 部门名称
  315. "cpersoncode"=>"", //业务员编码 暂时不要
  316. "itaxrate"=>"0",
  317. "cmemo"=>"T9销售订单:". $value['order_number'],
  318. "cdefine1"=>"",
  319. "cdefine2"=>"",
  320. "cdefine3"=>"",
  321. "cdefine4"=>"",
  322. "cdefine5"=>"",
  323. "cdefine6"=>"",
  324. "cdefine7"=>"",
  325. "cdefine8"=>"",
  326. "cdefine9"=>"",
  327. "cdefine10"=>"",
  328. "cdefine11"=>"",
  329. "cdefine12"=>"",
  330. "cdefine13"=>"",
  331. "cdefine14"=>"",
  332. "cdefine15"=>"",
  333. "cdefine16"=>"",
  334. "bodys"=>$bodys
  335. ];
  336. file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
  337. $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
  338. file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
  339. //剔除数据
  340. $id = array_diff($id, [$value['id']]);
  341. if(empty($return)) {
  342. $msg = '异常错误,请确认请求接口地址或地址不可达';
  343. $this->finalSettle($value['id'],U8Job::two, $msg);
  344. }else{
  345. if( ! empty($return['flag'])){
  346. $this->finalSettle($value['id'],U8Job::two);
  347. }else{
  348. $this->finalSettle($value['id'], U8Job::two, $return['msg']);
  349. }
  350. }
  351. }
  352. if(! empty($id)){
  353. $msg = "未找到同步数据";
  354. $this->finalSettle($id,U8Job::two, $msg);
  355. }
  356. }
  357. //最终处理
  358. public function finalSettle($data,$data_type, $msg = ''){
  359. if(! is_array($data)) $data = [$data];
  360. $time = time();
  361. $insert = [];
  362. U8Job::where('del_time',0)
  363. ->where('data_type',U8Job::one)
  364. ->whereIn('data',$data)
  365. ->update(['del_time' => $time]);
  366. foreach ($data as $value){
  367. if(empty($msg)){
  368. $insert[] = [
  369. 'data' => $value,
  370. 'data_type' => $data_type,
  371. 'crt_time' => $time,
  372. 'state' => U8Job::success,
  373. ];
  374. }else{
  375. $insert[] = [
  376. 'data' => $value,
  377. 'data_type' => $data_type,
  378. 'crt_time' => $time,
  379. 'state' => U8Job::failed,
  380. 'msg' => $msg
  381. ];
  382. }
  383. }
  384. U8Job::insert($insert);
  385. }
  386. public function getPurchaseData($id){
  387. $main = PurchaseOrder::whereIn('id',$id)
  388. ->where('del_time',0)
  389. ->get()->toArray();
  390. if(empty($main)) return [];
  391. $supplier = Supplier::whereIn('id',array_unique(array_column($main,'supplier')))
  392. ->pluck('title','id')
  393. ->toArray();
  394. $depart = Depart::whereIn('id',array_unique(array_column($main,'depart_id')))
  395. ->pluck('title','id')
  396. ->toArray();
  397. $emp = Employee::whereIn('id',array_unique(array_column($main,'purchase_id')))
  398. ->pluck('number','id')
  399. ->toArray();
  400. $code_map = BasicType::whereIn('id',array_unique(array_column($main,'purchase_type')))
  401. ->pluck('title','id')
  402. ->toArray();
  403. $sub = PurchaseOrderInfo::whereIn('purchase_order_id',$id)
  404. ->where('del_time',0)
  405. ->get()->toArray();
  406. $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
  407. ->get()->toArray();
  408. $product_map = array_column($product,null,'id');
  409. $sub_map = [];
  410. foreach ($sub as $value){
  411. $product_tmp = $product_map[$value['product_id']] ?? [];
  412. $value['code'] = $product_tmp['code'];
  413. //计算金额
  414. if($value['rate'] > 0){
  415. // ipertaxrate 税率
  416. // iunitprice 原币单价
  417. // itaxprice 原币含税单价
  418. // isum 原币价税合计
  419. // imoney 原币无税金额
  420. // itax 原币税额
  421. $value['ipertaxrate'] = $value['rate'];
  422. $rate = round($value['rate'] / 100,2);
  423. $value['iunitprice'] = round($value['price'] / (1 + $rate),2);
  424. $value['itaxprice'] = $value['price'];
  425. $value['isum'] = round($value['price'] * $value['number'],2);
  426. $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
  427. $value['itax'] = round($value['isum'] - $value['imoney'],2);
  428. }else{
  429. $value['ipertaxrate'] = 0;
  430. $value['iunitprice'] = $value['price'];
  431. $value['itaxprice'] = $value['price'];
  432. $value['isum'] = $value['price'] * $value['number'];
  433. $value['imoney'] = $value['isum'];
  434. $value['itax'] = 0;
  435. }
  436. $sub_map[$value['purchase_order_id']][] = $value;
  437. }
  438. foreach ($main as $key => $value){
  439. $main[$key]['cptname'] = $code_map[$value['purchase_type']] ?? "";
  440. $main[$key]['cvenname'] = $supplier[$value['supplier']] ?? "";
  441. $main[$key]['cdepname'] = $depart[$value['depart_id']] ?? "";
  442. // $main[$key]['cpersoncode'] = $emp[$value['purchase_id']] ?? "";
  443. $main[$key]['jobnumber'] = $emp[$value['purchase_id']] ?? "";
  444. $main[$key]['product'] = $sub_map[$value['id']] ?? [];
  445. }
  446. return $main;
  447. }
  448. public function getSaleOrderData($id){
  449. $main = SalesOrder::whereIn('id',$id)
  450. ->where('del_time',0)
  451. ->get()->toArray();
  452. if(empty($main)) return [];
  453. $main_map = array_column($main,null,'id');
  454. $sub = SalesOrderProductInfo::whereIn('sales_order_id',$id)
  455. ->where('del_time',0)
  456. ->get()->toArray();
  457. $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
  458. ->get()->toArray();
  459. $product_map = array_column($product,null,'id');
  460. $code_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($main,'sale_type'),array_column($main,'plat_type'))))
  461. ->pluck('title','id')
  462. ->toArray();
  463. $customer_map = Customer::whereIn('id',array_unique(array_column($main,'customer_id')))
  464. ->pluck('title','id')
  465. ->toArray();
  466. $depart = Depart::where('parent_id',0)
  467. ->pluck('title','id')
  468. ->toArray();
  469. $emp = Employee::whereIn('id',array_unique(array_column($main,'crt_id')))
  470. ->pluck('emp_name','id')
  471. ->toArray();
  472. $see = SeeRange::where('del_time',0)
  473. ->whereIn('data_id',array_column($main,'id'))
  474. ->where('data_type',SeeRange::type_seven)
  475. ->where('type',SeeRange::data_three)
  476. ->pluck('param_id','data_id')->toArray();//指派的分社
  477. $sub_map = [];
  478. foreach ($sub as $value){
  479. $product_tmp = $product_map[$value['product_id']] ?? [];
  480. $main_tmp = $main_map[$value['sales_order_id']] ?? [];
  481. // "itaxrate"=>$son['itaxrate'], //税率
  482. // "iunitprice"=>$son['iunitprice'],//原币单价
  483. // "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
  484. // "isum"=>$son['isum'], //原币价税合计
  485. // "imoney"=>$son['imoney'], //原币无税金额
  486. // "itax"=>$son['itax'],//原币税额
  487. //计算金额
  488. if($value['rate'] > 0){
  489. $value['itaxrate'] = $value['rate'];
  490. $rate = round($value['rate'] / 100,2);
  491. $value['iunitprice'] = round($value['price'] / (1 + $rate),2);
  492. $value['itaxunitprice'] = $value['price'];
  493. $value['isum'] = round($value['price'] * $value['number'],2);
  494. $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
  495. $value['itax'] = round($value['isum'] - $value['imoney'],2);
  496. }else{
  497. $value['itaxrate'] = 0;
  498. $value['iunitprice'] = $value['price'];
  499. $value['itaxunitprice'] = $value['price'];
  500. $value['isum'] = $value['price'] * $value['number'];
  501. $value['imoney'] = $value['isum'];
  502. $value['itax'] = 0;
  503. }
  504. $value['cdefine25'] = $code_map[$main_tmp['plat_type']] ?? ""; //平台类型
  505. $value['cdefine28'] = $main_tmp['plat_order'] ?? ""; //平台单号
  506. $top_depart_id = $see[$value['sales_order_id']] ?? 0;
  507. $value['cdefine29'] = $depart[$top_depart_id] ?? "";//分社施工
  508. $value['cdefine32'] = "";//直播销售 暂时没有
  509. $value['cdefine31'] = "";//客户名称(线上的时候就是空 线下的话就是表头的客户简称)
  510. $value['cdefine22'] = "";//手机号码 暂时没有
  511. $value['cdefine30'] = $emp[$main_tmp['crt_id']] ?? "";//业务员
  512. $value['code'] = $product_tmp['code'];//存货编码
  513. $sub_map[$value['sales_order_id']][] = $value;
  514. }
  515. foreach ($main as $key => $value){
  516. $main[$key]['cbustype'] = "普通销售"; //业务类型(本身就是中文)
  517. $main[$key]['cstname'] = $code_map[$value['sale_type']] ?? ""; //销售类型
  518. $main[$key]['ccusabbname'] = $customer_map[$value['customer_id']] ?? "";//客户简称
  519. $main[$key]['cdepname'] = $depart[$value['top_depart_id']] ?? "";//部门名称
  520. // $main[$key]['cpersoncode'] = $emp[$value['crt_id']] ?? "";//业务员
  521. $main[$key]['product'] = $sub_map[$value['id']] ?? [];
  522. }
  523. return $main;
  524. }
  525. public function post_helper($url, $data, $header = [], $timeout = 20){
  526. $ch = curl_init();
  527. curl_setopt($ch, CURLOPT_URL, $url);
  528. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  529. curl_setopt($ch, CURLOPT_ENCODING, '');
  530. curl_setopt($ch, CURLOPT_POST, 1);
  531. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  532. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  533. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  534. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  535. if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  536. $r = curl_exec($ch);
  537. curl_close($ch);
  538. return json_decode($r, true);
  539. }
  540. }