Boss.php 61 KB

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