Boss.php 66 KB

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