Boss.php 67 KB

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