Boss.php 79 KB

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