Systemretreat.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Systemretreat extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_whlabel','whlabel');
  8. $this->load->_model('Model_warehouse','warehouse');
  9. $this->load->_model('Model_excel','excel');
  10. $this->load->_model('Model_fullorder','fullorder');
  11. $this->load->_model('Model_fullordertt','fullordertt');
  12. $this->load->_model('Model_fullordersmt','fullordersmt');
  13. $this->load->_model('Model_outbound','outbound');
  14. $this->load->_model('Model_express','express');
  15. $this->load->_model('Model_shop','shop');
  16. $this->load->_model('Model_typeclass','typeclass');
  17. $this->load->_model('Model_country','country');
  18. $this->load->_model('Model_kdniao','kdniao');
  19. $this->load->_model('Model_notice','notice');
  20. $this->load->_model('Model_dhl','dhl');
  21. $this->load->_model('Model_usps','usps');
  22. $this->load->_model('Model_fedex','fedex');
  23. $this->load->_model('Model_ups','ups');
  24. $this->load->_model('Model_ali','ali');
  25. $this->load->_model('Model_dpd','dpd');
  26. $this->load->_model('Model_shop','shop');
  27. $this->load->_model('Model_user','user');
  28. $this->load->_model('Model_whlabel','whlabel');
  29. $this->load->_model('Model_specialstock','specialstock');
  30. $this->load->helper('url');
  31. }
  32. //定义方法的调用规则 获取URI第二段值
  33. public function _remap($arg,$arg_array)
  34. {
  35. if($arg == 'out')
  36. {
  37. $this->_out();
  38. }
  39. else
  40. {
  41. $this->_index();
  42. }
  43. }
  44. public function _out()
  45. {
  46. $post = $this->input->post(NULL, TRUE);
  47. if(isset($post['order']))
  48. {
  49. $time = time();
  50. $order = $this->input->post('order',true);
  51. if(substr($order,0,3) == '788' && substr($order,-4,4) == '0430')//Fedex联邦
  52. {
  53. $order = substr($order,0,12);
  54. }
  55. $y = $this->fullorder->get_waybill($order);
  56. $fullorder_name = 'fullorder';
  57. if(!$y)
  58. {
  59. $y = $this->fullorder->get_number($order);
  60. if(!$y)
  61. {
  62. $fullorder_name = 'fullordersmt';
  63. $y = $this->fullordersmt->get_waybill($order);
  64. if(!$y)
  65. {
  66. $y = $this->fullordersmt->get_number($order);
  67. if(!$y)
  68. {
  69. if(!$y)
  70. {
  71. $fullorder_name = 'fullordertt';
  72. $y = $this->fullordertt->get_waybill($order);
  73. if(!$y)
  74. {
  75. $y = $this->fullordertt->get_number($order);
  76. if(!$y)
  77. {
  78. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. if($y['library'] == 3)
  87. {
  88. //echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['retreattime']).' 已操作','success'=>false));exit;
  89. }
  90. if($y['library'] == 1)
  91. {
  92. echo json_encode(array('msg'=>'此数据未出库','success'=>false));exit;
  93. }
  94. $warehouse = $this->warehouse->read($y['type']);
  95. $this->db->trans_begin();
  96. if($warehouse['zd'] == '1')
  97. {
  98. $wl = $this->whlabel->find_all("zd = '".$y['number']."'");//查找是否有占用库存情况
  99. if($wl)//如果有那么清除所有占用
  100. {
  101. foreach ($wl as $v)
  102. {
  103. $this->whlabel->save(array('state'=>0,'zd'=>'','retreat'=>$time,'time'=>$time),$v['id']);//专属
  104. }
  105. }
  106. }
  107. if(stripos($y['whlabel'],'z|') !== false)
  108. {
  109. $wl = $this->specialstock->find_all("zd = '".$y['number']."'");
  110. if($wl)//如果有那么清除所有占用
  111. {
  112. foreach ($wl as $v)
  113. {
  114. $this->specialstock->save(array('state'=>0,'zd'=>'','retreat'=>$time,'time'=>$time),$v['id']);
  115. }
  116. }
  117. }
  118. $hbcfw = explode('|',trim($y['whlabel'],'|'));
  119. $hbcff = explode(';',trim($y['fpdata'],';'));
  120. $c = 0;
  121. $hbw = array();
  122. $hbf = array();
  123. for($i=0;$i<count($hbcfw);$i++)
  124. {
  125. $w = explode('-',$hbcfw[$i]);
  126. $f = explode('|',$hbcff[$i]);
  127. $f[9] = 0;
  128. $w[2] = 0;
  129. $hbw[] = implode("-",$w);
  130. $hbf[] = implode("|",$f);
  131. }
  132. $this->$fullorder_name->save(array('whlabel'=>'|'.implode("|",$hbw).'|','fpdata'=>implode(";",$hbf).';'),$y['id']);
  133. $user = $this->user->get_api($_SESSION['api']);
  134. $this->$fullorder_name->save(array('library'=>3,'retreattime'=>$time,'retreatdata'=>$y['retreatdata'].'['.$user['userid'].':'.date('Y-m-d H:i:s',time()).':'.$this->input->ip_address().']-'),$y['id']);
  135. if ($this->db->trans_status() === FALSE)
  136. {
  137. $this->db->trans_commit();
  138. echo json_encode(array('msg'=>'退库失败,请重试','success'=>false));exit;
  139. }
  140. else
  141. {
  142. $this->db->trans_commit();
  143. echo json_encode(array('success'=>true));exit;
  144. }
  145. }
  146. }
  147. public function _index()
  148. {
  149. $post = $this->input->post(NULL, TRUE);
  150. if(isset($_SESSION['api']))
  151. {
  152. $user = $this->user->get_api($_SESSION['api']);
  153. $usp = $user;
  154. $fgshop = "";$sid = "";$wid="";$wtype="";
  155. $usersp = explode('|',trim($user['shop'],'|'));
  156. $userwh = explode('|',trim($user['warehouse'],'|'));
  157. foreach ($usersp as $value)
  158. {
  159. $fgshop .= " shop = ".$value." or";
  160. $sid .= " id = ".$value." or";
  161. }
  162. foreach ($userwh as $value)
  163. {
  164. $wid .= " id = ".$value." or";
  165. $wtype .= " type = ".$value." or";
  166. }
  167. }
  168. if(isset($post['page']))
  169. {
  170. $page = $this->input->post('page',true);
  171. $perpage = $this->input->post('perpage',true);
  172. $timetk = $this->input->post('timetk',true);
  173. $timetj = $this->input->post('timetj',true);
  174. $shop = $this->input->post('shop',true);
  175. $source = $this->input->post('source',true);
  176. $orderinfo = $this->input->post('orderinfo',true);
  177. $number = $this->input->post('number',true);
  178. $waybill = $this->input->post('waybill',true);
  179. $express = $this->input->post('express',true);
  180. $type = $this->input->post('type',true);
  181. $lowe = $this->input->post('lowe',true);
  182. $timetk = strtotime($timetk);
  183. $timetj = strtotime($timetj);
  184. $where = (isset($_SESSION['api']))?"library = 3 and (".rtrim($wtype,'or').")":"id= '0'";
  185. if($timetk && $timetj)
  186. {
  187. $where .= " and retreattime > '$timetk' and retreattime < '$timetj'";
  188. }
  189. if($shop)
  190. {
  191. $where .= " and shop = '$shop'";
  192. }
  193. if($orderinfo)
  194. {
  195. $where .= " and orderinfo = '$orderinfo'";
  196. }
  197. if($number)
  198. {
  199. $where .= " and number = '$number'";
  200. }
  201. if($waybill)
  202. {
  203. $where .= " and waybill = '$waybill'";
  204. }
  205. if($express)
  206. {
  207. $where .= " and express = '$express'";
  208. }
  209. if($orderinfo)
  210. {
  211. $where .= " and orderinfo = '$orderinfo'";
  212. }
  213. if($type)
  214. {
  215. $where .= " and type = '$type'";
  216. }
  217. if($lowe)
  218. {
  219. $where .= " and shipremarks like '%$lowe%'";
  220. }
  221. //数据排序
  222. $order_str = "retreattime desc";
  223. if(empty($page))
  224. {
  225. $start = 0;
  226. $perpage = 1;
  227. }
  228. else
  229. {
  230. $start = ($page - 1)*$perpage;
  231. }
  232. //取得信息列表
  233. $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,state,librarytime,retreattime,shipremarks',$order_str,$start,$perpage);
  234. //格式化数据
  235. foreach ($info_list as $key=>$value)
  236. {
  237. $shop = $this->shop->read($value['shop']);
  238. $info_list[$key]['shop'] = $shop['shopname'];
  239. if($value['waybill'] == 0)
  240. {
  241. $info_list[$key]['waybill'] = "";
  242. }
  243. $express = $this->express->read($value['express']);
  244. $info_list[$key]['express'] = $express['servicename'];
  245. $warehouse = $this->warehouse->read($value['type']);
  246. $info_list[$key]['type'] = $warehouse['title'];
  247. $typeclass = $this->typeclass->read($value['state']);
  248. $info_list[$key]['state'] = $typeclass['spare'];
  249. $info_list[$key]['librarytime'] = date('Y-m-d H:i',$value['librarytime']);
  250. if($value['retreattime'] == '0')
  251. {
  252. $info_list[$key]['retreattime'] = '<em class="t"></em>';
  253. }
  254. else
  255. {
  256. $info_list[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i',$value['retreattime']).'</em>';
  257. }
  258. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['shipremarks']);
  259. }
  260. $info_listtt = $this->fullordertt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);
  261. //格式化数据
  262. foreach ($info_listtt as $key=>$value)
  263. {
  264. $shop = $this->shop->read($value['shop']);
  265. $info_listtt[$key]['shop'] = $shop['shopname'];
  266. if($value['waybill'] == 0)
  267. {
  268. $info_listtt[$key]['waybill'] = "";
  269. }
  270. $express = $this->express->read($value['express']);
  271. $info_listtt[$key]['express'] = $express['servicename'];
  272. $warehouse = $this->warehouse->read($value['type']);
  273. $info_listtt[$key]['type'] = $warehouse['title'];
  274. $typeclass = $this->typeclass->read($value['state']);
  275. $info_listtt[$key]['state'] = $typeclass['spare'];
  276. if($value['print'] == 1)
  277. {
  278. $info_listtt[$key]['print'] = '不可打印';
  279. }
  280. else if($value['print'] == 2)
  281. {
  282. $info_listtt[$key]['print'] = '未打印';
  283. }
  284. else if($value['print'] == 3)
  285. {
  286. $info_listtt[$key]['print'] = '已打印';
  287. }
  288. if($value['retreattime'] == '0')
  289. {
  290. $info_listtt[$key]['retreattime'] = '<em class="t"></em>';
  291. }
  292. else
  293. {
  294. $info_listtt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
  295. }
  296. }
  297. $info_listsmt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);
  298. //格式化数据
  299. foreach ($info_listsmt as $key=>$value)
  300. {
  301. $shop = $this->shop->read($value['shop']);
  302. $info_listsmt[$key]['shop'] = $shop['shopname'];
  303. if($value['waybill'] == 0)
  304. {
  305. $info_listsmt[$key]['waybill'] = "";
  306. }
  307. $express = $this->express->read($value['express']);
  308. $info_listsmt[$key]['express'] = $express['servicename'];
  309. $warehouse = $this->warehouse->read($value['type']);
  310. $info_listsmt[$key]['type'] = $warehouse['title'];
  311. $typeclass = $this->typeclass->read($value['state']);
  312. $info_listsmt[$key]['state'] = $typeclass['spare'];
  313. if($value['print'] == 1)
  314. {
  315. $info_listsmt[$key]['print'] = '不可打印';
  316. }
  317. else if($value['print'] == 2)
  318. {
  319. $info_listsmt[$key]['print'] = '未打印';
  320. }
  321. else if($value['print'] == 3)
  322. {
  323. $info_listsmt[$key]['print'] = '已打印';
  324. }
  325. if($value['retreattime'] == '0')
  326. {
  327. $info_listsmt[$key]['retreattime'] = '<em class="t"></em>';
  328. }
  329. else
  330. {
  331. $info_listsmt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
  332. }
  333. $info_listsmt[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['shipremarks']);
  334. }
  335. $total = $this->fullorder->find_count($where);
  336. $total += $this->fullordertt->find_count($where);
  337. $total += $this->fullordersmt->find_count($where);
  338. $pagenum = ceil($total/$perpage);
  339. $over = $total-($start+$perpage);
  340. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_listtt,$info_listsmt)));//$info_list_smt
  341. echo json_encode($rows);exit;
  342. }
  343. if(isset($_SESSION['api']))
  344. {
  345. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  346. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'));
  347. $this->data['wlshop'] = $wlshop;
  348. $this->data['warehouse'] = $warehouse;
  349. }
  350. $this->_Template('systemretreat',$this->data);
  351. }
  352. }