Bosstest.php 62 KB

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