Boss.php 68 KB

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