Bosstwo.php 77 KB

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