Purchaseorder.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Purchaseorder extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_purchaseorder','purchaseorder');
  7. $this->load->_model('Model_purchase','purchase');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_typeclass','typeclass');
  10. $this->load->_model('Model_express','express');
  11. $this->load->_model('Model_country','country');
  12. $this->load->_model('Model_productdescribe','productdescribe');
  13. $this->load->_model('Model_customs','customs');
  14. $this->load->_model('Model_detailed','detailed');
  15. $this->load->_model('Model_productdescription','productdescription');
  16. $this->load->_model('Model_logistics','logistics');
  17. $this->load->_model('Model_hl','hl');
  18. $this->load->_model('Model_excel','excel');
  19. $this->load->_model('Model_warehouse','warehouse');
  20. }
  21. //定义方法的调用规则 获取URI第二段值
  22. public function _remap($arg,$arg_array)
  23. {
  24. if($arg == 'add')//添加
  25. {
  26. $this->_add();
  27. }
  28. else if($arg == 'edit')//修改
  29. {
  30. $this->_edit($arg_array);
  31. }
  32. else if($arg == 'price')//获取供应商价格表
  33. {
  34. $this->_price();
  35. }
  36. else if($arg == 'del')//修改
  37. {
  38. $this->_del();
  39. }
  40. else if($arg == 'describe')
  41. {
  42. $this->_describe();
  43. }
  44. else if($arg == 'list')
  45. {
  46. $this->_list();
  47. }
  48. else if($arg == 'monitor')
  49. {
  50. $this->_monitor();
  51. }
  52. else if($arg == 'lssue')
  53. {
  54. $this->_lssue();
  55. }
  56. else
  57. {
  58. $this->_index();
  59. }
  60. }
  61. //管理
  62. public function _index()
  63. {
  64. $post = $this->input->post(NULL, TRUE);
  65. if(isset($post['page']))
  66. {
  67. $page = $this->input->post('page',true);
  68. $perpage = $this->input->post('perpage',true);
  69. $purchase = $this->input->post('purchase',true);//供应商
  70. $orderinfo = $this->input->post('orderinfo',true);//订单号
  71. $type = $this->input->post('type',true);//订单状态
  72. $ktime = $this->input->post('ktime',true);
  73. $jtime = $this->input->post('jtime',true);
  74. $ktime = strtotime($ktime);
  75. $jtime = strtotime($jtime);
  76. $where = "1=1";
  77. if($purchase)
  78. {
  79. $where .= " and purchase = '$purchase'";
  80. }
  81. if($ktime && $jtime)
  82. {
  83. $where .= " and addtime > '$ktime' and addtime < '$jtime'";
  84. }
  85. if($orderinfo)
  86. {
  87. $where .= " and orderinfo = '$orderinfo'";
  88. }
  89. if($type)
  90. {
  91. $where .= " and type = '$type'";
  92. }
  93. //数据排序
  94. $order_str = "id desc";
  95. if(empty($page))
  96. {
  97. $start = 0;
  98. $perpage = 1;
  99. }
  100. else
  101. {
  102. $start = ($page - 1)*$perpage;
  103. }
  104. //取得信息列表
  105. $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,monitor',$order_str,$start,$perpage);
  106. //格式化数据
  107. foreach ($info_list as $key=>$value)
  108. {
  109. $purchase = $this->purchase->read($value['purchase']);
  110. $info_list[$key]['purchase'] = $purchase['title'];
  111. if($value['type'] == 1)
  112. {
  113. $info_list[$key]['type'] = "待发货";
  114. }
  115. else if($value['type'] == 2)
  116. {
  117. $info_list[$key]['type'] = "已发货";
  118. }
  119. else if($value['type'] == 3)
  120. {
  121. $info_list[$key]['type'] = "已验收";
  122. }
  123. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  124. $info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);
  125. if($value['monitor'] == 0)
  126. {
  127. $info_list[$key]['monitor'] = "";
  128. }
  129. else
  130. {
  131. $info_list[$key]['monitor'] = date('Y-m-d H:i:s',$value['monitor']);
  132. }
  133. }
  134. $total = $this->purchaseorder->find_count($where);
  135. $pagenum = ceil($total/$perpage);
  136. $over = $total-($start+$perpage);
  137. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  138. echo json_encode($rows);exit;
  139. }
  140. $this->data['purchase'] = $this->purchase->find_all();
  141. $this->_Template('purchaseorder',$this->data);
  142. }
  143. //管理
  144. public function _list()
  145. {
  146. $this->_Template('purchaseorder_list',$this->data);
  147. }
  148. //添加
  149. public function _add()
  150. {
  151. $post = $this->input->post(NULL, TRUE);
  152. if(isset($post['purchase']))
  153. {
  154. $post['purchase'] = $this->input->post('purchase',true);
  155. $post['price'] = $this->input->post('price',true);
  156. $post['warehouse'] = $this->input->post('warehouse',true);
  157. $time = $this->input->post('time',true);
  158. $post['time'] = strtotime($time);
  159. $post['money'] = $this->input->post('money',true);
  160. $post['content'] = $this->input->post('content',true);
  161. $post['client'] = $this->input->post('client');
  162. $post['name'] = $this->input->post('name',true);
  163. $post['phone'] = $this->input->post('phone',true);
  164. $post['country'] = $this->input->post('country',true);
  165. $post['province'] = $this->input->post('province',true);
  166. $post['city'] = $this->input->post('city',true);
  167. $post['zipcode'] = $this->input->post('zipcode',true);
  168. $post['street'] = $this->input->post('street',true);
  169. $post['address'] = $this->input->post('address',true);
  170. $post['express'] = $this->input->post('express',true);
  171. $post['product'] = $this->input->post('fpdata',true);
  172. $post['orderinfo'] = date('Ymd',time()).rand(100,999);
  173. $post['addtime'] = time();
  174. if($this->purchaseorder->insert($post))
  175. {
  176. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  177. }
  178. else
  179. {
  180. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  181. }
  182. }
  183. $country = $this->country->find_all('1=1','id,name');//所有国家信息
  184. $this->data['country'] = $country;
  185. $purchase = $this->purchase->find_all('1=1','id,title');
  186. $this->data['purchase'] = $purchase;
  187. $this->_Template('purchaseorder_add',$this->data);
  188. //$price = explode('|',trim($purchase['price'],'|'));//数组化权限内容
  189. //$pricetitle = explode('|',trim($purchase['pricetitle'],'|'));//数组化权限内容
  190. }
  191. //修改
  192. public function _edit($arg_array)
  193. {
  194. $post = $this->input->post(NULL, TRUE);
  195. if(isset($post['id']))
  196. {
  197. $id = $this->input->post('id',true);
  198. $post['purchase'] = $this->input->post('purchase',true);
  199. $post['price'] = $this->input->post('price',true);
  200. $post['warehouse'] = $this->input->post('warehouse',true);
  201. $time = $this->input->post('time',true);
  202. $post['time'] = strtotime($time);
  203. $post['money'] = $this->input->post('money',true);
  204. $post['content'] = $this->input->post('content',true);
  205. $post['client'] = $this->input->post('client');
  206. $post['name'] = $this->input->post('name',true);
  207. $post['phone'] = $this->input->post('phone',true);
  208. $post['country'] = $this->input->post('country',true);
  209. $post['province'] = $this->input->post('province',true);
  210. $post['city'] = $this->input->post('city',true);
  211. $post['zipcode'] = $this->input->post('zipcode',true);
  212. $post['street'] = $this->input->post('street',true);
  213. $post['address'] = $this->input->post('address',true);
  214. $post['express'] = $this->input->post('express',true);
  215. $post['product'] = $this->input->post('fpdata',true);
  216. if($this->purchaseorder->save($post,$id))
  217. {
  218. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  219. }
  220. else
  221. {
  222. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  223. }
  224. }
  225. $arg_array = $arg_array[0];
  226. $purchaseorder = $this->purchaseorder->read($arg_array);
  227. $country = $this->country->find_all('1=1','id,name');//所有国家信息
  228. $this->data['purchaseorder'] = $purchaseorder;
  229. //获取供应商价格表开始
  230. $data = $this->purchase->read($purchaseorder['purchase']);
  231. $priceid = explode('|',rtrim($data['price'],'|'));//数组内容
  232. $pricetitle = explode('|',rtrim($data['pricetitle'],'|'));//数组内容
  233. $price = array();
  234. for($i=0;$i<count($priceid);$i++)
  235. {
  236. $price[] = array('id'=>$priceid[$i],'title'=>$pricetitle[$i]);
  237. }
  238. //获取供应商价格表结束
  239. $purchase = $this->purchase->find_all('1=1','id,title');
  240. $this->data['purchase'] = $purchase;
  241. $this->data['price'] = $price;
  242. $this->data['country'] = $country;
  243. $fpdata = explode('*',rtrim($purchaseorder['product'],'*'));
  244. foreach ($fpdata as $k=>$v)
  245. {
  246. $fpdata[$k] = explode('|',$v);
  247. }
  248. $this->data['fpdata'] = $fpdata;
  249. $this->_Template('purchaseorder_edit',$this->data);
  250. }
  251. //查找供应商价格表
  252. public function _price()
  253. {
  254. $post = $this->input->post(NULL, TRUE);
  255. if(isset($post['id']))
  256. {
  257. $id = $this->input->post('id',true);
  258. $data = $this->purchase->read($id);
  259. $priceid = explode('|',rtrim($data['price'],'|'));//数组内容
  260. $pricetitle = explode('|',rtrim($data['pricetitle'],'|'));//数组内容
  261. $price = array();
  262. for($i=0;$i<count($priceid);$i++)
  263. {
  264. $price[] = array('id'=>$priceid[$i],'title'=>$pricetitle[$i]);
  265. }
  266. echo json_encode(array('msg'=>($price),'success'=>true));exit;
  267. }
  268. }
  269. //查找商品价格
  270. public function _describe()
  271. {
  272. $post = $this->input->post(NULL, TRUE);
  273. if(isset($post['data']))
  274. {
  275. $data = $this->input->post('data');
  276. $priceid = $this->input->post('priceid');
  277. $data = explode('-',$data);
  278. $number = '';$num = count($data);
  279. //循环删除记录
  280. for($i=0;$i<$num-1;$i++)
  281. {
  282. if($data[$i] != 0)
  283. {
  284. $number=$number.$data[$i];
  285. if($i == 2)
  286. {
  287. $number=$number.$data[$num-1];
  288. }
  289. }
  290. }
  291. $list = $this->productdescribe->get_price($priceid,$number);
  292. if($list)
  293. {
  294. echo json_encode(array('msg'=>($list),'n'=>$data[$num-1],'success'=>true));
  295. }
  296. else
  297. {
  298. echo json_encode(array('msg'=>'此信息没有配置价格!','n'=>$data[$num-1],'success'=>false));exit;
  299. }
  300. }
  301. }
  302. //删除
  303. public function _del()
  304. {
  305. $post = $this->input->post(NULL, TRUE);
  306. if(isset($post['s']))
  307. {
  308. $id_arr = $this->input->post('s');
  309. $id_arr = explode(',',$id_arr);
  310. if(!$id_arr)
  311. {
  312. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  313. }
  314. //循环删除记录
  315. foreach ($id_arr as $v)
  316. {
  317. $this->purchaseorder->remove($v);
  318. }
  319. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  320. }
  321. }
  322. //管理
  323. public function _lssue()
  324. {
  325. $post = $this->input->post(NULL, TRUE);
  326. if(isset($post['id']))
  327. {
  328. $id = $this->input->post('id',true);
  329. if($this->purchaseorder->save(array('type'=>2,'lssue'=>time()),$id))
  330. {
  331. echo json_encode(array('msg'=>'操作成功','id'=>$id,'success'=>true));exit;
  332. }
  333. else
  334. {
  335. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  336. }
  337. }
  338. if(isset($post['page']))
  339. {
  340. $page = $this->input->post('page',true);
  341. $perpage = $this->input->post('perpage',true);
  342. $purchase = $this->input->post('purchase',true);//供应商
  343. $orderinfo = $this->input->post('orderinfo',true);//订单号
  344. $type = $this->input->post('type',true);//订单状态
  345. $ktime = $this->input->post('ktime',true);
  346. $jtime = $this->input->post('jtime',true);
  347. $ktime = strtotime($ktime);
  348. $jtime = strtotime($jtime);
  349. $where = "1=1 and type = 1";
  350. if($purchase)
  351. {
  352. $where .= " and purchase = '$purchase'";
  353. }
  354. if($ktime && $jtime)
  355. {
  356. $where .= " and addtime > '$ktime' and addtime < '$jtime'";
  357. }
  358. if($orderinfo)
  359. {
  360. $where .= " and orderinfo = '$orderinfo'";
  361. }
  362. if($type)
  363. {
  364. $where .= " and type = '$type'";
  365. }
  366. //数据排序
  367. $order_str = "id desc";
  368. if(empty($page))
  369. {
  370. $start = 0;
  371. $perpage = 1;
  372. }
  373. else
  374. {
  375. $start = ($page - 1)*$perpage;
  376. }
  377. //取得信息列表
  378. $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,currency',$order_str,$start,$perpage);
  379. //格式化数据
  380. foreach ($info_list as $key=>$value)
  381. {
  382. $purchase = $this->purchase->read($value['purchase']);
  383. $info_list[$key]['purchase'] = $purchase['title'];
  384. if($value['type'] == 1)
  385. {
  386. $info_list[$key]['type'] = "待发货";
  387. }
  388. else if($value['type'] == 2)
  389. {
  390. $info_list[$key]['type'] = "已发货";
  391. }
  392. else if($value['type'] == 3)
  393. {
  394. $info_list[$key]['type'] = "已验收";
  395. }
  396. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  397. $info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);
  398. $info_list[$key]['currency'] = "<p><b class='purchaseorder' data-id='".$value['id']."'>标记为已发货</b></p>";
  399. }
  400. $total = $this->purchaseorder->find_count($where);
  401. $pagenum = ceil($total/$perpage);
  402. $over = $total-($start+$perpage);
  403. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  404. echo json_encode($rows);exit;
  405. }
  406. $this->data['purchase'] = $this->purchase->find_all();
  407. $this->_Template('purchaseorder_lssue',$this->data);
  408. }
  409. //管理
  410. public function _monitor()
  411. {
  412. $post = $this->input->post(NULL, TRUE);
  413. if(isset($post['id']))
  414. {
  415. $id = $this->input->post('id',true);
  416. if($this->purchaseorder->save(array('type'=>3,'monitor'=>time()),$id))
  417. {
  418. echo json_encode(array('msg'=>'操作成功','id'=>$id,'success'=>true));exit;
  419. }
  420. else
  421. {
  422. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  423. }
  424. }
  425. if(isset($post['page']))
  426. {
  427. $page = $this->input->post('page',true);
  428. $perpage = $this->input->post('perpage',true);
  429. $purchase = $this->input->post('purchase',true);//供应商
  430. $orderinfo = $this->input->post('orderinfo',true);//订单号
  431. $type = $this->input->post('type',true);//订单状态
  432. $ktime = $this->input->post('ktime',true);
  433. $jtime = $this->input->post('jtime',true);
  434. $ktime = strtotime($ktime);
  435. $jtime = strtotime($jtime);
  436. $where = "1=1 and type = 2";
  437. if($purchase)
  438. {
  439. $where .= " and purchase = '$purchase'";
  440. }
  441. if($ktime && $jtime)
  442. {
  443. $where .= " and addtime > '$ktime' and addtime < '$jtime'";
  444. }
  445. if($orderinfo)
  446. {
  447. $where .= " and orderinfo = '$orderinfo'";
  448. }
  449. if($type)
  450. {
  451. $where .= " and type = '$type'";
  452. }
  453. //数据排序
  454. $order_str = "id desc";
  455. if(empty($page))
  456. {
  457. $start = 0;
  458. $perpage = 1;
  459. }
  460. else
  461. {
  462. $start = ($page - 1)*$perpage;
  463. }
  464. //取得信息列表
  465. $info_list = $this->purchaseorder->find_all($where,'id,purchase,orderinfo,type,time,addtime,lssue,currency',$order_str,$start,$perpage);
  466. //格式化数据
  467. foreach ($info_list as $key=>$value)
  468. {
  469. $purchase = $this->purchase->read($value['purchase']);
  470. $info_list[$key]['purchase'] = $purchase['title'];
  471. if($value['type'] == 1)
  472. {
  473. $info_list[$key]['type'] = "待发货";
  474. }
  475. else if($value['type'] == 2)
  476. {
  477. $info_list[$key]['type'] = "已发货";
  478. }
  479. else if($value['type'] == 3)
  480. {
  481. $info_list[$key]['type'] = "已验收";
  482. }
  483. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  484. $info_list[$key]['addtime'] = date('Y-m-d H:i:s',$value['addtime']);
  485. $info_list[$key]['lssue'] = date('Y-m-d H:i:s',$value['lssue']);
  486. $info_list[$key]['currency'] = "<p><b class='purchaseorder' data-id='".$value['id']."'>标记为已验收</b></p>";
  487. }
  488. $total = $this->purchaseorder->find_count($where);
  489. $pagenum = ceil($total/$perpage);
  490. $over = $total-($start+$perpage);
  491. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  492. echo json_encode($rows);exit;
  493. }
  494. $this->data['purchase'] = $this->purchase->find_all();
  495. $this->_Template('purchaseorder_monitor',$this->data);
  496. }
  497. }