Boss.php 68 KB

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