Boss.php 65 KB

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