Boss.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Boss extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_api','api');
  7. $this->load->_model('Model_apismt','apismt');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_fullorder','fullorder');
  10. $this->load->_model('Model_fullordertt','fullordertt');
  11. $this->load->_model('Model_fedex_cby','fedex_cby');
  12. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  13. $this->load->_model('Model_fullordersmt','fullordersmt');
  14. $this->load->_model('Model_customersmt','customersmt');
  15. $this->load->_model('Model_country','country');
  16. $this->load->_model('Model_hl','hl');
  17. $this->load->_model('Model_is','is');
  18. $this->load->_model('Model_kdniao','kdniao');
  19. $this->load->_model('Model_typeclass','typeclass');
  20. $this->load->_model('Model_warehouse','warehouse');
  21. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  22. $this->load->_model('Model_dhl','dhl');
  23. $this->load->_model('Model_usps','usps');
  24. $this->load->_model('Model_dhltest','dhltest');
  25. $this->load->_model('Model_customer','customer');
  26. $this->load->_model('Model_express','express');
  27. $this->load->_model('Model_notice','notice');
  28. $this->load->_model('Model_whlabel','whlabel');
  29. $this->load->_model('Model_productdescribe','productdescribe');
  30. $this->load->_model('Model_ljg','ljg');
  31. $this->load->_model('Model_commodityread','commodityread');
  32. $this->load->_model('Model_service','service');
  33. $this->load->_model('Model_fedex','fedex');
  34. $this->load->_model('Model_commodity','commodity');
  35. $this->load->_model('Model_fullordersmtorder','fullordersmtorder');
  36. $this->load->_model('Model_ali','ali');
  37. $this->load->_model('Model_fullordersmthb','fullordersmthb');
  38. $this->load->_model('Model_fullordersmtbf','fullordersmtbf');
  39. $this->load->_model('Model_taxzhengzhou','taxzhengzhou');
  40. $this->load->_model('Model_taxshanghai','taxshanghai');
  41. $this->load->_model('Model_excel','excel');
  42. $this->load->_model('Model_ups','ups');
  43. $this->load->_model('Model_dpd','dpd');
  44. $this->load->_model('Model_cne','cne');
  45. $this->load->_model('Model_outbound','outbound');
  46. $this->load->_model('Model_specialstock','specialstock');
  47. $this->load->_model('Model_setting','setting');
  48. $this->load->_model('Model_pay','pay');
  49. $this->load->_model('Model_shopsku','shopsku');
  50. }
  51. //定义方法的调用规则 获取URI第二段值
  52. public function _remap($arg,$arg_array)
  53. {
  54. if($arg == 'out')
  55. {
  56. $this->_out($arg_array);
  57. }
  58. else if($arg == 'sku')
  59. {
  60. $this->_sku();
  61. }
  62. else if($arg == 'spexcel')
  63. {
  64. $this->_spexcel();
  65. }
  66. else if($arg == 'qczd')
  67. {
  68. $this->_qczd();
  69. }
  70. else if($arg == 'setting')
  71. {
  72. $this->_setting();
  73. }
  74. else if($arg == 'sctime')
  75. {
  76. $this->_sctime();
  77. }
  78. else if($arg == 'dpex')
  79. {
  80. $this->_dpex();
  81. }
  82. else if($arg == 'dpay')
  83. {
  84. $this->_dpay();
  85. }
  86. else if($arg == 'excellkh')
  87. {
  88. $this->_excellkh();
  89. }
  90. else if($arg == 'excelshop')
  91. {
  92. $this->_excelshop();
  93. }
  94. else
  95. {
  96. $this->_index();
  97. }
  98. }
  99. public function _index()
  100. {
  101. $setting = $this->setting->get_settings();
  102. $this->data['excelpass'] = $setting['excelpass'];
  103. $this->data['excelusernum'] = $setting['excelusernum'];
  104. $this->data['exceljmnum'] = $setting['exceljmnum'];
  105. $this->data['sctime'] = $setting['sctime'];
  106. $this->_Template('boss',$this->data);
  107. }
  108. public function _out($arg_array)
  109. {
  110. $post = $this->input->post(NULL, TRUE);
  111. if(isset($post['order']))
  112. {
  113. $time = $this->input->post('time',true);
  114. $time = strtotime($time);
  115. $order = $this->input->post('order',true);
  116. $weight = $this->input->post('weight',true);
  117. if(!isset($weight))//测试没问题后可以删
  118. {
  119. $weight = '';
  120. }
  121. if(substr($order,0,3) == '788' && substr($order,-4,4) == '0430')//Fedex联邦
  122. {
  123. $order = substr($order,0,12);
  124. }
  125. if(strlen($order) == '34')//联邦杭州超长运单截取
  126. {
  127. $order = substr($order,22,12);
  128. }
  129. if(!$order)
  130. {
  131. echo json_encode(array('msg'=>'出库信息不能为空!','success'=>false));exit;
  132. }
  133. $fullorder_name = 'fullorder';$outtype = 1;
  134. $y = $this->fullorder->get_waybill($order);
  135. if(!$y)
  136. {
  137. $y = $this->fullorder->get_number($order);
  138. $outtype = 2;
  139. if(!$y)
  140. {
  141. $fullorder_name = 'fullordersmt';$outtype = 1;
  142. $y = $this->fullordersmt->get_waybill($order);
  143. if(!$y)
  144. {
  145. $y = $this->fullordersmt->get_number($order);
  146. $outtype = 2;
  147. if(!$y)
  148. {
  149. $fullorder_name = 'fullordertt';$outtype = 1;
  150. $y = $this->fullordertt->get_waybill($order);
  151. if(!$y)
  152. {
  153. $y = $this->fullordertt->get_number($order);
  154. $outtype = 2;
  155. if(!$y)
  156. {
  157. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. if($y['mergeid'] == '1')
  165. {
  166. $y = $this->$fullorder_name->read($y['merge']);
  167. }
  168. $express = $this->express->read($y['express']);
  169. if($y['state'] == 216 && $fullorder_name == 'fullordersmt')
  170. {
  171. $y['librarynot'] = '客户已取消!';
  172. }
  173. if(($y['print'] != 3 || $y['libraryconfirm'] == 1 || $y['state'] == 214 || $y['state'] == 217 || $y['state'] == 283 || $y['state'] == 206 || $y['state'] == 205 || $y['state'] == 204 || $y['state'] == 210 || $y['state'] == 211 || $y['state'] == 212 || ($y['state'] == 216 && $fullorder_name == 'fullordersmt')) && $y['type'] != 3)//独立站216先关了
  174. {
  175. echo json_encode(array('msg'=>'禁止出库!'.$y['librarynot'],'success'=>false));exit;
  176. }
  177. if($y['library'] > 1)
  178. {
  179. echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作','success'=>false));exit;
  180. }
  181. if($express['out'] != 3)
  182. {
  183. if($express['out'] != $outtype)
  184. {
  185. $smlx = ($express['out']=='1')?'运单':'发货单';
  186. echo json_encode(array('msg'=>'扫描类型错误!此单需要扫描'.$smlx,'success'=>false));exit;
  187. }
  188. }
  189. if($y['type'] != 7 && $y['waybill'] != '' && $y['printtype'] == '1')
  190. {
  191. $y['waybill'] = trim($y['waybill'],' ');
  192. if(strlen($y['waybill']) == 12 && $y['express'] != 24 && $y['express'] != 31 && $y['express'] != 38 && $y['express'] != 41 && $y['express'] != 6 && $y['express'] != 43 && $y['express'] != 48 && $y['express'] != 50)
  193. {
  194. echo json_encode(array('msg'=>'出库物流和系统不匹配,请联系梦体解决'.$y['express'].'-1','success'=>false));exit;
  195. }
  196. else if(strlen($y['waybill']) == 10 && $y['express'] != 1 && $y['express'] != 37 && $y['express'] != 49 && $y['express'] != 42)
  197. {
  198. echo json_encode(array('msg'=>'出库物流和系统不匹配,请联系梦体解决'.$y['express'].'-2','success'=>false));exit;
  199. }
  200. else if(strlen($y['waybill']) == 18 && $y['express'] != 3)
  201. {
  202. echo json_encode(array('msg'=>'出库物流和系统不匹配,请联系梦体解决'.$y['express'].'-3','success'=>false));exit;
  203. }
  204. }
  205. if(($y['express'] == '24' || $y['express'] == '3' || $y['express'] == '28' || $y['express'] == '33' || $y['express'] == '42') && $y['type'] != 6)//杭州除外
  206. {
  207. $numweight = str_replace('kg','',$weight);
  208. if($weight == '' || $numweight < '0.1' || !is_numeric($numweight))
  209. {
  210. echo json_encode(array('msg'=>'此单需要称重!','success'=>false));exit;
  211. }
  212. $yzweight = explode('.',$numweight);
  213. if($yzweight[0] == '')
  214. {
  215. echo json_encode(array('msg'=>'重量错误,请重新称重!','success'=>false));exit;
  216. }
  217. if($numweight > '0.98' && $y['express'] == '3')
  218. {
  219. echo json_encode(array('msg'=>'UPS大于0.98公斤需要拆包!','success'=>false));exit;
  220. }
  221. if($numweight > '2' && $y['express'] == '37')
  222. {
  223. echo json_encode(array('msg'=>'杭州DHL大于2公斤需要联系店员!','success'=>false));exit;
  224. }
  225. if($numweight >= '10' && ($y['express'] == '24' || $y['express'] == '31'))
  226. {
  227. echo json_encode(array('msg'=>'联邦不能大于10公斤!','success'=>false));exit;
  228. }
  229. }
  230. if(((time() - $y['printtime']) > (15*24*3600) || $y['printtime'] < 1590211800) && $y['express'] == '24' && $y['type'] != 6)//杭州店铺除外
  231. {
  232. echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  233. }
  234. if((time() - $y['printtime']) > (4*24*3600) && $y['express'] == '3' && $y['type'] != 6)//杭州店铺除外
  235. {
  236. //echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  237. echo json_encode(array('msg'=>'此运单过期无法出库,请联系成会处理!','success'=>false));exit;
  238. }
  239. if((time() - $y['printtime']) > (7*24*3600) && $y['express'] == '37' && $y['type'] != 6)//杭州店铺除外
  240. {
  241. echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  242. }
  243. $this->db->trans_begin();
  244. $warehouse = $this->warehouse->read($y['type']);
  245. if($warehouse['zd'] == '1')
  246. {
  247. if($warehouse['bdck'] == '')
  248. {
  249. echo json_encode(array('msg'=>'仓库设置错误!','success'=>false));exit;
  250. }
  251. $bdck = $warehouse['bdck'];
  252. $wh = $this->_fout_db($y,$warehouse,$bdck);
  253. if($wh['fh'] == 2)
  254. {
  255. $kcyz = $this->ck->get_kc($y['state'],$warehouse,$y['shop'],$y['number'],$y['whlabel'],$y['fpdata']);
  256. if($kcyz['fpdata'] != '' && $kcyz['t'] == '0')
  257. {
  258. $x['whlabel'] = $kcyz['whlabel'];
  259. $x['fpdata'] = $kcyz['fpdata'];
  260. $y['whlabel'] = $x['whlabel'];
  261. $this->$fullorder_name->save($x,$y['id']);
  262. }
  263. $wh = $this->_fout_db($y,$warehouse,$bdck);
  264. if($wh['fh'] == 2)
  265. {
  266. echo json_encode(array('msg'=>'库存占用量与实际出库量不符!','success'=>false));exit;
  267. }
  268. }
  269. foreach ($wh['sj'] as $v)
  270. {
  271. $this->$bdck->save(array('state'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$v['id']);
  272. }
  273. }
  274. if($fullorder_name == 'fullordersmt')
  275. {
  276. $stt = ($y['waybill']!='')?209:$y['state'];
  277. $this->$fullorder_name->save(array('library'=>2,'state'=>$stt,'librarytime'=>$time,'weight'=>$weight),$y['id']);
  278. }
  279. else
  280. {
  281. if($y['type'] == 3)
  282. {
  283. $this->$fullorder_name->save(array('print'=>3,'printtime'=>$time,'printnumber'=>1,'state'=>216,'libraryconfirm'=>2,'library'=>2,'librarytime'=>$time,'weight'=>$weight),$y['id']);
  284. }
  285. else
  286. {
  287. $this->$fullorder_name->save(array('library'=>2,'librarytime'=>$time,'weight'=>$weight),$y['id']);
  288. }
  289. }
  290. if ($this->db->trans_status() === TRUE)
  291. {
  292. $this->db->trans_commit();
  293. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  294. }
  295. else
  296. {
  297. $this->db->trans_rollback();
  298. echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));
  299. }
  300. }
  301. }
  302. public function _fout_db($y,$warehouse,$bdck)//对比占单是否正确
  303. {
  304. $wh = $this->$bdck->find_all("zd = '".$y['number']."' and warehouse = '".$y['type']."' and (state = '0' or state = '9')");
  305. $cpsl = 0;
  306. $pp = explode('|',trim($y['whlabel'],'|'));
  307. foreach ($pp as $va)
  308. {
  309. $num = explode('-',$va);
  310. if(isset($num[2]))
  311. {
  312. if(stripos($num[2],$warehouse['hz']) !== false)
  313. {
  314. $cpsl += $num[1];
  315. }
  316. }
  317. }
  318. if(count($wh) == $cpsl)
  319. {
  320. return array('fh'=>1,'sj'=>$wh);
  321. }
  322. else
  323. {
  324. return array('fh'=>2);
  325. }
  326. }
  327. public function _sku()//测试SKU
  328. {
  329. $post = $this->input->post(NULL, TRUE);
  330. if(isset($post['sku']))
  331. {
  332. $sku = $this->input->post('sku',true);
  333. if($sku == '')
  334. {
  335. echo json_encode(array('msg'=>'SKU不能为空!','success'=>false));exit;
  336. }
  337. $gethl = $this->hl->get_hl();//获取即时汇率
  338. $dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');
  339. $dtc = array();
  340. foreach ($dictionaries as $v)
  341. {
  342. if(stripos($v['spare'],'|') !== false)//如果有多个值
  343. {
  344. $v['spare'] = explode('|',$v['spare']);
  345. foreach ($v['spare'] as $k=>$vs)
  346. {
  347. if(stripos($v['zh'],'|') !== false)
  348. {
  349. $vzh = explode('|',$v['zh']);
  350. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  351. }
  352. else
  353. {
  354. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  355. }
  356. }
  357. }
  358. else
  359. {
  360. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  361. }
  362. }
  363. $dictionaries2 = $this->typeclass->find_all();
  364. foreach ($dictionaries2 as $v)
  365. {
  366. $dtctitle[$v['id']] = $v['title'];
  367. }
  368. /* 匹配结束 */
  369. /* 价格加入 */
  370. $money = array();
  371. $productdescribe = $this->productdescribe->find_all('1=1');
  372. foreach ($productdescribe as $v)
  373. {
  374. $money[$v['number']] = array();
  375. }
  376. /* 价格加入 */
  377. /* 匹配ID加入 */
  378. $int = array();
  379. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  380. foreach ($intdata as $v)
  381. {
  382. $v['spare'] = explode('|',$v['spare']);
  383. $int[$v['id']] = $v['spare'][0];
  384. }
  385. /* 匹配ID加入 */
  386. $zjsku = array();
  387. $shopsku = $this->shopsku->find_all();
  388. foreach ($shopsku as $val)
  389. {
  390. $ss = explode(',',trim($val['shop'],','));
  391. foreach ($ss as $v)
  392. {
  393. if(isset($zjsku[$v]))
  394. {
  395. $zjsku[$v] .= ','.trim($val['sku'],',');
  396. }
  397. else
  398. {
  399. $zjsku[$v] = trim($val['sku'],',');
  400. }
  401. }
  402. }
  403. /* 匹配ID结束 */
  404. $q = '';
  405. $quantity = explode(',',trim($sku,','));
  406. foreach ($quantity as $v)
  407. {
  408. $q .= '1;';
  409. }
  410. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  411. $shop = $this->shop->read(19);
  412. if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
  413. {
  414. $sku = rtrim($sku,',').','.$zjsku[$shop['id']];
  415. }
  416. $r = $this->api->matching(trim($q,';'),$sku,$dtc,$money,$int,$dtctitle,$shop);
  417. $p = '';
  418. $product = explode(';',trim($r['product'],';'));
  419. if($r['title'] != '' && $product)
  420. {
  421. foreach ($product as $v)
  422. {
  423. $vc = explode('|',$v);
  424. $p .= $vc[1].'<br>';
  425. }
  426. $r['title'] = str_replace(array('<','>'),array('&lt;','&gt;'),$r['title']);
  427. echo json_encode(array('msg'=>'仓库品名:'.$r['title'].'<br>商品名称:'.$p,'success'=>true,'r'=>$r));exit;
  428. }
  429. else
  430. {
  431. echo json_encode(array('msg'=>'SKU错误','success'=>false));exit;
  432. }
  433. }
  434. }
  435. public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle)
  436. {
  437. $sl = explode(';',$quantity);
  438. $x=0;$product = '';//product 每单多产品链接组合
  439. $purchase = 0;$cost = 0;//每单所有产品总成本价格;
  440. $whlabel = '|';//库存产品码
  441. $nr = '';$cs = array();
  442. $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/');
  443. $h = array('-','-','','','-','');
  444. $issku = str_replace(array('(',')'),array('(',')'),$issku);
  445. $issku = str_replace(array(' <','> '),array('<','>'),$issku);
  446. $issku = strtolower($issku);
  447. $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除
  448. $varsku = strtolower($varsku);//转小写
  449. $sku = explode(',',$varsku);//多产品分割为多数组
  450. $pd = explode(',',$issku);
  451. $cid = array();
  452. $slpx = array();
  453. $tqjcskua = array();//先检测是否只匹配品名
  454. $tqjcskub = array();
  455. $tqjcqda = array();
  456. $tqjcqdb = array();
  457. $tqjcgit = array();//礼物类放SKU顺序中间
  458. $tqjcgitpd = array();//礼物类放SKU顺序中间
  459. foreach ($sku as $k=>$value)
  460. {
  461. //查找是否有头套和HD开始
  462. $cf = explode('-',trim($value,'-'));
  463. $cf = array_filter($cf);
  464. foreach ($cf as $v)
  465. {
  466. if(isset($dtc[$v]['id']))
  467. {
  468. $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']);
  469. }
  470. }
  471. if(isset($cid['44']) && isset($cid['18']) && isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id']))
  472. {
  473. $value = '-'.$value.'-';
  474. $sku[$k] = '-'.$sku[$k].'-';
  475. $pd[$k] = '-'.$pd[$k].'-';
  476. $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value);
  477. $value = str_replace('-'.$cid['44']['spare'],'-',$value);
  478. $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]);
  479. $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]);
  480. $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]);
  481. $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]);
  482. $value = strtolower(trim($value,'-'));
  483. $pd[$k] = strtolower(trim($pd[$k],'-'));
  484. $sku[$k] = strtolower(trim($sku[$k],'-'));
  485. }
  486. //查找是否有头套和HD结束
  487. if(isset($dtc[$value]['classid']))
  488. {
  489. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  490. {
  491. $tqjcskua[$k] = $value;
  492. $tqjcqda[$k] = $pd[$k];
  493. continue;
  494. }
  495. }
  496. if(stripos($value,'gift') !== false)
  497. {
  498. $tqjcgit[$k] = $value;
  499. $tqjcgitpd[$k] = $pd[$k];
  500. continue;
  501. }
  502. $tqjcskub[$k] = $value;
  503. $tqjcqdb[$k] = $pd[$k];
  504. }
  505. $sku = $tqjcskub+$tqjcgit+$tqjcskua;
  506. $newsl = array();
  507. foreach ($sku as $k=>$value)
  508. {
  509. if(!isset($sl[$k]))
  510. {
  511. $sl[$k] = 1;
  512. }
  513. $newsl[] = $sl[$k];
  514. }
  515. $sl = array_values($newsl);
  516. $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda;
  517. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  518. $pd = array_values($pd);
  519. /**
  520. $tqjcskua = array();//先检测是否只匹配品名
  521. $tqjcskub = array();
  522. foreach ($sku as $k=>$value)
  523. {
  524. if(isset($dtc[$value]['classid']))
  525. {
  526. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  527. {
  528. $tqjcskua[$k] = $value;
  529. continue;
  530. }
  531. }
  532. $tqjcskub[$k] = $value;
  533. }
  534. $sku = $tqjcskub+$tqjcskua;
  535. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  536. **/
  537. foreach ($sku as $value)
  538. {
  539. $bmsku = '';
  540. if(stripos($value,'-<') !== false && stripos($value,'>-') === false)
  541. {
  542. $isskufg = explode('-<',$value);
  543. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  544. }
  545. if(stripos($value,'-<') !== false && stripos($value,'>-') !== false)
  546. {
  547. $isskufg = explode('-<',$value);
  548. $isskufgh = explode('>-',$isskufg[1]);
  549. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  550. }
  551. if(stripos($value,'-<') === false && stripos($value,'>-') !== false)
  552. {
  553. $isskufg = explode('>-',$value);
  554. $bmsku = strtoupper($isskufg[0]).'&gt;';
  555. }
  556. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') === false)
  557. {
  558. $isskufg = explode('-&lt;',$value);
  559. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  560. }
  561. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') !== false)
  562. {
  563. $isskufg = explode('-&lt;',$value);
  564. $isskufgh = explode('&gt;-',$isskufg[1]);
  565. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  566. }
  567. if(stripos($value,'-&lt;') === false && stripos($value,'&gt;-') !== false)
  568. {
  569. $isskufg = explode('&gt;-',$value);
  570. $bmsku = strtoupper($isskufg[0]).'&gt;';
  571. }
  572. $value = trim($value,' ');$cpson = array();$cplf = array();
  573. $thisid='';$tha=array();$thb=array();
  574. $purchasemy=0;$costmy=0;$salespricemy=0;
  575. $djay = array();//每单单个产品公司销售价格
  576. $ptitlea='';$ptitleb='';//每单产品名称
  577. $cpa='';$cpb='';$fc = 0;
  578. $number = array('dc'=>'','c'=>'');
  579. $classid = $this->classid->sku();
  580. $pm = $classid;//品名顺序
  581. //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加
  582. $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容
  583. //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型)
  584. $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',39=>'');//头套
  585. $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'');//卡子发,7=>33重量
  586. $cpgi = array(16=>131,34=>'');//礼物
  587. $cpac = array(16=>133,35=>'');//配件
  588. $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>'');
  589. $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>'');
  590. if((preg_match('/\d\*\df/',$pd[$x]) || preg_match('/\df/',$pd[$x]) || stripos($pd[$x],'+F') !== false || stripos($pd[$x],'Frontal') !== false) && stripos($pd[$x],'wig') === false && stripos($pd[$x],'Bob') === false)
  591. {
  592. $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197;
  593. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'');//蕾丝发块
  594. $fc = 1;
  595. }
  596. else if((preg_match('/\d\*\dc/',$pd[$x]) || preg_match('/\dc/',$pd[$x]) || stripos($pd[$x],'+C') !== false || stripos($pd[$x],'Closure') !== false) && stripos($pd[$x],'wig') === false && stripos($pd[$x],'Bob') === false)
  597. {
  598. $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195;
  599. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'');//蕾丝发块
  600. if(stripos($pd[$x],'2*6') !== false)
  601. {
  602. $cplf[12] = 76;
  603. }
  604. $fc = 1;
  605. }
  606. $cpcppd = 0;
  607. $cpcptype = $this->typeclass->find_all("classid = 33");
  608. foreach ($cpcptype as $v)
  609. {
  610. $val = explode('|',trim($v['spare'],'|'));
  611. foreach ($val as $vv)
  612. {
  613. if(stripos($pd[$x],$vv) !== false)
  614. {
  615. $cpcppd++;
  616. }
  617. }
  618. }
  619. if($fc==1)
  620. {
  621. $cpson = $cplf;
  622. }
  623. else if ((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false) && stripos($pd[$x],'Syn') === false && stripos($pd[$x],'Gift') === false)//
  624. {
  625. $cpson = $cptt;
  626. }
  627. else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0)
  628. {
  629. $cpson = $cphxhair;
  630. $cp = $cpson;
  631. }
  632. else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0)
  633. {
  634. $cpson = $cphxtt;
  635. $cp = $cpson;
  636. }
  637. else if ($cpcppd > 0)
  638. {
  639. $cpson = $cpcp;
  640. $cp = $cpcp;
  641. }
  642. else if (stripos($pd[$x],'Gift') !== false)
  643. {
  644. $cpson = $cpgi;
  645. }
  646. else if (stripos($pd[$x],'Accs') !== false)
  647. {
  648. $cpson = $cpac;
  649. }
  650. else
  651. {
  652. $cpson = $cp;
  653. }
  654. //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品
  655. $cs[$x] = $cpson;
  656. $son = explode('-',$value);//字符串转数组
  657. $snum = 0;$cpsl = 0;
  658. foreach ($son as $val)
  659. {
  660. if(stripos($val,'^') !== false)
  661. {
  662. $snum += str_replace('^','',$val);
  663. }
  664. if(isset($dtc[$val]))//如果能匹配到
  665. {
  666. if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品
  667. {
  668. $cpsl++;
  669. if(!is_numeric($val))
  670. {
  671. $pm['c'] = $dtc[$val]['zh'];
  672. }
  673. else
  674. {
  675. $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面
  676. }
  677. $number['c'] = $val;
  678. }
  679. else
  680. {
  681. if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部
  682. {
  683. $cp[$dtc[$val]['classid']] = $dtc[$val]['id'];
  684. }
  685. if(isset($cpson[$dtc[$val]['classid']]))
  686. {
  687. if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色
  688. {
  689. $cpson[$dtc[$val]['classid']] = $dtc[$val]['id'];
  690. }
  691. }
  692. /**
  693. if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发')
  694. {
  695. $slpx[] = 1;
  696. $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh'];
  697. }
  698. else
  699. **/
  700. if($dtc[$val]['classid'] == '999')
  701. {
  702. $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配
  703. }
  704. else
  705. {
  706. $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配
  707. }
  708. }
  709. }
  710. else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串
  711. {
  712. $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型
  713. if(isset($cpson[16]))
  714. {
  715. if($cpson[16] != 128)
  716. {
  717. $cpslnum = explode(' ',trim($val,' '));
  718. $cpsl += count($cpslnum);
  719. $pm['dc'] = $val.$j;//写入多尺寸字符串
  720. }
  721. }
  722. else
  723. {
  724. $cpslnum = explode(' ',trim($val,' '));
  725. $cpsl += count($cpslnum);
  726. $pm['dc'] = $val.$j;
  727. }
  728. $number['dc'] = $val;
  729. }
  730. }
  731. if($sl[$x] > 1 || $snum > 1)
  732. {
  733. $slx = $sl[$x];
  734. if($snum>1)
  735. {
  736. $slx = ($slx>1)?$slx:1;
  737. $slx *= $snum;
  738. }
  739. $slpx[] = $cpsl;
  740. $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串
  741. }
  742. else
  743. {
  744. if($cpsl > 0)
  745. {
  746. $slpx[] = $cpsl;
  747. }
  748. $slx = 1;
  749. $pdpm = $bmsku.implode("",$pm);
  750. if($pdpm != '')
  751. {
  752. $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串
  753. }
  754. }
  755. //以下是特殊类型的匹配
  756. if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false)
  757. {
  758. $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr);
  759. }
  760. $weightsku = array();
  761. $weightdata = $this->weight->find_all();
  762. foreach ($weightdata as $w)
  763. {
  764. $weightsku[$w['features']] = $w['weight'];
  765. }
  766. if($number['dc'] != '')
  767. {
  768. if(stripos($pd[$x],'+') !== false)
  769. {
  770. foreach ($cp as $v)
  771. {
  772. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  773. }
  774. }
  775. else
  776. {
  777. foreach ($cpson as $v)
  778. {
  779. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  780. }
  781. }
  782. $dc = explode(' ',trim($number['dc'],' '));
  783. for($i=0;$i<count($dc);$i++)
  784. {
  785. if(isset($dtc[$dc[$i]]['id']))
  786. {
  787. $thisid = $dtc[$dc[$i]]['id'];
  788. /**
  789. $tha[$dc[$i]] = isset($tha[$dc[$i]])?array('zh'=>$tha[$dc[$i]]['zh'],'id'=>$tha[$dc[$i]]['id'],'count'=>$tha[$dc[$i]]['count']+1):array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  790. **/
  791. //一样的不再合并
  792. $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  793. }
  794. }
  795. foreach ($tha as $v)
  796. {
  797. $item = array_merge($cp);$weight = 0;
  798. if($cp['16'] == '126')
  799. {
  800. $weight = $weightsku['126'];
  801. }
  802. else if($cp['16'] == '127')
  803. {
  804. if(isset($item[9]))
  805. {
  806. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  807. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  808. if(isset($weightsku[$sku127a]))
  809. {
  810. $weight = $weightsku[$sku127a];
  811. }
  812. else if(isset($weightsku[$sku127b]))
  813. {
  814. $weight = $weightsku[$sku127b];
  815. }
  816. }
  817. }
  818. else if($cp['16'] == '128')
  819. {
  820. if(isset($item[8]))
  821. {
  822. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  823. if(isset($weightsku[$sku128]))
  824. {
  825. $weight = $weightsku[$sku128];
  826. }
  827. }
  828. }
  829. $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型
  830. $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|';
  831. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  832. $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  833. }
  834. }
  835. if($number['c'] != '')
  836. {
  837. $fk = $cp;
  838. foreach ($cpson as $k=>$v)
  839. {
  840. $fk[$k] = $v;//+号左右ID合并右完整ID
  841. }
  842. foreach ($fk as $v)
  843. {
  844. $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  845. }
  846. $c = explode(' ',trim($number['c'],' '));
  847. for($i=0;$i<count($c);$i++)
  848. {
  849. $thisid = $dtc[$c[$i]]['id'];
  850. /**
  851. $thb[$c[$i]] = isset($thb[$c[$i]])?array('zh'=>$thb[$c[$i]]['zh'],'id'=>$thb[$c[$i]]['id'],'count'=>$thb[$c[$i]]['count']+1):array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  852. **/
  853. //一样的不再合并
  854. $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  855. }
  856. foreach ($thb as $v)
  857. {
  858. $item = array_merge($fk);$weight = 0;
  859. if($fk['16'] == '126')
  860. {
  861. $weight = $weightsku[$item[0]];
  862. }
  863. else if($fk['16'] == '127')
  864. {
  865. if(isset($item[9]))
  866. {
  867. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  868. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  869. if(isset($weightsku[$sku127a]))
  870. {
  871. $weight = $weightsku[$sku127a];
  872. }
  873. else if(isset($weightsku[$sku127b]))
  874. {
  875. $weight = $weightsku[$sku127b];
  876. }
  877. }
  878. }
  879. else if($fk['16'] == '128')
  880. {
  881. if(isset($item[8]))
  882. {
  883. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  884. if(isset($weightsku[$sku128]))
  885. {
  886. $weight = $weightsku[$sku128];
  887. }
  888. }
  889. }
  890. $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
  891. $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
  892. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  893. $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  894. }
  895. }
  896. if (stripos($pd[$x],'Gift-') !== false)
  897. {
  898. $ptitleg = '';
  899. foreach ($cpson as $v)
  900. {
  901. $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  902. }
  903. $whlabel .= implode("",$cpson).'-'.$slx.'-0|';
  904. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  905. }
  906. $x++;
  907. $purchase += $purchasemy;
  908. $cost += $costmy;
  909. }
  910. $product = str_replace('--','-',$product);
  911. $qbslpx = 0;$wcslpx = '';
  912. foreach ($slpx as $v)
  913. {
  914. $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
  915. $qbslpx += $v;
  916. }
  917. $nr = str_replace(array('(',')'),array('(',')'),$nr);
  918. if(stripos($whlabel,'|--|') !== false)
  919. {
  920. $whlabel = '';
  921. $product = '';
  922. }
  923. return array('title'=>preg_replace(array('/(\s+)/','/分\s/u'),array(' ','分'),trim($nr,';')),'purchase'=>$purchase,'cost'=>$cost,'product'=>str_replace(array('---','--'),array('-','-'),$product),'whlabel'=>$whlabel,'wcslpx'=>trim($wcslpx,'|'),'cs'=>$sku);
  924. }
  925. public function _spexcel()
  926. {
  927. $tc = array();
  928. $typeclass = $this->typeclass->find_all();
  929. foreach ($typeclass as $v)
  930. {
  931. $tc[$v['id']] = $v;
  932. }
  933. if(isset($_SESSION['api']))
  934. {
  935. $user = $this->user->get_api($_SESSION['api']);
  936. $usp = $user;
  937. $fgshop = "";$sid = "";$excelshop="";
  938. $usersp = explode('|',trim($user['shop'],'|'));
  939. foreach ($usersp as $value)
  940. {
  941. $fgshop .= " shop = ".$value." or";
  942. $sid .= " id = ".$value." or";
  943. }
  944. $userexcel = explode('|',trim($user['excelshop'],'|'));
  945. foreach ($userexcel as $value)
  946. {
  947. $excelshop .= " shop = ".$value." or";
  948. }
  949. if($excelshop != "")
  950. {
  951. $excelshop = "(".rtrim($excelshop,'or').")";
  952. }
  953. }
  954. $post = $this->input->post(NULL, TRUE);
  955. if(isset($_GET['category']))
  956. {
  957. $timetk = $this->input->get('timetk',true);
  958. $timetj = $this->input->get('timetj',true);
  959. $color = $this->input->get('color',true);
  960. $lowe = $this->input->get('lowe',true);
  961. $size = $this->input->get('size',true);
  962. $grade = $this->input->get('grade',true);
  963. $lacetype = $this->input->get('lacetype',true);
  964. $category = $this->input->get('category',true);
  965. $shop = $this->input->get('shop',true);
  966. $density = $this->input->get('density',true);
  967. $time = $this->input->get('time',true);
  968. $timetk = strtotime($timetk);
  969. $timetj = strtotime($timetj);
  970. $where = "";
  971. if($category)
  972. {
  973. $where .= "fpdata like '%-".$category."-%' and ";
  974. }
  975. if($color)
  976. {
  977. $where .= "fpdata like '%-".$color."-%' and ";
  978. }
  979. if($size)
  980. {
  981. $where .= "fpdata like '%-".$size."-%' and ";
  982. }
  983. if($grade)
  984. {
  985. $where .= "fpdata like '%-".$grade."-%' and ";
  986. }
  987. if($shop)
  988. {
  989. $where .= "shop = '$shop' and ";
  990. }
  991. else
  992. {
  993. $where .= $excelshop." and ";
  994. }
  995. if($lowe)
  996. {
  997. $where .= "fpdata like '%-".$lowe."-%' and ";
  998. }
  999. if($density)
  1000. {
  1001. $where .= "fpdata like '%-".$density."-%' and ";
  1002. }
  1003. if($lacetype)
  1004. {
  1005. $where .= "fpdata like '%-".$lacetype."-%' and ";
  1006. }
  1007. $dataa = $this->fullorder->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'",'fpdata,number,whlabel','id desc');
  1008. $datab = $this->fullordersmt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj' and shop != '9'",'fpdata,number,whlabel','id desc');
  1009. $datac = $this->fullordertt->find_all($where.$time." > '$timetk' and ".$time." < '$timetj'",'fpdata,number,whlabel','id desc');
  1010. $data = array_merge($dataa,$datab,$datac);
  1011. $sp = array();$cs = array();
  1012. foreach ($data as $val)
  1013. {
  1014. $f = explode(';',trim($val['fpdata'],';'));
  1015. $w = explode('|',trim($val['whlabel'],'|'));
  1016. foreach ($f as $k=>$v)
  1017. {
  1018. if($category)
  1019. {
  1020. if(stripos($v,'-'.$category.'-') === false)
  1021. {
  1022. continue;
  1023. }
  1024. }
  1025. if($color)
  1026. {
  1027. if(stripos($v,'-'.$color.'-') === false)
  1028. {
  1029. continue;
  1030. }
  1031. }
  1032. if($lowe)
  1033. {
  1034. if(stripos($v,'-'.$lowe.'-') === false)
  1035. {
  1036. continue;
  1037. }
  1038. }
  1039. if($size)
  1040. {
  1041. if(stripos($v,$size.',') === false)
  1042. {
  1043. continue;
  1044. }
  1045. }
  1046. if($grade)
  1047. {
  1048. if(stripos($v,'-'.$grade.'-') === false)
  1049. {
  1050. continue;
  1051. }
  1052. }
  1053. if($lacetype)
  1054. {
  1055. if(stripos($v,'-'.$lacetype.'-') === false)
  1056. {
  1057. continue;
  1058. }
  1059. }
  1060. if($density)
  1061. {
  1062. if(stripos($v,'-'.$density.'-') === false)
  1063. {
  1064. continue;
  1065. }
  1066. }
  1067. $title = explode('|',$v);
  1068. $fg = str_replace(array('-163-','-164-','-165-','-166-','-0-','-126-','-127-','-128-','-197-','-195-'),'-',$title[0]);
  1069. $fg = explode(',',$fg);
  1070. $fg = explode('-',trim($fg[1].$fg[0],'-'));
  1071. $pm = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'','dc'=>'','c'=>'',12=>'',25=>'',26=>'',14=>'',27=>'',10=>'',6=>'',9=>'',39=>'',999=>'',9999=>'');//品名顺序
  1072. foreach($fg as $vv)
  1073. {
  1074. if(isset($tc[$vv]['zh']))
  1075. {
  1076. $zh = explode('|',trim($tc[$vv]['zh'],'|'));
  1077. $pm[$tc[$vv]['classid']] = $zh[0];
  1078. }
  1079. }
  1080. $zh = implode(" ",$pm);
  1081. $zh = str_replace('自然色 ','',rtrim($zh,' '));
  1082. $zh = str_replace(array(' ',' ',' ',' ',' ',' ',' '),' ',$zh);
  1083. if(isset($sp[$title[1]]))
  1084. {
  1085. $sp[$title[1]]['n'] += $title[2];
  1086. }
  1087. else
  1088. {
  1089. $wh = explode('-',$w[$k]);
  1090. $wsku = $this->whlabel->find_all("number = '".$wh[0]."' and sku != 'Preset'");
  1091. $whs = (isset($wsku[0]['sku']))?$wsku[0]['sku']:'';
  1092. $sp[$title[1]] = array('t'=>$title[1],'z'=>$zh,'w'=>$whs,'n'=>$title[2]);
  1093. }
  1094. }
  1095. }
  1096. $sp = array_values($sp);
  1097. $title = "商品统计".date('Y-m-d H-i-s',time());
  1098. $titlename = "<table border=1>
  1099. <tr>
  1100. <td>名称</td>
  1101. <td>中文</td>
  1102. <td>SKU</td>
  1103. <td>数量</td>
  1104. </tr>
  1105. </table>";
  1106. $filename = $title.".xls";
  1107. $tail = "\n";
  1108. $this->excel->get_fz2($sp,$titlename,$filename,$tail);
  1109. }
  1110. }
  1111. public function _setting()
  1112. {
  1113. $post = $this->input->post(NULL, TRUE);
  1114. if(isset($post['excelpass']))
  1115. {
  1116. $excelpass = $this->input->post('excelpass',true);
  1117. $exceljmnum = $this->input->post('exceljmnum',true);
  1118. $excelusernum = $this->input->post('excelusernum',true);
  1119. if($excelpass == '')
  1120. {
  1121. echo json_encode(array('msg'=>'密码不能为空','success'=>false));exit;
  1122. }
  1123. if($exceljmnum < 1 || $excelusernum < 1)
  1124. {
  1125. echo json_encode(array('msg'=>'数量不可以小于1','success'=>false));exit;
  1126. }
  1127. $this->setting->save(array('svalue'=>$excelpass),'excelpass');
  1128. echo json_encode(array('msg'=>'Excel加密密码修改成功','success'=>false));exit;
  1129. }
  1130. }
  1131. public function _sctime()
  1132. {
  1133. $post = $this->input->post(NULL, TRUE);
  1134. if(isset($post['sctime']))
  1135. {
  1136. $sctime = $this->input->post('sctime',true);
  1137. if(!is_numeric($sctime))
  1138. {
  1139. echo json_encode(array('msg'=>'必须为正整数的数字!','success'=>false));exit;
  1140. }
  1141. $sctime = ($sctime>0)?$sctime*3600:0;
  1142. $this->setting->save(array('svalue'=>$sctime),'sctime');
  1143. echo json_encode(array('msg'=>'时差修改成功!','success'=>false));exit;
  1144. }
  1145. }
  1146. public function _dpay()
  1147. {
  1148. $post = $this->input->post(NULL, TRUE);
  1149. if(isset($post['pay']))
  1150. {
  1151. $pay = $this->input->post('pay',true);
  1152. $timetk = $this->input->post('timetk',true);
  1153. $timetj = $this->input->post('timetj',true);
  1154. $timetk = strtotime($timetk);
  1155. $timetj = strtotime($timetj);
  1156. $where = "shouldmoney > '0' and dtime > '$timetk' and dtime < '$timetj' and pay = '$pay'";
  1157. if(!$pay)
  1158. {
  1159. echo json_encode(array('msg'=>'请选择支付方式!','success'=>false));exit;
  1160. }
  1161. $fullorder = $this->fullorder->find_all($where);
  1162. $this->db->trans_begin();
  1163. $cs = array();
  1164. $p = $this->pay->get_typeclass($pay);
  1165. foreach($fullorder as $v)
  1166. {
  1167. $yga = $v['shouldmoney'];//金额
  1168. $ygc = $p['estimaterate'];//预估到账公式
  1169. $ifbudget = eval("return $yga*1.$ygc;");
  1170. if($ifbudget > 0)
  1171. {
  1172. $this->fullorder->save(array('budget'=>$ifbudget,'estimaterate'=>$ygc),$v['id']);
  1173. }
  1174. }
  1175. if ($this->db->trans_status() === TRUE)
  1176. {
  1177. $this->db->trans_commit();
  1178. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  1179. }
  1180. else
  1181. {
  1182. $this->db->trans_rollback();
  1183. echo json_encode(array('msg'=>'失败,请重试','success'=>false));
  1184. }
  1185. }
  1186. }
  1187. public function _dpex()
  1188. {
  1189. $post = $this->input->post(NULL, TRUE);
  1190. if(isset($post['n']))
  1191. {
  1192. $number = $this->input->post('n',true);
  1193. $postdata = $this->input->post('postdata',true);
  1194. $postdata = json_decode($postdata,true);
  1195. $d = array();
  1196. foreach ($postdata as $val)
  1197. {
  1198. $d[] = array(
  1199. 'Money' => 'USD',//货币单位
  1200. //'Sku' => '123123',//产品 Sku (OrderType 为仓储订单必传)
  1201. 'Cnname' => $val['zh'],//产品中文名
  1202. 'Enname' => $val['en'].'*'.$val['num'],//产品英文名
  1203. 'Price' => $val['dj']*1,//单价
  1204. 'Weight' => $val['zl']*1,//重量
  1205. 'Num' => $val['num']*1,//数量
  1206. 'CustomsCode'=> $val['hg']//海关编码
  1207. );
  1208. }
  1209. $fullorder = $this->fullorder->get_number($number);
  1210. if(!$fullorder)
  1211. {
  1212. $fullorder = $this->fullordersmt->get_number($number);
  1213. }
  1214. if(!$fullorder)
  1215. {
  1216. echo json_encode(array('msg'=>'没有此编号的订单!','success'=>false));exit;
  1217. }
  1218. $fullorder = $this->_text($fullorder);
  1219. $fullorder['number'] = $fullorder['number'].'-'.date('s',time());//订单号重复修改新订单好
  1220. $data = $fullorder;
  1221. $url = "http://ambcargo.kingtrans.cn/PostInterfaceService?method=createOrder";
  1222. $Clientid = 'LYFZP';
  1223. $Token = 'NGkJSDx3bAxojl1YN232';
  1224. $code = array('DPEX'=>array('11','DPEX','1'),'ARAMEX'=>array('002','安迈世',0),'FEDEX'=>array('FEDEX_1CC','FEDEX_1CC',';lab10_10'),'UPS'=>array('04','UPS',0),'DHL'=>array('06','DHL',';lab10_10'),'FED-SN-IP'=>array('07','FED-SN-IP',';lab10_10'),'WML-FEDEX-ZZ'=>array('05','WML-FEDEX-ZZ',';lab10_10'),'FED-XS-F'=>array('03','FED-XS-F',';lab10_10'),'CNE'=>array('08','全球优先CNE','label10x10;0'),'TCNE'=>array('09','E速宝特惠','label10x10;0'));
  1225. $printcode = $code[$data['printcode']];
  1226. //创建并预报订单
  1227. $count = array(
  1228. 'Verify' => array(
  1229. 'Clientid'=>$Clientid,
  1230. 'Token'=>$Token
  1231. ),
  1232. 'OrderType' => '1',//1:快件订单 2:快递制单-非实时返回单号 3:仓储订单 4:快递制单-实时返回单号(等待时间较 长)。此方法选择 4,后续如需调用其他 方法,例如调用删除接口,其他方法 OrderType 请选择 2。
  1233. 'OrderDatas' => array(0=>array(
  1234. 'CustomerNumber' => $data['number'],//订单号
  1235. 'ChannelCode' => $printcode[0],//渠道代码
  1236. 'CountryCode' => $data['lb'],//国家二字码
  1237. 'TotalWeight' => $data['zzl'],//订单重量
  1238. 'TotalValue' => $data['zsbjz'],//申报价值
  1239. 'Number' => $data['zjs'],//件数
  1240. 'Note' => $data['number'],//备注
  1241. /**
  1242. 'Insurance' => array(//是否购买保险
  1243. 'Code' => '',//保险类型
  1244. 'Value' => '',//保险金额
  1245. ),
  1246. **/
  1247. 'FeePayData' => array(//运费支付信息
  1248. 'FeePayType' => 'PP',//支付方式 [ PP:预付,CC:到付, TP:第三方]
  1249. 'FeePayAccountNumber' => '',//支付账号 支付方式为 TP 时必传 支付方式为 PP 并且渠道 UPS 时必传
  1250. 'FeePayCountryCode' => '',//支付账号对应国家 支付方式为 TP 时必传
  1251. 'FeePayPostCode' => '',//支付账号对应邮编 支付方式为 TP 并且渠道 FEDEX 时必传
  1252. ),
  1253. 'TaxPayData' => array(//税金/关税支付信息 OrderType 为 [快递制单] 时必传字段
  1254. 'TaxPayType' => 'PP',//支付方式 [ PP:预付,CC:到付, TP:第三方]
  1255. 'TaxPayAccountNumber' => '',//支付账号 支付方式为 TP 时必传 支付方式为 PP 并且渠道 UPS 时必传
  1256. 'TaxPayCountryCode' => '',//支付账号对应国家 支付方式为 TP 时必传
  1257. 'TaxPayPostCode' => '',//支付账号对应邮编 支付方式为 TP 并且渠道 FEDEX 时必传
  1258. ),
  1259. 'Recipient' => array(//收件人信息
  1260. 'Name' => $data['name'],//姓名
  1261. 'Addres1' => $data['address'],//地址1
  1262. 'Addres2' => $data['address2'],//地址2
  1263. 'Mobile' => preg_replace('/\D/s','',$data['phone']),//手机
  1264. 'Province' => $data['province'],//省/州
  1265. 'City' => $data['city'],//城市
  1266. 'Post' => trim($data['zipcode'],' '),//邮编
  1267. ),
  1268. 'OrderItems' => $d))
  1269. /**,
  1270. 'Volumes' => array(//材积明细 (OrderType 为快递制单必传)
  1271. 'Weight' => '123123',//实重
  1272. 'Number' => '123123',//件数
  1273. 'Length' => '123123',//长
  1274. 'Width' => '123123',//宽
  1275. 'Height' => '123123',//高
  1276. ),
  1277. **/
  1278. );
  1279. $count = json_encode($count,true);
  1280. $ch = curl_init();
  1281. curl_setopt($ch,CURLOPT_URL,$url);
  1282. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1283. curl_setopt($ch,CURLOPT_HEADER,0);
  1284. curl_setopt($ch,CURLOPT_POST, 1);
  1285. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  1286. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('json'=>$count)));
  1287. $res = curl_exec($ch);
  1288. curl_close($ch);
  1289. $res = json_decode($res,true);
  1290. if(!isset($res['returnDatas'][0]['corpBillid']))
  1291. {
  1292. echo json_encode(array('msg'=>$res['returnDatas'][0]['message'],'success'=>false));exit;
  1293. }
  1294. else
  1295. {
  1296. $yd = $this->get_dpex_yd($res['returnDatas'][0]['corpBillid'],$printcode[2]);
  1297. $fp = $this->get_dpex_fp($res['returnDatas'][0]['corpBillid'],$count);
  1298. if($yd != 'c' && $fp != 'c')
  1299. {
  1300. echo json_encode(array('msg'=>'<p><a href="'.$fp.'" target="_blank">查看发票</a> <a href="'.$yd.'" target="_blank">查看运单</a></p>','success'=>true));exit;
  1301. }
  1302. else
  1303. {
  1304. echo json_encode(array('msg'=>'获取运单失败,请重试','success'=>false));exit;
  1305. }
  1306. }
  1307. }
  1308. }
  1309. public function _text($fullorder)
  1310. {
  1311. /** 发票地址信息暂时无用
  1312. $fullorder['baddress'] = explode(',',$fullorder['baddress']);
  1313. $fullorder['baddress'] = array_reverse($fullorder['baddress']);
  1314. $fullorder['baddress'][1] = $country['ename'];
  1315. **/
  1316. //获取所用相关信息
  1317. $warehouse = $this->warehouse->read($fullorder['type']);
  1318. $country = $this->country->read($fullorder['country']);//订单国家信息
  1319. $fcountry = $this->country->read($warehouse['country']);//仓库国家信息
  1320. $warehouse['country'] = $fcountry['ename'];//仓库国家名
  1321. $warehouse['lb'] = $fcountry['lb'];//仓库国家编码
  1322. $fullorder['warehouse'] = $warehouse;//仓库数据加入订单
  1323. $fullorder['lb'] = $country['lb'];//订单国家编码加入
  1324. $fullorder['country'] = $country['ename'];//订单国家名
  1325. $fullorder['zhou'] = $country['continent'];//所属州
  1326. $express = $this->express->read($fullorder['express']);
  1327. $fullorder['express'] = $express['servicename'];
  1328. $fullorder['account'] = $express['account'];
  1329. $fullorder['printcode'] = $express['printcode'];
  1330. $fullorder['time'] = date('Y-m-d',time());
  1331. $fullorder['times'] = date('Y-m-d H:i',time());
  1332. $fullorder['sbbm']= ($fullorder['sbpm'] == 'Hair Sample') ? 67042000 : 67041100;
  1333. $fullorder['address'] = str_replace(array('&'),array('&#38;'),$fullorder['address']);
  1334. $fullorder['address2'] = str_replace(array('&'),array('&#38;'),$fullorder['address2']);
  1335. $fullorder['shipremarks'] = str_replace(array('<','>',';',';'),array('&lt','&gt',';<br>',';<br>'),$fullorder['shipremarks']);
  1336. $shop = $this->shop->read($fullorder['shop']);
  1337. $fullorder['shop'] = $shop['shopname'];
  1338. if(is_numeric($fullorder['pay']))
  1339. {
  1340. $pay = $this->typeclass->read($fullorder['pay']);
  1341. if($pay['classid'] == '4')
  1342. {
  1343. $fullorder['pay'] = $pay['title'];
  1344. }
  1345. }
  1346. if($fullorder['printcode'] != "USPS")
  1347. {
  1348. $fullorder['client'] = htmlspecialchars($fullorder['client']);
  1349. $fullorder['name'] = htmlspecialchars($fullorder['name']);
  1350. }
  1351. //增加退货单所需信息
  1352. $pt = '';
  1353. $fpdata = explode(';',trim($fullorder['fpdata'],';'));
  1354. foreach ($fpdata as $v)
  1355. {
  1356. $p = explode('|',trim($v,'|'));
  1357. $pt .= '<p>'.$p[1].' * '.$p[2].'</p>';
  1358. }
  1359. $fullorder['pt'] = $pt;
  1360. return $fullorder;
  1361. }
  1362. public function get_dpex_yd($waybill,$PrintPaper)
  1363. {
  1364. $url = "http://ambcargo.kingtrans.cn/PostInterfaceService?method=printOrderLabel";
  1365. $Clientid = 'LYFZP';
  1366. $Token = 'NGkJSDx3bAxojl1YN232';
  1367. $count = array(
  1368. 'Verify' => array(
  1369. 'Clientid'=>$Clientid,
  1370. 'Token'=>$Token
  1371. ),
  1372. 'CorpBillidDatas'=> array(0=>array('CorpBillid'=>$waybill)),
  1373. 'OrderType'=> "1",//1:快件订单 2:快递制单 3:仓库订单
  1374. 'PrintPaper'=> $PrintPaper,//打印纸张 快递制单只固定为:label 和 A4
  1375. 'PrintContent'=> "1"//打印内容 1:地址标签 2:报关单 3:配货信息 可自由组合用“,”号隔开 如:1,2,3
  1376. );
  1377. $count = json_encode($count,true);
  1378. $ch = curl_init();
  1379. curl_setopt($ch,CURLOPT_URL,$url);
  1380. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1381. curl_setopt($ch,CURLOPT_HEADER,0);
  1382. curl_setopt($ch,CURLOPT_POST, 1);
  1383. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  1384. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('json'=>$count)));
  1385. $res = curl_exec($ch);
  1386. curl_close($ch);
  1387. $res = json_decode($res,true);
  1388. if($res['statusCode'] == 'success')
  1389. {
  1390. return $res['url'];
  1391. }
  1392. else
  1393. {
  1394. return 'c';
  1395. }
  1396. }
  1397. public function get_dpex_fp($waybill)
  1398. {
  1399. $url = "http://ambcargo.kingtrans.cn/PostInterfaceService?method=printOrderInvoice";
  1400. $Clientid = 'LYFZP';
  1401. $Token = 'NGkJSDx3bAxojl1YN232';
  1402. $count = array(
  1403. 'Verify' => array(
  1404. 'Clientid'=>$Clientid,
  1405. 'Token'=>$Token
  1406. ),
  1407. 'CorpBillidDatas'=> array(0=>array('CorpBillid'=>$waybill))
  1408. );
  1409. $count = json_encode($count,true);
  1410. $ch = curl_init();
  1411. curl_setopt($ch,CURLOPT_URL,$url);
  1412. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1413. curl_setopt($ch,CURLOPT_HEADER,0);
  1414. curl_setopt($ch,CURLOPT_POST, 1);
  1415. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  1416. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query(array('json'=>$count)));
  1417. $res = curl_exec($ch);
  1418. curl_close($ch);
  1419. $res = json_decode($res,true);
  1420. if($res['statusCode'] == 'success')
  1421. {
  1422. return $res['url'];
  1423. }
  1424. else
  1425. {
  1426. return 'c';
  1427. }
  1428. }
  1429. public function _excellkh()
  1430. {
  1431. if(isset($_SESSION['api']))
  1432. {
  1433. $user = $this->user->get_api($_SESSION['api']);
  1434. $usp = $user;
  1435. $fgshop = "";$sid = "";
  1436. $user = explode('|',trim($user['shop'],'|'));
  1437. foreach ($user as $value)
  1438. {
  1439. if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27')
  1440. {
  1441. $fgshop .= " shop = ".$value." or";//去掉指定的店铺
  1442. }
  1443. $sid .= " id = ".$value." or";
  1444. }
  1445. }
  1446. $post = $this->input->post(NULL, TRUE);
  1447. if(isset($_GET['time']))
  1448. {
  1449. $s = $this->input->get('shop',true);
  1450. $time = $this->input->get('time',true);
  1451. $timetk = $this->input->get('timetk',true);
  1452. $timetj = $this->input->get('timetj',true);
  1453. $timetk = strtotime($timetk);
  1454. $timetj = strtotime($timetj);
  1455. if($s)
  1456. {
  1457. $shop = $this->shop->find_all("id = '$shop'");
  1458. }
  1459. else
  1460. {
  1461. $shop = $this->shop->find_all("type = 269 and (".rtrim($sid,'or').')');
  1462. }
  1463. $d = array();
  1464. $k = $timetk-24*3600;//少一天为增加选择开始天时间
  1465. $j = $timetj;
  1466. $n = ($j-$k)/(24*3600);
  1467. if($n < 1)
  1468. {
  1469. $n = 1;
  1470. }
  1471. for($i=1;$i<$n;$i++)
  1472. {
  1473. $t = $j-($n*24*60*60)+($i*24*60*60);
  1474. foreach($shop as $val)
  1475. {
  1476. $data = $this->fullorder->find_all("$time > '$t' and $time < '".($t+24*3600)."' and shop = '".$val['id']."'");
  1477. $dd = 0;$m = 0;
  1478. foreach($data as $v)
  1479. {
  1480. $customer = $this->customer->get_email($v['email'],$v['shop']);
  1481. $customernum = $this->fullorder->find_count("email = '".$v['email']."' and shop = '".$v['shop']."'");
  1482. preg_match_all('/[0-9]/u',$v['phone'],$result);
  1483. $numphone = join('',$result[0]);
  1484. $customerc = $this->customer->find_all("type = 1 and shop = '".$v['shop']."' and address = '".$v['address']."' and numphone = '".$numphone."'",'*','id desc');
  1485. if($customer)
  1486. {
  1487. if(($customer['type'] == 1 && $customernum > 1) || (isset($customerc[0]['num']) && $customerc[0]['num'] > 1))// || $customerc['type'] == 1 && $customerc['num'] > 1
  1488. {
  1489. $dd++;
  1490. $m += $v['shouldmoney'];
  1491. }
  1492. }
  1493. }
  1494. $d[] = array(date('Y-m-d',$t),$val['shopname'],count($data),sprintf("%01.2f",array_sum(array_column($data,'shouldmoney'))),$dd,$m);
  1495. }
  1496. }
  1497. $title = "老客户数据统计".date('Y-m-d H-i-s',time());
  1498. $titlename = "<table border=1>
  1499. <tr>
  1500. <td>时间</td>
  1501. <td>店铺</td>
  1502. <td>订单数</td>
  1503. <td>订单金额 </td>
  1504. <td>老客户订单数</td>
  1505. <td>老客户订单金额</td>
  1506. </tr>
  1507. </table>";
  1508. $filename = $title.".xls";
  1509. $tail = "\n";
  1510. $this->excel->get_fz2($d,$titlename,$filename,$tail);
  1511. }
  1512. }
  1513. public function _excelshop()
  1514. {
  1515. if(isset($_SESSION['api']))
  1516. {
  1517. $user = $this->user->get_api($_SESSION['api']);
  1518. $usp = $user;
  1519. $fgshop = "";$sid = "";
  1520. $user = explode('|',trim($user['shop'],'|'));
  1521. foreach ($user as $value)
  1522. {
  1523. if($value != '18' && $value != '19' && $value != '12' && $value != '13' && $value != '9' && $value != '15' && $value != '27')
  1524. {
  1525. $fgshop .= " shop = ".$value." or";//去掉指定的店铺
  1526. }
  1527. $sid .= " id = ".$value." or";
  1528. }
  1529. }
  1530. $post = $this->input->post(NULL, TRUE);
  1531. if(isset($_GET['time']))
  1532. {
  1533. $s = $this->input->get('shop',true);
  1534. $time = $this->input->get('time',true);
  1535. $timetk = $this->input->get('timetk',true);
  1536. $timetj = $this->input->get('timetj',true);
  1537. $timetk = strtotime($timetk);
  1538. $timetj = strtotime($timetj);
  1539. if($s)
  1540. {
  1541. $shop = $this->shop->find_all("id = '$shop'");
  1542. }
  1543. else
  1544. {
  1545. $shop = $this->shop->find_all("type = 269 and (".rtrim($sid,'or').')');
  1546. }
  1547. $d = array();
  1548. $k = $timetk-24*3600;//少一天为增加选择开始天时间
  1549. $j = $timetj;
  1550. $n = ($j-$k)/(24*3600);
  1551. if($n < 1)
  1552. {
  1553. $n = 1;
  1554. }
  1555. for($i=1;$i<$n;$i++)
  1556. {
  1557. $t = $j-($n*24*60*60)+($i*24*60*60);
  1558. foreach($shop as $val)
  1559. {
  1560. $data = $this->fullorder->find_all("$time > '$t' and $time < '".($t+24*3600)."' and shop = '".$val['id']."'");
  1561. $dd = 0;$m = 0;
  1562. $d[] = array(date('Y-m-d',$t),$val['shopname'],count($data),sprintf("%01.2f",array_sum(array_column($data,'shouldmoney'))));
  1563. }
  1564. }
  1565. $title = "店铺数据统计".date('Y-m-d H-i-s',time());
  1566. $titlename = "<table border=1>
  1567. <tr>
  1568. <td>时间</td>
  1569. <td>店铺</td>
  1570. <td>订单数</td>
  1571. <td>订单金额 </td>
  1572. </tr>
  1573. </table>";
  1574. $filename = $title.".xls";
  1575. $tail = "\n";
  1576. $this->excel->get_fz2($d,$titlename,$filename,$tail);
  1577. }
  1578. }
  1579. public function _qczd()
  1580. {
  1581. $post = $this->input->post(NULL, TRUE);
  1582. if(isset($post['number']))
  1583. {
  1584. $number = $this->input->post('number',true);
  1585. if(!$number || $number == '' || $number == NULL)
  1586. {
  1587. echo json_encode(array('msg'=>'没有编号信息','success'=>false));exit;
  1588. }
  1589. $a = $this->whlabel->find_all("zd = '$number' and state = '0'");
  1590. foreach ($a as $v)
  1591. {
  1592. $this->whlabel->save(array('zd'=>''),$v['id']);
  1593. }
  1594. echo json_encode(array('msg'=>'清除完成!','success'=>true));exit;
  1595. }
  1596. }
  1597. }