Registration.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Registration extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_user','user');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_registration','registration');
  9. $this->load->_model('Model_fullorder','fullorder');
  10. $this->load->_model('Model_fullordertt','fullordertt');
  11. $this->load->_model('Model_fullordersmt','fullordersmt');
  12. $this->load->_model('Model_fullordertt','fullordertt');
  13. $this->load->_model('Model_fullorderam','fullorderam');
  14. $this->load->_model('Model_shop','shop');
  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 == 'rows')//修改
  32. {
  33. $this->_rows();
  34. }
  35. else if($arg == 'see')//修改
  36. {
  37. $this->_see($arg_array);
  38. }
  39. else if($arg == 'order')//修改
  40. {
  41. $this->_order();
  42. }
  43. else
  44. {
  45. $this->_index();
  46. }
  47. }
  48. //管理
  49. public function _index()
  50. {
  51. if(isset($_SESSION['api']))
  52. {
  53. $user = $this->user->get_api($_SESSION['api']);
  54. $usp = $user;
  55. $fgshop = "";$sid = "";
  56. $usersp = explode('|',trim($user['shop'],'|'));
  57. foreach ($usersp as $value)
  58. {
  59. $fgshop .= " shop = ".$value." or";
  60. $sid .= " id = ".$value." or";
  61. }
  62. }
  63. else
  64. {
  65. $vip = 0;
  66. header('Location: /');exit;
  67. }
  68. $post = $this->input->post(NULL, TRUE);
  69. if(isset($post['page']))
  70. {
  71. $page = $this->input->post('page',true);
  72. $perpage = $this->input->post('perpage',true);
  73. $number = $this->input->post('number',true);
  74. $orderinfo = $this->input->post('orderinfo',true);
  75. $state = $this->input->post('state',true);
  76. $objective = $this->input->post('objective',true);
  77. $name = $this->input->post('name',true);
  78. $phone = $this->input->post('phone',true);
  79. $where = "1=1 and (".rtrim($fgshop,'or').")";
  80. //数据排序
  81. $order_str = "id desc";
  82. if(empty($page))
  83. {
  84. $start = 0;
  85. $perpage = 1;
  86. }
  87. else
  88. {
  89. $start = ($page - 1)*$perpage;
  90. }
  91. if($number)
  92. {
  93. $where .= " and number = '$number'";
  94. }
  95. if($orderinfo)
  96. {
  97. $where .= " and orderinfo = '$orderinfo'";
  98. }
  99. if($state)
  100. {
  101. $where .= " and state = '$state'";
  102. }
  103. if($objective)
  104. {
  105. $where .= " and objective = '$objective'";
  106. }
  107. if($name)
  108. {
  109. $where .= " and name like '%$name%'";
  110. }
  111. if($phone)
  112. {
  113. $where .= " and phone like '%$phone%'";
  114. }
  115. //取得信息列表
  116. $info_list = $this->registration->find_all($where,'id,number,state,objective,address,stime,product,name,phone,content,usacontent',$order_str,$start,$perpage);
  117. //格式化数据
  118. foreach ($info_list as $key=>$value)
  119. {
  120. $d = $this->registration->read($value['id']);
  121. if($value['state'] == 1)
  122. {
  123. $info_list[$key]['state'] = '沟通中';
  124. }
  125. else if($value['state'] == 2)
  126. {
  127. $info_list[$key]['state'] = '<font style="color:#F00">待客户上门</font>';
  128. }
  129. else if($value['state'] == 3)
  130. {
  131. $info_list[$key]['state'] = '已自提';
  132. }
  133. else if($value['state'] == 4)
  134. {
  135. $info_list[$key]['state'] = '已退货';
  136. }
  137. else if($value['state'] == 5)
  138. {
  139. $info_list[$key]['state'] = '已换货';
  140. }
  141. if($value['objective'] == 1)
  142. {
  143. $info_list[$key]['objective'] = '仅自提';
  144. }
  145. else if($value['objective'] == 2)
  146. {
  147. $info_list[$key]['objective'] = '仅退货';
  148. }
  149. else if($value['objective'] == 3)
  150. {
  151. $info_list[$key]['objective'] = '退换货';
  152. }
  153. else if($value['objective'] == 4)
  154. {
  155. $info_list[$key]['objective'] = '安装头套';
  156. }
  157. if($value['address'] == 1)
  158. {
  159. $info_list[$key]['address'] = 'BK850';
  160. }
  161. else if($value['address'] == 2)
  162. {
  163. $info_list[$key]['address'] = 'Manhattan819';
  164. }
  165. else if($value['address'] == 3)
  166. {
  167. $info_list[$key]['address'] = 'Flatbush933';
  168. }
  169. $info_list[$key]['number'] = "<p>".$value['number']."</p><p>".$d['orderinfo']."</p>";
  170. if($d['red'] == 1)
  171. {
  172. $info_list[$key]['content'] = "<font style='color:#F00'>".$value['content']."</font>";
  173. }
  174. }
  175. $total = $this->registration->find_count($where);
  176. $pagenum = ceil($total/$perpage);
  177. $over = $total-($start+$perpage);
  178. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  179. echo json_encode($rows);exit;
  180. }
  181. $this->_Template('registration',$this->data);
  182. }
  183. //添加
  184. public function _add()
  185. {
  186. $post = $this->input->post(NULL, TRUE);
  187. if(isset($post['state']))
  188. {
  189. $post['number'] = $this->input->post('number',true);
  190. $post['orderinfo'] = $this->input->post('orderinfo',true);
  191. $post['objective'] = $this->input->post('objective',true);
  192. $post['thproduct'] = $this->input->post('thproduct',true);
  193. if($post['objective'] == 1 && $post['product'] == '')
  194. {
  195. echo json_encode(array('msg'=>'必须填写待取货物!','success'=>false));exit;
  196. }
  197. if($post['objective'] == 2 && $post['thproduct'] == '')
  198. {
  199. echo json_encode(array('msg'=>'必须填写退货货物!','success'=>false));exit;
  200. }
  201. if($post['objective'] == 3 && ($post['thproduct'] == '' || $post['product'] == ''))
  202. {
  203. echo json_encode(array('msg'=>'必须填写待取货物和退货货物!','success'=>false));exit;
  204. }
  205. $f = $this->typeclass->find_all("classid = '32' and id != 2297");
  206. $t = 0;
  207. foreach ($f as $v)
  208. {
  209. $fl = $v['bqsku'];
  210. $b = $this->$fl->get_number($post['number']);
  211. $d = $this->$fl->get_orderinfo($post['orderinfo']);
  212. if($d && $b)
  213. {
  214. $t += 1;
  215. }
  216. }
  217. if($t < 1)
  218. {
  219. echo json_encode(array('msg'=>'编号或订单号填写错误','success'=>false));exit;
  220. }
  221. $red = $this->input->post('red',true);
  222. $post['ted'] = rtrim($red,',');
  223. if($this->registration->insert($post))
  224. {
  225. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  226. }
  227. else
  228. {
  229. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  230. }
  231. }
  232. $this->_Template('registration_add',$this->data);
  233. }
  234. //修改
  235. public function _edit($arg_array)
  236. {
  237. $post = $this->input->post(NULL, TRUE);
  238. if(isset($post['id']))
  239. {
  240. $id = $this->input->post('id',true);
  241. $t = 0;
  242. $post['number'] = $this->input->post('number',true);
  243. $post['orderinfo'] = $this->input->post('orderinfo',true);
  244. $post['objective'] = $this->input->post('objective',true);
  245. $post['thproduct'] = $this->input->post('thproduct',true);
  246. if($post['objective'] == 1 && $post['product'] == '')
  247. {
  248. echo json_encode(array('msg'=>'必须填写待取货物!','success'=>false));exit;
  249. }
  250. if($post['objective'] == 2 && $post['thproduct'] == '')
  251. {
  252. echo json_encode(array('msg'=>'必须填写退货货物!','success'=>false));exit;
  253. }
  254. if($post['objective'] == 3 && ($post['thproduct'] == '' || $post['product'] == ''))
  255. {
  256. echo json_encode(array('msg'=>'必须填写待取货物和退货货物!','success'=>false));exit;
  257. }
  258. $f = $this->typeclass->find_all("classid = '32' and id != 2297");
  259. foreach ($f as $v)
  260. {
  261. $fl = $v['bqsku'];
  262. $b = $this->$fl->get_number($post['number']);
  263. $d = $this->$fl->get_orderinfo($post['orderinfo']);
  264. if($d && $b)
  265. {
  266. $t += 1;
  267. }
  268. }
  269. if($t < 1)
  270. {
  271. echo json_encode(array('msg'=>'编号或订单号填写错误','success'=>false));exit;
  272. }
  273. $red = $this->input->post('red',true);
  274. $post['ted'] = rtrim($red,',');
  275. if($this->registration->save($post,$id))
  276. {
  277. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  278. }
  279. else
  280. {
  281. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  282. }
  283. }
  284. $arg_array = $arg_array[0];
  285. $registration = $this->registration->read($arg_array);
  286. $this->data['registration'] = $registration;
  287. $this->_Template('registration_edit',$this->data);
  288. }
  289. //删除
  290. public function _del()
  291. {
  292. $post = $this->input->post(NULL, TRUE);
  293. if(isset($post['s']))
  294. {
  295. $id_arr = $this->input->post('s');
  296. $id_arr = explode(',',$id_arr);
  297. if(!$id_arr)
  298. {
  299. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  300. }
  301. //循环删除记录
  302. foreach ($id_arr as $v)
  303. {
  304. $this->registration->remove($v);
  305. }
  306. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  307. }
  308. }
  309. //数据
  310. public function _rows()
  311. {
  312. if(isset($_SESSION['api']))
  313. {
  314. $user = $this->user->get_api($_SESSION['api']);
  315. $fgshop = "";
  316. $warehouse = explode('|',trim($user['warehouse'],'|'));
  317. foreach ($warehouse as $value)
  318. {
  319. $fgshop .= " warehouse = ".$value." or";
  320. }
  321. }
  322. else
  323. {
  324. $vip = 0;
  325. header('Location: /');exit;
  326. }
  327. $post = $this->input->post(NULL, TRUE);
  328. if(isset($post['page']))
  329. {
  330. $page = $this->input->post('page',true);
  331. $perpage = $this->input->post('perpage',true);
  332. $number = $this->input->post('number',true);
  333. $orderinfo = $this->input->post('orderinfo',true);
  334. $state = $this->input->post('state',true);
  335. $objective = $this->input->post('objective',true);
  336. $name = $this->input->post('name',true);
  337. $phone = $this->input->post('phone',true);
  338. $where = "1=1 and (".rtrim($fgshop,'or').")";
  339. //数据排序
  340. $order_str = "id desc";
  341. if(empty($page))
  342. {
  343. $start = 0;
  344. $perpage = 1;
  345. }
  346. else
  347. {
  348. $start = ($page - 1)*$perpage;
  349. }
  350. if($number)
  351. {
  352. $where .= " and number = '$number'";
  353. }
  354. if($orderinfo)
  355. {
  356. $where .= " and orderinfo = '$orderinfo'";
  357. }
  358. if($state)
  359. {
  360. $where .= " and state = '$state'";
  361. }
  362. if($objective)
  363. {
  364. $where .= " and objective = '$objective'";
  365. }
  366. if($name)
  367. {
  368. $where .= " and name like '%$name%'";
  369. }
  370. if($phone)
  371. {
  372. $where .= " and phone like '%$phone%'";
  373. }
  374. //取得信息列表
  375. $info_list = $this->registration->find_all($where,'id,number,state,objective,address,stime,product,name,phone,content,usacontent',$order_str,$start,$perpage);
  376. //格式化数据
  377. foreach ($info_list as $key=>$value)
  378. {
  379. $d = $this->registration->read($value['id']);
  380. if($value['state'] == 1)
  381. {
  382. $info_list[$key]['state'] = '沟通中';
  383. }
  384. else if($value['state'] == 2)
  385. {
  386. $info_list[$key]['state'] = '<font style="color:#F00">待客户上门</font>';
  387. }
  388. else if($value['state'] == 3)
  389. {
  390. $info_list[$key]['state'] = '已自提';
  391. }
  392. else if($value['state'] == 4)
  393. {
  394. $info_list[$key]['state'] = '已退货';
  395. }
  396. else if($value['state'] == 5)
  397. {
  398. $info_list[$key]['state'] = '已换货';
  399. }
  400. if($value['objective'] == 1)
  401. {
  402. $info_list[$key]['objective'] = '仅自提';
  403. }
  404. else if($value['objective'] == 2)
  405. {
  406. $info_list[$key]['objective'] = '仅退货';
  407. }
  408. else if($value['objective'] == 3)
  409. {
  410. $info_list[$key]['objective'] = '退换货';
  411. }
  412. else if($value['objective'] == 4)
  413. {
  414. $info_list[$key]['objective'] = '安装头套';
  415. }
  416. if($value['address'] == 1)
  417. {
  418. $info_list[$key]['address'] = 'BK850';
  419. }
  420. else if($value['address'] == 2)
  421. {
  422. $info_list[$key]['address'] = 'Manhattan819';
  423. }
  424. else if($value['address'] == 3)
  425. {
  426. $info_list[$key]['address'] = 'Flatbush933';
  427. }
  428. $info_list[$key]['number'] = "<p>".$value['number']."</p><p>".$d['orderinfo']."</p>";
  429. if($d['red'] == 1)
  430. {
  431. $info_list[$key]['content'] = "<font style='color:#F00'>".$value['content']."</font>";
  432. }
  433. }
  434. $total = $this->registration->find_count($where);
  435. $pagenum = ceil($total/$perpage);
  436. $over = $total-($start+$perpage);
  437. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  438. echo json_encode($rows);exit;
  439. }
  440. $this->_Template('registration_rows',$this->data);
  441. }
  442. public function _see($arg_array)
  443. {
  444. $post = $this->input->post(NULL, TRUE);
  445. if(isset($post['id']))
  446. {
  447. $id = $this->input->post('id',true);
  448. if($this->registration->save($post,$id))
  449. {
  450. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  451. }
  452. else
  453. {
  454. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  455. }
  456. }
  457. $arg_array = $arg_array[0];
  458. $product = '';
  459. $registration = $this->registration->read($arg_array);
  460. $lk = explode(',',rtrim($registration['url'],','));
  461. for($i=0;$i<count($lk);$i++)
  462. {
  463. $product .= '<a href="'.$lk[$i].'" target="_blank">'.$lk[$i].'</a>,';
  464. }
  465. $registration['url'] = rtrim($product,',');
  466. $this->data['registration'] = $registration;
  467. $this->_Template('registration_see',$this->data);
  468. }
  469. public function _order()
  470. {
  471. $post = $this->input->post(NULL, TRUE);
  472. if(isset($post['number']))
  473. {
  474. $data = array();
  475. $f = $this->typeclass->find_all("classid = '32' and id != 2297");
  476. $number = $this->input->post('number',true);
  477. foreach ($f as $v)
  478. {
  479. $fl = $v['bqsku'];
  480. $d = $this->$fl->get_number($number);
  481. if($d)
  482. {
  483. $data = $d;
  484. continue;
  485. }
  486. }
  487. if($data)
  488. {
  489. if($data['source'] == 1)
  490. {
  491. $shop = $this->shop->read($data['shop']);
  492. $data['url'] = $shop['url'];
  493. }
  494. else
  495. {
  496. $product = '';
  497. $lk = explode(',',$data['link']);
  498. for($i=0;$i<count($lk);$i++)
  499. {
  500. $product .= $lk[$i].',';
  501. }
  502. $data['url'] = $product;
  503. }
  504. echo json_encode(array('msg'=>$data,'success'=>true));exit;
  505. }
  506. else
  507. {
  508. echo json_encode(array('msg'=>'请检查编号是否正确','success'=>false));exit;
  509. }
  510. }
  511. }
  512. }