Boss.php 67 KB

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