U8ServerService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. if(! is_array($data)) $data = [$data];
  109. $id = $data;
  110. //映射ip是否通畅
  111. $bool = $this->isDomainAvailable($this->u8['domain']);
  112. if(! $bool) {
  113. $msg = 'U8程序外部域名不可达';
  114. $this->finalSettle($id, U8Job::one,$msg);
  115. return;
  116. }
  117. //获取数据
  118. $result = $this->getPurchaseData($id);
  119. if(empty($result)) {
  120. $msg = "同步数据获取失败";
  121. $this->finalSettle($id, U8Job::one, $msg);
  122. return;
  123. }
  124. //u8接口参数组织
  125. $post = $this->post_common;
  126. $post['entity'] = "U8PO_PomainSave";
  127. $time = date("Y-m-d");
  128. foreach ($result as $value){
  129. $bodys = [];
  130. foreach ($value['product'] as $son){
  131. //子表数据
  132. $bodys[] = [
  133. "iappids"=>"", //子表id
  134. "cinvcode"=>$son['code'], //存货编码
  135. "iquantity"=>$son['number'], //数量
  136. "inum"=>$son['number'], //件数
  137. "ipertaxrate"=>$son['ipertaxrate'], //税率
  138. "iunitprice"=>$son['iunitprice'], //原币单价
  139. "itaxprice"=>$son['itaxprice'], //原币含税单价
  140. "isum"=>$son['isum'], //原币价税合计
  141. "imoney"=>$son['imoney'], //原币无税金额
  142. "itax"=>$son['itax'],//原币税额
  143. "cbmemo"=>$son['mark'], //表体备注
  144. "cdefine22"=>"",
  145. "cdefine23"=>"",
  146. "cdefine24"=>"",
  147. "cdefine25"=>"",
  148. "cdefine26"=>"",
  149. "cdefine27"=>"",
  150. "cdefine28"=>"",
  151. "cdefine29"=>"",
  152. "cdefine30"=>"",
  153. "cdefine31"=>"",
  154. "cdefine32"=>"",
  155. "cdefine33"=>"",
  156. "cdefine34"=>"",
  157. "cdefine35"=>"",
  158. "cdefine36"=>"",
  159. "cdefine37"=>"",
  160. "cfree1"=>"",
  161. "cfree2"=>"",
  162. "cfree3"=>"",
  163. "cfree4"=>"",
  164. "cfree5"=>"",
  165. "cfree6"=>"",
  166. "cfree7"=>"",
  167. "cfree8"=>"",
  168. "cfree9"=>"",
  169. "cfree10"=>""
  170. ];
  171. }
  172. //最终数据
  173. $post['data'] = [
  174. "cpoid"=>"",
  175. "dpodate"=>date("Y-m-d",$value['crt_time']),
  176. "cmemo"=>"T9采购单:" . $value['order_number'],
  177. "cmaker"=>"admin",
  178. "cmaketime"=>$time,
  179. "IsExamine"=>false,
  180. "cptname"=>$value['cptname']??"",//采购类型
  181. "cvencode"=>"", //供应商编码
  182. "cvenname"=>$value['cvenname'], //供应商名称
  183. "cdepcode"=>"", //部门编号
  184. "cdepname"=>"", //部门名称 $value['cdepname']
  185. "cpersoncode"=>"", //业务员编码jobnumber
  186. "jobnumber"=>$value['jobnumber'], //业务员编码
  187. "cdefine1"=>"",
  188. "cdefine2"=>"",
  189. "cdefine3"=>"",
  190. "cdefine4"=>"",
  191. "cdefine5"=>"",
  192. "cdefine6"=>"",
  193. "cdefine7"=>"",
  194. "cdefine8"=>"",
  195. "cdefine9"=>"",
  196. "cdefine10"=>"",
  197. "cdefine11"=>"",
  198. "cdefine12"=>"",
  199. "cdefine13"=>"",
  200. "cdefine14"=>"",
  201. "cdefine15"=>"",
  202. "cdefine16"=>"",
  203. "bodys"=>$bodys
  204. ];
  205. file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
  206. $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
  207. file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
  208. //剔除数据
  209. $id = array_diff($id, [$value['id']]);
  210. if(empty($return)) {
  211. $msg = '异常错误,请确认请求接口地址或地址不可达';
  212. $this->finalSettle($value['id'], U8Job::one, $msg);
  213. }else{
  214. if( ! empty($return['flag'])){
  215. $this->finalSettle($value['id'], U8Job::one);
  216. }else{
  217. $this->finalSettle($value['id'], U8Job::one, $return['msg']);
  218. }
  219. }
  220. }
  221. if(! empty($id)){
  222. $msg = "未找到同步数据";
  223. $this->finalSettle($id, U8Job::one, $msg);
  224. }
  225. }
  226. //销售订单(合同)保存
  227. public function U8SaleOrderSave($data){
  228. if(! is_array($data)) $data = [$data];
  229. $id = $data;
  230. //映射ip是否通畅
  231. $bool = $this->isDomainAvailable($this->u8['domain']);
  232. if(! $bool) {
  233. $msg = 'U8程序外部域名不可达';
  234. $this->finalSettle($id, U8Job::two, $msg);
  235. return;
  236. }
  237. //获取数据
  238. $result = $this->getSaleOrderData($id);
  239. if(empty($result)) {
  240. $msg = "同步数据获取失败";
  241. $this->finalSettle($id, U8Job::two, $msg);
  242. return;
  243. }
  244. //u8接口参数组织
  245. $post = $this->post_common;
  246. $post['entity'] = "U8SaleOrderSave";
  247. $time = date("Y-m-d");
  248. $time1 = date("Y-m-d H:i:s");
  249. foreach ($result as $value){
  250. $bodys = [];
  251. // $cdefine31 = "";
  252. // if(! empty($value['cstname']) && $value['cstname'] == "线下销售") $cdefine31 = $value['cstname'];
  253. foreach ($value['product'] as $son){
  254. //子表数据
  255. $bodys[] = [
  256. "cinvcode"=>$son['code'], //存货编码
  257. "iquantity"=>$son['number'], //数量
  258. "inum"=>$son['number'], //件数
  259. "itaxrate"=>$son['itaxrate'], //税率
  260. "iunitprice"=>$son['iunitprice'],//原币单价
  261. "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
  262. "isum"=>$son['isum'], //原币价税合计
  263. "imoney"=>$son['imoney'], //原币无税金额
  264. "itax"=>$son['itax'],//原币税额
  265. "cbmemo"=>$son['mark'], //表体备注
  266. // "iappids"=>"", //子表id
  267. // "cinvcode"=>$son['code'], //存货编码
  268. // "iquantity"=>$son['number'], //数量
  269. // "inum"=>$son['number'], //件数
  270. // "ipertaxrate"=>$son['ipertaxrate'], //税率
  271. // "iunitprice"=>$son['iunitprice'], //原币单价
  272. // "itaxprice"=>$son['itaxprice'], //原币含税单价
  273. // "isum"=>$son['isum'], //原币价税合计
  274. // "imoney"=>$son['imoney'], //原币无税金额
  275. // "itax"=>$son['itax'],//原币税额
  276. // "cbmemo"=>$son['mark'], //表体备注
  277. "cdefine22"=>$son['cdefine22'], //手机号码
  278. "cdefine23"=>"",
  279. "cdefine24"=>"",
  280. "cdefine25"=>$son['cdefine25'], //平台类型
  281. "cdefine26"=>"",
  282. "cdefine27"=>"",
  283. "cdefine28"=>$son['cdefine28'], //平台单号
  284. "cdefine29"=>$son['cdefine29'], //分社施工
  285. "cdefine30"=>$son['cdefine30'], //业务员
  286. "cdefine31"=>$son['cdefine31'], //客户名称
  287. "cdefine32"=>$son['cdefine32'], //直播销售
  288. "cdefine33"=>"",
  289. "cdefine34"=>"",
  290. "cdefine35"=>"",
  291. "cdefine36"=>"",
  292. "cdefine37"=>"",
  293. "cfree1"=>"",
  294. "cfree2"=>"",
  295. "cfree3"=>"",
  296. "cfree4"=>"",
  297. "cfree5"=>"",
  298. "cfree6"=>"",
  299. "cfree7"=>"",
  300. "cfree8"=>"",
  301. "cfree9"=>"",
  302. "cfree10"=>""
  303. ];
  304. }
  305. //最终数据
  306. $post['data'] = [
  307. "csocode"=>'',
  308. "ddate"=> $time,
  309. "cmaker"=>"admin",
  310. "dcreatesystime"=>$time1,
  311. "cstcode"=>"",
  312. "cbustype" => $value['cbustype'], //业务类型
  313. "cstname"=>$value['cstname'], //销售类型
  314. "ccuscode"=>"",
  315. "ccusabbname"=>$value['ccusabbname'], //客户简称
  316. "cdepcode"=>"",
  317. "cdepname"=>"", // 部门名称 $value['cdepname']
  318. "cpersoncode"=>"", //业务员编码 暂时不要
  319. "jobnumber"=>$value['jobnumber'],//业务员工号
  320. "itaxrate"=>"0",
  321. "cmemo"=>"T9销售订单:". $value['order_number'],
  322. "cdefine1"=>"",
  323. "cdefine2"=>"",
  324. "cdefine3"=>"",
  325. "cdefine4"=>"",
  326. "cdefine5"=>"",
  327. "cdefine6"=>"",
  328. "cdefine7"=>"",
  329. "cdefine8"=>"",
  330. "cdefine9"=>"",
  331. "cdefine10"=>"",
  332. "cdefine11"=>"",
  333. "cdefine12"=>"",
  334. "cdefine13"=>"",
  335. "cdefine14"=>"",
  336. "cdefine15"=>"",
  337. "cdefine16"=>"",
  338. "bodys"=>$bodys
  339. ];
  340. file_put_contents('record_purchase.txt',"请求参数:" . json_encode($post) . PHP_EOL,8);
  341. $return = $this->post_helper($this->u8_api,json_encode($post), ['Content-Type:application/json']);
  342. file_put_contents('record_purchase.txt',"返回结果:" . json_encode($return). PHP_EOL,8);
  343. //剔除数据
  344. $id = array_diff($id, [$value['id']]);
  345. if(empty($return)) {
  346. $msg = '异常错误,请确认请求接口地址或地址不可达';
  347. $this->finalSettle($value['id'],U8Job::two, $msg);
  348. }else{
  349. if( ! empty($return['flag'])){
  350. $this->finalSettle($value['id'],U8Job::two);
  351. }else{
  352. $this->finalSettle($value['id'], U8Job::two, $return['msg']);
  353. }
  354. }
  355. }
  356. if(! empty($id)){
  357. $msg = "未找到同步数据";
  358. $this->finalSettle($id,U8Job::two, $msg);
  359. }
  360. }
  361. //最终处理
  362. public function finalSettle($data,$data_type, $msg = ''){
  363. if(! is_array($data)) $data = [$data];
  364. $time = time();
  365. $insert = [];
  366. U8Job::where('del_time',0)
  367. ->where('data_type',$data_type)
  368. ->whereIn('data',$data)
  369. ->update(['del_time' => $time]);
  370. foreach ($data as $value){
  371. if(empty($msg)){
  372. $insert[] = [
  373. 'data' => $value,
  374. 'data_type' => $data_type,
  375. 'crt_time' => $time,
  376. 'state' => U8Job::success,
  377. ];
  378. }else{
  379. $insert[] = [
  380. 'data' => $value,
  381. 'data_type' => $data_type,
  382. 'crt_time' => $time,
  383. 'state' => U8Job::failed,
  384. 'msg' => $msg
  385. ];
  386. }
  387. }
  388. U8Job::insert($insert);
  389. }
  390. public function getPurchaseData($id){
  391. $main = PurchaseOrder::whereIn('id',$id)
  392. ->where('del_time',0)
  393. ->get()->toArray();
  394. if(empty($main)) return [];
  395. $supplier = Supplier::whereIn('id',array_unique(array_column($main,'supplier')))
  396. ->pluck('title','id')
  397. ->toArray();
  398. // $depart = Depart::whereIn('id',array_unique(array_column($main,'depart_id')))
  399. // ->pluck('title','id')
  400. // ->toArray();
  401. $emp = Employee::whereIn('id',array_unique(array_column($main,'purchase_id')))
  402. ->pluck('number','id')
  403. ->toArray();
  404. $code_map = BasicType::whereIn('id',array_unique(array_column($main,'purchase_type')))
  405. ->pluck('title','id')
  406. ->toArray();
  407. $sub = PurchaseOrderInfo::whereIn('purchase_order_id',$id)
  408. ->where('del_time',0)
  409. ->get()->toArray();
  410. $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
  411. ->get()->toArray();
  412. $product_map = array_column($product,null,'id');
  413. $sub_map = [];
  414. foreach ($sub as $value){
  415. $product_tmp = $product_map[$value['product_id']] ?? [];
  416. $value['code'] = $product_tmp['code'];
  417. //计算金额
  418. if($value['rate'] > 0){
  419. // ipertaxrate 税率
  420. // iunitprice 原币单价
  421. // itaxprice 原币含税单价
  422. // isum 原币价税合计
  423. // imoney 原币无税金额
  424. // itax 原币税额
  425. $value['ipertaxrate'] = $value['rate'];
  426. $rate = round($value['rate'] / 100,2);
  427. $value['iunitprice'] = round($value['price'] / (1 + $rate),2);
  428. $value['itaxprice'] = $value['price'];
  429. $value['isum'] = round($value['price'] * $value['number'],2);
  430. $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
  431. $value['itax'] = round($value['isum'] - $value['imoney'],2);
  432. }else{
  433. $value['ipertaxrate'] = 0;
  434. $value['iunitprice'] = $value['price'];
  435. $value['itaxprice'] = $value['price'];
  436. $value['isum'] = $value['price'] * $value['number'];
  437. $value['imoney'] = $value['isum'];
  438. $value['itax'] = 0;
  439. }
  440. $sub_map[$value['purchase_order_id']][] = $value;
  441. }
  442. foreach ($main as $key => $value){
  443. $main[$key]['cptname'] = $code_map[$value['purchase_type']] ?? "";
  444. $main[$key]['cvenname'] = $supplier[$value['supplier']] ?? "";
  445. // $main[$key]['cdepname'] = $depart[$value['depart_id']] ?? "";
  446. // $main[$key]['cpersoncode'] = $emp[$value['purchase_id']] ?? "";
  447. $main[$key]['jobnumber'] = $emp[$value['purchase_id']] ?? "";
  448. $main[$key]['product'] = $sub_map[$value['id']] ?? [];
  449. }
  450. return $main;
  451. }
  452. public function getSaleOrderData($id){
  453. $main = SalesOrder::whereIn('id',$id)
  454. ->where('del_time',0)
  455. ->get()->toArray();
  456. if(empty($main)) return [];
  457. $main_map = array_column($main,null,'id');
  458. $sub = SalesOrderProductInfo::whereIn('sales_order_id',$id)
  459. ->where('del_time',0)
  460. ->get()->toArray();
  461. $product = Product::whereIn('id',array_unique(array_column($sub,'product_id')))
  462. ->get()->toArray();
  463. $product_map = array_column($product,null,'id');
  464. $code_id = array_filter(array_unique(array_merge_recursive(array_column($main,'sale_type'),array_column($main,'plat_type'))));
  465. $code_map = BasicType::whereIn('id',$code_id)
  466. ->pluck('title','id')
  467. ->toArray();
  468. $customer_map = Customer::whereIn('id',array_unique(array_column($main,'customer_id')))
  469. ->pluck('title','id')
  470. ->toArray();
  471. $depart = Depart::where('parent_id',0)
  472. ->pluck('title','id')
  473. ->toArray();
  474. $emp = Employee::whereIn('id',array_unique(array_column($main,'crt_id')))
  475. ->pluck('number','id')
  476. ->toArray();
  477. $see = SeeRange::where('del_time',0)
  478. ->whereIn('data_id',array_column($main,'id'))
  479. ->where('data_type',SeeRange::type_seven)
  480. ->where('type',SeeRange::data_three)
  481. ->pluck('param_id','data_id')->toArray();//指派的分社
  482. $sub_map = [];
  483. foreach ($sub as $value){
  484. $product_tmp = $product_map[$value['product_id']] ?? [];
  485. $main_tmp = $main_map[$value['sales_order_id']] ?? [];
  486. // "itaxrate"=>$son['itaxrate'], //税率
  487. // "iunitprice"=>$son['iunitprice'],//原币单价
  488. // "itaxunitprice"=>$son['itaxunitprice'], // 原币含税单价
  489. // "isum"=>$son['isum'], //原币价税合计
  490. // "imoney"=>$son['imoney'], //原币无税金额
  491. // "itax"=>$son['itax'],//原币税额
  492. //计算金额
  493. if($value['rate'] > 0){
  494. $value['itaxrate'] = $value['rate'];
  495. $rate = round($value['rate'] / 100,2);
  496. $value['iunitprice'] = round($value['price'] / (1 + $rate),2);
  497. $value['itaxunitprice'] = $value['price'];
  498. $value['isum'] = round($value['price'] * $value['number'],2);
  499. $value['imoney'] = round($value['iunitprice'] * $value['number'],2);
  500. $value['itax'] = round($value['isum'] - $value['imoney'],2);
  501. }else{
  502. $value['itaxrate'] = 0;
  503. $value['iunitprice'] = $value['price'];
  504. $value['itaxunitprice'] = $value['price'];
  505. $value['isum'] = $value['price'] * $value['number'];
  506. $value['imoney'] = $value['isum'];
  507. $value['itax'] = 0;
  508. }
  509. $value['cdefine25'] = $code_map[$main_tmp['plat_type']] ?? ""; //平台类型
  510. $value['cdefine28'] = $main_tmp['plat_order'] ?? ""; //平台单号
  511. $top_depart_id = $see[$value['sales_order_id']] ?? 0;
  512. $value['cdefine29'] = $depart[$top_depart_id] ?? "";//分社施工
  513. $value['cdefine32'] = "";//直播销售 暂时没有
  514. $value['cdefine31'] = $customer_map[$main_tmp['customer_id']] ?? "";//客户名称
  515. $value['cdefine22'] = $main_tmp['customer_contact'] ?? "";//手机号码
  516. // $value['cdefine31'] = "";//客户名称(线上的时候就是空 线下的话就是表头的客户简称)
  517. // $value['cdefine22'] = "";//手机号码 暂时没有
  518. $value['cdefine30'] = $emp[$main_tmp['crt_id']] ?? "";//业务员
  519. $value['code'] = $product_tmp['code'];//存货编码
  520. $sub_map[$value['sales_order_id']][] = $value;
  521. }
  522. foreach ($main as $key => $value){
  523. $plat_type = $code_map[$value['plat_type']] ?? "";
  524. if($plat_type == "营销部"){
  525. $ccusabbname = "营销部客户";
  526. }else{
  527. $ccusabbname = $customer_map[$value['customer_id']] ?? "";
  528. }
  529. $main[$key]['cbustype'] = "普通销售"; //业务类型(本身就是中文)
  530. $main[$key]['cstname'] = SalesOrder::$model_type_title[$value['model_type']] ?? ""; //销售类型
  531. $main[$key]['ccusabbname'] = $ccusabbname;//客户简称
  532. // $main[$key]['cdepname'] = $depart[$value['top_depart_id']] ?? "";//部门名称
  533. // $main[$key]['cpersoncode'] = $emp[$value['crt_id']] ?? "";//业务员
  534. $main[$key]['jobnumber'] = $emp[$value['crt_id']] ?? "";
  535. $main[$key]['product'] = $sub_map[$value['id']] ?? [];
  536. }
  537. return $main;
  538. }
  539. public function post_helper($url, $data, $header = [], $timeout = 20){
  540. $ch = curl_init();
  541. curl_setopt($ch, CURLOPT_URL, $url);
  542. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  543. curl_setopt($ch, CURLOPT_ENCODING, '');
  544. curl_setopt($ch, CURLOPT_POST, 1);
  545. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  546. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  547. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  548. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  549. if(!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  550. $r = curl_exec($ch);
  551. curl_close($ch);
  552. return json_decode($r, true);
  553. }
  554. }