Systemwigsout_old.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Systemwigsout extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_systemwigsout','systemwigsout');
  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. if(isset($_SESSION['api']))
  54. {
  55. $user = $this->user->get_api($_SESSION['api']);
  56. $usp = $user;
  57. $fgshop = "";$sid = "";$wid="";$wtype="";
  58. $usersp = explode('|',trim($user['shop'],'|'));
  59. $userwh = explode('|',trim($user['warehouse'],'|'));
  60. foreach ($usersp as $value)
  61. {
  62. $fgshop .= " shop = ".$value." or";
  63. $sid .= " id = ".$value." or";
  64. }
  65. foreach ($userwh as $value)
  66. {
  67. $wid .= " id = ".$value." or";
  68. $wtype .= " type = ".$value." or";
  69. }
  70. }
  71. $kx = '';$zjtab = '';
  72. if($user['userid'] == 'toutao')
  73. {
  74. $kx = '<option value="1">头套</option>';
  75. }
  76. else if($user['userid'] == 'ranse')
  77. {
  78. $kx = '<option value="2">染色</option>';
  79. }
  80. else if($user['userid'] == 'qvfa')
  81. {
  82. $kx = '<option value="3">曲发</option>';
  83. $zjtab = 'qf';
  84. }
  85. else if($user['userid'] == 'body')
  86. {
  87. $kx = '<option value="4">BODY</option>';
  88. }
  89. else if($user['userid'] == 'faxingshi')
  90. {
  91. $kx = '<option value="5">发型师染色</option>';
  92. }
  93. else if($user['userid'] == 'houchuli')
  94. {
  95. $kx = '<option value="6">后处理</option>';
  96. $zjtab = 'hcl';
  97. }
  98. if(isset($_SESSION['api']))
  99. {
  100. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  101. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  102. $this->data['wlshop'] = $wlshop;
  103. $this->data['warehouse'] = $warehouse;
  104. $this->data['warehouse'] = $warehouse;
  105. $this->data['vip'] = $user['vip'];
  106. $this->data['kx'] = $kx;
  107. $this->data['zjtab'] = $zjtab;
  108. }
  109. $this->_Template('systemwigsout',$this->data);
  110. }
  111. public function _data()
  112. {
  113. $post = $this->input->post(NULL, TRUE);
  114. if(isset($post['page']))
  115. {
  116. $api = $this->input->post('api',true);
  117. $page = $this->input->post('page',true);
  118. $perpage = $this->input->post('perpage',true);
  119. $number = $this->input->post('number',true);
  120. $type = $this->input->post('type',true);
  121. $cz = $this->input->post('cz',true);
  122. $zjtab = $this->input->post('zjtab',true);
  123. $timetk = $this->input->post('timetk',true);
  124. $timetj = $this->input->post('timetj',true);
  125. $timetk = strtotime($timetk);
  126. $timetj = strtotime($timetj);
  127. $where = "type != 0";
  128. if(isset($_SESSION['api']))
  129. {
  130. if($type)
  131. {
  132. $where .= " and type = '$type'";
  133. }
  134. else
  135. {
  136. $uw = '';
  137. $u = $this->user->get_api($_SESSION['api']);
  138. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  139. foreach ($u['warehouse'] as $v)
  140. {
  141. $uw .= " type = '$v' or";
  142. }
  143. $uw = rtrim($uw,'or');
  144. $uw = " and (".ltrim($uw,' ').")";
  145. $where .= $uw;
  146. }
  147. }
  148. $gctime = "gctime".$cz;
  149. if($timetk)
  150. {
  151. $where .= " and $gctime like '%".date('Ymd',$timetk)."%'";
  152. }
  153. if($number)
  154. {
  155. $where .= " and number = '$number'";
  156. }
  157. if($cz)
  158. {
  159. $where .= " and cz like '%~".$cz."-%'";
  160. }
  161. if($zjtab)
  162. {
  163. $where .= " and cz like '%~".$zjtab."-%'";
  164. }
  165. //数据排序
  166. $order_str = "id desc";
  167. if(empty($page))
  168. {
  169. $start = 0;
  170. $perpage = 1;
  171. }
  172. else
  173. {
  174. $start = ($page - 1)*$perpage;
  175. }
  176. //取得信息列表
  177. $info_list = $this->systemwigsout->find_all($where,'id,number,shipremarks,printtime,time,quantity',$order_str,$start,$perpage);
  178. //格式化数据
  179. foreach ($info_list as $key=>$value)
  180. {
  181. $dd = $this->systemwigsout->read($value['id']);
  182. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  183. if($dd['ly'] == '1')
  184. {
  185. $info_list[$key]['time'] = '小单<br>';
  186. }
  187. else
  188. {
  189. $info_list[$key]['time'] = '';
  190. }
  191. $cz = explode('|',trim($dd['cz'],'|'));
  192. $zw = array(1=>'头套',2=>'染色',3=>'曲发',4=>'body',5=>'发型师染色',6=>'后处理');
  193. $lxzw = array(1=>'入库',2=>'出库');
  194. if($dd['cz'] != '' && count($cz) > 0)
  195. {
  196. for($i=0;$i<count($cz);$i++)
  197. {
  198. $czfl = explode('-',trim($cz[$i],'~'));
  199. $ctime = 'ctime'.$czfl[0];
  200. $ct = explode('-',trim($dd[$ctime],'-'));
  201. $info_list[$key]['time'] .= $zw[$czfl[0]].'-'.$lxzw[$czfl[1]].':'.date('Y-m-d H:i:s',trim($ct[$czfl[1]-1],'-')).'<br>';
  202. }
  203. }
  204. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  205. }
  206. $total = $this->systemwigsout->find_count($where);
  207. $pagenum = ceil($total/$perpage);
  208. $over = $total-($start+$perpage);
  209. $exdata = 0;
  210. $count = $this->systemwigsout->find_all($where);
  211. foreach ($count as $v)
  212. {
  213. $exdata += $v['quantity'];
  214. }
  215. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$exdata,'exdata'=>$exdata);
  216. echo json_encode($rows);exit;
  217. }
  218. }
  219. public function _out()
  220. {
  221. $post = $this->input->post(NULL, TRUE);
  222. if(isset($post['number']))
  223. {
  224. $time = time();
  225. $number = $this->input->post('number',true);
  226. $type = $this->input->post('type',true);
  227. $ps = $this->input->post('ps',true);
  228. $cz = $this->input->post('cz',true);
  229. $lx = $this->input->post('lx',true);
  230. $ly = $this->input->post('ly',true);
  231. $timetk = $this->input->post('timetk',true);
  232. $timetj = $this->input->post('timetj',true);
  233. $timetk = strtotime($timetk);
  234. $timetj = strtotime($timetj);
  235. if(!$number)
  236. {
  237. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  238. }
  239. if(!$type)
  240. {
  241. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  242. }
  243. if(!$cz)
  244. {
  245. echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;
  246. }
  247. if(!$lx)
  248. {
  249. echo json_encode(array('msg'=>'请选择需要操作的类型!','success'=>false));exit;
  250. }
  251. if(!$ly)
  252. {
  253. $ly = 0;
  254. }
  255. $nu = $this->fullorder->get_number($number);
  256. if(!$nu)
  257. {
  258. $nu = $this->fullordersmt->get_number($number);
  259. }
  260. if(!$nu)
  261. {
  262. echo json_encode(array('msg'=>'错误!未找到此编号的订单','success'=>false));exit;
  263. }
  264. if($nu['printtime'] == '0')
  265. {
  266. echo json_encode(array('msg'=>'错误,此单没有打印时间!请联系店员核实','success'=>false));exit;
  267. }
  268. $systemwigsout = $this->systemwigsout->get_num($number);
  269. if($cz == '1')
  270. {
  271. if($systemwigsout)
  272. {
  273. if($systemwigsout['ly'] != '0')
  274. {
  275. echo json_encode(array('msg'=>'错误,此订单已于小单方式录入系统!','success'=>false));exit;
  276. }
  277. if(stripos($systemwigsout['cz'],'~'.$cz.'-'.$lx) !== false && stripos($systemwigsout['cz'],'~'.$cz.'-1') === false)
  278. {
  279. echo json_encode(array('msg'=>'错误,系统中已有此类型记录!','success'=>false));exit;
  280. }
  281. if(stripos($systemwigsout['cz'],'~1-2') !== false && $lx == '2')
  282. {
  283. echo json_encode(array('msg'=>'错误,此订单已有出库记录!','success'=>false));exit;
  284. }
  285. if(stripos($systemwigsout['cz'],'~6-2') === false && $lx == '1')
  286. {
  287. echo json_encode(array('msg'=>'错误,此订单已进入后续流程,还未结束!','success'=>false));exit;
  288. }
  289. $cz1 = explode('-',$systemwigsout['ctime1']);$gcz1 = explode('-',$systemwigsout['gctime1']);
  290. if($this->systemwigsout->save(array('cz'=>$systemwigsout['cz'].'|~'.$cz.'-'.$lx,'ctime1'=>$time.'-'.$cz1[0],'gctime1'=>date('YmdH',$time).'-'.$gcz1[0]),$systemwigsout['id']))
  291. {
  292. echo json_encode(array('music'=>'1','success'=>true));exit;
  293. }
  294. else
  295. {
  296. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  297. }
  298. }
  299. else
  300. {
  301. if($lx == '1')
  302. {
  303. echo json_encode(array('msg'=>'错误,此订单没有出库记录','success'=>false));exit;
  304. }
  305. if($this->systemwigsout->insert(array('type'=>$type,'cz'=>'~'.$cz.'-'.$lx,'number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'gtime'=>date('YmdH',$time),'time'=>$time,'ctime1'=>$time.'-'.$time,'gctime1'=>date('YmdH',$time).'-'.date('YmdH',$time))))
  306. {
  307. echo json_encode(array('music'=>'1','success'=>true));exit;
  308. }
  309. else
  310. {
  311. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  312. }
  313. }
  314. }
  315. else
  316. {
  317. if($systemwigsout)
  318. {
  319. if(stripos($systemwigsout['cz'],'~'.$cz.'-'.$lx) !== false)
  320. {
  321. echo json_encode(array('msg'=>'错误,系统中已有此类型记录!','success'=>false));exit;
  322. }
  323. if(stripos($systemwigsout['cz'],'~'.$cz.'-1') === false && $lx == '2')
  324. {
  325. echo json_encode(array('msg'=>'错误,请先进行入库操作!','success'=>false));exit;
  326. }
  327. else if(stripos($systemwigsout['cz'],'~2-') === false && stripos($systemwigsout['cz'],'~3-') === false && stripos($systemwigsout['cz'],'~4-') === false && stripos($systemwigsout['cz'],'~5-') === false && $cz == '6')
  328. {
  329. echo json_encode(array('msg'=>'错误,没有前置流程不可进入后处理!','success'=>false));exit;
  330. }
  331. else if(stripos($systemwigsout['cz'],'~2-2') === false && stripos($systemwigsout['cz'],'~3-2') === false && stripos($systemwigsout['cz'],'~4-2') === false && stripos($systemwigsout['cz'],'~5-2') === false && $cz == '6')
  332. {
  333. echo json_encode(array('msg'=>'错误,前置流程未出库!','success'=>false));exit;
  334. }
  335. else if((stripos($systemwigsout['cz'],'~2-') !== false || stripos($systemwigsout['cz'],'~3-') !== false || stripos($systemwigsout['cz'],'~4-') !== false || stripos($systemwigsout['cz'],'~5-') !== false) && stripos($systemwigsout['cz'],'~'.$cz.'-') === false && $cz != '6')
  336. {
  337. echo json_encode(array('msg'=>'错误,系统中已有同类型记录!','success'=>false));exit;
  338. }
  339. else if(stripos($systemwigsout['cz'],'~1-1') !== false)
  340. {
  341. echo json_encode(array('msg'=>'错误,此订单流程已结束!','success'=>false));exit;
  342. }
  343. else
  344. {
  345. $ctime = array('ctime1'=>$systemwigsout['ctime1'],'ctime2'=>$systemwigsout['ctime2'],'ctime3'=>$systemwigsout['ctime3'],'ctime4'=>$systemwigsout['ctime4'],'ctime5'=>$systemwigsout['ctime5'],'ctime6'=>$systemwigsout['ctime6'],'gctime1'=>$systemwigsout['gctime1'],'gctime2'=>$systemwigsout['gctime2'],'gctime3'=>$systemwigsout['gctime3'],'gctime4'=>$systemwigsout['gctime4'],'gctime5'=>$systemwigsout['gctime5'],'gctime6'=>$systemwigsout['gctime6']);
  346. if($cz == '2' || $cz == '3' || $cz == '4' || $cz == '5' || $cz == '6')
  347. {
  348. if($lx == '1')
  349. {
  350. $ctime['ctime'.$cz] = $time;
  351. $ctime['gctime'.$cz] = date('YmdH',$time);
  352. }
  353. else
  354. {
  355. $ctime['ctime'.$cz] = $systemwigsout['ctime'.$cz].'-'.$time;
  356. $ctime['gctime'.$cz] = $systemwigsout['gctime'.$cz].'-'.date('YmdH',$time);
  357. }
  358. }
  359. $this->systemwigsout->save(array('cz'=>$systemwigsout['cz'].'|~'.$cz.'-'.$lx,'ctime2'=>$ctime['ctime2'],'ctime3'=>$ctime['ctime3'],'ctime4'=>$ctime['ctime4'],'ctime5'=>$ctime['ctime5'],'ctime6'=>$ctime['ctime6'],'gctime2'=>$ctime['gctime2'],'gctime3'=>$ctime['gctime3'],'gctime4'=>$ctime['gctime4'],'gctime5'=>$ctime['gctime5'],'gctime6'=>$ctime['gctime6']),$systemwigsout['id']);
  360. echo json_encode(array('music'=>$cz.'-'.$lx,'success'=>true));exit;
  361. }
  362. }
  363. else if($cz == '3' && $lx == '1' && $ly == '1')
  364. {
  365. if($this->systemwigsout->insert(array('type'=>$type,'cz'=>'~'.$cz.'-'.$lx,'number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'ly'=>$ly,'gtime'=>date('YmdH',$time),'time'=>$time,'ctime3'=>$time,'gctime3'=>date('YmdH',$time))))
  366. {
  367. echo json_encode(array('music'=>'1','success'=>true));exit;
  368. }
  369. else
  370. {
  371. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  372. }
  373. }
  374. else if($cz == '4' && $lx == '1')
  375. {
  376. if($this->systemwigsout->insert(array('type'=>$type,'cz'=>'~1-2|~'.$cz.'-'.$lx.'|~'.$cz.'-2','number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'gtime'=>date('YmdH',$time),'time'=>$time,'ctime1'=>$time.'-'.$time,'gctime1'=>date('YmdH',$time).'-'.date('YmdH',$time),'ctime4'=>$time.'-'.$time,'gctime4'=>date('YmdH',$time).'-'.date('YmdH',$time))))
  377. {
  378. echo json_encode(array('music'=>'1','success'=>true));exit;
  379. }
  380. else
  381. {
  382. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  383. }
  384. }
  385. else if($cz == '5' && $lx == '1')
  386. {
  387. if($this->systemwigsout->insert(array('type'=>$type,'cz'=>'~1-2|~'.$cz.'-'.$lx,'number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'gtime'=>date('YmdH',$time),'time'=>$time,'ctime1'=>$time.'-'.$time,'gctime1'=>date('YmdH',$time).'-'.date('YmdH',$time),'ctime5'=>$time,'gctime5'=>date('YmdH',$time))))
  388. {
  389. echo json_encode(array('music'=>'1','success'=>true));exit;
  390. }
  391. else
  392. {
  393. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  394. }
  395. }
  396. else if($cz == '3' && $lx != '1' && $ly == '1')
  397. {
  398. echo json_encode(array('msg'=>'错误,请先进行入库!','success'=>false));exit;
  399. }
  400. else
  401. {
  402. echo json_encode(array('msg'=>'错误,此订单头套仓未出库!','success'=>false));exit;
  403. }
  404. }
  405. }
  406. }
  407. public function _barcode($arg_array)
  408. {
  409. $dir = 'data/img/'.date('Ymd',time()).'/';
  410. if(!is_dir('./'.$dir))mkdir('./'.$dir,0777);
  411. $imgUrl = $dir.$arg_array.'.png';
  412. // 引用class文件夹对应的类
  413. require_once('./data/barcodegen/class/BCGFontFile.php');
  414. require_once('./data/barcodegen/class/BCGColor.php');
  415. require_once('./data/barcodegen/class/BCGDrawing.php');
  416. // 条形码的编码格式
  417. require_once('./data/barcodegen/class/BCGcode128.barcode.php');
  418. // 加载字体大小
  419. $font = new \BCGFontFile('./data/barcodegen/Arial.ttf', 18);
  420. //设置条形码颜色
  421. $color_black = new \BCGColor(0, 0, 0);
  422. $color_white = new \BCGColor(255, 255, 255);
  423. $drawException = null;
  424. try
  425. {
  426. $code = new \BCGcode128();
  427. $code->setScale(2);
  428. $code->setThickness(30); // 条形码的厚度
  429. $code->setForegroundColor($color_black); // 条形码颜色
  430. $code->setBackgroundColor($color_white); // 条形码间隙颜色
  431. $code->setFont($font); //设置引用字体 条形码下方的文字
  432. $code->parse($arg_array); // 条形码需要的数据内容
  433. }
  434. catch(\Exception $exception)
  435. {
  436. $drawException = $exception;
  437. }
  438. $drawing = new \BCGDrawing($imgUrl, $color_white);
  439. if($drawException)
  440. {
  441. $drawing->drawException($drawException);
  442. }
  443. else
  444. {
  445. $drawing->setBarcode($code);
  446. $drawing->draw();
  447. }
  448. // Header that says it is an image (remove it if you save the barcode to a file)
  449. //header('Content-Type: image/png');
  450. //header('Content-Disposition: inline; filename="barcode.png"');
  451. // Draw (or save) the image into PNG format.
  452. $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);
  453. return 'http://'.$_SERVER['HTTP_HOST'].'/data/img/'.date('Ymd',time()).'/'.$arg_array.'.png';
  454. //return "<img src='".$data."' />";
  455. }
  456. public function _excel()
  457. {
  458. if(isset($_GET['fexcel']))
  459. {
  460. $timetk = $this->input->get('timetk',true);
  461. $timetj = $this->input->get('timetj',true);
  462. $type = $this->input->get('type',true);
  463. $cz = $this->input->get('cz',true);
  464. $number = $this->input->get('number',true);
  465. $timetk = strtotime($timetk.':0:0');
  466. $timetj = strtotime($timetj);
  467. $gctime = "gctime".$cz;
  468. $where = "type != 0 and $gctime like '%-".date('YmdH',$timetk)."'";
  469. if(isset($_SESSION['api']))
  470. {
  471. if($type)
  472. {
  473. $where .= " and type = '$type'";
  474. $warehouse = $this->warehouse->read($type);
  475. $titletype = "---".$warehouse['title'];
  476. }
  477. else
  478. {
  479. $uw = '';
  480. $u = $this->user->get_api($_SESSION['api']);
  481. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  482. foreach ($u['warehouse'] as $v)
  483. {
  484. $uw .= " type = '$v' or";
  485. }
  486. $uw = rtrim($uw,'or');
  487. $uw = " and (".ltrim($uw,' ').")";
  488. $where .= $uw;
  489. $titletype = "";
  490. }
  491. }
  492. else
  493. {
  494. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  495. }
  496. if($number)
  497. {
  498. $where .= " and number = '$number'";
  499. }
  500. if($cz)
  501. {
  502. $where .= " and cz like '%~".$cz."-%'";
  503. }
  504. $data = array();
  505. $datafy = array();
  506. $j = 0;
  507. $info_list = $this->systemwigsout->find_all($where,'number,shipremarks,printtime,quantity');
  508. foreach ($info_list as $key=>$value)
  509. {
  510. $img = $this->_barcode($value['number']);
  511. $info_list[$key]['number'] = ".<img width='260' src='".$img."' />";
  512. $info_list[$key]['shipremarks'] = $value['shipremarks'];
  513. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  514. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['shipremarks']);
  515. }
  516. $title = date('Y-m-d H-i',time()).'扫码统计表'.$titletype;
  517. $titlename = "<table border=1 >
  518. <tr><th colspan='4' align='left'><h3>".$title."<h3></th></tr>
  519. <tr>
  520. <td>编号</td>
  521. <td>仓库品名</td>
  522. <td>打印时间</td>
  523. <td>数量</td>
  524. </tr></table><table><tr></tr>";
  525. $filename = $title.".xls";
  526. $tail = "\n";
  527. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  528. <head>
  529. </head><body>";
  530. $str .= $titlename;
  531. foreach ($info_list as $key=>$value)
  532. {
  533. $str .= "<tr style=' border-bottom:1 double #000;'>";
  534. foreach ($value as $ke=>$va)
  535. {
  536. $tj = '';
  537. if($ke == 'number')
  538. {
  539. $str .= "<td style='padding-left:400px;'>".$va."</td>";//使用文本格式
  540. }
  541. else
  542. {
  543. $str .= "<td>".$va."</td>";//使用文本格式
  544. }
  545. }
  546. $str .= "</tr><tr></tr><tr></tr>\n";
  547. }
  548. $str .= $tail;
  549. $str .= "</table></body></html>";
  550. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  551. header( "Content-type: application/octet-stream" );
  552. header( "Content-Disposition: attachment; filename=".$filename );
  553. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  554. header( "Pragma: no-cache" );
  555. header( "Expires: 0" );
  556. exit($str);
  557. //echo "<pre>";
  558. //print_r($info_list);
  559. }
  560. }
  561. public function _add()
  562. {
  563. $post = $this->input->post(NULL, TRUE);
  564. if(isset($post['number']))
  565. {
  566. $where = "gtime = '".date('Ymd',time())."'";
  567. $number = $this->input->post('number',true);
  568. $id = $this->input->post('id',true);
  569. $type = $this->input->post('type',true);
  570. $time = $this->input->post('time',true);
  571. $time = strtotime($time);
  572. if($id)
  573. {
  574. if($type)
  575. {
  576. $where .= " and type = '$type'";
  577. }
  578. else
  579. {
  580. $uw = '';
  581. $u = $this->user->get_api($id);
  582. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  583. foreach ($u['warehouse'] as $v)
  584. {
  585. $uw .= " type = '$v' or";
  586. }
  587. $uw = rtrim($uw,'or');
  588. $uw = " and (".ltrim($uw,' ').")";
  589. $where .= $uw;
  590. }
  591. }
  592. if(!$number)
  593. {
  594. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  595. }
  596. if(!$type)
  597. {
  598. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  599. }
  600. $nu = $this->fullorder->get_number($number);
  601. if(!$nu)
  602. {
  603. $nu = $this->fullordersmt->get_number($number);
  604. }
  605. if(!$nu)
  606. {
  607. echo json_encode(array('msg'=>'错误!未找到此编号的订单','success'=>false));exit;
  608. }
  609. if($nu['printtime'] == '0')
  610. {
  611. echo json_encode(array('msg'=>'错误,此单没有打印时间!请联系店员核实','success'=>false));exit;
  612. }
  613. $data = 0;
  614. $count = $this->systemwigsout->find_all($where);
  615. foreach ($count as $v)
  616. {
  617. $data += $v['quantity'];
  618. }
  619. $systemwigsout = $this->systemwigsout->get_number($number);
  620. if($systemwigsout)
  621. {
  622. $this->systemwigsout->save(array('quantity'=>$systemwigsout['quantity']+1),$systemwigsout['id']);
  623. echo json_encode(array('title'=>'添加成功','msg'=>$data+1,'music'=>'1','success'=>true));exit;
  624. }
  625. else
  626. {
  627. if($this->systemwigsout->insert(array('type'=>$type,'number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'gtime'=>date('YmdH',time()),'time'=>time())))
  628. {
  629. echo json_encode(array('title'=>'添加成功','msg'=>$data+1,'music'=>'1','success'=>true));exit;
  630. }
  631. else
  632. {
  633. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  634. }
  635. }
  636. }
  637. }
  638. public function _del()
  639. {
  640. $post = $this->input->post(NULL, TRUE);
  641. if(isset($post['delarr']))
  642. {
  643. $number = $this->input->post('number',true);
  644. $type = $this->input->post('type',true);
  645. $timetk = $this->input->post('timetk',true);
  646. $timetj = $this->input->post('timetj',true);
  647. $timetk = strtotime($timetk);
  648. $timetj = strtotime($timetj);
  649. $where = "type != 0";
  650. if(isset($_SESSION['api']))
  651. {
  652. if($type)
  653. {
  654. $where .= " and type = '$type'";
  655. }
  656. else
  657. {
  658. $uw = '';
  659. $u = $this->user->get_api($_SESSION['api']);
  660. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  661. foreach ($u['warehouse'] as $v)
  662. {
  663. $uw .= " type = '$v' or";
  664. }
  665. $uw = rtrim($uw,'or');
  666. $uw = " and (".ltrim($uw,' ').")";
  667. $where .= $uw;
  668. }
  669. }
  670. if($timetk && $timetj)
  671. {
  672. $where .= " and time > '$timetk' and time < '$timetj'";
  673. }
  674. if($number)
  675. {
  676. $where .= " and number = '$number'";
  677. }
  678. $id_arr = $this->input->post('delarr');
  679. $id_arr = explode(',',rtrim($id_arr,','));
  680. if(!$id_arr)
  681. {
  682. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  683. }
  684. //循环删除记录
  685. $a=0;
  686. foreach ($id_arr as $v)
  687. {
  688. if($this->systemwigsout->remove($v))
  689. {
  690. $a++;
  691. }
  692. }
  693. if($a == count($id_arr))
  694. {
  695. $data = 0;
  696. $count = $this->systemwigsout->find_all($where);
  697. foreach ($count as $v)
  698. {
  699. $data += $v['quantity'];
  700. }
  701. echo json_encode(array('del'=>$id_arr,'data'=>$data-$a,'msg'=>'删除成功!','success'=>true));
  702. }
  703. else
  704. {
  705. echo json_encode(array('del'=>$id_arr,'msg'=>'部分记录删除失败,请查询确认!','success'=>true));
  706. }
  707. }
  708. }
  709. public function _hb()
  710. {
  711. $dataorder = array();
  712. /* 订单加入键值-k */
  713. $fdata = $this->fullorder->find_all('dtime > "'.(time()-50*24*3600).'" and printtime > 0','number,orderinfo,fpdata,shipremarks');
  714. foreach ($fdata as $v)
  715. {
  716. $dataorder[$v['number']] = $v;
  717. }
  718. $sdata = $this->fullordersmt->find_all('dtime > "'.(time()-50*24*3600).'" and printtime > 0','number,orderinfo,fpdata,shipremarks');
  719. foreach ($sdata as $v)
  720. {
  721. $dataorder[$v['number']] = $v;
  722. }
  723. /* 匹配ID加入 */
  724. $tc = array();$ztc = array();$tclass = array();
  725. $typeclass = $this->typeclass->find_all();
  726. foreach ($typeclass as $v)
  727. {
  728. $ztc[$v['id']] = $v['zh'];
  729. $tc[$v['id']] = $v['title'];
  730. $tclass[$v['id']] = $v['classid'];
  731. }
  732. $dir = '/data/excel/'.date('Ymd',time()).'/';
  733. $config['upload_path'] = '.'.$dir ;
  734. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  735. $config['allowed_types'] = 'xls|xlsx|csv';
  736. $config['max_size'] = 10240;
  737. $this->load->library('upload', $config);
  738. $this->upload->initialize($config);
  739. if ($this->upload->do_upload('userfile'))
  740. {
  741. $full_path = $dir.$this->upload->data('file_name');
  742. $fileName = '.' . $full_path;
  743. if (!file_exists($fileName))
  744. {
  745. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  746. }
  747. else
  748. {
  749. require_once "./data/excel/PHPExcel/IOFactory.php";
  750. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  751. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  752. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  753. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  754. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  755. ++$column;//如果列数大于26行
  756. $list = array();
  757. for ($i = 2; $i <= $row; $i++) // 行数循环
  758. {
  759. $data = array();
  760. for ($c = 'A'; $c != $column; $c++) // 列数循环
  761. {
  762. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  763. }
  764. $list[] = $data;
  765. }
  766. }
  767. $ed = array();$i = 0;$j = 0;$dcdata = array();$yc = '';
  768. $cmf_arr = array_column($list, '1');
  769. array_multisort($cmf_arr, SORT_ASC, $list);
  770. foreach ($list as $key=>$value)
  771. {
  772. $number = $value['1'];
  773. $bbtime = $value['7'];
  774. if(stripos($number,'QM') !== false)
  775. {
  776. continue;
  777. }
  778. if(isset($dataorder[$number]))
  779. {
  780. $thisnumber = $dataorder[$number];$thisshipremarks = array();
  781. if(stripos($thisnumber['fpdata'],';') !== false)
  782. {
  783. $fpdata = explode(';',rtrim($thisnumber['fpdata'],';'));
  784. foreach ($fpdata as $ke=>$va)
  785. {
  786. $title = '';
  787. $fg = explode('|',$va);
  788. $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
  789. $cp = explode('-',rtrim($fg[0],'-'));
  790. if(isset($cp[5]))
  791. {
  792. $tt = $ztc[$cp[5]];
  793. }
  794. else
  795. {
  796. $tt = '';
  797. }
  798. $md = '';
  799. foreach ($cp as $v)
  800. {
  801. if(!isset($tclass[$v]))
  802. {
  803. continue;
  804. }
  805. if($tclass[$v] == '10')
  806. {
  807. $md = $tc[$v];
  808. }
  809. }
  810. if(isset($cp[4]))
  811. {
  812. $dchx = $tc[$cp[4]];
  813. }
  814. else
  815. {
  816. $dchx = ' ';
  817. }
  818. $thisshipremarks[] = array($tt,$tc[$cp[3]],$md,$dchx,$fg[5],$fg[2]);//头套种类,颜色,密度,花型,尺寸,数量
  819. }
  820. }
  821. $thisnumber['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$thisnumber['shipremarks']);
  822. $dcdata[] = array('number'=>$thisnumber['number'],'time'=>$bbtime,'shipremarks'=>$thisnumber['shipremarks'],'fpdata'=>$thisshipremarks);
  823. }
  824. else
  825. {
  826. $ed[] = array($number.'-系统未找到此订单信息');
  827. $i++;
  828. continue;
  829. }
  830. }
  831. if($i > 0)
  832. {
  833. $yc = $i.'条异常';
  834. }
  835. $title = date('Y-m-d H:i:s',time())." 产品详细信息";
  836. $titlename = "<table border=1>
  837. <tr><th colspan='29' align='left'><h3>".$title."<h3></th></tr>
  838. <tr>
  839. <td>订单编号</td>
  840. <td>配货时间</td>
  841. <td>仓库品名</td>
  842. <td>
  843. <table border=1>
  844. <tr><td colspan='4' align='center'>订单产品信息</td></tr>
  845. <tr>
  846. <td>种类</td>
  847. <td>颜色</td>
  848. <td>密度</td>
  849. <td>花型</td>
  850. <td>尺寸</td>
  851. <td>数量</td>
  852. </tr>
  853. </table>
  854. </td>
  855. <td>总条数</td>
  856. </tr>
  857. </table>";
  858. $filename = $title.".xls";
  859. $tail = "\n";
  860. $downexcel = $this->get_fz($dcdata,$titlename,$filename,$tail);
  861. $time = date('Ymd',time());
  862. $dir = '/data/excel/'.$time.'/';
  863. $file_name = $title;
  864. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  865. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  866. fwrite($myfile,$downexcel);
  867. fclose($myfile);
  868. $goexcel = $dir.$file_name.'.xls';
  869. echo json_encode(array('msg'=>'操作成功 '.$yc,'goexcel'=>$goexcel,'success'=>true));exit;
  870. }
  871. else
  872. {
  873. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  874. }
  875. }
  876. public function get_fz($info_list,$titlename,$filename,$tail)
  877. {
  878. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  879. <head>
  880. <!--[if gte mso 9]><xml>
  881. <x:ExcelWorkbook>
  882. <x:ExcelWorksheets>
  883. <x:ExcelWorksheet>
  884. <x:Name>EXCEL</x:Name>
  885. <x:WorksheetOptions>
  886. <x:Print>
  887. <x:ValidPrinterInfo />
  888. </x:Print>
  889. </x:WorksheetOptions>
  890. </x:ExcelWorksheet>
  891. </x:ExcelWorksheets>
  892. </x:ExcelWorkbook>
  893. </xml>
  894. <![endif]-->
  895. </head><body>";
  896. $str .= $titlename;
  897. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  898. foreach ($info_list as $key=>$value)
  899. {
  900. if($value['fpdata'] == '')
  901. {
  902. continue;
  903. }
  904. $str .= "<tr>";
  905. foreach ($value as $ke=>$va)
  906. {
  907. if($ke == 'orderinfo' || $ke == 'waybill')
  908. {
  909. $str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".$va."</td>";
  910. }
  911. else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle')
  912. {
  913. $str .= "<td align='left'>".$va."</td>";
  914. }
  915. }
  916. $str .= "<td><table border=1>";
  917. $a = 0;
  918. foreach ($value['fpdata'] as $k=>$v)
  919. {
  920. $vd = '';
  921. foreach ($v as $vv)
  922. {
  923. $vd .= "<td>".$vv."</td>";
  924. }
  925. $str .= "<tr>".$vd."</tr>";
  926. $endv = is_numeric(end($v))?end($v):0;
  927. $a = $a + $endv;
  928. }
  929. $str .= "</table></td>";
  930. $str .= "<td>".$a."</td>";
  931. $str .= "</tr>\n";
  932. }
  933. $str .= $tail;
  934. $str .= "</table></body></html>";
  935. return $str;
  936. //return $str;
  937. }
  938. }