Orderurl.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Orderurl extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_typeclass','typeclass');
  7. $this->load->_model('Model_orderurl','orderurl');
  8. $this->load->_model('Model_express','express');
  9. $this->load->_model('Model_warehouse','warehouse');
  10. $this->load->_model('Model_shop','shop');
  11. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  12. $this->load->_model('Model_fullorder','fullorder');
  13. $this->load->_model('Model_fullordertt','fullordertt');
  14. $this->load->_model('Model_fullordersmt','fullordersmt');
  15. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg,$arg_array)
  18. {
  19. if($arg == 'add')//添加
  20. {
  21. $this->_add();
  22. }
  23. else if($arg == 'edit')//修改
  24. {
  25. $this->_edit($arg_array);
  26. }
  27. else if($arg == 'del')//修改
  28. {
  29. $this->_del();
  30. }
  31. else if($arg == 'order')//修改
  32. {
  33. $this->_order();
  34. }
  35. else
  36. {
  37. $this->_index();
  38. }
  39. }
  40. public function _index()
  41. {
  42. if(isset($_SESSION['api']))
  43. {
  44. $user = $this->user->get_api($_SESSION['api']);
  45. $usp = $user;
  46. $fgshop = "";$sid = "";
  47. $user = explode('|',trim($user['shop'],'|'));
  48. foreach ($user as $value)
  49. {
  50. $fgshop .= " shop = ".$value." or";
  51. $sid .= " id = ".$value." or";
  52. }
  53. }
  54. $post = $this->input->post(NULL, TRUE);
  55. if(isset($post['page']))
  56. {
  57. $page = $this->input->post('page',true);
  58. $perpage = $this->input->post('perpage',true);
  59. $shop = $this->input->post('shop',true);
  60. $url = $this->input->post('url',true);
  61. $title = $this->input->post('title',true);
  62. $where = "(".rtrim($fgshop,'or').")";
  63. //数据排序
  64. $order_str = "id asc";
  65. if(empty($page))
  66. {
  67. $start = 0;
  68. $perpage = 1;
  69. }
  70. else
  71. {
  72. $start = ($page - 1)*$perpage;
  73. }
  74. if($shop)
  75. {
  76. $where .= " and shop = '$shop'";
  77. }
  78. if($title)
  79. {
  80. $where .= " and title like '%$title%'";
  81. }
  82. if($url)
  83. {
  84. $where .= " and url like '%$url%'";
  85. }
  86. //取得信息列表
  87. $info_list = $this->orderurl->find_all($where,'id,title,url',$order_str,$start,$perpage);
  88. $total = $this->orderurl->find_count($where);
  89. $pagenum = ceil($total/$perpage);
  90. $over = $total-($start+$perpage);
  91. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  92. echo json_encode($rows);exit;
  93. }
  94. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  95. $this->data['wlshop'] = $wlshop;
  96. $this->_Template('orderurl',$this->data);
  97. }
  98. public function _order()
  99. {
  100. if(isset($_SESSION['api']))
  101. {
  102. $user = $this->user->get_api($_SESSION['api']);
  103. $usp = $user;
  104. $fgshop = "";$sid = "";
  105. $user = explode('|',trim($user['shop'],'|'));
  106. foreach ($user as $value)
  107. {
  108. $sid .= " id = ".$value." or";
  109. }
  110. }
  111. else
  112. {
  113. echo "请重新登录";
  114. }
  115. $post = $this->input->post(NULL, TRUE);
  116. if(isset($post['page']))
  117. {
  118. $page = $this->input->post('page',true);
  119. $perpage = $this->input->post('perpage',true);
  120. $warehouse = $this->input->post('warehouse',true);
  121. $xztime = $this->input->post('xztime',true);
  122. $timetk = $this->input->post('timetkk',true);
  123. $timetj = $this->input->post('timetjj',true);
  124. $shop = $this->input->post('shop',true);
  125. $source = $this->input->post('source',true);
  126. $orderinfo = $this->input->post('orderinfo',true);
  127. $number = $this->input->post('number',true);
  128. $sfxh = $this->input->post('sfxh',true);
  129. $express = $this->input->post('express',true);
  130. $waybill = $this->input->post('waybill',true);
  131. $library = $this->input->post('library',true);
  132. $country = $this->input->post('country',true);
  133. $so = $this->input->post('so',true);
  134. $libraryconfirm = $this->input->post('libraryconfirm',true);
  135. $print = $this->input->post('print',true);
  136. $state = $this->input->post('state',true);
  137. $timetk = strtotime($timetk);
  138. $timetj = strtotime($timetj);
  139. /**
  140. $sj = $this->input->post('sj',true);
  141. if($sj)
  142. {
  143. $sj = $this->input->post('sj',true);
  144. }
  145. else
  146. {
  147. $sj = "fullorder";
  148. }
  149. **/
  150. $sj = "fullorder";
  151. $where = "mergeid = 0";
  152. if($warehouse)
  153. {
  154. $where .= " and type = '$warehouse'";
  155. }
  156. if($timetk && $timetj)
  157. {
  158. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  159. }
  160. if($orderinfo)
  161. {
  162. $where .= " and orderinfo = '$orderinfo'";
  163. }
  164. if($number)
  165. {
  166. $where .= " and number = '$number'";
  167. }
  168. if($express)
  169. {
  170. $where .= " and express = '$express'";
  171. }
  172. if($waybill)
  173. {
  174. $where .= " and waybill = '$waybill'";
  175. }
  176. if($library)
  177. {
  178. $where .= " and library = '$library'";
  179. }
  180. if($print)
  181. {
  182. $where .= " and print = '$print'";
  183. }
  184. if($libraryconfirm)
  185. {
  186. $where .= " and libraryconfirm = '$libraryconfirm'";
  187. }
  188. if($state)
  189. {
  190. $where .= " and state = '$state'";
  191. }
  192. if($shop)
  193. {
  194. $where .= " and shop = '$shop'";
  195. }
  196. if($country)
  197. {
  198. $where .= " and country = '$country'";
  199. }
  200. if($sfxh != '')
  201. {
  202. $where .= " and sfxh = '$sfxh'";
  203. }
  204. if($so)
  205. {
  206. $where .= " and shipremarks like '%$so%'";
  207. }
  208. if($source)
  209. {
  210. if($source == '2d')
  211. {
  212. $where .= " and source >= '2'";
  213. }
  214. else
  215. {
  216. $where .= " and source = '$source'";
  217. }
  218. }
  219. if(isset($_SESSION['api']))
  220. {
  221. foreach ($user as $value)
  222. {
  223. $fgshop .= " shop = ".$value." or";
  224. }
  225. $where .= " and (".rtrim($fgshop,'or').")";
  226. }
  227. //数据排序
  228. $order_str = "librarytime desc";
  229. if(empty($page))
  230. {
  231. $start = 0;
  232. $perpage = 1;
  233. }
  234. else
  235. {
  236. $start = ($page - 1)*$perpage;
  237. }
  238. //取得信息列表
  239. $info_list = $this->$sj->find_all($where,'id,shop,type,orderinfo,number,waybill,express,librarytime',$order_str,$start,$perpage);
  240. //格式化数据
  241. foreach ($info_list as $key=>$value)
  242. {
  243. $shop = $this->shop->read($value['shop']);
  244. $info_list[$key]['shop'] = $shop['shopname'];
  245. $express = $this->express->read($value['express']);
  246. $info_list[$key]['express'] = $express['servicename'];
  247. $warehouse = $this->warehouse->read($value['type']);
  248. $info_list[$key]['type'] = $warehouse['title'];
  249. if($value['librarytime'] == '0')
  250. {
  251. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  252. }
  253. else
  254. {
  255. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  256. }
  257. }
  258. $total = $this->$sj->find_count($where);
  259. $pagenum = ceil($total/$perpage);
  260. $over = $total-($start+$perpage);
  261. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  262. echo json_encode($rows);exit;
  263. }
  264. $this->data['express'] = $this->express->find_all();
  265. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  266. $this->data['wlshop'] = $wlshop;
  267. $this->data['fullorderexcel'] = $this->fullorderexcel->find_all('type=2','*','idorder desc');//导出模板
  268. $this->_Template('orderurl_order',$this->data);
  269. }
  270. //添加
  271. public function _add()
  272. {
  273. if(isset($_SESSION['api']))
  274. {
  275. $user = $this->user->get_api($_SESSION['api']);
  276. $usp = $user;
  277. $fgshop = "";$sid = "";
  278. $user = explode('|',trim($user['shop'],'|'));
  279. foreach ($user as $value)
  280. {
  281. $sid .= " id = ".$value." or";
  282. }
  283. }
  284. $post = $this->input->post(NULL, TRUE);
  285. if(isset($post['url']))
  286. {
  287. $d = $this->orderurl->get_url($post['url']);
  288. if($d)
  289. {
  290. echo json_encode(array('msg'=>'已有此链接','success'=>false));exit;
  291. }
  292. if($this->orderurl->insert($post))
  293. {
  294. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  295. }
  296. else
  297. {
  298. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  299. }
  300. }
  301. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  302. $this->data['wlshop'] = $wlshop;
  303. $this->_Template('orderurl_add',$this->data);
  304. }
  305. //修改
  306. public function _edit($arg_array)
  307. {
  308. if(isset($_SESSION['api']))
  309. {
  310. $user = $this->user->get_api($_SESSION['api']);
  311. $usp = $user;
  312. $fgshop = "";$sid = "";
  313. $user = explode('|',trim($user['shop'],'|'));
  314. foreach ($user as $value)
  315. {
  316. $sid .= " id = ".$value." or";
  317. }
  318. }
  319. $post = $this->input->post(NULL, TRUE);
  320. if(isset($post['id']))
  321. {
  322. $id = $this->input->post('id',true);
  323. if($this->orderurl->save($post,$id))
  324. {
  325. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  326. }
  327. else
  328. {
  329. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  330. }
  331. }
  332. $arg_array = $arg_array[0];
  333. $orderurl = $this->orderurl->read($arg_array);
  334. $this->data['orderurl'] = $orderurl;
  335. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  336. $this->data['wlshop'] = $wlshop;
  337. $this->_Template('orderurl_edit',$this->data);
  338. }
  339. //删除
  340. public function _del()
  341. {
  342. $post = $this->input->post(NULL, TRUE);
  343. if(isset($post['s']))
  344. {
  345. $id_arr = $this->input->post('s');
  346. $id_arr = explode(',',$id_arr);
  347. if(!$id_arr)
  348. {
  349. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  350. }
  351. //循环删除记录
  352. foreach ($id_arr as $v)
  353. {
  354. $this->orderurl->remove($v);
  355. }
  356. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  357. }
  358. }
  359. }