Systemwigs.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Systemwigs extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_systemwigs','systemwigs');
  7. $this->load->_model('Model_excel','excel');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_warehouse','warehouse');
  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_typeclass','typeclass');
  14. }
  15. //定义方法的调用规则 获取URI第二段值
  16. public function _remap($arg,$arg_array)
  17. {
  18. if($arg == 'data')
  19. {
  20. $this->_data();
  21. }
  22. else if($arg == 'out')
  23. {
  24. $this->_out();
  25. }
  26. else if($arg == 'del')
  27. {
  28. $this->_del();
  29. }
  30. else if($arg == 'add')
  31. {
  32. $this->_add();
  33. }
  34. else if($arg == 'excel')
  35. {
  36. $this->_excel();
  37. }
  38. else if($arg == 'barcode')
  39. {
  40. $this->_barcode($arg_array);
  41. }
  42. else if($arg == 'hb')
  43. {
  44. $this->_hb();
  45. }
  46. else
  47. {
  48. $this->_index();
  49. }
  50. }
  51. public function _index()
  52. {
  53. $this->_Template('systemwigs',$this->data);
  54. }
  55. public function _data()
  56. {
  57. $post = $this->input->post(NULL, TRUE);
  58. if(isset($post['page']))
  59. {
  60. $page = $this->input->post('page',true);
  61. $perpage = $this->input->post('perpage',true);
  62. $number = $this->input->post('number',true);
  63. $type = $this->input->post('type',true);
  64. $timetk = $this->input->post('timetk',true);
  65. $timetk = strtotime($timetk);
  66. $where = "type != 0";
  67. if($timetk)
  68. {
  69. $where .= " and gtime like '%".date('Ymd',$timetk)."%'";
  70. }
  71. if($type)
  72. {
  73. $where .= " and type = '$type'";
  74. }
  75. //数据排序
  76. $order_str = "id desc";
  77. if(empty($page))
  78. {
  79. $start = 0;
  80. $perpage = 1;
  81. }
  82. else
  83. {
  84. $start = ($page - 1)*$perpage;
  85. }
  86. //取得信息列表
  87. $info_list = $this->systemwigs->find_all($where,'id,number,shipremarks,outtime,num',$order_str,$start,$perpage);
  88. //格式化数据
  89. foreach ($info_list as $key=>$value)
  90. {
  91. $outtime = explode('|',trim($value['outtime'],'|'));
  92. $num = explode('|',trim($value['num'],'|'));
  93. $info_list[$key]['outtime'] = '';
  94. $info_list[$key]['num'] = '';
  95. foreach ($outtime as $v)
  96. {
  97. $info_list[$key]['outtime'] .= date('Y-m-d H:i:s',$v).'<br>';
  98. }
  99. foreach ($num as $v)
  100. {
  101. $info_list[$key]['num'] .= $v.'<br>';
  102. }
  103. $info_list[$key]['outtime'] = trim($info_list[$key]['outtime'],'<br>');
  104. $info_list[$key]['num'] = trim($info_list[$key]['num'],'<br>');
  105. }
  106. $total = $this->systemwigs->find_count($where);
  107. $pagenum = ceil($total/$perpage);
  108. $over = $total-($start+$perpage);
  109. $exdata = 0;
  110. $count = $this->systemwigs->find_all($where." and gtime like '%".date('Ymd',time())."%' ");
  111. foreach ($count as $v)
  112. {
  113. $gtime = explode('|',trim($v['gtime'],'|'));
  114. $num = explode('|',trim($v['num'],'|'));
  115. $gtime = array_flip($gtime);
  116. $exdata += $num[$gtime[date('Ymd',time())]];
  117. }
  118. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$exdata);
  119. echo json_encode($rows);exit;
  120. }
  121. }
  122. public function _out()
  123. {
  124. $post = $this->input->post(NULL, TRUE);
  125. if(isset($post['number']))
  126. {
  127. $number = $this->input->post('number',true);
  128. $type = $this->input->post('type',true);
  129. $time = time();
  130. if(!$number)
  131. {
  132. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  133. }
  134. if(!$type)
  135. {
  136. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  137. }
  138. $nu = $this->fullorder->get_number($number);
  139. if(!$nu)
  140. {
  141. $nu = $this->fullordersmt->get_number($number);
  142. }
  143. if(!$nu)
  144. {
  145. echo json_encode(array('msg'=>'错误!未找到此编号的订单','success'=>false));exit;
  146. }
  147. $systemwigs = $this->systemwigs->get_num($number);
  148. if($systemwigs)
  149. {
  150. $gtime = explode('|',trim($systemwigs['gtime'],'|'));
  151. $gtime = array_flip($gtime);
  152. if(isset($gtime[date('Ymd',$time)]))
  153. {
  154. $num = explode('|',trim($systemwigs['num'],'|'));
  155. $num[$gtime[date('Ymd',$time)]] += 1;
  156. $num = '|'.implode('|',$num);
  157. if($this->systemwigs->save(array('num'=>$num),$systemwigs['id']))
  158. {
  159. echo json_encode(array('music'=>'1','success'=>true));exit;
  160. }
  161. else
  162. {
  163. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  164. }
  165. }
  166. else
  167. {
  168. if($this->systemwigs->save(array('num'=>'|1'.$systemwigs['num'],'gtime'=>'|'.date('Ymd',$time).$systemwigs['gtime'],'outtime'=>'|'.$time.$systemwigs['outtime']),$systemwigs['id']))
  169. {
  170. echo json_encode(array('music'=>'1','success'=>true));exit;
  171. }
  172. else
  173. {
  174. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  175. }
  176. }
  177. }
  178. else
  179. {
  180. if($this->systemwigs->insert(array('number'=>$number,'type'=>$type,'shipremarks'=>$nu['shipremarks'],'fpdata'=>$nu['fpdata'],'outtime'=>'|'.$time,'gtime'=>'|'.date('Ymd',$time),'num'=>'|1')))
  181. {
  182. echo json_encode(array('music'=>'1','success'=>true));exit;
  183. }
  184. else
  185. {
  186. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  187. }
  188. }
  189. }
  190. }
  191. public function _del()
  192. {
  193. $post = $this->input->post(NULL, TRUE);
  194. if(isset($post['delarr']))
  195. {
  196. $number = $this->input->post('number',true);
  197. $type = $this->input->post('type',true);
  198. $timetk = $this->input->post('timetk',true);
  199. $timetj = $this->input->post('timetj',true);
  200. $timetk = strtotime($timetk);
  201. $timetj = strtotime($timetj);
  202. $where = "type != 0";
  203. if(isset($_SESSION['api']))
  204. {
  205. if($type)
  206. {
  207. $where .= " and type = '$type'";
  208. }
  209. else
  210. {
  211. $uw = '';
  212. $u = $this->user->get_api($_SESSION['api']);
  213. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  214. foreach ($u['warehouse'] as $v)
  215. {
  216. $uw .= " type = '$v' or";
  217. }
  218. $uw = rtrim($uw,'or');
  219. $uw = " and (".ltrim($uw,' ').")";
  220. $where .= $uw;
  221. }
  222. }
  223. if($timetk && $timetj)
  224. {
  225. $where .= " and time > '$timetk' and time < '$timetj'";
  226. }
  227. if($number)
  228. {
  229. $where .= " and number = '$number'";
  230. }
  231. $id_arr = $this->input->post('delarr');
  232. $id_arr = explode(',',rtrim($id_arr,','));
  233. if(!$id_arr)
  234. {
  235. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  236. }
  237. //循环删除记录
  238. $a=0;
  239. foreach ($id_arr as $v)
  240. {
  241. if($this->systemwigs->remove($v))
  242. {
  243. $a++;
  244. }
  245. }
  246. if($a == count($id_arr))
  247. {
  248. $data = 0;
  249. $count = $this->systemwigs->find_all($where);
  250. foreach ($count as $v)
  251. {
  252. $data += $v['quantity'];
  253. }
  254. echo json_encode(array('del'=>$id_arr,'data'=>$data-$a,'msg'=>'删除成功!','success'=>true));
  255. }
  256. else
  257. {
  258. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  259. }
  260. }
  261. }
  262. public function _excel()
  263. {
  264. /* 匹配ID加入 */
  265. $tc = array();$ztc = array();$tclass = array();
  266. $typeclass = $this->typeclass->find_all();
  267. foreach ($typeclass as $v)
  268. {
  269. $ztc[$v['id']] = $v['zh'];
  270. $tc[$v['id']] = $v['title'];
  271. $tclass[$v['id']] = $v['classid'];
  272. }
  273. $timetk = $this->input->get('timetk',true);
  274. $timetk = strtotime($timetk);
  275. $dcdata = array();
  276. $list = $this->systemwigs->find_all("gtime like '%".date('Ymd',$timetk)."%'");
  277. foreach ($list as $key=>$value)
  278. {
  279. $thisnumber = $value;$thisshipremarks = array();
  280. if(stripos($thisnumber['fpdata'],';') !== false)
  281. {
  282. $fpdata = explode(';',rtrim($thisnumber['fpdata'],';'));
  283. foreach ($fpdata as $ke=>$va)
  284. {
  285. $title = '';
  286. $fg = explode('|',$va);
  287. $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
  288. $cp = explode('-',rtrim($fg[0],'-'));
  289. if(isset($cp[5]))
  290. {
  291. $tt = $ztc[$cp[5]];
  292. }
  293. else
  294. {
  295. $tt = '';
  296. }
  297. $md = '';
  298. foreach ($cp as $v)
  299. {
  300. if(!isset($tclass[$v]))
  301. {
  302. continue;
  303. }
  304. if($tclass[$v] == '10')
  305. {
  306. $md = $tc[$v];
  307. }
  308. }
  309. if(isset($cp[4]))
  310. {
  311. $dchx = $tc[$cp[4]];
  312. }
  313. else
  314. {
  315. $dchx = ' ';
  316. }
  317. $thisshipremarks[] = array($tt,$tc[$cp[3]],$md,$dchx,$fg[5],$fg[2]);//头套种类,颜色,密度,花型,尺寸,数量
  318. }
  319. }
  320. $thisnumber['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$thisnumber['shipremarks']);
  321. $dcdata[] = array('number'=>$thisnumber['number'],'shipremarks'=>$thisnumber['shipremarks'],'fpdata'=>$thisshipremarks);
  322. }
  323. $title = date('Y-m-d H:i:s',time())." 产品详细信息";
  324. $titlename = "<table border=1>
  325. <tr><th colspan='29' align='left'><h3>".$title."<h3></th></tr>
  326. <tr>
  327. <td>订单编号</td>
  328. <td>仓库品名</td>
  329. <td>
  330. <table border=1>
  331. <tr><td colspan='4' align='center'>订单产品信息</td></tr>
  332. <tr>
  333. <td>种类</td>
  334. <td>颜色</td>
  335. <td>密度</td>
  336. <td>花型</td>
  337. <td>尺寸</td>
  338. <td>数量</td>
  339. </tr>
  340. </table>
  341. </td>
  342. <td>总条数</td>
  343. </tr>
  344. </table>";
  345. $filename = $title.".xls";
  346. $tail = "\n";
  347. $downexcel = $this->excel->get_fz($dcdata,$titlename,$filename,$tail);
  348. $time = date('Ymd',time());
  349. $dir = '/data/excel/'.$time.'/';
  350. $file_name = $title;
  351. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  352. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  353. fwrite($myfile,$downexcel);
  354. fclose($myfile);
  355. $goexcel = $dir.$file_name.'.xls';
  356. echo json_encode(array('msg'=>'操作成功 ','goexcel'=>$goexcel,'success'=>true));exit;
  357. }
  358. public function get_fz($info_list,$titlename,$filename,$tail)
  359. {
  360. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  361. <head>
  362. <!--[if gte mso 9]><xml>
  363. <x:ExcelWorkbook>
  364. <x:ExcelWorksheets>
  365. <x:ExcelWorksheet>
  366. <x:Name>EXCEL</x:Name>
  367. <x:WorksheetOptions>
  368. <x:Print>
  369. <x:ValidPrinterInfo />
  370. </x:Print>
  371. </x:WorksheetOptions>
  372. </x:ExcelWorksheet>
  373. </x:ExcelWorksheets>
  374. </x:ExcelWorkbook>
  375. </xml>
  376. <![endif]-->
  377. </head><body>";
  378. $str .= $titlename;
  379. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  380. foreach ($info_list as $key=>$value)
  381. {
  382. if($value['fpdata'] == '')
  383. {
  384. continue;
  385. }
  386. $str .= "<tr>";
  387. foreach ($value as $ke=>$va)
  388. {
  389. if($ke == 'orderinfo' || $ke == 'waybill')
  390. {
  391. $str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".$va."</td>";
  392. }
  393. else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle')
  394. {
  395. $str .= "<td align='left'>".$va."</td>";
  396. }
  397. }
  398. $str .= "<td><table border=1>";
  399. $a = 0;
  400. foreach ($value['fpdata'] as $k=>$v)
  401. {
  402. $vd = '';
  403. foreach ($v as $vv)
  404. {
  405. $vd .= "<td>".$vv."</td>";
  406. }
  407. $str .= "<tr>".$vd."</tr>";
  408. $endv = is_numeric(end($v))?end($v):0;
  409. $a = $a + $endv;
  410. }
  411. $str .= "</table></td>";
  412. $str .= "<td>".$a."</td>";
  413. $str .= "</tr>\n";
  414. }
  415. $str .= $tail;
  416. $str .= "</table></body></html>";
  417. return $str;
  418. //return $str;
  419. }
  420. }