Boss.php 85 KB

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