Boss.php 64 KB

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