Boss.php 61 KB

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