Fullorderout.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Fullorderout extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_shop','shop');
  6. $this->load->_model('Model_fullorder','fullorder');
  7. $this->load->_model('Model_fullordertt','fullordertt');
  8. $this->load->_model('Model_fullordersmt','fullordersmt');
  9. $this->load->_model('Model_fullorderout','fullorderout');
  10. $this->load->_model('Model_country','country');
  11. $this->load->_model('Model_express','express');
  12. $this->load->_model('Model_whlabel','whlabel');
  13. $this->load->_model('Model_specialstock','specialstock');
  14. $this->load->_model('Model_fullorderoutlist','fullorderoutlist');
  15. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg,$arg_array)
  18. {
  19. if($arg == 'edit')
  20. {
  21. $this->_edit($arg_array);
  22. }
  23. else if($arg == 'cz')
  24. {
  25. $this->_cz($arg_array);
  26. }
  27. else if($arg == 'list')
  28. {
  29. $this->_list($arg_array);
  30. }
  31. else
  32. {
  33. $this->_index();
  34. }
  35. }
  36. public function _index()
  37. {
  38. if(isset($_SESSION['api']))
  39. {
  40. $user = $this->user->get_api($_SESSION['api']);
  41. $usp = $user;
  42. $fgshop = "";$sid = "";
  43. $user = explode('|',trim($user['shop'],'|'));
  44. foreach ($user as $value)
  45. {
  46. $fgshop .= " shop = ".$value." or";
  47. $sid .= " id = ".$value." or";
  48. }
  49. }
  50. $post = $this->input->post(NULL, TRUE);
  51. if(isset($post['page']))
  52. {
  53. $page = $this->input->post('page',true);
  54. $perpage = $this->input->post('perpage',true);
  55. $name = $this->input->post('name',true);
  56. $shop = $this->input->post('shop',true);
  57. $number = $this->input->post('number',true);
  58. $orderinfo = $this->input->post('orderinfo',true);
  59. $waybill = $this->input->post('waybill',true);
  60. $timetk = $this->input->post('timetkk',true);
  61. $timetj = $this->input->post('timetjj',true);
  62. $timetk = strtotime($timetk);
  63. $timetj = strtotime($timetj);
  64. $where = "1 = 1";
  65. if($timetk && $timetj)
  66. {
  67. $where .= " and stime > '$timetk' and stime < '$timetj'";
  68. }
  69. if($name)
  70. {
  71. $where .= " and name = '$name'";
  72. }
  73. if($shop)
  74. {
  75. $where .= " and shop = '$shop'";
  76. }
  77. if($number)
  78. {
  79. $where .= " and number = '$number'";
  80. }
  81. if($orderinfo)
  82. {
  83. $where .= " and orderinfo = '$orderinfo'";
  84. }
  85. if($waybill)
  86. {
  87. $where .= " and waybill = '$waybill'";
  88. }
  89. //数据排序
  90. $order_str = "stime desc";
  91. if(empty($page))
  92. {
  93. $start = 0;
  94. $perpage = 1;
  95. }
  96. else
  97. {
  98. $start = ($page - 1)*$perpage;
  99. }
  100. //取得信息列表
  101. $info_list = $this->fullorderout->find_all($where,'id,shop,name,number,orderinfo,express,waybill,stime',$order_str,$start,$perpage);
  102. foreach ($info_list as $key=>$value)
  103. {
  104. $shop = $this->shop->read($value['shop']);
  105. $info_list[$key]['shop'] = $shop['shopname'];
  106. $express = $this->express->read($value['express']);
  107. $info_list[$key]['express'] = $express['servicename'];
  108. $info_list[$key]['stime'] = date('Y-d-m H:i:s',$value['stime']);
  109. }
  110. $total = $this->fullorderout->find_count($where);
  111. $pagenum = ceil($total/$perpage);
  112. $over = $total-($start+$perpage);
  113. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  114. echo json_encode($rows);exit;
  115. }
  116. if(isset($post['hq']))
  117. {
  118. $label = $this->input->post('hq',true);
  119. $warehouse = $this->input->post('warehouse',true);
  120. if(!$label)
  121. {
  122. echo json_encode(array('msg'=>'输入信息不能为空!','success'=>false));exit;
  123. }
  124. $fullorder_name = 'fullorder';$outtype = 1;
  125. $y = $this->fullorder->get_waybill($label);
  126. if(!$y)
  127. {
  128. $y = $this->fullorder->get_number($label);
  129. if(!$y)
  130. {
  131. $fullorder_name = 'fullordersmt';$outtype = 1;
  132. $y = $this->fullordersmt->get_waybill($label);
  133. if(!$y)
  134. {
  135. $y = $this->fullordersmt->get_number($label);
  136. if(!$y)
  137. {
  138. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  139. }
  140. }
  141. }
  142. }
  143. $y['stime'] = time();
  144. unset($y['id']);
  145. $fpdata = explode(';',rtrim($y['fpdata'],';'));
  146. $y['fpdata'] = '';
  147. foreach ($fpdata as $k=>$v)
  148. {
  149. $d = explode('|',$v);
  150. $c = $d[2];
  151. for($i=0;$i<$c;$i++)
  152. {
  153. $d['2'] = 0;
  154. $d['3'] = '';
  155. $y['fpdata'] .= implode("|",$d).';';
  156. }
  157. }
  158. $whlabellist = '|';
  159. $whlabel = explode('|',trim($y['whlabel'],'|'));
  160. foreach ($whlabel as $k=>$v)
  161. {
  162. $d = explode('-',$v);
  163. $c = $d[1];
  164. for($i=0;$i<$c;$i++)
  165. {
  166. $d['1'] = 1;
  167. $whlabellist .= implode("-",$d).'|';
  168. }
  169. }
  170. $y['whlabel'] = $whlabellist;
  171. $y['content'] = '';
  172. if($this->fullorderout->insert($y))
  173. {
  174. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  175. }
  176. else
  177. {
  178. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  179. }
  180. }
  181. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  182. $this->data['wlshop'] = $wlshop;
  183. $this->_Template('fullorderout',$this->data);
  184. }
  185. public function _edit($arg_array)
  186. {
  187. if(isset($_SESSION['api']))
  188. {
  189. $user = $this->user->get_api($_SESSION['api']);
  190. if($user['vip'] == 1)
  191. {
  192. $vip = 1;
  193. }
  194. else
  195. {
  196. $vip = 0;
  197. }
  198. }
  199. else
  200. {
  201. $vip = 0;
  202. }
  203. $post = $this->input->post(NULL, TRUE);
  204. if(isset($post['id']))
  205. {
  206. $id = $this->input->post('id',true);
  207. $data = $this->fullorderout->read($id);
  208. $content = $this->input->post('content',true);
  209. $fpdata = $this->input->post('fpdata',true);
  210. $torderinfo = $this->input->post('torderinfo',true);
  211. $thexpress = $this->input->post('thexpress',true);
  212. $fpdata = preg_replace(array('/(\_+)/'),array(' '),$fpdata);
  213. $fpdata =str_replace(array(' |','| '),array('|','|'),$fpdata);
  214. $number = $this->input->post('number',true);
  215. $whlabel = $data['whlabel'];
  216. $whlabellist = explode('|',trim($whlabel,'|'));
  217. $fpdatalist = explode(';',rtrim($fpdata,';'));
  218. $asd = array();
  219. $this->db->trans_begin();
  220. foreach ($whlabellist as $k=>$v)
  221. {
  222. $list = $this->fullorderoutlist->get_u($number,$v,$k);
  223. if($list)
  224. {
  225. $read = explode('|',trim($fpdatalist[$k],'|'));
  226. $this->fullorderoutlist->save(array('content'=>$content,'fpdata'=>$fpdatalist[$k],'torderinfo'=>$torderinfo,'thexpress'=>$thexpress,'fd'=>$read[3]),$list['id']);
  227. }
  228. }
  229. $this->fullorderout->save(array('content'=>$content,'fpdata'=>$fpdata,'torderinfo'=>$torderinfo,'thexpress'=>$thexpress),$id);
  230. if ($this->db->trans_status() === TRUE)
  231. {
  232. $this->db->trans_commit();
  233. echo json_encode(array('msg'=>'提交成功','id'=>$id,'asd'=>$whlabellist,'success'=>true));exit;
  234. }
  235. else
  236. {
  237. $this->db->trans_rollback();
  238. echo json_encode(array('msg'=>'提交失败,请重试','success'=>false));exit;
  239. }
  240. }
  241. $arg_array = $arg_array[0];$fpdata = array();
  242. $fullorder = $this->fullorderout->read($arg_array);
  243. $this->data['fullorder'] = $fullorder;
  244. $shop = $this->shop->read($fullorder['shop']);
  245. $this->data['shop'] = $shop['shopname'];
  246. $express = $this->express->read($fullorder['express']);
  247. $this->data['express'] = $express['servicename'];
  248. $country = $this->country->read($fullorder['country']);
  249. $this->data['country'] = $country['ename'];$f = array();
  250. $whlabel = explode('|',trim($fullorder['whlabel'],'|'));
  251. $fpdata = explode(';',rtrim($fullorder['fpdata'],';'));
  252. foreach ($fpdata as $k=>$v)
  253. {
  254. $d = explode('|',$v);
  255. $d['w'] = $whlabel[$k];
  256. $f[] = $d;
  257. }
  258. $this->data['fpdata'] = $f;
  259. $this->_Template('fullorderout_edit',$this->data);
  260. }
  261. public function _cz()
  262. {
  263. $post = $this->input->post(NULL, TRUE);
  264. if(isset($post['czid']))
  265. {
  266. $time = time();
  267. $czid = $this->input->post('czid',true);
  268. $whlabel = $this->input->post('whlabel',true);
  269. $number = $this->input->post('number',true);
  270. $x = $this->input->post('x',true);
  271. $data = $this->fullorderout->get_number($number);
  272. $fpdata = explode(';',rtrim($data['fpdata'],';'));
  273. $title = array(1=>'加入库存',2=>'退回国内',3=>'美仓销售',4=>'货物错误',5=>'待入库存');
  274. $d = explode('|',$fpdata[$x]);
  275. $d[2] = $czid;
  276. $fpdata[$x] = implode("|",$d);
  277. $this->db->trans_begin();
  278. $k = 0;
  279. if($czid == 1)
  280. {
  281. $k = explode('-',$whlabel);
  282. if($k[2] == 'z')//特殊库存
  283. {
  284. $t = $this->specialstock->get_cxzd($k[0],$number);
  285. if($t)
  286. {
  287. $this->specialstock->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$t['id']);
  288. $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']);
  289. }
  290. else
  291. {
  292. $d[2] = 5;
  293. $fpdata[$x] = implode("|",$d);
  294. $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']);
  295. }
  296. }
  297. else
  298. {
  299. $t = $this->whlabel->get_cxzd($k[0],$number);
  300. if($t)
  301. {
  302. $this->whlabel->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$t['id']);
  303. $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']);
  304. }
  305. else
  306. {
  307. $d[2] = 5;
  308. $fpdata[$x] = implode("|",$d);
  309. $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']);
  310. }
  311. }
  312. $post = $data;
  313. $post['pzt'] = $d[2];
  314. $post['fpdata'] = $fpdata[$x];
  315. $post['whlabel'] = $whlabel;
  316. $post['time'] = time();
  317. $post['num'] = $x;
  318. unset($post['id']);
  319. $this->fullorderoutlist->insert($post);
  320. if ($this->db->trans_status() === TRUE)
  321. {
  322. $this->db->trans_commit();
  323. echo json_encode(array('msg'=>'操作成功!','id'=>$d[2],'title'=>$title[$d[2]],'x'=>$x,'success'=>true));exit;
  324. }
  325. else
  326. {
  327. $this->db->trans_rollback();
  328. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  329. }
  330. }
  331. else
  332. {
  333. $post = $data;
  334. $post['pzt'] = $czid;
  335. $post['fpdata'] = $fpdata[$x];
  336. $post['whlabel'] = $whlabel;
  337. $post['time'] = time();
  338. $post['num'] = $x;
  339. unset($post['id']);
  340. $this->fullorderoutlist->insert($post);
  341. $this->fullorderout->save(array('fpdata'=>implode(";",$fpdata).';'),$data['id']);
  342. if ($this->db->trans_status() === TRUE)
  343. {
  344. $this->db->trans_commit();
  345. echo json_encode(array('msg'=>'操作成功!','id'=>$czid,'title'=>$title[$czid],'x'=>$x,'success'=>true));exit;
  346. }
  347. else
  348. {
  349. $this->db->trans_rollback();
  350. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  351. }
  352. }
  353. }
  354. }
  355. public function _list()
  356. {
  357. if(isset($_SESSION['api']))
  358. {
  359. $user = $this->user->get_api($_SESSION['api']);
  360. $usp = $user;
  361. $fgshop = "";$sid = "";
  362. $user = explode('|',trim($user['shop'],'|'));
  363. foreach ($user as $value)
  364. {
  365. $fgshop .= " shop = ".$value." or";
  366. $sid .= " id = ".$value." or";
  367. }
  368. }
  369. $post = $this->input->post(NULL, TRUE);
  370. if(isset($post['page']))
  371. {
  372. $page = $this->input->post('page',true);
  373. $perpage = $this->input->post('perpage',true);
  374. $name = $this->input->post('name',true);
  375. $shop = $this->input->post('shop',true);
  376. $number = $this->input->post('number',true);
  377. $orderinfo = $this->input->post('orderinfo',true);
  378. $waybill = $this->input->post('waybill',true);
  379. $pzt = $this->input->post('pzt',true);
  380. $timetk = $this->input->post('timetkk',true);
  381. $timetj = $this->input->post('timetjj',true);
  382. $timetk = strtotime($timetk);
  383. $timetj = strtotime($timetj);
  384. $where = "1 = 1";
  385. if($timetk && $timetj)
  386. {
  387. $where .= " and stime > '$timetk' and stime < '$timetj'";
  388. }
  389. if($name)
  390. {
  391. $where .= " and name = '$name'";
  392. }
  393. if($shop)
  394. {
  395. $where .= " and shop = '$shop'";
  396. }
  397. if($number)
  398. {
  399. $where .= " and number = '$number'";
  400. }
  401. if($orderinfo)
  402. {
  403. $where .= " and orderinfo = '$orderinfo'";
  404. }
  405. if($waybill)
  406. {
  407. $where .= " and waybill = '$waybill'";
  408. }
  409. if($pzt)
  410. {
  411. $where .= " and pzt = '$pzt'";
  412. }
  413. //数据排序
  414. $order_str = "stime desc";
  415. if(empty($page))
  416. {
  417. $start = 0;
  418. $perpage = 1;
  419. }
  420. else
  421. {
  422. $start = ($page - 1)*$perpage;
  423. }
  424. //取得信息列表
  425. $info_list = $this->fullorderoutlist->find_all($where,'id,shop,pzt,number,fpdata,fd,stime',$order_str,$start,$perpage);
  426. foreach ($info_list as $key=>$value)
  427. {
  428. if($value['pzt'] == 1)
  429. {
  430. $info_list[$key]['pzt'] = '加入库存';
  431. }
  432. else if($value['pzt'] == 2)
  433. {
  434. $info_list[$key]['pzt'] = '退回国内';
  435. }
  436. else if($value['pzt'] == 3)
  437. {
  438. $info_list[$key]['pzt'] = '美仓销售';
  439. }
  440. else if($value['pzt'] == 4)
  441. {
  442. $info_list[$key]['pzt'] = '货物错误';
  443. }
  444. else if($value['pzt'] == 5)
  445. {
  446. $info_list[$key]['pzt'] = '待入库存';
  447. }
  448. $shop = $this->shop->read($value['shop']);
  449. $info_list[$key]['shop'] = $shop['shopname'];
  450. $title = explode('|',trim($value['fpdata'],'|'));
  451. $info_list[$key]['fpdata'] = $title[1];
  452. $info_list[$key]['stime'] = date('Y-d-m H:i:s',$value['stime']);
  453. }
  454. $total = $this->fullorderoutlist->find_count($where);
  455. $pagenum = ceil($total/$perpage);
  456. $over = $total-($start+$perpage);
  457. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  458. echo json_encode($rows);exit;
  459. }
  460. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  461. $this->data['wlshop'] = $wlshop;
  462. $this->_Template('fullorderoutlist',$this->data);
  463. }
  464. }