Bosstwo.php 77 KB

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