Boss.php 63 KB

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