Boss.php 83 KB

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