Apiyy.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Apiyy extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_api','api');
  7. $this->load->_model('Model_shop','shop');
  8. $this->load->_model('Model_fullorder','fullorder');
  9. $this->load->_model('Model_fullordertt','fullordertt');
  10. $this->load->_model('Model_fullordersmt','fullordersmt');
  11. $this->load->_model('Model_country','country');
  12. $this->load->_model('Model_hl','hl');
  13. $this->load->_model('Model_is','is');
  14. $this->load->_model('Model_kdniao','kdniao');
  15. $this->load->_model('Model_typeclass','typeclass');
  16. $this->load->_model('Model_warehouse','warehouse');
  17. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  18. $this->load->_model('Model_dhl','dhl');
  19. $this->load->_model('Model_usps','usps');
  20. $this->load->_model('Model_ups','ups');
  21. $this->load->_model('Model_dhltest','dhltest');
  22. $this->load->_model('Model_customer','customer');
  23. $this->load->_model('Model_express','express');
  24. $this->load->_model('Model_notice','notice');
  25. $this->load->_model('Model_emaildata','emaildata');
  26. $this->load->_model('Model_whlabel','whlabel');
  27. $this->load->_model('Model_productdescribe','productdescribe');
  28. $this->load->_model('Model_ljg','ljg');
  29. $this->load->_model('Model_commodityread','commodityread');
  30. $this->load->_model('Model_service','service');
  31. $this->load->_model('Model_fedex','fedex');
  32. $this->load->_model('Model_apismt','apismt');
  33. $this->load->_model('Model_cne','cne');
  34. $this->load->_model('Model_specialstock','specialstock');
  35. $this->load->_model('Model_whlabellabel','whlabellabel');
  36. $this->load->_model('Model_allocation','allocation');
  37. $this->load->_model('Model_yswaybill','yswaybill');
  38. $this->load->_model('Model_paypal','paypal');
  39. $this->load->_model('Model_17track','17track');
  40. $this->load->_model('Model_ck','ck');
  41. $this->load->_model('Model_weight','weight');
  42. $this->load->_model('Model_pay','pay');
  43. $this->load->_model('Model_setting','setting');
  44. $this->load->_model('Model_classid','classid');
  45. $this->load->_model('Model_apitt','apitt');
  46. $this->load->_model('Model_customertt','customertt');
  47. $this->load->_model('Model_als','als');
  48. $this->load->_model('Model_apiyy','apiyy');
  49. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  50. $this->load->_model('Model_excel','excel');
  51. }
  52. //定义方法的调用规则 获取URI第二段值
  53. public function _remap($arg,$arg_array)
  54. {
  55. if($arg == 'c')
  56. {
  57. $this->_c();
  58. }
  59. else if($arg == 'excel')
  60. {
  61. $this->_excel($arg_array);
  62. }
  63. else if($arg == 'rz')
  64. {
  65. $this->_rz($arg_array);
  66. }
  67. }
  68. public function _excel($arg_array)
  69. {
  70. $filePath = './data/yyexcel/'.$arg_array[0].'/excel.txt';
  71. $fileContent = file_get_contents($filePath);
  72. if ($fileContent !== false)
  73. {
  74. header( 'Content-Type: application/vnd.ms-excel; name=excel' );
  75. header( 'Content-type: application/octet-stream' );
  76. header( 'Content-Disposition: attachment; filename='.$arg_array[0].'.xls');
  77. header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
  78. header( 'Pragma: no-cache' );
  79. header( 'Expires: 0' );
  80. echo $fileContent;
  81. }
  82. else
  83. {
  84. echo "文件无法读取";
  85. }
  86. }
  87. public function _rz($arg_array)
  88. {
  89. $a = './data/yylog/RK-'.$arg_array[0].'.txt';
  90. if(is_file($a))
  91. {
  92. $myfile = fopen($a, "r") or die("Unable to open file!");
  93. $bc = fread($myfile,filesize($a));
  94. fclose($myfile);
  95. $zt = explode('\n',trim($bc,'\n'));
  96. //$bc = json_decode($bc,true);
  97. $nr = array();
  98. foreach($zt as $k=>$val)
  99. {
  100. $xx = explode(' = ',trim($val,' = '));
  101. if(stripos($xx[0],'RK-F') !== false)
  102. {
  103. $nr[$k][][0] = '入库发送';
  104. }
  105. else if(stripos($xx[0],'RK-J') !== false)
  106. {
  107. $nr[$k][][0] = '入库接收';
  108. }
  109. else if(stripos($xx[0],'SH-F') !== false)
  110. {
  111. $nr[$k][][0] = '审核发送';
  112. }
  113. else if(stripos($xx[0],'SH-J') !== false)
  114. {
  115. $nr[$k][][0] = '审核接收';
  116. }
  117. else if(stripos($xx[0],'DC-F') !== false)
  118. {
  119. $nr[$k][][0] = '调出发送';
  120. }
  121. else if(stripos($xx[0],'DC-J') !== false)
  122. {
  123. $nr[$k][][0] = '调出接收';
  124. }
  125. $nr[$k][][1] = $xx[1];
  126. }
  127. echo "<pre>";
  128. print_r($nr);
  129. }
  130. else
  131. {
  132. echo '无';
  133. }
  134. }
  135. public function _c()
  136. {
  137. $asd = array();
  138. $f = array('fullordersmt','fullordertt','fullorder');
  139. foreach($f as $v)
  140. {
  141. $d = $this->$v->find_all("librarytime > '".(time()-(5*24*3600))."' and (type = '13' or type = '16') and dbapi < 99");
  142. if($d)
  143. {
  144. $h = $this->_list($d,$v);
  145. foreach($h as $vv)
  146. {
  147. $x = 0;$c = 0;
  148. $xs = $this->apiyy->_cxxsdd($vv['0']);
  149. $chd = $this->apiyy->_cxchd($vv['0']);
  150. if(isset($xs['Data'][0]))
  151. {
  152. $vv[] = '成功';
  153. $x = 1;
  154. }
  155. else
  156. {
  157. $vv[] = '无';
  158. }
  159. if(isset($chd['Data'][0]))
  160. {
  161. $vv[] = '成功';
  162. $c = 1;
  163. }
  164. else
  165. {
  166. $vv[] = '无';
  167. }
  168. if($x==1 && $c==1)
  169. {
  170. $this->$v->save(array('dbapi'=>99),$vv[4]);
  171. }
  172. $asd[] = $vv;
  173. }
  174. }
  175. }
  176. $title = "表 ".date("Y-m-d");
  177. $titlename = "<table border=1>
  178. <tr><th colspan='6' align='left'><h3>".$title."<h3></th></tr>
  179. <tr>
  180. <td>编号</td>
  181. <td>销售订单发送</td>
  182. <td>销售订单接收</td>
  183. <td>出货单发送</td>
  184. <td>出货单接收</td>
  185. <td>销售订单验证</td>
  186. <td>出货单验证</td>
  187. </tr>
  188. </table>";
  189. $filename = $title.".xls";
  190. $tail = "\n";
  191. $data = $this->excel->get_fz2_bc($asd,$titlename,$filename,$tail);
  192. $orderinfo = time();
  193. $pdtime = date('Y-m-d',time());
  194. $folderPath = './data/yyexcel/'.$pdtime; // 文件夹路径
  195. $permissions = 0777; // 权限设置
  196. if (!file_exists($folderPath)) { mkdir($folderPath, $permissions); }//创建文件夹
  197. file_exists($folderPath);
  198. if(!is_file($folderPath."/".$orderinfo.".txt"))
  199. {
  200. $myfile = fopen($folderPath."/excel.txt", "w") or die("Unable to open file!");
  201. fwrite($myfile, $data);
  202. fclose($myfile);
  203. }
  204. else
  205. {
  206. $myfile = fopen($folderPath."/exce.txt", "a+") or die("Unable to open file!");
  207. fwrite($myfile, $data);
  208. fclose($myfile);
  209. }
  210. }
  211. public function _list($d,$fullorder)//获取订单列表
  212. {
  213. $xx = array();
  214. foreach($d as $k=>$data)
  215. {
  216. $xx[$k] = array(0=>$data['number'],'xsf'=>'','xss'=>'','fhf'=>'','fhs'=>'',4=>$data['id']);
  217. $kh = $this->shop->read($data['shop']);
  218. $classid = $this->classid->sku();
  219. $tcall = $this->typeclass->find_all();
  220. $typeclass = array();
  221. foreach ($tcall as $v)
  222. {
  223. $tcjm[$v['id']] = array($v['jm'],$v['classid']);
  224. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  225. }
  226. $bm = '03';
  227. $xysc = array();
  228. $data['lh'] = array();
  229. $scid = '';$cw = '';$lc = 0;
  230. $sku = explode(';',trim($data['fpdata'],';'));
  231. $whlabelsc = explode('|',trim($data['whlabel'],'|'));
  232. foreach($sku as $key=>$val)
  233. {
  234. if(stripos($val,'-131-') !== false)
  235. {
  236. continue;
  237. }
  238. $pm = $classid;
  239. $jm = $classid;
  240. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  241. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$val);
  242. $ts = explode('|',trim($features,'|'));
  243. if(stripos($ts[0],',') !== false)
  244. {
  245. $ft = explode(',',$ts[0]);
  246. $features = explode('-',trim($ft[1],'-'));
  247. $features[] = $ft[0];
  248. }
  249. else
  250. {
  251. $features = explode('-',trim($ts[0],'-'));
  252. }
  253. foreach($features as $k=>$v)
  254. {
  255. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  256. {
  257. if($typeclass[$v]['bm'] != '')
  258. {
  259. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  260. }
  261. }
  262. if($v != 0)
  263. {
  264. if(isset($pm[$typeclass[$v]['classid']]))
  265. {
  266. if($typeclass[$v]['title'] == '9A')
  267. {
  268. $pm[$typeclass[$v]['classid']] = '9A';
  269. }
  270. else if($typeclass[$v]['title'] == '10A')
  271. {
  272. $pm[$typeclass[$v]['classid']] = '10A';
  273. }
  274. else
  275. {
  276. $clzh = $typeclass[$v]['zh'];
  277. if(stripos($typeclass[$v]['zh'],'|') !== false)
  278. {
  279. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  280. $clzh = $clzh[0];
  281. }
  282. $pm[$typeclass[$v]['classid']] = $clzh;
  283. }
  284. }
  285. if(isset($jm[$typeclass[$v]['classid']]))
  286. {
  287. if($typeclass[$v]['jm'])
  288. {
  289. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  290. }
  291. }
  292. }
  293. }
  294. $jm = array_filter($jm);//去除空值
  295. $jm = implode("-",$jm);
  296. $pm = array_filter($pm);//去除空值
  297. $zh = implode(" ",$pm);
  298. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  299. $lh = $this->apiyy->get_cjlp(array('jm'=>$jm,'title'=>$ts[1],'zh'=>$zh,'bm'=>$bm.implode("",$bmpx)));
  300. if(isset($lh['Data'][0]))
  301. {
  302. if($lh['Data'][0]['m_isSucess'] != 1)
  303. {
  304. if($lh['Data'][0]['m_errorMsg'] != '料号 已存在,请重新输入!')
  305. {
  306. $xx[$k][1] = $lh;
  307. $this->apiyy->insert(array('number'=>$data['number'],'error'=>$lh['Data'][0]['m_errorMsg'],'type'=>'料号','cs'=>$fullorder));
  308. continue;
  309. }
  310. }
  311. }
  312. else
  313. {
  314. $this->apiyy->insert(array('number'=>$data['number'],'error'=>json_encode($lh),'type'=>'料号','cs'=>$fullorder));
  315. continue;
  316. }
  317. $data['lh'][] = array('sku'=>$jm,'ts'=>$ts[2]);
  318. if(stripos($val,'-131-') !== false)
  319. {
  320. continue;
  321. }
  322. if(stripos($val,'-126-') !== false)
  323. {
  324. $drck = '12003';//进入发条库
  325. }
  326. else if(stripos($val,'-127-') !== false)
  327. {
  328. $drck = '12004';//进入发块库
  329. }
  330. else
  331. {
  332. $drck = '12006';//其它进入完成库
  333. }
  334. }
  335. $data['yyid'] = $kh['yyid'];
  336. @$ay = $this->apiyy->_neworder($data,$classid,$tcall);
  337. $xx[$k]['xsf'] = $ay['fs'];
  338. $xx[$k]['xss'] = $ay['fh'];
  339. if($ay['c'] != 0)
  340. {
  341. $this->$fullorder->save(array('dbapi'=>0),$data['id']);
  342. $this->apiyy->insert(array('number'=>$data['number'],'type'=>'销售订单','error'=>$ay['error'],'cs'=>$fullorder));
  343. }
  344. else
  345. {
  346. $this->$fullorder->save(array('dbapi'=>99),$data['id']);
  347. $chdfs = '';$chdjs = '';$chdcg = 0;
  348. foreach($data['lh'] as $k=>$v)
  349. {
  350. $chd = array('number'=>$data['number'],'i'=>$k+1,'ts'=>$v['ts']);
  351. $c = $this->apiyy->get_chd($chd);
  352. $chdfs = $c['1'];
  353. $chdjs = json_encode($c['0']);
  354. if($c['Data'][0]['m_isSucess'] == 1)
  355. {
  356. $chdcg += 1;
  357. }
  358. }
  359. $xx[$k]['fhf'] = $chdfs;
  360. $xx[$k]['fhs'] = $chdjs;
  361. if($chdcg == count($data['lh']))
  362. {
  363. $cs = $this->$fullorder->save(array('dbapi'=>100),$data['id']);
  364. }
  365. }
  366. }
  367. return $xx;
  368. }
  369. }