Distribution.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Distribution 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_distribution','distribution');
  8. $this->load->_model('Model_typeclass','typeclass');
  9. $this->load->_model('Model_warehouse','warehouse');
  10. $this->load->_model('Model_productprice','productprice');
  11. $this->load->_model('Model_excel','excel');
  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 == 'drmb')//修改
  32. {
  33. $this->_drmb();
  34. }
  35. else if($arg == 'dr')
  36. {
  37. $this->_dr();
  38. }
  39. else if($arg == 'db')
  40. {
  41. $this->_db();
  42. }
  43. else
  44. {
  45. $this->_index();
  46. }
  47. }
  48. //管理
  49. public function _index()
  50. {
  51. $t = array();
  52. $typeclass = $this->typeclass->find_all();
  53. foreach ($typeclass as $v)
  54. {
  55. $t[$v['id']] = $v['title'];
  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. $category = $this->input->post('category',true);
  63. $where = "1=1 ";
  64. //数据排序
  65. $order_str = "id asc";
  66. if($category)
  67. {
  68. $where .= "and category = '$category'";
  69. }
  70. if(empty($page))
  71. {
  72. $start = 0;
  73. $perpage = 1;
  74. }
  75. else
  76. {
  77. $start = ($page - 1)*$perpage;
  78. }
  79. //取得信息列表
  80. $info_list = $this->distribution->find_all($where,'id,category,lace,density,size,weight,pb',$order_str,$start,$perpage);
  81. //格式化数据
  82. foreach ($info_list as $key=>$value)
  83. {
  84. if(isset($t[$value['category']]))
  85. {
  86. $info_list[$key]['category'] = $t[$value['category']];
  87. }
  88. if(isset($t[$value['lace']]))
  89. {
  90. $info_list[$key]['lace'] = $t[$value['lace']];
  91. }
  92. if(isset($t[$value['density']]))
  93. {
  94. $info_list[$key]['density'] = $t[$value['density']];
  95. }
  96. if(isset($t[$value['size']]))
  97. {
  98. $info_list[$key]['size'] = $t[$value['size']];
  99. }
  100. if($value['pb'] != '')
  101. {
  102. $info_list[$key]['pb'] = '';
  103. $pb = explode('/',trim($value['pb'],'/'));
  104. foreach ($pb as $vv)
  105. {
  106. $vv = explode('*',trim($vv,'*'));
  107. foreach ($vv as $v)
  108. {
  109. $info_list[$key]['pb'] .= '<p>'.trim($v,' ').'</p>';
  110. }
  111. }
  112. }
  113. }
  114. $total = $this->distribution->find_count($where);
  115. $pagenum = ceil($total/$perpage);
  116. $over = $total-($start+$perpage);
  117. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  118. echo json_encode($rows);exit;
  119. }
  120. $this->_Template('distribution',$this->data);
  121. }
  122. //添加
  123. public function _add()
  124. {
  125. $post = $this->input->post(NULL, TRUE);
  126. if(isset($post['category']))
  127. {
  128. $category = $this->input->post('category',true);
  129. $lace = $this->input->post('lace',true);
  130. $density = $this->input->post('density',true);
  131. $size = $this->input->post('size',true);
  132. $size = trim($size,',');
  133. $pb = $this->input->post('pb',true);
  134. $post['category'] = (isset($t[$category]))?$t[$category]:'';
  135. $post['lace'] = (isset($t[$lace]))?$t[$lace]:'';
  136. $post['density'] = (isset($t[$density]))?$t[$density]:'';
  137. $post['size'] = (isset($t[$size]))?$t[$size]:'';
  138. $post['pb'] = $pb;
  139. if($post['category'] == '' || $post['size'] == '')
  140. {
  141. echo json_encode(array('msg'=>'提交信息有误,请检查','success'=>false));exit;
  142. }
  143. $gl = '';$fl = array();$zzl = 0;$cw = 0;$xq = '';
  144. if($pb != '')
  145. {
  146. if($post['category'] == 128)
  147. {
  148. $pb = explode('/',trim($pb,'/'));
  149. $ftpb = $this->ft($pb);
  150. if($ftpb['cw'] > 0)
  151. {
  152. $cw++;
  153. }
  154. else
  155. {
  156. $xq .= $ftpb['pb'];
  157. }
  158. if(isset($pb[1]))//有蕾丝头套
  159. {
  160. $xq .= $pb['1'].'+';//发块
  161. }
  162. $hf = $this->js($xq);
  163. }
  164. else
  165. {
  166. if(stripos($pb,'/') !== false)
  167. {
  168. $cw++;
  169. }
  170. $xq .= $pb;
  171. $pb = explode('+',trim($pb,'+'));
  172. $hf = $this->js($pb);
  173. }
  174. }
  175. else
  176. {
  177. echo json_encode(array('msg'=>'请填写配比信息!','success'=>false));exit;
  178. }
  179. if($cw > 0)
  180. {
  181. echo json_encode(array('msg'=>'配比信息错误,请检查!','success'=>false));exit;
  182. }
  183. $post['gl'] = $hf['gl'];
  184. $post['weight'] = $hf['zzl'];
  185. $post['zh'] = $hf['zh'];
  186. $post['time'] = time();
  187. $pid = $post['category'].'-'.$post['lace'].'-'.$post['density'].'-'.$post['size'];
  188. $post['pid'] = str_replace(array('---','--'),'-',$pid);
  189. $post['pbxq'] = trim($xq,'+');
  190. if($this->distribution->insert($post))
  191. {
  192. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  193. }
  194. else
  195. {
  196. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  197. }
  198. }
  199. $this->_Template('distribution_add',$this->data);
  200. }
  201. //修改
  202. public function _edit($arg_array)
  203. {
  204. $post = $this->input->post(NULL, TRUE);
  205. if(isset($post['id']))
  206. {
  207. $id = $this->input->post('id',true);
  208. $category = $this->input->post('category',true);
  209. $lace = $this->input->post('lace',true);
  210. $density = $this->input->post('density',true);
  211. $size = $this->input->post('size',true);
  212. $size = trim($size,',');
  213. $pb = $this->input->post('pb',true);
  214. $post['category'] = (isset($t[$category]))?$t[$category]:'';
  215. $post['lace'] = (isset($t[$lace]))?$t[$lace]:'';
  216. $post['density'] = (isset($t[$density]))?$t[$density]:'';
  217. $post['size'] = (isset($t[$size]))?$t[$size]:'';
  218. $post['pb'] = $pb;
  219. if($post['category'] == '' || $post['size'] == '')
  220. {
  221. echo json_encode(array('msg'=>'提交信息有误,请检查','success'=>false));exit;
  222. }
  223. $gl = '';$fl = array();$zzl = 0;$cw = 0;$xq = '';
  224. if($pb != '')
  225. {
  226. if($post['category'] == 128)
  227. {
  228. $pb = explode('/',trim($pb,'/'));
  229. $ftpb = $this->ft($pb);
  230. if($ftpb['cw'] > 0)
  231. {
  232. $cw++;
  233. }
  234. else
  235. {
  236. $xq .= $ftpb['pb'];
  237. }
  238. if(isset($pb[1]))//有蕾丝头套
  239. {
  240. $xq .= $pb['1'].'+';//发块
  241. }
  242. $hf = $this->js($xq);
  243. }
  244. else
  245. {
  246. if(stripos($pb,'/') !== false)
  247. {
  248. $cw++;
  249. }
  250. $xq .= $pb;
  251. $pb = explode('+',trim($pb,'+'));
  252. $hf = $this->js($pb);
  253. }
  254. }
  255. else
  256. {
  257. echo json_encode(array('msg'=>'请填写配比信息!','success'=>false));exit;
  258. }
  259. if($cw > 0)
  260. {
  261. echo json_encode(array('msg'=>'配比信息错误,请检查!','success'=>false));exit;
  262. }
  263. $post['gl'] = $hf['gl'];
  264. $post['weight'] = $hf['zzl'];
  265. $post['zh'] = $hf['zh'];
  266. $post['time'] = time();
  267. $pid = $post['category'].'-'.$post['lace'].'-'.$post['density'].'-'.$post['size'];
  268. $post['pid'] = str_replace(array('---','--'),'-',$pid);
  269. $post['pbxq'] = trim($xq,'+');
  270. if($this->distribution->save($post,$id))
  271. {
  272. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  273. }
  274. else
  275. {
  276. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  277. }
  278. }
  279. $arg_array = $arg_array[0];
  280. $distribution = $this->distribution->read($arg_array);
  281. $this->data['distribution'] = $distribution;
  282. $this->_Template('distribution_edit',$this->data);
  283. }
  284. //删除
  285. public function _del()
  286. {
  287. $post = $this->input->post(NULL, TRUE);
  288. if(isset($post['s']))
  289. {
  290. $id_arr = $this->input->post('s');
  291. $id_arr = explode(',',$id_arr);
  292. if(!$id_arr)
  293. {
  294. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  295. }
  296. //循环删除记录
  297. foreach ($id_arr as $v)
  298. {
  299. $this->distribution->remove($v);
  300. }
  301. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  302. }
  303. }
  304. public function _drmb()
  305. {
  306. $title = '导入模板';
  307. $titlename = "<table border=1>
  308. <tr align='center'>
  309. <td>类目</td>
  310. <td>蕾丝类型</td>
  311. <td>密度</td>
  312. <td>尺寸</td>
  313. <td style='width:300px'>配比 (按照右侧格式填写)</td>
  314. <td>发条 :原材料尺寸-克数+原材料尺寸-克数 具体示例: 6-0.2+8-0.2+10-0.3+12-0.3<br>
  315. 发块: 原材料尺寸-克数+原材料尺寸-克数 具体示例: 8-0.1+10-0.1+12-0.25+14-0.25+16-0.3<br>
  316. 不含蕾丝头套:填写所需发条的尺寸(发条尺寸-克数+发条尺寸-克数+发条尺寸-克数) 具体示例: 14-20+16-10+18-8<br>
  317. 有发块的蕾丝头套(/后填发块原材料配比):发条尺寸-克数+发条尺寸-克数+发条尺寸-克数/发块原材料配比 具体示例: 14-20+16-10+18-8/18<br>
  318. 无发块的蕾丝头套(/后填蕾丝配比):发条尺寸-克数+发条尺寸-克数+发条尺寸-克数/蕾丝原材料配比 具体示例: 14-20+16-10+18-8/6-0.2+8-0.2+10-0.1<br>
  319. 全蕾丝头套:原材料尺寸-克数+原材料尺寸-克数 具体示例: 6-0.2+8-0.2+10-0.3+12-0.3<br></td>
  320. </tr></table>";
  321. $lm = array('发条','发块前头','头套');
  322. $md = $this->typeclass->find_all("classid = '10'");
  323. $ttls = $this->typeclass->find_all("classid = '18'");
  324. $fkls = $this->typeclass->find_all("classid = '25' or classid = '26'");
  325. $cc = $this->typeclass->find_all("classid = '14'");
  326. $rowsdq = array();
  327. foreach ($lm as $vvv)
  328. {
  329. if($vvv == '头套')
  330. {
  331. foreach ($ttls as $vv)
  332. {
  333. foreach ($md as $v)
  334. {
  335. foreach ($cc as $val)
  336. {
  337. if(stripos($v['zh'],'|') !== false)
  338. {
  339. $vzh = explode('|',$v['zh']);
  340. $v['zh'] = $vzh[0];
  341. }
  342. if($val['spare'] == 'Short Hair')
  343. {
  344. $val['spare'] = '短款';
  345. }
  346. $rowsdq[] = array($vvv,$vv['zh'],$v['title'],$val['spare'],'');
  347. }
  348. }
  349. }
  350. }
  351. else if($vvv == '发块前头')
  352. {
  353. foreach ($fkls as $vv)
  354. {
  355. foreach ($md as $v)
  356. {
  357. foreach ($cc as $val)
  358. {
  359. if(stripos($v['zh'],'|') !== false)
  360. {
  361. $vzh = explode('|',$v['zh']);
  362. $v['zh'] = $vzh[0];
  363. }
  364. if($val['spare'] == 'Short Hair')
  365. {
  366. $val['spare'] = '短款';
  367. }
  368. $rowsdq[] = array($vvv,$vv['zh'],$v['title'],$val['spare'],'');
  369. }
  370. }
  371. }
  372. }
  373. else
  374. {
  375. foreach ($cc as $val)
  376. {
  377. if($val['spare'] == 'Short Hair')
  378. {
  379. $val['spare'] = '短款';
  380. }
  381. $rowsdq[] = array($vvv,'','',$val['spare'],'');
  382. }
  383. }
  384. }
  385. $filename = $title.".xls";
  386. $tail = "\n";
  387. $this->excel->get_fz2($rowsdq,$titlename,$filename,$tail);
  388. }
  389. public function _dr()
  390. {
  391. $dir = '/data/excel/'.date('Ymd',time()).'/';
  392. $config['upload_path'] = '.'.$dir ;
  393. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  394. $config['allowed_types'] = 'xls|xlsx|csv';
  395. $config['max_size'] = 10240;
  396. $this->load->library('upload', $config);
  397. $this->upload->initialize($config);
  398. if ($this->upload->do_upload('userfile'))
  399. {
  400. $full_path = $dir.$this->upload->data('file_name');
  401. $fileName = '.' . $full_path;
  402. if (!file_exists($fileName))
  403. {
  404. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  405. }
  406. else
  407. {
  408. libxml_use_internal_errors(true);
  409. require_once "./data/excel/PHPExcel/IOFactory.php";
  410. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  411. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  412. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  413. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  414. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  415. ++$column;//如果列数大于26行
  416. $list = array();
  417. for ($i = 2; $i <= $row; $i++) // 行数循环
  418. {
  419. $data = array();
  420. for ($c = 'A'; $c != $column; $c++) // 列数循环
  421. {
  422. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  423. }
  424. $list[] = $data;
  425. }
  426. }
  427. $tz = array();$bs = array();
  428. $typeclassa = $this->typeclass->find_all("zh != ''");
  429. foreach ($typeclassa as $v)
  430. {
  431. $tz[$v['zh']] = $v['id'];
  432. }
  433. $typeclassb = $this->typeclass->find_all("bqsku != ''");
  434. foreach ($typeclassb as $v)
  435. {
  436. $bs[$v['bqsku']] = $v['id'];
  437. }
  438. $i = 0;$j = 0;$ed = array();$x=0;$cs = array();
  439. foreach ($list as $k=>$v)
  440. {
  441. $hs = $k+2;
  442. $post['category']= (isset($tz[$v[0]]))?$tz[$v[0]]:'';
  443. $post['lace'] = (isset($tz[$v[1]]))?$tz[$v[1]]:'';
  444. $post['density'] = (isset($bs[$v[2]]))?$bs[$v[2]]:'';
  445. $post['size'] = (isset($bs[$v[3]]))?$bs[$v[3]]:'';
  446. $post['pb'] = $v[4];
  447. $pb = $v[4];
  448. $gl = '';$fl = array();$zzl = 0;$cw = 0;$xq = '';
  449. if($pb != null)
  450. {
  451. if($post['category'] == 128)
  452. {
  453. $pb = explode('/',trim($pb,'/'));
  454. $ftpb = $this->ft($pb);
  455. if($ftpb['cw'] > 0)
  456. {
  457. $j++;
  458. $ed[] = array('第'.$hs.'行导入失败,发条的配比信息有误!');
  459. continue;
  460. }
  461. else
  462. {
  463. $xq .= $ftpb['pb'];
  464. }
  465. if(isset($pb[1]))//有蕾丝头套
  466. {
  467. $xq .= $pb['1'].'+';//发块
  468. }
  469. $hf = $this->js($xq);
  470. }
  471. else
  472. {
  473. if(stripos($pb,'/') !== false)
  474. {
  475. $j++;
  476. $ed[] = array('第'.$hs.'行导入失败,请检查配比内容1');
  477. continue;
  478. }
  479. $xq .= $v[4];
  480. $hf = $this->js($pb);
  481. }
  482. if($hf['cw'] > 0)
  483. {
  484. $j++;
  485. $ed[] = array($hf['cw'].' - '.json_encode($hf['nr']).' - 第'.$hs.'行导入失败,请检查配比内容2');
  486. continue;
  487. }
  488. $post['gl'] = $hf['gl'];
  489. $post['weight'] = $hf['zzl'];
  490. $post['zh'] = $hf['zh'];
  491. $pid = $post['category'].'-'.$post['lace'].'-'.$post['density'].'-'.$post['size'];
  492. $post['pid'] = str_replace(array('---','--'),'-',$pid);
  493. $post['pbxq'] = trim($xq,'+');
  494. $x = $this->distribution->get_pid($post['pid']);
  495. if($x)
  496. {
  497. if(!$this->distribution->save($post,$x['id']))
  498. {
  499. $j++;
  500. $ed[] = array('第'.$hs.'行导入失败,请重试1');
  501. }
  502. }
  503. else
  504. {
  505. $post['time'] = time();
  506. if(!$this->distribution->insert($post))
  507. {
  508. $j++;
  509. $ed[] = array('第'.$hs.'行导入失败,请重试2');
  510. }
  511. }
  512. }
  513. }
  514. if($j > 0)
  515. {
  516. $time = date('Ymd',time());
  517. $tt = date('Ymd',time());
  518. $title = '导入错误信息-'.$tt;
  519. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  520. $tail = "\n";
  521. $filename = $title.".xls";
  522. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  523. $dir = '/data/excel/'.$time.'/';
  524. $file_name = 'error_'.$time.rand(1000,9999);
  525. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  526. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  527. fwrite($myfile,$ecl);
  528. fclose($myfile);
  529. $error = $dir.$file_name.'.xls';
  530. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
  531. }
  532. else
  533. {
  534. echo json_encode(array('msg'=>'导入成功!','error'=>$cs,'success'=>true));exit;
  535. }
  536. }
  537. }
  538. public function ft($pb)
  539. {
  540. $t = array();$bs = array();
  541. $typeclass = $this->typeclass->find_all();
  542. foreach ($typeclass as $v)
  543. {
  544. $t[$v['id']] = $v['id'];
  545. $bs[$v['bqsku']] = $v['id'];
  546. }
  547. $xq = '';$j = 0;
  548. $pb[0] = explode('+',trim($pb[0],'+'));
  549. foreach ($pb[0] as $val) //发条
  550. {
  551. $sz = explode('-',$val);
  552. if(!isset($sz[1]) || !isset($bs[$sz[0]]))
  553. {
  554. $j++;
  555. break;
  556. }
  557. $sizedata = $this->distribution->ge_size(126,$bs[$sz[0]]);
  558. if(!$sizedata)
  559. {
  560. $j++;
  561. break;
  562. }
  563. $bl = $sz[1]/$sizedata['weight'];
  564. $ftpb = explode('+',$sizedata['pb']);
  565. foreach ($ftpb as $v)
  566. {
  567. $xxzl = explode('-',$v);
  568. $xq .= $xxzl[0].'-'.sprintf("%01.2f",$xxzl[1]*$bl).'+';
  569. }
  570. }
  571. if($j > 0)
  572. {
  573. return array('cw'=>1);
  574. }
  575. else
  576. {
  577. return array('cw'=>0,'pb'=>$xq);
  578. }
  579. }
  580. public function js($data)
  581. {
  582. $zzl = 0;$gl = '';$fl=array();$cw=0;$nr = array();$zh = '';
  583. $pb = explode('+',trim($data,'+'));
  584. if(isset($pb))
  585. {
  586. foreach ($pb as $k=>$v)
  587. {
  588. $v = explode('-',trim($v,'-'));
  589. if(!isset($v[1]))
  590. {
  591. $cw = 1;
  592. $nr[] = array($pb,$pb[$k]);
  593. break;
  594. }
  595. if(!is_numeric($v[0]) || !is_numeric($v[1]))
  596. {
  597. $cw = 2;
  598. $nr[] = array($pb,$pb[$k]);
  599. break;
  600. }
  601. $zzl += $v[1];
  602. if(isset($fl[$v[0]]))
  603. {
  604. $fl[$v[0]] += $v[1];
  605. }
  606. else
  607. {
  608. $fl[$v[0]] = $v[1];
  609. }
  610. }
  611. foreach ($fl as $k=>$v)
  612. {
  613. $zh .= $k.'inch:'.$v.'g<br>';
  614. $gl .= $k.'-'.$v.'+';
  615. }
  616. }
  617. else
  618. {
  619. $cw = 3;
  620. }
  621. if($cw < 1)
  622. {
  623. return array('cw'=>0,'gl'=>trim($gl,'+'),'zzl'=>$zzl,'zh'=>trim($zh,'<br>'));
  624. }
  625. else
  626. {
  627. return array('cw'=>$cw,'nr'=>$nr);
  628. }
  629. }
  630. public function _db()
  631. {
  632. $t = array();$y = array();$w = array();$cc = array();
  633. $typeclass = $this->typeclass->find_all();
  634. foreach ($typeclass as $v)
  635. {
  636. if($v['classid'] == 14)
  637. {
  638. $cc[$v['bqsku']] = 0;
  639. }
  640. $t[$v['id']] = $v['bqsku'];
  641. }
  642. $post = $this->input->post(NULL, TRUE);
  643. if(isset($_GET['dktime']))
  644. {
  645. $ktime = $this->input->get('dktime',true);
  646. $jtime = $this->input->get('djtime',true);
  647. $ktime = strtotime($ktime);
  648. $jtime = strtotime($jtime);
  649. $pb = array();$zz = '';
  650. $distribution = $this->distribution->find_all();
  651. foreach ($distribution as $val)
  652. {
  653. $pb[$val['pid']] = array('weight'=>$val['weight'],'gl'=>$val['gl'],'zh'=>$val['zh']);
  654. }
  655. $where = "shop != '9' and shop != '26' and type != '3' and type != '5' and type != '7' and type != '8' and type != '9' and type != '10' and type != '12' and library = '2' and librarytime > '".$ktime."' and librarytime < '".$jtime."'";
  656. $dlz = $this->fullorder->find_all($where,'id,fpdata,number,orderinfo','id desc',0,5);
  657. $smt = $this->fullordersmt->find_all($where,'id,fpdata,number,orderinfo','id desc',0,5);
  658. $data = array_merge($dlz,$smt);
  659. $product = array();
  660. foreach ($data as $val)
  661. {
  662. $sy = array();
  663. $cp = explode(';',trim($val['fpdata'],';'));
  664. foreach ($cp as $v)
  665. {
  666. $a = 0;
  667. $v = explode('|',trim($v,'|'));
  668. $qb = explode(',',$v[0]);
  669. $szid = $qb[0];//尺寸ID
  670. if(!isset($qb[1]))
  671. {
  672. $w[] = array('number'=>$val['number'],'orderinfo'=>$val['orderinfo'],'产品参数错误',$v);
  673. continue;
  674. }
  675. $qb = explode('-',trim($qb[1],'-'));//尺寸外其它参数
  676. if($qb[0] == '126')
  677. {
  678. if(isset($pb[$qb[0].'-'.$szid]))
  679. {
  680. $a = 1;
  681. $zz .= $pb[$qb[0].'-'.$szid]['gl'].'+';
  682. $y[] = array('number'=>$val['number'],'orderinfo'=>$val['orderinfo'],'title'=>$v[1],'weight'=>$pb[$qb[0].'-'.$szid]['weight'].'g','zh'=>$pb[$qb[0].'-'.$szid]['zh']);
  683. }
  684. }
  685. else if($qb[0] == '127')
  686. {
  687. if(isset($pb[$qb[0].'-'.$qb[6].'-'.$qb[7].'-'.$szid]))
  688. {
  689. $a = 1;
  690. $zz .= $pb[$qb[0].'-'.$qb[6].'-'.$qb[7].'-'.$szid]['gl'].'+';
  691. $y[] = array('number'=>$val['number'],'orderinfo'=>$val['orderinfo'],'title'=>$v[1],'weight'=>$pb[$qb[0].'-'.$qb[6].'-'.$qb[7].'-'.$szid]['weight'].'g','zh'=>$pb[$qb[0].'-'.$qb[6].'-'.$qb[7].'-'.$szid]['zh']);
  692. }
  693. }
  694. else if($qb[0] == '128')
  695. {
  696. if(isset($pb[$qb[0].'-'.$qb[4].'-'.$qb[6].'-'.$szid]))
  697. {
  698. $a = 1;
  699. $zz .= $pb[$qb[0].'-'.$qb[4].'-'.$qb[6].'-'.$szid]['gl'].'+';
  700. $y[] = array('number'=>$val['number'],'orderinfo'=>$val['orderinfo'],'title'=>$v[1],'weight'=>$pb[$qb[0].'-'.$qb[4].'-'.$qb[6].'-'.$szid]['weight'].'g','zh'=>$pb[$qb[0].'-'.$qb[4].'-'.$qb[6].'-'.$szid]['zh']);
  701. }
  702. }
  703. if($a == 0)
  704. {
  705. $w[] = array('number'=>$val['number'],'orderinfo'=>$val['orderinfo'],'','');
  706. }
  707. }
  708. }
  709. $zz = explode('+',trim($zz,'+'));
  710. foreach ($zz as $v)
  711. {
  712. $cd = explode('-',trim($v,'-'));
  713. if(isset($cc[$cd[0]]))
  714. {
  715. $cc[$cd[0]] += $cd[1];
  716. }
  717. }
  718. $zzcx = '';
  719. foreach ($cc as $k=>$v)
  720. {
  721. $zzcx .= $k.'inch:'.$v.'g'.'<br>';
  722. }
  723. $title = date('Y-m-d',$ktime).' 至 '.date('Y-m-d',$jtime).'订单原材料配比';
  724. $titlename = "<table border=1>
  725. <tr align='center'>
  726. <td>编号</td>
  727. <td>订单号</td>
  728. <td>产品名称</td>
  729. <td>总重量</td>
  730. <td>配比详情</td>
  731. </tr></table>";
  732. $filename = $title.".xls";
  733. $tail = "<tr align='center'><td></td><td></td><td></td><td>所有尺寸合并数据:</td><td>".trim($zzcx,'<br>')."</td></tr>";
  734. $this->excel->get_fz2($y,$titlename,$filename,$tail);
  735. }
  736. }
  737. }