Apt.php 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. header("Access-Control-Allow-Origin: *");
  3. class Apt extends Start_Controller {
  4. public function __construct(){
  5. parent::__construct();
  6. $this->load->library('session');
  7. $this->load->_model('Model_whlabel','whlabel');
  8. $this->load->_model('Model_warehouse','warehouse');
  9. $this->load->_model('Model_productprice','productprice');
  10. $this->load->_model('Model_excel','excel');
  11. $this->load->_model('Model_fullorder','fullorder');
  12. $this->load->_model('Model_fullordertt','fullordertt');
  13. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  14. $this->load->_model('Model_fullordersmt','fullordersmt');
  15. $this->load->_model('Model_outbound','outbound');
  16. $this->load->_model('Model_express','express');
  17. $this->load->_model('Model_shop','shop');
  18. $this->load->_model('Model_typeclass','typeclass');
  19. $this->load->_model('Model_country','country');
  20. $this->load->_model('Model_kdniao','kdniao');
  21. $this->load->_model('Model_notice','notice');
  22. $this->load->_model('Model_dhl','dhl');
  23. $this->load->_model('Model_usps','usps');
  24. $this->load->_model('Model_fedex','fedex');
  25. $this->load->_model('Model_fedex_cby','fedex_cby');
  26. $this->load->_model('Model_ups','ups');
  27. $this->load->_model('Model_ali','ali');
  28. $this->load->_model('Model_dpd','dpd');
  29. $this->load->_model('Model_shop','shop');
  30. $this->load->_model('Model_user','user');
  31. $this->load->_model('Model_whlabel','whlabel');
  32. $this->load->helper('url');
  33. }
  34. //定义方法的调用规则 获取URI第二段值
  35. public function _remap($arg,$arg_array)
  36. {
  37. if($arg == 'fout')//出库页
  38. {
  39. $this->_fout();
  40. }
  41. else if($arg == 'printing')//打印操作
  42. {
  43. $this->_printing();
  44. }
  45. else if($arg == 'print')//打印操作
  46. {
  47. $this->_print();
  48. }
  49. else if($arg == 'fhd')//打印操作
  50. {
  51. $this->_fhd($arg_array);
  52. }
  53. else if($arg == 'outbound')//打印操作
  54. {
  55. $this->_outbound($arg_array);
  56. }
  57. else if($arg == 'fedex')//联邦打印页面
  58. {
  59. $this->_fedex($arg_array);
  60. }
  61. else if($arg == 'fhdusa')//打印操作
  62. {
  63. $this->_fhdusa($arg_array);
  64. }
  65. else if($arg == 'shop')
  66. {
  67. $this->_shop();
  68. }
  69. else if($arg == 'lowe')
  70. {
  71. $this->_lowe();
  72. }
  73. else if($arg == 'warehouse')
  74. {
  75. $this->_warehouse();
  76. }
  77. else if($arg == 'express')
  78. {
  79. $this->_express();
  80. }
  81. else if($arg == 'select')
  82. {
  83. $this->_select();
  84. }
  85. else if($arg == 'retreat')
  86. {
  87. $this->_retreat();
  88. }
  89. else if($arg == 'excel')
  90. {
  91. $this->_excel();
  92. }
  93. else if($arg == 'exceldy')
  94. {
  95. $this->_exceldy();
  96. }
  97. else if($arg == 'number')//扫描发货单打印运单
  98. {
  99. $this->_number();
  100. }
  101. else if($arg == 'fedexhz')//扫描发货单打印运单
  102. {
  103. $this->_fedexhz();
  104. }
  105. else if($arg == 'cpexcel')
  106. {
  107. $this->_cpexcel();
  108. }
  109. else
  110. {
  111. $this->_index();
  112. }
  113. }
  114. //管理
  115. public function _index()
  116. {
  117. $post = $this->input->post(NULL, TRUE);
  118. if(isset($post['userid']))
  119. {
  120. $userid = $this->input->post('userid',true);
  121. $userpass = $this->input->post('userpass',true);
  122. $password = sha1($userpass);
  123. $user = $this->user->get_uid($userid,'dlz');
  124. if($user)
  125. {
  126. if($user['type'] == 2)
  127. {
  128. echo json_encode(array('msg'=>"账户已停用",'success'=>false));exit;
  129. }
  130. if($user['userpass'] == $password)
  131. {
  132. $this->user->get_land($user); //更新登录数据
  133. echo json_encode(array('url'=>'?id='.$user['api'],'id'=>$user['api'],'success'=>true));exit;
  134. }
  135. else
  136. {
  137. echo json_encode(array('msg'=>"用户或密码不正确",'success'=>false));exit;
  138. }
  139. }
  140. else
  141. {
  142. echo json_encode(array('msg'=>"用户不正确",'success'=>false));exit;
  143. }
  144. }
  145. }
  146. //出库
  147. public function _fout()
  148. {
  149. $post = $this->input->post(NULL, TRUE);
  150. if(isset($post['order']))
  151. {
  152. $time = time();
  153. $order = $this->input->post('order',true);
  154. $weight = $this->input->post('weight',true);
  155. if(!isset($weight))//测试没问题后可以删
  156. {
  157. $weight = '';
  158. }
  159. if(substr($order,0,3) == '788' && substr($order,-4,4) == '0430')//Fedex联邦
  160. {
  161. $order = substr($order,0,12);
  162. }
  163. if(strlen($order) == '34')//联邦杭州超长运单截取
  164. {
  165. $order = substr($order,22,12);
  166. }
  167. if(!$order)
  168. {
  169. echo json_encode(array('msg'=>'出库信息无能为空!','success'=>false));exit;
  170. }
  171. $fullorder_name = 'fullorder';$outtype = 1;
  172. $y = $this->fullorder->get_waybill($order);
  173. if(!$y)
  174. {
  175. $y = $this->fullorder->get_number($order);
  176. $outtype = 2;
  177. if(!$y)
  178. {
  179. $fullorder_name = 'fullordersmt';$outtype = 1;
  180. $y = $this->fullordersmt->get_waybill($order);
  181. if(!$y)
  182. {
  183. $y = $this->fullordersmt->get_number($order);
  184. $outtype = 2;
  185. if(!$y)
  186. {
  187. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  188. /**
  189. $fullorder_name = 'fullorder_smt';
  190. $y = $this->fullorder_smt->get_waybill($order);
  191. if(!$y)
  192. {
  193. $y = $this->fullorder_smt->get_number($order);
  194. if(!$y)
  195. {
  196. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  197. }
  198. }
  199. **/
  200. }
  201. }
  202. }
  203. }
  204. if($y['mergeid'] == '1')
  205. {
  206. $y = $this->$fullorder_name->read($y['merge']);
  207. }
  208. $express = $this->express->read($y['express']);
  209. if($y['state'] == 216 && $fullorder_name == 'fullordersmt')
  210. {
  211. $y['librarynot'] = '客户已取消!';
  212. }
  213. 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'))//独立站216先关了
  214. {
  215. echo json_encode(array('msg'=>$y['librarynot'],'success'=>false));exit;
  216. }
  217. if($y['library'] > 1)
  218. {
  219. echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['librarytime']).' 已操作','success'=>false));exit;
  220. }
  221. if($express['out'] != 3)
  222. {
  223. if($express['out'] != $outtype)
  224. {
  225. $smlx = ($express['out']=='1')?'运单':'发货单';
  226. echo json_encode(array('msg'=>'扫描类型错误!此单需要扫描'.$smlx,'success'=>false));exit;
  227. }
  228. }
  229. if($y['express'] == '9999999')//if($y['express'] == '24' || $y['express'] == '3')
  230. {
  231. $numweight = str_replace('kg','',$weight);
  232. if($weight == '' || $numweight < '0.1')
  233. {
  234. echo json_encode(array('msg'=>'此单需要称重!','success'=>false));exit;
  235. }
  236. }
  237. if(((time() - $y['printtime']) > (15*24*3600) || $y['printtime'] < 1590211800) && $y['express'] == '24')
  238. {
  239. echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  240. }
  241. if((time() - $y['printtime']) > (3*24*3600) && $y['express'] == '3')
  242. {
  243. echo json_encode(array('yd'=>1,'id'=>$y['id'],'express'=>$y['express'],'name'=>$fullorder_name,'success'=>true));exit;
  244. }
  245. $warehouse = $this->warehouse->read($y['type']);
  246. if($warehouse['zd'] == '1')
  247. {
  248. $whlabel = $this->whlabel->find_all("zd = '".$y['number']."' and warehouse = '".$y['type']."' and (state = '0' or state = '9')");
  249. $cpsl = 0;
  250. $pp = explode('|',trim($y['whlabel'],'|'));
  251. foreach ($pp as $va)
  252. {
  253. $num = explode('-',$va);
  254. $cpsl += $num[1];
  255. }
  256. if(count($whlabel) < 1 && $warehouse['ys'] != 1)//以后吧 && $warehouse['ys'] != 1去掉 前期防止没占用的不能出
  257. {
  258. echo json_encode(array('msg'=>'此订单未占用库存','success'=>false));exit;
  259. }
  260. else if(count($whlabel) != $cpsl && $warehouse['ys'] != 1)//以后吧 && $warehouse['ys'] != 1去掉 前期防止没占用的不能出
  261. {
  262. echo json_encode(array('msg'=>'库存占用量与实际出库量不符','success'=>false));exit;
  263. }
  264. else
  265. {
  266. foreach ($whlabel as $v)
  267. {
  268. $this->whlabel->save(array('state'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$v['id']);
  269. }
  270. }
  271. /**
  272. $ckcg = 0;$save = array();
  273. $pp = explode('|',trim($y['whlabel'],'|'));
  274. foreach ($pp as $va)
  275. {
  276. $uid = array();//储存可用出库产品的ID
  277. $num = explode('-',$va);
  278. $shopwhlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '".$y['type']."' and shop !='' and shop like '%,".$y['shop'].",%'");
  279. $whlabel = $this->whlabel->find_all("state = 0 and number = '$num[0]' and warehouse = '".$y['type']."' and (shop IS NULL or shop = '')");
  280. if($shopwhlabel)
  281. {
  282. if(count($shopwhlabel) >= $num[1])//如果专用的条数大于需求
  283. {
  284. for($i=0;$i<$num[1];$i++)
  285. {
  286. $uid[] = $shopwhlabel[$i]['id'];
  287. }
  288. $save[] = $uid;
  289. }
  290. else if(count($shopwhlabel) < $num[1] && count($whlabel) >= $num[1])//如果专用的条数小于需求,但专用的条数+通用的条数大于等于需求,判断为可用,有限扣减专用数
  291. {
  292. for($x=0;$x<$num[1];$x++)
  293. {
  294. $uid[] = $whlabel[$x]['id'];
  295. }
  296. $save[] = $uid;
  297. }
  298. else
  299. {
  300. $ckcg++;
  301. }
  302. }
  303. else if(!$whlabel || count($whlabel) < $num[1])
  304. {
  305. $ckcg++;
  306. }
  307. else
  308. {
  309. for($i=0;$i<$num[1];$i++)
  310. {
  311. $uid[] = $whlabel[$i]['id'];
  312. }
  313. $save[] = $uid;
  314. }
  315. }
  316. if($ckcg > 0)
  317. {
  318. echo json_encode(array('msg'=>'无法匹配库存或库存为0','success'=>false));exit;
  319. }
  320. else
  321. {
  322. foreach ($save as $vb)
  323. {
  324. foreach ($vb as $vc)
  325. {
  326. $this->whlabel->save(array('state'=>1,'orderinfo'=>$y['orderinfo'],'waybill'=>$y['waybill'],'outk'=>$time,'time'=>$time),$vc);
  327. }
  328. }
  329. }
  330. **/
  331. }
  332. if($fullorder_name == 'fullordersmt')
  333. {
  334. $stt = ($y['waybill']!='')?209:$y['state'];
  335. if($this->$fullorder_name->save(array('library'=>2,'state'=>$stt,'librarytime'=>$time,'weight'=>$weight),$y['id']))
  336. {
  337. echo json_encode(array('success'=>true));exit;
  338. }
  339. else
  340. {
  341. echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit;
  342. }
  343. }
  344. else
  345. {
  346. if($this->$fullorder_name->save(array('library'=>2,'librarytime'=>$time,'weight'=>$weight),$y['id']))
  347. {
  348. echo json_encode(array('success'=>true));exit;
  349. }
  350. else
  351. {
  352. echo json_encode(array('msg'=>'出库失败,请重试','success'=>false));exit;
  353. }
  354. }
  355. }
  356. if(isset($post['page']))
  357. {
  358. $api = $this->input->post('api',true);
  359. if(isset($api))
  360. {
  361. $user = $this->user->get_api($api);
  362. $usp = $user;
  363. $fgshop = "";$sid = "";$wid="";$wtype="";
  364. $usersp = explode('|',trim($user['shop'],'|'));
  365. $userwh = explode('|',trim($user['warehouse'],'|'));
  366. foreach ($usersp as $value)
  367. {
  368. $fgshop .= " shop = ".$value." or";
  369. $sid .= " id = ".$value." or";
  370. }
  371. foreach ($userwh as $value)
  372. {
  373. $wid .= " id = ".$value." or";
  374. $wtype .= " type = ".$value." or";
  375. }
  376. }
  377. $page = $this->input->post('page',true);
  378. $perpage = $this->input->post('perpage',true);
  379. $timetk = $this->input->post('timetk',true);
  380. $timetj = $this->input->post('timetj',true);
  381. $shop = $this->input->post('shop',true);
  382. $source = $this->input->post('source',true);
  383. $orderinfo = $this->input->post('orderinfo',true);
  384. $number = $this->input->post('number',true);
  385. $library = $this->input->post('library',true);
  386. $waybill = $this->input->post('waybill',true);
  387. $express = $this->input->post('express',true);
  388. $type = $this->input->post('type',true);
  389. $lowe = $this->input->post('lowe',true);
  390. $so = $this->input->post('so',true);
  391. $librarytime = $this->input->post('librarytime',true);
  392. $timetk = strtotime($timetk);
  393. $timetj = strtotime($timetj);
  394. $cxtime = 'id';
  395. $where = (isset($_SESSION['api']) || $api)?"library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3 and (".rtrim($wtype,'or').")":"library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3";
  396. if($timetk && $timetj && $library == 2 && $librarytime != 1)
  397. {
  398. $cxtime = 'reviewtime';
  399. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  400. }
  401. else if($timetk && $timetj && $library == 2 && $librarytime == 1)
  402. {
  403. $cxtime = 'librarytime';
  404. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  405. }
  406. if($shop)
  407. {
  408. $where .= " and shop = '$shop'";
  409. }
  410. if($number)
  411. {
  412. $where .= " and number = '$number'";
  413. }
  414. if($library)
  415. {
  416. $where .= " and library = '$library'";
  417. }
  418. if($waybill)
  419. {
  420. $where .= " and waybill = '$waybill'";
  421. }
  422. if($express)
  423. {
  424. $where .= " and express = '$express'";
  425. }
  426. if($orderinfo)
  427. {
  428. $where .= " and orderinfo = '$orderinfo'";
  429. }
  430. if($type)
  431. {
  432. $where .= " and type = '$type'";
  433. }
  434. if($lowe)
  435. {
  436. $where .= " and shipremarks like '%$lowe%'";
  437. }
  438. if($so)
  439. {
  440. $where .= " and shipremarks like '%$so%'";
  441. }
  442. //数据排序
  443. $order_str = $cxtime." desc";
  444. if(empty($page))
  445. {
  446. $start = 0;
  447. $perpage = 1;
  448. }
  449. else
  450. {
  451. $start = ($page - 1)*$perpage;
  452. }
  453. //取得信息列表
  454. $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str,$start,$perpage);
  455. //格式化数据
  456. foreach ($info_list as $key=>$value)
  457. {
  458. $shop = $this->shop->read($value['shop']);
  459. $info_list[$key]['shop'] = $shop['shopname'];
  460. if($value['waybill'] == '0')
  461. {
  462. $info_list[$key]['waybill'] = "";
  463. }
  464. $express = $this->express->read($value['express']);
  465. $info_list[$key]['express'] = $express['servicename'];
  466. $warehouse = $this->warehouse->read($value['type']);
  467. $info_list[$key]['type'] = $warehouse['title'];
  468. if($value['print'] == 1)
  469. {
  470. $info_list[$key]['print'] = '不可打印';
  471. }
  472. else if($value['print'] == 2)
  473. {
  474. $info_list[$key]['print'] = '未打印';
  475. }
  476. else if($value['print'] == 3)
  477. {
  478. $info_list[$key]['print'] = '已打印';
  479. }
  480. if($value['library'] == 1)
  481. {
  482. $info_list[$key]['library'] = '<em class="c">未出库</em>';
  483. }
  484. else if($value['library'] == 2)
  485. {
  486. $info_list[$key]['library'] = '<em class="c">已出库</em>';
  487. }
  488. else if($value['library'] == 3)
  489. {
  490. $info_list[$key]['library'] = '<em class="c">已退库</em>';
  491. }
  492. if($value['librarytime'] == '0')
  493. {
  494. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  495. }
  496. else
  497. {
  498. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  499. }
  500. }
  501. $info_list_smt = $this->fullorder_smt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str,$start,$perpage);
  502. //格式化数据
  503. foreach ($info_list_smt as $key=>$value)
  504. {
  505. $shop = $this->shop->read($value['shop']);
  506. $info_list_smt[$key]['shop'] = $shop['shopname'];
  507. if($value['waybill'] == '0')
  508. {
  509. $info_list_smt[$key]['waybill'] = "";
  510. }
  511. $express = $this->express->read($value['express']);
  512. $info_list_smt[$key]['express'] = $express['servicename'];
  513. $warehouse = $this->warehouse->read($value['type']);
  514. $info_list_smt[$key]['type'] = $warehouse['title'];
  515. if($value['print'] == 1)
  516. {
  517. $info_list_smt[$key]['print'] = '不可打印';
  518. }
  519. else if($value['print'] == 2)
  520. {
  521. $info_list_smt[$key]['print'] = '未打印';
  522. }
  523. else if($value['print'] == 3)
  524. {
  525. $info_list_smt[$key]['print'] = '已打印';
  526. }
  527. if($value['library'] == 1)
  528. {
  529. $info_list_smt[$key]['library'] = '<em class="c">未出库</em>';
  530. }
  531. else if($value['library'] == 2)
  532. {
  533. $info_list_smt[$key]['library'] = '<em class="c">已出库</em>';
  534. }
  535. else if($value['library'] == 3)
  536. {
  537. $info_list_smt[$key]['library'] = '<em class="c">已退库</em>';
  538. }
  539. if($value['librarytime'] == '0')
  540. {
  541. $info_list_smt[$key]['librarytime'] = '<em class="t"></em>';
  542. }
  543. else
  544. {
  545. $info_list_smt[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  546. }
  547. }
  548. $info_listsmt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str,$start,$perpage);
  549. //格式化数据
  550. foreach ($info_listsmt as $key=>$value)
  551. {
  552. $shop = $this->shop->read($value['shop']);
  553. $info_listsmt[$key]['shop'] = $shop['shopname'];
  554. if($value['waybill'] == '0')
  555. {
  556. $info_listsmt[$key]['waybill'] = "";
  557. }
  558. $express = $this->express->read($value['express']);
  559. $info_listsmt[$key]['express'] = $express['servicename'];
  560. $warehouse = $this->warehouse->read($value['type']);
  561. $info_listsmt[$key]['type'] = $warehouse['title'];
  562. if($value['print'] == 1)
  563. {
  564. $info_listsmt[$key]['print'] = '不可打印';
  565. }
  566. else if($value['print'] == 2)
  567. {
  568. $info_listsmt[$key]['print'] = '未打印';
  569. }
  570. else if($value['print'] == 3)
  571. {
  572. $info_listsmt[$key]['print'] = '已打印';
  573. }
  574. if($value['library'] == 1)
  575. {
  576. $info_listsmt[$key]['library'] = '<em class="c">未出库</em>';
  577. }
  578. else if($value['library'] == 2)
  579. {
  580. $info_listsmt[$key]['library'] = '<em class="c">已出库</em>';
  581. }
  582. else if($value['library'] == 3)
  583. {
  584. $info_listsmt[$key]['library'] = '<em class="c">已退库</em>';
  585. }
  586. if($value['librarytime'] == '0')
  587. {
  588. $info_listsmt[$key]['librarytime'] = '<em class="t"></em>';
  589. }
  590. else
  591. {
  592. $info_listsmt[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  593. }
  594. }
  595. $total = $this->fullorder->find_count($where);
  596. $total += $this->fullorder_smt->find_count($where);
  597. $total += $this->fullordersmt->find_count($where);
  598. $pagenum = ceil($total/$perpage);
  599. $over = $total-($start+$perpage);
  600. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_list_smt,$info_listsmt)));
  601. echo json_encode($rows);exit;
  602. }
  603. $this->data['express'] = $this->express->find_all();
  604. $this->_Template('apt_out',$this->data);
  605. }
  606. //退库
  607. public function _retreat()
  608. {
  609. $post = $this->input->post(NULL, TRUE);
  610. if(isset($post['order']))
  611. {
  612. $time = time();
  613. $order = $this->input->post('order',true);
  614. if(substr($order,0,3) == '788' && substr($order,-4,4) == '0430')//Fedex联邦
  615. {
  616. $order = substr($order,0,12);
  617. }
  618. $y = $this->fullorder->get_waybill($order);
  619. $fullorder_name = 'fullorder';
  620. if(!$y)
  621. {
  622. $y = $this->fullorder->get_number($order);
  623. if(!$y)
  624. {
  625. $fullorder_name = 'fullorder_smt';
  626. $y = $this->fullorder_smt->get_waybill($order);
  627. if(!$y)
  628. {
  629. $y = $this->fullorder_smt->get_number($order);
  630. if(!$y)
  631. {
  632. $fullorder_name = 'fullordersmt';
  633. $y = $this->fullordersmt->get_waybill($order);
  634. if(!$y)
  635. {
  636. $y = $this->fullordersmt->get_number($order);
  637. if(!$y)
  638. {
  639. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  640. }
  641. }
  642. }
  643. }
  644. }
  645. }
  646. if($y['library'] == 3)
  647. {
  648. echo json_encode(array('msg'=>'此数据 '.date('Y-m-d H:i:s',$y['retreattime']).' 已操作','success'=>false));exit;
  649. }
  650. if($y['library'] == 1)
  651. {
  652. echo json_encode(array('msg'=>'此数据未出库','success'=>false));exit;
  653. }
  654. $warehouse = $this->warehouse->read($y['type']);
  655. if($warehouse['zd'] == '1')
  656. {
  657. $wl = $this->whlabel->find_all("zd = '".$y['number']."'");//查找是否有占用库存情况
  658. if($wl)//如果有那么清除所有占用
  659. {
  660. $i = 0;
  661. foreach ($wl as $v)
  662. {
  663. $this->whlabel->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$v['id']);//专属
  664. $i++;
  665. }
  666. if($i != count($wl))
  667. {
  668. echo json_encode(array('msg'=>"退库错误,请重试",'success'=>false));exit;
  669. }
  670. }
  671. /**
  672. $ckcg = 0;$save = array();
  673. $pp = explode('|',trim($y['whlabel'],'|'));
  674. foreach ($pp as $va)
  675. {
  676. $uid = array();//储存可用出库产品的ID
  677. $num = explode('-',$va);
  678. $whlabel = $this->whlabel->find_all("state = 1 and number = '$num[0]' and warehouse = '".$y['type']."' and orderinfo = '".$y['orderinfo']."' and waybill = '".$y['waybill']."'");
  679. if(!$whlabel || count($whlabel) != $num[1])
  680. {
  681. $ckcg++;
  682. }
  683. else
  684. {
  685. for($i=0;$i<$num[1];$i++)
  686. {
  687. $uid[] = $whlabel[$i]['id'];
  688. }
  689. $save[] = $uid;
  690. }
  691. }
  692. if($ckcg > 0)
  693. {
  694. echo json_encode(array('msg'=>'有产品无出库信息','success'=>false));exit;
  695. }
  696. else
  697. {
  698. foreach ($save as $vb)
  699. {
  700. foreach ($vb as $vc)
  701. {
  702. $this->whlabel->save(array('state'=>0,'retreat'=>$time,'time'=>$time),$vc);
  703. }
  704. }
  705. }
  706. **/
  707. }
  708. if($this->$fullorder_name->save(array('library'=>3,'retreattime'=>$time),$y['id']))
  709. {
  710. echo json_encode(array('success'=>true));exit;
  711. }
  712. else
  713. {
  714. echo json_encode(array('msg'=>'退库失败,请重试','success'=>false));exit;
  715. }
  716. }
  717. if(isset($post['page']))
  718. {
  719. $api = $this->input->post('api',true);
  720. if(isset($api))
  721. {
  722. $user = $this->user->get_api($api);
  723. $usp = $user;
  724. $fgshop = "";$sid = "";$wid="";$wtype="";
  725. $usersp = explode('|',trim($user['shop'],'|'));
  726. $userwh = explode('|',trim($user['warehouse'],'|'));
  727. foreach ($usersp as $value)
  728. {
  729. $fgshop .= " shop = ".$value." or";
  730. $sid .= " id = ".$value." or";
  731. }
  732. foreach ($userwh as $value)
  733. {
  734. $wid .= " id = ".$value." or";
  735. $wtype .= " type = ".$value." or";
  736. }
  737. }
  738. $page = $this->input->post('page',true);
  739. $perpage = $this->input->post('perpage',true);
  740. $timetk = $this->input->post('timetk',true);
  741. $timetj = $this->input->post('timetj',true);
  742. $shop = $this->input->post('shop',true);
  743. $source = $this->input->post('source',true);
  744. $orderinfo = $this->input->post('orderinfo',true);
  745. $number = $this->input->post('number',true);
  746. $waybill = $this->input->post('waybill',true);
  747. $express = $this->input->post('express',true);
  748. $type = $this->input->post('type',true);
  749. $lowe = $this->input->post('lowe',true);
  750. $timetk = strtotime($timetk);
  751. $timetj = strtotime($timetj);
  752. $where = (isset($_SESSION['api']) || $api)?"library=3 and gtime > 20190127 and (".rtrim($wtype,'or').")":"library=3 and gtime > 20190127";
  753. if($timetk && $timetj)
  754. {
  755. $where .= " and retreattime > '$timetk' and retreattime < '$timetj'";
  756. }
  757. if($shop)
  758. {
  759. $where .= " and shop = '$shop'";
  760. }
  761. if($orderinfo)
  762. {
  763. $where .= " and orderinfo = '$orderinfo'";
  764. }
  765. if($number)
  766. {
  767. $where .= " and number = '$number'";
  768. }
  769. if($waybill)
  770. {
  771. $where .= " and waybill = '$waybill'";
  772. }
  773. if($express)
  774. {
  775. $where .= " and express = '$express'";
  776. }
  777. if($orderinfo)
  778. {
  779. $where .= " and orderinfo = '$orderinfo'";
  780. }
  781. if($type)
  782. {
  783. $where .= " and type = '$type'";
  784. }
  785. if($lowe)
  786. {
  787. $where .= " and shipremarks like '%$lowe%'";
  788. }
  789. //数据排序
  790. $order_str = "retreattime desc";
  791. if(empty($page))
  792. {
  793. $start = 0;
  794. $perpage = 1;
  795. }
  796. else
  797. {
  798. $start = ($page - 1)*$perpage;
  799. }
  800. //取得信息列表
  801. $info_list = $this->fullorder->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);
  802. //格式化数据
  803. foreach ($info_list as $key=>$value)
  804. {
  805. $shop = $this->shop->read($value['shop']);
  806. $info_list[$key]['shop'] = $shop['shopname'];
  807. if($value['waybill'] == 0)
  808. {
  809. $info_list[$key]['waybill'] = "";
  810. }
  811. $express = $this->express->read($value['express']);
  812. $info_list[$key]['express'] = $express['servicename'];
  813. $warehouse = $this->warehouse->read($value['type']);
  814. $info_list[$key]['type'] = $warehouse['title'];
  815. $typeclass = $this->typeclass->read($value['state']);
  816. $info_list[$key]['state'] = $typeclass['spare'];
  817. if($value['print'] == 1)
  818. {
  819. $info_list[$key]['print'] = '不可打印';
  820. }
  821. else if($value['print'] == 2)
  822. {
  823. $info_list[$key]['print'] = '未打印';
  824. }
  825. else if($value['print'] == 3)
  826. {
  827. $info_list[$key]['print'] = '已打印';
  828. }
  829. if($value['retreattime'] == '0')
  830. {
  831. $info_list[$key]['retreattime'] = '<em class="t"></em>';
  832. }
  833. else
  834. {
  835. $info_list[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
  836. }
  837. }
  838. $info_list_smt = $this->fullorder_smt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);
  839. //格式化数据
  840. foreach ($info_list_smt as $key=>$value)
  841. {
  842. $shop = $this->shop->read($value['shop']);
  843. $info_list_smt[$key]['shop'] = $shop['shopname'];
  844. if($value['waybill'] == 0)
  845. {
  846. $info_list_smt[$key]['waybill'] = "";
  847. }
  848. $express = $this->express->read($value['express']);
  849. $info_list_smt[$key]['express'] = $express['servicename'];
  850. $warehouse = $this->warehouse->read($value['type']);
  851. $info_list_smt[$key]['type'] = $warehouse['title'];
  852. $typeclass = $this->typeclass->read($value['state']);
  853. $info_list_smt[$key]['state'] = $typeclass['spare'];
  854. if($value['print'] == 1)
  855. {
  856. $info_list_smt[$key]['print'] = '不可打印';
  857. }
  858. else if($value['print'] == 2)
  859. {
  860. $info_list_smt[$key]['print'] = '未打印';
  861. }
  862. else if($value['print'] == 3)
  863. {
  864. $info_list_smt[$key]['print'] = '已打印';
  865. }
  866. if($value['retreattime'] == '0')
  867. {
  868. $info_list_smt[$key]['retreattime'] = '<em class="t"></em>';
  869. }
  870. else
  871. {
  872. $info_list_smt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
  873. }
  874. }
  875. $info_listsmt = $this->fullordersmt->find_all($where,'id,shop,type,orderinfo,number,waybill,express,print,state,retreattime,shipremarks',$order_str,$start,$perpage);
  876. //格式化数据
  877. foreach ($info_listsmt as $key=>$value)
  878. {
  879. $shop = $this->shop->read($value['shop']);
  880. $info_listsmt[$key]['shop'] = $shop['shopname'];
  881. if($value['waybill'] == 0)
  882. {
  883. $info_listsmt[$key]['waybill'] = "";
  884. }
  885. $express = $this->express->read($value['express']);
  886. $info_listsmt[$key]['express'] = $express['servicename'];
  887. $warehouse = $this->warehouse->read($value['type']);
  888. $info_listsmt[$key]['type'] = $warehouse['title'];
  889. $typeclass = $this->typeclass->read($value['state']);
  890. $info_listsmt[$key]['state'] = $typeclass['spare'];
  891. if($value['print'] == 1)
  892. {
  893. $info_listsmt[$key]['print'] = '不可打印';
  894. }
  895. else if($value['print'] == 2)
  896. {
  897. $info_listsmt[$key]['print'] = '未打印';
  898. }
  899. else if($value['print'] == 3)
  900. {
  901. $info_listsmt[$key]['print'] = '已打印';
  902. }
  903. if($value['retreattime'] == '0')
  904. {
  905. $info_listsmt[$key]['retreattime'] = '<em class="t"></em>';
  906. }
  907. else
  908. {
  909. $info_listsmt[$key]['retreattime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['retreattime']).'</em>';
  910. }
  911. }
  912. $total = $this->fullorder->find_count($where);
  913. $total += $this->fullorder_smt->find_count($where);
  914. $total += $this->fullordersmt->find_count($where);
  915. $pagenum = ceil($total/$perpage);
  916. $over = $total-($start+$perpage);
  917. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>(array_merge($info_list,$info_list_smt,$info_listsmt)));
  918. echo json_encode($rows);exit;
  919. }
  920. $this->data['express'] = $this->express->find_all();
  921. $this->_Template('apt_retreat',$this->data);
  922. }
  923. //打印页面
  924. public function _print()
  925. {
  926. $post = $this->input->post(NULL, TRUE);
  927. if(isset($_SESSION['api']))
  928. {
  929. $user = $this->user->get_api($_SESSION['api']);
  930. $usp = $user;
  931. $fgshop = "";$sid = "";$wid="";
  932. $usersp = explode('|',trim($user['shop'],'|'));
  933. $userwh = explode('|',trim($user['warehouse'],'|'));
  934. foreach ($usersp as $value)
  935. {
  936. $fgshop .= " shop = ".$value." or";
  937. $sid .= " id = ".$value." or";
  938. }
  939. foreach ($userwh as $value)
  940. {
  941. $wid .= " id = ".$value." or";
  942. }
  943. }
  944. if(isset($post['page']))
  945. {
  946. $api = $this->input->post('api',true);
  947. $page = $this->input->post('page',true);
  948. $perpage = $this->input->post('perpage',true);
  949. $timetk = $this->input->post('timetk',true);
  950. $timetj = $this->input->post('timetj',true);
  951. $shop = $this->input->post('shop',true);
  952. $print = $this->input->post('print',true);
  953. $express = $this->input->post('express',true);
  954. $waybill = $this->input->post('waybill',true);
  955. $printtype = $this->input->post('printtype',true);
  956. $orderinfo = $this->input->post('orderinfo',true);
  957. $number = $this->input->post('number',true);
  958. $type = $this->input->post('type',true);
  959. $lowe = $this->input->post('lowe',true);
  960. $info = $this->input->post('info',true);
  961. $ji = $this->input->post('ji',true);
  962. $so = $this->input->post('so',true);
  963. $timetk = strtotime($timetk);
  964. $timetj = strtotime($timetj);
  965. if(isset($api))
  966. {
  967. $user = $this->user->get_api($api);
  968. $usp = $user;
  969. $fgshop = "";$sid = "";$wid="";$wtype="";
  970. $usersp = explode('|',trim($user['shop'],'|'));
  971. $userwh = explode('|',trim($user['warehouse'],'|'));
  972. foreach ($usersp as $value)
  973. {
  974. $fgshop .= " shop = ".$value." or";
  975. $sid .= " id = ".$value." or";
  976. }
  977. foreach ($userwh as $value)
  978. {
  979. $wid .= " id = ".$value." or";
  980. $wtype .= " type = ".$value." or";
  981. }
  982. }
  983. $where = (isset($_SESSION['api']) || $api)?"mergeid != '1' and (".rtrim($fgshop,'or').") and (".rtrim($wtype,'or').")":"mergeid != '1'";
  984. if($print == 3)
  985. {
  986. $where .= " and printtime > '$timetk' and printtime < '$timetj' and print = 3";
  987. }
  988. else
  989. {
  990. $where .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1 and state = 207";
  991. }
  992. if($shop)
  993. {
  994. $where .= " and shop = '$shop'";
  995. }
  996. if($express)
  997. {
  998. $where .= " and express = '$express'";
  999. }
  1000. if($printtype)
  1001. {
  1002. $where .= " and printtype = '$printtype'";
  1003. }
  1004. if($orderinfo)
  1005. {
  1006. $where .= " and orderinfo = '$orderinfo'";
  1007. }
  1008. if($number)
  1009. {
  1010. $where .= " and number = '$number'";
  1011. }
  1012. if($waybill)
  1013. {
  1014. $where .= " and waybill = '$waybill'";
  1015. }
  1016. if($type)
  1017. {
  1018. $where .= " and type = '$type'";
  1019. }
  1020. if($lowe)
  1021. {
  1022. $where .= " and fpdata like '%-$lowe-%'";
  1023. }
  1024. if($ji)
  1025. {
  1026. $where .= " and shipremarks like '%急%'";
  1027. }
  1028. if($so)
  1029. {
  1030. $where .= " and shipremarks like '%$so%'";
  1031. }
  1032. //数据排序
  1033. $order_str = ($print != 3)?"id desc":"printtime desc";
  1034. if(empty($page))
  1035. {
  1036. $start = 0;
  1037. $perpage = 1;
  1038. }
  1039. else
  1040. {
  1041. $start = ($page - 1)*$perpage;
  1042. }
  1043. $info_list = array();
  1044. $info_listsmt = array();
  1045. $dlz = 0; $smt = 0;
  1046. if($info != 'fullordersmt')
  1047. {
  1048. //取得信息列表
  1049. $info_list = $this->fullorder->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);
  1050. //格式化数据
  1051. foreach ($info_list as $key=>$value)
  1052. {
  1053. $info_list[$key]['id'] = $value['id'].'-fullorder';
  1054. $shop = $this->shop->read($value['shop']);
  1055. $info_list[$key]['shop'] = $shop['shopname'];
  1056. $express = $this->express->read($value['express']);
  1057. if($express)
  1058. {
  1059. $info_list[$key]['express'] = $express['servicename'];
  1060. }
  1061. else
  1062. {
  1063. $info_list[$key]['express'] = '未选择';
  1064. }
  1065. if($value['printtime'] != 0)
  1066. {
  1067. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1068. }
  1069. else
  1070. {
  1071. $info_list[$key]['printtime'] = '无';
  1072. }
  1073. if($value['print'] == 1)
  1074. {
  1075. $info_list[$key]['print'] = "禁止打印";
  1076. }
  1077. else if($value['print'] == 2)
  1078. {
  1079. $info_list[$key]['print'] = "未打印";
  1080. }
  1081. else if($value['print'] == 3)
  1082. {
  1083. $info_list[$key]['print'] = "已打印";
  1084. }
  1085. if($value['printtype'] == 1)
  1086. {
  1087. $info_list[$key]['printtype'] = "运单";
  1088. }
  1089. else if($value['printtype'] == 2)
  1090. {
  1091. $info_list[$key]['printtype'] = "发货单";
  1092. }
  1093. else if($value['printtype'] == 0)
  1094. {
  1095. $info_list[$key]['printtype'] = "未选择";
  1096. }
  1097. }
  1098. $dlz = $this->fullorder->find_count($where);
  1099. }
  1100. /**
  1101. $info_list_smt = $this->fullorder_smt->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);
  1102. //格式化数据
  1103. foreach ($info_list_smt as $key=>$value)
  1104. {
  1105. $info_list_smt[$key]['id'] = $value['id'].'-fullorder_smt';
  1106. $shop = $this->shop->read($value['shop']);
  1107. $info_list_smt[$key]['shop'] = $shop['shopname'];
  1108. $express = $this->express->read($value['express']);
  1109. if($express)
  1110. {
  1111. $info_list_smt[$key]['express'] = $express['servicename'];
  1112. }
  1113. else
  1114. {
  1115. $info_list_smt[$key]['express'] = '未选择';
  1116. }
  1117. if($value['printtime'] != 0)
  1118. {
  1119. $info_list_smt[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1120. }
  1121. else
  1122. {
  1123. $info_list_smt[$key]['printtime'] = '无';
  1124. }
  1125. if($value['print'] == 1)
  1126. {
  1127. $info_list_smt[$key]['print'] = "禁止打印";
  1128. }
  1129. else if($value['print'] == 2)
  1130. {
  1131. $info_list_smt[$key]['print'] = "未打印";
  1132. }
  1133. else if($value['print'] == 3)
  1134. {
  1135. $info_list_smt[$key]['print'] = "已打印";
  1136. }
  1137. if($value['printtype'] == 1)
  1138. {
  1139. $info_list_smt[$key]['printtype'] = "运单";
  1140. }
  1141. else if($value['printtype'] == 2)
  1142. {
  1143. $info_list_smt[$key]['printtype'] = "发货单";
  1144. }
  1145. else if($value['printtype'] == 0)
  1146. {
  1147. $info_list_smt[$key]['printtype'] = "未选择";
  1148. }
  1149. }
  1150. **/
  1151. if($info != 'fullorder')
  1152. {
  1153. $info_listsmt = $this->fullordersmt->find_all($where,'id,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str,$start,$perpage);
  1154. //格式化数据
  1155. foreach ($info_listsmt as $key=>$value)
  1156. {
  1157. $info_listsmt[$key]['id'] = $value['id'].'-fullordersmt';
  1158. $shop = $this->shop->read($value['shop']);
  1159. $info_listsmt[$key]['shop'] = $shop['shopname'];
  1160. $express = $this->express->read($value['express']);
  1161. if($express)
  1162. {
  1163. $info_listsmt[$key]['express'] = $express['servicename'];
  1164. }
  1165. else
  1166. {
  1167. $info_listsmt[$key]['express'] = '未选择';
  1168. }
  1169. if($value['printtime'] != 0)
  1170. {
  1171. $info_listsmt[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1172. }
  1173. else
  1174. {
  1175. $info_listsmt[$key]['printtime'] = '无';
  1176. }
  1177. if($value['print'] == 1)
  1178. {
  1179. $info_listsmt[$key]['print'] = "禁止打印";
  1180. }
  1181. else if($value['print'] == 2)
  1182. {
  1183. $info_listsmt[$key]['print'] = "未打印";
  1184. }
  1185. else if($value['print'] == 3)
  1186. {
  1187. $info_listsmt[$key]['print'] = "已打印";
  1188. }
  1189. if($value['printtype'] == 1)
  1190. {
  1191. $info_listsmt[$key]['printtype'] = "运单";
  1192. }
  1193. else if($value['printtype'] == 2)
  1194. {
  1195. $info_listsmt[$key]['printtype'] = "发货单";
  1196. }
  1197. else if($value['printtype'] == 0)
  1198. {
  1199. $info_listsmt[$key]['printtype'] = "未选择";
  1200. }
  1201. }
  1202. $smt += $this->fullordersmt->find_count($where);
  1203. }
  1204. //$total += $this->fullorder_smt->find_count($where);
  1205. $total = $dlz+$smt;
  1206. $rows = array_merge($info_list,$info_listsmt);
  1207. //$rows = array_slice($rows,$start,$perpage);
  1208. $pagenum = ceil($total/$perpage);
  1209. $over = $total-($start+$perpage);
  1210. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($rows));//array_merge($info_list,$info_list_smt,$info_listsmt)
  1211. echo json_encode($rows);exit;
  1212. }
  1213. if(isset($_SESSION['api']))
  1214. {
  1215. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1216. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'));
  1217. $this->data['wlshop'] = $wlshop;
  1218. $this->data['warehouse'] = $warehouse;
  1219. }
  1220. $this->_Template('apt_print',$this->data);
  1221. }
  1222. //打印
  1223. public function _printing()
  1224. {
  1225. $post = $this->input->post(NULL, TRUE);
  1226. if(isset($post['s']))
  1227. {
  1228. $v = $this->input->post('s');
  1229. $va = explode(',',rtrim($v,','));
  1230. $n = $this->input->post('n');
  1231. $type = 3;$text = array();$text['data'] = array();$time = time();
  1232. $pd = explode('-',$va[$n]);
  1233. $va[$n] = $pd[0];
  1234. $fullorder_name = $pd[1];
  1235. $fullorder = $this->$fullorder_name->read($va[$n]);
  1236. if(isset($va[$n+1]))
  1237. {
  1238. $xyz = explode('-',$va[$n+1]);
  1239. $sf = $this->$fullorder_name->read($xyz[0]);
  1240. if($sf['printtype'] == 1 && $fullorder['printtype'] == 2)
  1241. {
  1242. sleep(15);
  1243. }
  1244. }
  1245. $fullorder = $this->_text($fullorder);//获取所需信息
  1246. $oldprinttime = ($fullorder['printtime'] > 0)?$fullorder['oldprinttime'].$fullorder['printtime'].'-':'';
  1247. $fullorder['printtime'] = date('m-d H:i',$time);//打印用时间、发货单用,不能删
  1248. if($fullorder['printtype'] == 1 && $fullorder['library'] != 2)// && $fullorder['library'] != 2
  1249. {
  1250. if($fullorder['printcode'] == "DHL")//如果打印过那么重新获取运单
  1251. {
  1252. sleep(12);
  1253. $barcode = $this->dhl->get_data($fullorder);//获取DHL快递信息
  1254. if(isset($barcode['AirwayBillNumber']))
  1255. {
  1256. $bctime = date('Ymd',$time);
  1257. $Hwaybill = $barcode['AirwayBillNumber'];
  1258. $Hfp = $this->_pdf($barcode['LabelImage']['MultiLabels']['MultiLabel']['DocImageVal'],'f-'.$Hwaybill,$bctime);
  1259. $Hyd = $this->_pdf($barcode['LabelImage']['OutputImage'],'y-'.$Hwaybill,$bctime);
  1260. if(isset($Hfp) && isset($Hyd) && isset($Hwaybill))
  1261. {
  1262. if($fullorder['waybill'] != "")
  1263. {
  1264. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1265. }
  1266. else
  1267. {
  1268. $oldwaybill = $fullorder['oldwaybill'];
  1269. }
  1270. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1271. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1272. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1273. {
  1274. $type = 1;
  1275. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder);
  1276. }
  1277. }
  1278. }
  1279. else
  1280. {
  1281. $failed = (isset($barcode['Response']['Status']['Condition']['ConditionData'])?$barcode['Response']['Status']['Condition']['ConditionData']:$barcode['Response']['Status']['Condition'][0]['ConditionData']);
  1282. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
  1283. }
  1284. }
  1285. else if($fullorder['printcode'] == "USPS")
  1286. {
  1287. sleep(10);
  1288. $barcode = $this->usps->get_data($fullorder);//获取DHL快递信息
  1289. if(isset($barcode['LabelImage']))
  1290. {
  1291. $bctime = date('Ymd',$time);
  1292. $Hwaybill = $barcode['BarcodeNumber'];
  1293. $Hyd = $this->_pdf($barcode['LabelImage'],'y-'.$Hwaybill,$bctime);
  1294. if(isset($barcode['LabelImage']) && isset($Hwaybill))
  1295. {
  1296. if($fullorder['waybill'] != "")
  1297. {
  1298. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1299. }
  1300. else
  1301. {
  1302. $oldwaybill = $fullorder['oldwaybill'];
  1303. }
  1304. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1305. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1306. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1307. {
  1308. $type = 1;
  1309. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
  1310. }
  1311. }
  1312. }
  1313. else
  1314. {
  1315. $failed = $barcode['Description'];//错误提示
  1316. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
  1317. }
  1318. }
  1319. else if($fullorder['printcode'] == "FEDEXGF")//官方FEDEX接口
  1320. {
  1321. sleep(10);
  1322. $barcode = $this->fedex->get_data($fullorder);//获取联邦快递信息
  1323. if($barcode['x'] == 1)
  1324. {
  1325. $bctime = date('Ymd',$time);
  1326. $Hwaybill = $barcode['waybill'];
  1327. $Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
  1328. $Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
  1329. if(isset($barcode['label']) && isset($Hwaybill))
  1330. {
  1331. if($fullorder['waybill'] != "")
  1332. {
  1333. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1334. }
  1335. else
  1336. {
  1337. $oldwaybill = $fullorder['oldwaybill'];
  1338. }
  1339. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1340. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1341. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1342. {
  1343. $type = 1;
  1344. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
  1345. }
  1346. }
  1347. }
  1348. else
  1349. {
  1350. $failed = $barcode['Description'];//错误提示
  1351. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
  1352. }
  1353. }
  1354. else if($fullorder['printcode'] == "FEDEXCBY")//官方FEDEX接口许昌玉美桥
  1355. {
  1356. sleep(10);
  1357. $barcode = $this->fedex_cby->get_data($fullorder);//获取联邦快递信息
  1358. if($barcode['x'] == 1)
  1359. {
  1360. $bctime = date('Ymd',$time);
  1361. $Hwaybill = $barcode['waybill'];
  1362. $Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
  1363. $Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
  1364. if(isset($barcode['label']) && isset($Hwaybill))
  1365. {
  1366. if($fullorder['waybill'] != "")
  1367. {
  1368. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1369. }
  1370. else
  1371. {
  1372. $oldwaybill = $fullorder['oldwaybill'];
  1373. }
  1374. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1375. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1376. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1377. {
  1378. $type = 1;
  1379. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
  1380. }
  1381. }
  1382. }
  1383. else
  1384. {
  1385. $failed = $barcode['Description'];//错误提示
  1386. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
  1387. }
  1388. }
  1389. /** DPD只获取运单号不打印运单 **/
  1390. else if($fullorder['printcode'] == "DPD")
  1391. {
  1392. sleep(15);//不打印运单 4秒延时
  1393. if($fullorder['zhou'] == '12')//欧洲
  1394. {
  1395. if($fullorder_name == 'fullordersmt')//速卖通9610
  1396. {
  1397. $fullorder['ysfs'] == '1921';
  1398. }
  1399. else if($fullorder_name == 'fullorder')//独立站9610
  1400. {
  1401. $fullorder['ysfs'] == '2021';
  1402. }
  1403. }
  1404. else if($fullorder['zhou'] == '13')//非洲
  1405. {
  1406. $fullorder['ysfs'] == '1881';
  1407. }
  1408. //$fullorder['ysfs'] == '2041';//欧洲全程不包双清、税
  1409. //$fullorder['ysfs'] == '1981';//欧洲速卖通非9610
  1410. //$fullorder['ysfs'] == '2001';//欧洲独立站非9610
  1411. $barcode = $this->dpd->get_data($fullorder);//获取信息
  1412. if($barcode['x'] == 1)//$barcode['a'] == 2 && $Hyd['a'] == 2
  1413. {
  1414. $bctime = date('Ymd',$time);
  1415. $Hwaybill = $barcode['waybill'];//运单号
  1416. if($fullorder['waybill'] != "")
  1417. {
  1418. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1419. }
  1420. else
  1421. {
  1422. $oldwaybill = $fullorder['oldwaybill'];
  1423. }
  1424. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1425. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1426. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1427. {
  1428. $type = 2;
  1429. $text = array('data'=>$fullorder);
  1430. }
  1431. }
  1432. else
  1433. {
  1434. $failed = $barcode['Description'];
  1435. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
  1436. }
  1437. }
  1438. /** 阿里仓联邦不打印运单模式
  1439. else if($fullorder['printcode'] == "FEDEX" || $fullorder['printcode'] == "TOLL" || $fullorder['printcode'] == "ARAMEX")
  1440. {
  1441. sleep(4);//不打印运单 4秒延时
  1442. $lj = $this->ali->get_lj($fullorder['number'],2,'订单修改');
  1443. $barcode = $this->ali->get_data($fullorder);//获取DHL快递信息
  1444. //$Hyd = $this->ali->get_label($fullorder['number'],1);//目前不需要打印标签
  1445. //1:10 X 10标签 2:A4纸 3:10X15标签 默认1
  1446. if($barcode['a'] == 2)//$barcode['a'] == 2 && $Hyd['a'] == 2
  1447. {
  1448. $bctime = date('Ymd',$time);
  1449. $Hwaybill = $barcode['number'];//运单号
  1450. //$this->_pdfurl($Hyd['pdf'],'y-'.$Hwaybill,$bctime);//目前不需要打印标签
  1451. if($fullorder['waybill'] != "")
  1452. {
  1453. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1454. }
  1455. else
  1456. {
  1457. $oldwaybill = $fullorder['oldwaybill'];
  1458. }
  1459. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1460. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1461. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1462. {
  1463. $type = 2;
  1464. $text = array('data'=>$fullorder);
  1465. }
  1466. }
  1467. else
  1468. {
  1469. $failed = $barcode['m'];
  1470. //$failed = isset($barcode['m'])?$barcode['m']:'-(此单已预报,务必先取消再允许打印)';//获取运单号错误提示
  1471. //$failed .= isset($Hyd['m'])?$Hyd['m']:'';//获取标签错误提示
  1472. if($fullorder['print'] == 3)
  1473. {
  1474. $this->$fullorder_name->save(array('libraryconfirm'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
  1475. }
  1476. else
  1477. {
  1478. $this->$fullorder_name->save(array('print'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
  1479. }
  1480. }
  1481. }
  1482. **/
  1483. else if($fullorder['printcode'] == "FEDEX" || $fullorder['printcode'] == "TOLL" || $fullorder['printcode'] == "ARAMEX")
  1484. {
  1485. sleep(13);//不打印运单 4秒延时
  1486. $lj = $this->ali->get_lj($fullorder['number'],2,'订单修改');
  1487. $barcode = $this->ali->get_data($fullorder);//获取快递信息
  1488. $Hyd = $this->ali->get_label($fullorder['number'],1);//目前不需要打印标签
  1489. //1:10 X 10标签 2:A4纸 3:10X15标签 默认1
  1490. if($barcode['a'] == 2 && $Hyd['a'] == 2)
  1491. {
  1492. $bctime = date('Ymd',$time);
  1493. $Hwaybill = $barcode['number'];//运单号
  1494. $this->_pdfurl($Hyd['pdf'],'y-'.$Hwaybill,$bctime);//上传PDF
  1495. if($fullorder['waybill'] != "")
  1496. {
  1497. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1498. }
  1499. else
  1500. {
  1501. $oldwaybill = $fullorder['oldwaybill'];
  1502. }
  1503. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1504. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1505. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1506. {
  1507. $type = 1;
  1508. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
  1509. }
  1510. }
  1511. else
  1512. {
  1513. //$failed = $barcode['m'];
  1514. $failed = isset($barcode['m'])?$barcode['m']:'-(此单已预报,务必先取消再允许打印)';//获取运单号错误提示
  1515. $failed .= isset($Hyd['m'])?$Hyd['m']:'';//获取标签错误提示
  1516. if($fullorder['print'] == 3)
  1517. {
  1518. $this->$fullorder_name->save(array('libraryconfirm'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
  1519. }
  1520. else
  1521. {
  1522. $this->$fullorder_name->save(array('print'=>1,'failed'=>date('Y-m-d H:i:s',time()).$failed),$va[$n]);
  1523. }
  1524. }
  1525. }
  1526. else if($fullorder['printcode'] == "UPS")//接口
  1527. {
  1528. sleep(25);
  1529. $barcode = $this->ups->get_data($fullorder);//获取快递信息
  1530. if($barcode['x'] == 1)
  1531. {
  1532. $bctime = date('Ymd',$time);
  1533. $Hwaybill = $barcode['waybill'];
  1534. $Hyd = $this->_pdfurl($barcode['label'],'y-'.$Hwaybill,$bctime);
  1535. if(isset($barcode['label']) && isset($Hwaybill))
  1536. {
  1537. if($fullorder['waybill'] != "")
  1538. {
  1539. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  1540. }
  1541. else
  1542. {
  1543. $oldwaybill = $fullorder['oldwaybill'];
  1544. }
  1545. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  1546. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1547. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  1548. {
  1549. $type = 1;
  1550. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
  1551. }
  1552. }
  1553. }
  1554. else
  1555. {
  1556. $failed = $barcode['Description'];//错误提示
  1557. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$va[$n]);
  1558. }
  1559. }
  1560. else
  1561. {
  1562. $this->$fullorder_name->save(array('print'=>1,'failed'=>'未找到此快递运单接口'),$va[$n]);
  1563. }
  1564. if($fullorder_name == 'fullordersmt' || $fullorder_name == 'fullorder_smt')
  1565. {
  1566. $text['data']['dplx'] = '速卖通';
  1567. }
  1568. else
  1569. {
  1570. $text['data']['dplx']= '独立站';
  1571. }
  1572. $rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);
  1573. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  1574. }
  1575. else if($fullorder['printtype'] == 2 && $fullorder['library'] != 2)
  1576. {
  1577. sleep(15);
  1578. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  1579. if($this->$fullorder_name->save(array('libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldprinttime'=>$oldprinttime),$va[$n]))
  1580. {
  1581. $type = 2;
  1582. $text = array('data'=>$fullorder);
  1583. }
  1584. if($fullorder_name == 'fullordersmt' || $fullorder_name == 'fullorder_smt')
  1585. {
  1586. $text['data']['dplx']= '速卖通';
  1587. }
  1588. else
  1589. {
  1590. $text['data']['dplx']= '独立站';
  1591. }
  1592. $rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);
  1593. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  1594. }
  1595. else
  1596. {
  1597. if($fullorder_name == 'fullordersmt' || $fullorder_name == 'fullorder_smt')
  1598. {
  1599. $text['data']['dplx']= '速卖通';
  1600. }
  1601. else
  1602. {
  1603. $text['data']['dplx']= '独立站';
  1604. }
  1605. $rows = array('type'=>$type,'n'=>$n-1,'data'=>$v,'text'=>$text);
  1606. echo json_encode(array('msg'=>'该订单已出库,无法打印!','success'=>false));exit;
  1607. }
  1608. }
  1609. }
  1610. public function _outbound()
  1611. {
  1612. $post = $this->input->post(NULL, TRUE);
  1613. if(isset($post['page']))
  1614. {
  1615. $api = $this->input->post('api',true);
  1616. $page = $this->input->post('page',true);
  1617. $perpage = $this->input->post('perpage',true);
  1618. $number = $this->input->post('number',true);
  1619. $waybill = $this->input->post('waybill',true);
  1620. $express = $this->input->post('express',true);
  1621. $type = $this->input->post('type',true);
  1622. $timetk = $this->input->post('timetk',true);
  1623. $timetj = $this->input->post('timetj',true);
  1624. $timetk = strtotime($timetk);
  1625. $timetj = strtotime($timetj);
  1626. $where = "type != 0";
  1627. if(isset($api))
  1628. {
  1629. if($type)
  1630. {
  1631. $where .= " and type = '$type'";
  1632. }
  1633. else
  1634. {
  1635. $uw = '';
  1636. $u = $this->user->get_api($api);
  1637. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  1638. foreach ($u['warehouse'] as $v)
  1639. {
  1640. $uw .= " type = '$v' or";
  1641. }
  1642. $uw = rtrim($uw,'or');
  1643. $uw = " and (".ltrim($uw,' ').")";
  1644. $where .= $uw;
  1645. }
  1646. }
  1647. if($timetk && $timetj)
  1648. {
  1649. $where .= " and time > '$timetk' and time < '$timetj'";
  1650. }
  1651. if($number)
  1652. {
  1653. $where .= " and number = '$number'";
  1654. }
  1655. if($waybill)
  1656. {
  1657. $where .= " and waybill = '$waybill'";
  1658. }
  1659. if($express)
  1660. {
  1661. $where .= " and express = '$express'";
  1662. }
  1663. //数据排序
  1664. $order_str = "id desc";
  1665. if(empty($page))
  1666. {
  1667. $start = 0;
  1668. $perpage = 1;
  1669. }
  1670. else
  1671. {
  1672. $start = ($page - 1)*$perpage;
  1673. }
  1674. //取得信息列表
  1675. $info_list = $this->outbound->find_all($where,'id,type,express,number,waybill,time',$order_str,$start,$perpage);
  1676. //格式化数据
  1677. foreach ($info_list as $key=>$value)
  1678. {
  1679. if($value['waybill'] == '0')
  1680. {
  1681. $info_list[$key]['waybill'] = "无";
  1682. }
  1683. if($value['express'] == '0')
  1684. {
  1685. $info_list[$key]['express'] = "无";
  1686. }
  1687. else
  1688. {
  1689. $express = $this->express->read($value['express']);
  1690. $info_list[$key]['express'] = $express['servicename'];
  1691. }
  1692. $warehouse = $this->warehouse->read($value['type']);
  1693. $info_list[$key]['type'] = $warehouse['title'];
  1694. $info_list[$key]['time'] = '<em class="t">'.date('Y-m-d H:i:s',$value['time']).'</em>';
  1695. }
  1696. $ex = array();
  1697. $ed = $this->outbound->find_all($where,'express');
  1698. foreach ($ed as $key=>$value)
  1699. {
  1700. if(isset($ex[$value['express']]))
  1701. {
  1702. $ex[$value['express']] += 1;
  1703. }
  1704. else
  1705. {
  1706. $ex[$value['express']] = 1;
  1707. }
  1708. }
  1709. $exdata = '';
  1710. foreach ($ex as $k=>$v)
  1711. {
  1712. $e = $this->express->read($k);
  1713. $exdata .= "<li>".$e['servicename'].":".$v."单</li>";
  1714. }
  1715. $datacount = $this->outbound->find_count("gtime = '".date('Ymd',time())."'");
  1716. $total = $this->outbound->find_count($where);
  1717. $pagenum = ceil($total/$perpage);
  1718. $over = $total-($start+$perpage);
  1719. $adm = ($api == '21a6d1cfb3cc66471680bd61ae94e8fa7af75bfb')?1:2;
  1720. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$datacount,'adm'=>$adm,'exdata'=>$exdata);
  1721. echo json_encode($rows);exit;
  1722. }
  1723. }
  1724. public function _excel()
  1725. {
  1726. if(isset($_GET['fexcel']))
  1727. {
  1728. $dowid = $this->input->get('a');
  1729. $wid = "";
  1730. if($dowid != "")
  1731. {
  1732. $id_arr = explode(',',rtrim($dowid,','));
  1733. foreach ($id_arr as $v)
  1734. {
  1735. $wid .= " id = 0 or";
  1736. $wid .= " id = '$v' or";
  1737. }
  1738. $wid = " and".rtrim($wid,'or');
  1739. }
  1740. $id = $this->input->get('id',true);
  1741. $t = $this->input->get('t',true);
  1742. $timetk = $this->input->get('timetk',true);
  1743. $timetj = $this->input->get('timetj',true);
  1744. $shop = $this->input->get('shop',true);
  1745. $source = $this->input->get('source',true);
  1746. $orderinfo = $this->input->get('orderinfo',true);
  1747. $number = $this->input->get('number',true);
  1748. $library = $this->input->get('library',true);
  1749. $waybill = $this->input->get('waybill',true);
  1750. $express = $this->input->get('express',true);
  1751. $type = $this->input->get('type',true);
  1752. $so = $this->input->get('so',true);
  1753. $timetk = strtotime($timetk);
  1754. $timetj = strtotime($timetj);
  1755. $where = "library!=3 and libraryconfirm=2 and mergeid = 0 and print = 3";
  1756. if($timetk && $timetj && $library == 2)
  1757. {
  1758. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  1759. }
  1760. else
  1761. {
  1762. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  1763. }
  1764. if($id)
  1765. {
  1766. if($type)
  1767. {
  1768. $where .= " and type = '$type'";
  1769. }
  1770. else
  1771. {
  1772. $uw = '';
  1773. $u = $this->user->get_api($id);
  1774. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  1775. foreach ($u['warehouse'] as $v)
  1776. {
  1777. $uw .= " type = '$v' or";
  1778. }
  1779. $uw = rtrim($uw,'or');
  1780. $uw = " and (".ltrim($uw,' ').")";
  1781. $where .= $uw;
  1782. }
  1783. }
  1784. else
  1785. {
  1786. echo json_encode(array('msg'=>'导出失败,请更新!','success'=>false));exit;
  1787. }
  1788. if($shop)
  1789. {
  1790. $where .= " and shop = '$shop'";
  1791. }
  1792. if($number)
  1793. {
  1794. $where .= " and number = '$number'";
  1795. }
  1796. if($library)
  1797. {
  1798. $where .= " and library = '$library'";
  1799. }
  1800. if($waybill)
  1801. {
  1802. $where .= " and waybill = '$waybill'";
  1803. }
  1804. if($express)
  1805. {
  1806. $where .= " and express = '$express'";
  1807. }
  1808. if($orderinfo)
  1809. {
  1810. $where .= " and orderinfo = '$orderinfo'";
  1811. }
  1812. if($so)
  1813. {
  1814. $where .= " and shipremarks like '%$so%'";
  1815. }
  1816. //数据排序
  1817. $order_str = ($print != 3)?"id desc":"librarytime desc";
  1818. if(empty($page))
  1819. {
  1820. $start = 0;
  1821. $perpage = 1;
  1822. }
  1823. else
  1824. {
  1825. $start = ($page - 1)*$perpage;
  1826. }
  1827. //取得信息列表
  1828. $info_list = $this->fullorder->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts',$order_str);
  1829. //格式化数据
  1830. foreach ($info_list as $key=>$value)
  1831. {
  1832. $shop = $this->shop->read($value['shop']);
  1833. $info_list[$key]['shop'] = $shop['shopname'];
  1834. if($value['waybill'] == '0')
  1835. {
  1836. $info_list[$key]['waybill'] = "";
  1837. }
  1838. $express = $this->express->read($value['express']);
  1839. $info_list[$key]['express'] = $express['servicename'];
  1840. $warehouse = $this->warehouse->read($value['type']);
  1841. $info_list[$key]['type'] = $warehouse['title'];
  1842. if($value['print'] == 1)
  1843. {
  1844. $info_list[$key]['print'] = '不可打印';
  1845. }
  1846. else if($value['print'] == 2)
  1847. {
  1848. $info_list[$key]['print'] = '未打印';
  1849. }
  1850. else if($value['print'] == 3)
  1851. {
  1852. $info_list[$key]['print'] = '已打印';
  1853. }
  1854. if($value['library'] == 1)
  1855. {
  1856. $info_list[$key]['library'] = '<em class="c">未出库</em>';
  1857. }
  1858. else if($value['library'] == 2)
  1859. {
  1860. $info_list[$key]['library'] = '<em class="c">已出库</em>';
  1861. }
  1862. else if($value['library'] == 3)
  1863. {
  1864. $info_list[$key]['library'] = '<em class="c">已退库</em>';
  1865. }
  1866. if($value['librarytime'] == '0')
  1867. {
  1868. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  1869. }
  1870. else
  1871. {
  1872. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  1873. }
  1874. }
  1875. //取得信息列表
  1876. $info_listsmt = $this->fullordersmt->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks,ts',$order_str);
  1877. //格式化数据
  1878. foreach ($info_listsmt as $key=>$value)
  1879. {
  1880. $shop = $this->shop->read($value['shop']);
  1881. $info_listsmt[$key]['shop'] = $shop['shopname'];
  1882. if($value['waybill'] == '0')
  1883. {
  1884. $info_listsmt[$key]['waybill'] = "";
  1885. }
  1886. $express = $this->express->read($value['express']);
  1887. $info_listsmt[$key]['express'] = $express['servicename'];
  1888. $warehouse = $this->warehouse->read($value['type']);
  1889. $info_listsmt[$key]['type'] = $warehouse['title'];
  1890. if($value['print'] == 1)
  1891. {
  1892. $info_listsmt[$key]['print'] = '不可打印';
  1893. }
  1894. else if($value['print'] == 2)
  1895. {
  1896. $info_listsmt[$key]['print'] = '未打印';
  1897. }
  1898. else if($value['print'] == 3)
  1899. {
  1900. $info_listsmt[$key]['print'] = '已打印';
  1901. }
  1902. if($value['library'] == 1)
  1903. {
  1904. $info_listsmt[$key]['library'] = '<em class="c">未出库</em>';
  1905. }
  1906. else if($value['library'] == 2)
  1907. {
  1908. $info_listsmt[$key]['library'] = '<em class="c">已出库</em>';
  1909. }
  1910. else if($value['library'] == 3)
  1911. {
  1912. $info_listsmt[$key]['library'] = '<em class="c">已退库</em>';
  1913. }
  1914. if($value['librarytime'] == '0')
  1915. {
  1916. $info_listsmt[$key]['librarytime'] = '<em class="t"></em>';
  1917. }
  1918. else
  1919. {
  1920. $info_listsmt[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  1921. }
  1922. }
  1923. //取得信息列表
  1924. $info_list_smt = $this->fullorder_smt->find_all($where.$wid,'shop,type,orderinfo,number,waybill,express,print,library,librarytime,shipremarks',$order_str);
  1925. //格式化数据
  1926. foreach ($info_list_smt as $key=>$value)
  1927. {
  1928. $shop = $this->shop->read($value['shop']);
  1929. $info_list_smt[$key]['shop'] = $shop['shopname'];
  1930. if($value['waybill'] == '0')
  1931. {
  1932. $info_list_smt[$key]['waybill'] = "";
  1933. }
  1934. $express = $this->express->read($value['express']);
  1935. $info_list_smt[$key]['express'] = $express['servicename'];
  1936. $warehouse = $this->warehouse->read($value['type']);
  1937. $info_list_smt[$key]['type'] = $warehouse['title'];
  1938. if($value['print'] == 1)
  1939. {
  1940. $info_list_smt[$key]['print'] = '不可打印';
  1941. }
  1942. else if($value['print'] == 2)
  1943. {
  1944. $info_list_smt[$key]['print'] = '未打印';
  1945. }
  1946. else if($value['print'] == 3)
  1947. {
  1948. $info_list_smt[$key]['print'] = '已打印';
  1949. }
  1950. if($value['library'] == 1)
  1951. {
  1952. $info_list_smt[$key]['library'] = '<em class="c">未出库</em>';
  1953. }
  1954. else if($value['library'] == 2)
  1955. {
  1956. $info_list_smt[$key]['library'] = '<em class="c">已出库</em>';
  1957. }
  1958. else if($value['library'] == 3)
  1959. {
  1960. $info_list_smt[$key]['library'] = '<em class="c">已退库</em>';
  1961. }
  1962. if($value['librarytime'] == '0')
  1963. {
  1964. $info_list_smt[$key]['librarytime'] = '<em class="t"></em>';
  1965. }
  1966. else
  1967. {
  1968. $info_list_smt[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  1969. }
  1970. }
  1971. $title = '订单出库-'.date('Ymd',time());
  1972. $titlename = "<table border=1>".$t."<td>条数</td></table>";
  1973. $tail = "\n";
  1974. $filename = $title.".xls";
  1975. $this->excel->get_fz2(array_merge($info_list,$info_list_smt,$info_listsmt),$titlename,$filename,$tail);
  1976. }
  1977. }
  1978. public function _cpexcel()
  1979. {
  1980. if(isset($_GET['excel']))
  1981. {
  1982. $id = $this->input->get('id',true);
  1983. $timetk = $this->input->get('timetk',true);
  1984. $timetj = $this->input->get('timetj',true);
  1985. $shop = $this->input->get('shop',true);
  1986. $library = $this->input->get('library',true);
  1987. $type = $this->input->get('type',true);
  1988. $number = $this->input->get('number',true);
  1989. $orderinfo = $this->input->get('orderinfo',true);
  1990. $number = $this->input->get('number',true);
  1991. $express = $this->input->get('express',true);
  1992. $timetk = strtotime($timetk);
  1993. $timetj = strtotime($timetj);
  1994. $where = "mergeid = 0";
  1995. if($timetk && $timetj && $library == 2)
  1996. {
  1997. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  1998. }
  1999. else
  2000. {
  2001. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  2002. }
  2003. if($id)
  2004. {
  2005. if($type)
  2006. {
  2007. $where .= " and type = '$type'";
  2008. }
  2009. else
  2010. {
  2011. $uw = '';
  2012. $u = $this->user->get_api($id);
  2013. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  2014. foreach ($u['warehouse'] as $v)
  2015. {
  2016. $uw .= " type = '$v' or";
  2017. }
  2018. $uw = rtrim($uw,'or');
  2019. $uw = " and (".ltrim($uw,' ').")";
  2020. $where .= $uw;
  2021. }
  2022. }
  2023. if($shop)
  2024. {
  2025. $where .= " and shop = '$shop'";
  2026. }
  2027. if($library)
  2028. {
  2029. $where .= " and library = '$library'";
  2030. }
  2031. if($number)
  2032. {
  2033. $where .= " and number = '$number'";
  2034. }
  2035. if($orderinfo)
  2036. {
  2037. $where .= " and orderinfo = '$orderinfo'";
  2038. }
  2039. if($express)
  2040. {
  2041. $where .= " and express = '$express'";
  2042. }
  2043. /* 匹配ID加入 */
  2044. $tc = array();
  2045. $typeclass = $this->typeclass->find_all();
  2046. foreach ($typeclass as $v)
  2047. {
  2048. $tc[$v['id']] = $v['title'];
  2049. }
  2050. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$refundj=0;$cost=0;$lr=0;
  2051. //取得信息列表
  2052. $info_lista = $this->fullordersmt->find_all($where,'fpdata');
  2053. $info_listb = $this->fullorder->find_all($where,'fpdata');
  2054. $info_list = array_merge($info_lista,$info_listb);
  2055. //格式化数据
  2056. $i = 0;$cpexcel = array();
  2057. foreach ($info_list as $key=>$value)
  2058. {
  2059. if(stripos($value['fpdata'],';') !== false)
  2060. {
  2061. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  2062. foreach ($fpdata as $ke=>$va)
  2063. {
  2064. $title = '';
  2065. $fg = explode('|',$va);
  2066. $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
  2067. $cp = explode('-',rtrim($fg[0],'-'));
  2068. $dj = $tc[$cp[2]];
  2069. $ys = $tc[$cp[3]];
  2070. unset($cp[0],$cp[1],$cp[2],$cp[3]);
  2071. foreach ($cp as $v)
  2072. {
  2073. $title .= $tc[$v].' ';
  2074. }
  2075. $cpexcel[$ke] = array($fg[5],$dj,$ys,$title,$fg[2]);//内容,尺寸,等级,颜色,数量
  2076. }
  2077. }
  2078. $i++;
  2079. }
  2080. $title = "统计信息";
  2081. $titlename = "<table border=1>
  2082. <tr>
  2083. <td>尺寸</td>
  2084. <td>等级</td>
  2085. <td>颜色</td>
  2086. <td>花型</td>
  2087. <td>数量</td>
  2088. </tr>
  2089. </table>";
  2090. $filename = $title.".xls";
  2091. $tail = "\n";
  2092. $this->excel->get_fz2($cpexcel,$titlename,$filename,$tail);
  2093. }
  2094. }
  2095. public function _exceldy()
  2096. {
  2097. if(isset($_GET['fexcel']))
  2098. {
  2099. $dowid = $this->input->get('a');
  2100. $wid = "";
  2101. if($dowid != "")
  2102. {
  2103. $id_arr = explode(',',rtrim($dowid,','));
  2104. foreach ($id_arr as $v)
  2105. {
  2106. $wid .= " id = 0 or";
  2107. $wid .= " id = '$v' or";
  2108. }
  2109. $wid = " and".rtrim($wid,'or');
  2110. }
  2111. $id = $this->input->get('id',true);
  2112. $t = $this->input->get('t',true);
  2113. $print = $this->input->get('print',true);
  2114. $timetk = $this->input->get('timetk',true);
  2115. $timetj = $this->input->get('timetj',true);
  2116. $shop = $this->input->get('shop',true);
  2117. $source = $this->input->get('source',true);
  2118. $orderinfo = $this->input->get('orderinfo',true);
  2119. $number = $this->input->get('number',true);
  2120. $waybill = $this->input->get('waybill',true);
  2121. $express = $this->input->get('express',true);
  2122. $type = $this->input->get('type',true);
  2123. $so = $this->input->get('so',true);
  2124. $timetk = strtotime($timetk);
  2125. $timetj = strtotime($timetj);
  2126. $where = "mergeid = 0";
  2127. if($print == 3)
  2128. {
  2129. $where .= " and printtime > '$timetk' and printtime < '$timetj' and print = 3";
  2130. }
  2131. else
  2132. {
  2133. $where .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1 and state = 207";
  2134. }
  2135. if($id)
  2136. {
  2137. if($type)
  2138. {
  2139. $where .= " and type = '$type'";
  2140. }
  2141. else
  2142. {
  2143. $uw = '';
  2144. $u = $this->user->get_api($id);
  2145. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  2146. foreach ($u['warehouse'] as $v)
  2147. {
  2148. $uw .= " type = '$v' or";
  2149. }
  2150. $uw = rtrim($uw,'or');
  2151. $uw = " and (".ltrim($uw,' ').")";
  2152. $where .= $uw;
  2153. }
  2154. }
  2155. else
  2156. {
  2157. echo json_encode(array('msg'=>'导出失败,请更新!','success'=>false));exit;
  2158. }
  2159. if($print)
  2160. {
  2161. $where .= " and print = '$print'";
  2162. }
  2163. if($shop)
  2164. {
  2165. $where .= " and shop = '$shop'";
  2166. }
  2167. if($number)
  2168. {
  2169. $where .= " and number = '$number'";
  2170. }
  2171. if($waybill)
  2172. {
  2173. $where .= " and waybill = '$waybill'";
  2174. }
  2175. if($express)
  2176. {
  2177. $where .= " and express = '$express'";
  2178. }
  2179. if($orderinfo)
  2180. {
  2181. $where .= " and orderinfo = '$orderinfo'";
  2182. }
  2183. if($so)
  2184. {
  2185. $where .= " and shipremarks like '%$so%'";
  2186. }
  2187. //数据排序
  2188. $order_str = ($print != 3)?"id desc":"printtime desc";
  2189. if(empty($page))
  2190. {
  2191. $start = 0;
  2192. $perpage = 1;
  2193. }
  2194. else
  2195. {
  2196. $start = ($page - 1)*$perpage;
  2197. }
  2198. //取得信息列表
  2199. $info_list = $this->fullorder->find_all($where.$wid,'type,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str);
  2200. //格式化数据
  2201. foreach ($info_list as $key=>$value)
  2202. {
  2203. $shop = $this->shop->read($value['shop']);
  2204. $info_list[$key]['shop'] = $shop['shopname'];
  2205. if($value['waybill'] == '0')
  2206. {
  2207. $info_list[$key]['waybill'] = "";
  2208. }
  2209. $express = $this->express->read($value['express']);
  2210. $info_list[$key]['express'] = $express['servicename'];
  2211. $warehouse = $this->warehouse->read($value['type']);
  2212. $info_list[$key]['type'] = $warehouse['title'];
  2213. if($value['print'] == 1)
  2214. {
  2215. $info_list[$key]['print'] = '不可打印';
  2216. }
  2217. else if($value['print'] == 2)
  2218. {
  2219. $info_list[$key]['print'] = '未打印';
  2220. }
  2221. else if($value['print'] == 3)
  2222. {
  2223. $info_list[$key]['print'] = '已打印';
  2224. }
  2225. if($value['printtype'] == 1)
  2226. {
  2227. $info_list[$key]['printtype'] = '运单';
  2228. }
  2229. else if($value['printtype'] == 2)
  2230. {
  2231. $info_list[$key]['printtype'] = '发货单';
  2232. }
  2233. if($value['printtime'] == '0')
  2234. {
  2235. $info_list[$key]['printtime'] = '<em class="t"></em>';
  2236. }
  2237. else
  2238. {
  2239. $info_list[$key]['printtime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['printtime']).'</em>';
  2240. }
  2241. }
  2242. //取得信息列表
  2243. $info_listsmt = $this->fullordersmt->find_all($where.$wid,'type,shop,orderinfo,number,express,waybill,print,printtype,printnumber,printtime,shipremarks',$order_str);
  2244. //格式化数据
  2245. foreach ($info_listsmt as $key=>$value)
  2246. {
  2247. $shop = $this->shop->read($value['shop']);
  2248. $info_listsmt[$key]['shop'] = $shop['shopname'];
  2249. if($value['waybill'] == '0')
  2250. {
  2251. $info_listsmt[$key]['waybill'] = "";
  2252. }
  2253. $express = $this->express->read($value['express']);
  2254. $info_listsmt[$key]['express'] = $express['servicename'];
  2255. $warehouse = $this->warehouse->read($value['type']);
  2256. $info_listsmt[$key]['type'] = $warehouse['title'];
  2257. if($value['print'] == 1)
  2258. {
  2259. $info_listsmt[$key]['print'] = '不可打印';
  2260. }
  2261. else if($value['print'] == 2)
  2262. {
  2263. $info_listsmt[$key]['print'] = '未打印';
  2264. }
  2265. else if($value['print'] == 3)
  2266. {
  2267. $info_listsmt[$key]['print'] = '已打印';
  2268. }
  2269. if($value['printtype'] == 1)
  2270. {
  2271. $info_listsmt[$key]['printtype'] = '运单';
  2272. }
  2273. else if($value['printtype'] == 2)
  2274. {
  2275. $info_listsmt[$key]['printtype'] = '发货单';
  2276. }
  2277. if($value['printtime'] == '0')
  2278. {
  2279. $info_listsmt[$key]['printtime'] = '<em class="t"></em>';
  2280. }
  2281. else
  2282. {
  2283. $info_listsmt[$key]['printtime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['printtime']).'</em>';
  2284. }
  2285. }
  2286. $title = '订单打印-'.date('Ymd',time());
  2287. $titlename = "<table border=1><td>仓库</td>".$t."</table>";
  2288. $tail = "\n";
  2289. $filename = $title.".xls";
  2290. $this->excel->get_fz2(array_merge($info_list,$info_listsmt),$titlename,$filename,$tail);
  2291. }
  2292. }
  2293. public function _fedexhz()
  2294. {
  2295. $post = $this->input->post(NULL, TRUE);
  2296. if(isset($post['id']))
  2297. {
  2298. $id = $this->input->post('id',true);
  2299. $fullorder_name = $this->input->post('name',true);
  2300. $express = $this->input->post('express',true);
  2301. $express = $this->express->read($express);
  2302. $fullorder = $this->$fullorder_name->read($id);
  2303. if($fullorder['type'] == '2')
  2304. {
  2305. $fullorder['type'] = 1;
  2306. }
  2307. $time = time();
  2308. $fullorder = $this->_text($fullorder);//获取所需信息
  2309. $oldprinttime = ($fullorder['printtime'] > 0)?$fullorder['oldprinttime'].$fullorder['printtime'].'-':'';
  2310. $fullorder['printtime'] = date('m-d H:i',$time);//打印用时间、发货单用,不能删
  2311. $time = time();
  2312. if($express['printcode'] == "FEDEXGF")
  2313. {
  2314. $barcode = $this->fedex->get_data($fullorder);//获取联邦快递信息
  2315. if($barcode['x'] == 1)
  2316. {
  2317. $bctime = date('Ymd',$time);
  2318. $Hwaybill = $barcode['waybill'];
  2319. $Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
  2320. $Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
  2321. if(isset($barcode['label']) && isset($Hwaybill))
  2322. {
  2323. if($fullorder['waybill'] != "")
  2324. {
  2325. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  2326. }
  2327. else
  2328. {
  2329. $oldwaybill = $fullorder['oldwaybill'];
  2330. }
  2331. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  2332. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  2333. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$fullorder['id']))
  2334. {
  2335. $warehouse = $this->warehouse->read($fullorder['type']);
  2336. echo json_encode(array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','printer3'=>$warehouse['printer3'],'printer4'=>$warehouse['printer4'],'success'=>true));exit;
  2337. }
  2338. else
  2339. {
  2340. echo json_encode(array('msg'=>'打印错误,请联系店员','cw'=>'写入数据库错误','success'=>false));exit;
  2341. }
  2342. }
  2343. }
  2344. else
  2345. {
  2346. echo json_encode(array('msg'=>'打印错误,请联系店员','cw'=>$barcode['Description'],'success'=>false));exit;
  2347. }
  2348. }
  2349. else if($express['printcode'] == "UPSXXXXXXXXX")//接口UPS暂时不打
  2350. {
  2351. $barcode = $this->ups->get_data($fullorder);//获取快递信息
  2352. if($barcode['x'] == 1)
  2353. {
  2354. $bctime = date('Ymd',$time);
  2355. $Hwaybill = $barcode['waybill'];
  2356. $Hyd = $this->_pdfurl($barcode['label'],'y-'.$Hwaybill,$bctime);
  2357. if(isset($barcode['label']) && isset($Hwaybill))
  2358. {
  2359. if($fullorder['waybill'] != "")
  2360. {
  2361. $oldwaybill = $fullorder['oldwaybill'].'-'.date('Ymd',$time).'/'.$fullorder['waybill'];
  2362. }
  2363. else
  2364. {
  2365. $oldwaybill = $fullorder['oldwaybill'];
  2366. }
  2367. $oldwaybill .= '-'.$bctime.'/'.$Hwaybill;
  2368. $fullorder['printnumber'] = $fullorder['printnumber'] +1;//不能删
  2369. if($this->$fullorder_name->save(array('waybill'=>$Hwaybill,'libraryconfirm'=>2,'librarynot'=>'','printtime'=>$time,'printnumber'=>$fullorder['printnumber'],'print'=>3,'oldwaybill'=>$oldwaybill,'oldprinttime'=>$oldprinttime),$va[$n]))
  2370. {
  2371. $type = 1;
  2372. $text = array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf','data'=>$fullorder,'id'=>$fullorder['id'],'pt'=>$fullorder_name);
  2373. }
  2374. }
  2375. }
  2376. else
  2377. {
  2378. echo json_encode(array('msg'=>'打印错误,请联系店员','cw'=>$barcode['Description'],'success'=>false));exit;
  2379. }
  2380. }
  2381. else
  2382. {
  2383. echo json_encode(array('msg'=>'打印错误,请联系店员','success'=>false));exit;
  2384. }
  2385. }
  2386. }
  2387. //扫描发货单出运单开始
  2388. public function _number()
  2389. {
  2390. $post = $this->input->post(NULL, TRUE);
  2391. if(isset($post['order']))
  2392. {
  2393. $order = $this->input->post('order',true);
  2394. $fullorder_name = 'fullorder';
  2395. $y = $this->fullorder->get_number($order);
  2396. if(!$y)
  2397. {
  2398. $fullorder_name = 'fullordersmt';
  2399. $y = $this->fullordersmt->get_number($order);
  2400. if(!$y)
  2401. {
  2402. echo json_encode(array('msg'=>'无此发货单数据!','success'=>false));exit;
  2403. }
  2404. }
  2405. if($y['express'] != '24')
  2406. {
  2407. echo json_encode(array('msg'=>'物流方式不正确!','success'=>false));exit;
  2408. }
  2409. $data = $this->get_fedex_hz_number($y,$fullorder_name);
  2410. $warehouse = $this->warehouse->read($y['type']);
  2411. if(isset($data['yd']))
  2412. {
  2413. echo json_encode(array('numberyd'=>$data['yd'],'printer1'=>$warehouse['printer1'],'success'=>true));exit;
  2414. }
  2415. else
  2416. {
  2417. echo json_encode(array('msg'=>$data,'cw'=>$data,'success'=>false));exit;
  2418. }
  2419. }
  2420. }
  2421. public function get_fedex_hz_number($fullorder,$fullorder_name)
  2422. {
  2423. $time = time();
  2424. $fullorder = $this->_text($fullorder);//获取所需信息
  2425. $oldprinttime = ($fullorder['printtime'] > 0)?$fullorder['oldprinttime'].$fullorder['printtime'].'-':'';
  2426. $fullorder['printtime'] = date('m-d H:i',$time);//打印用时间、发货单用,不能删
  2427. $time = time();
  2428. $barcode = $this->fedex->get_data($fullorder);//获取联邦快递信息
  2429. if($barcode['x'] == 1)
  2430. {
  2431. $bctime = date('Ymd',$time);
  2432. $Hwaybill = $barcode['waybill'];
  2433. $Hyd = $this->_pdf($barcode['label'],'y-'.$Hwaybill,$bctime);
  2434. $Hfp = $this->_pdf($barcode['invoice'],'f-'.$Hwaybill,$bctime);//开通ETD模式,保留PDF,不需要打印
  2435. if(isset($barcode['label']) && isset($Hwaybill))
  2436. {
  2437. $oldwaybill = $fullorder['oldwaybill'].'-'.$bctime.'/'.$Hwaybill;
  2438. if($this->$fullorder_name->save(array('print'=>3,'waybill'=>$Hwaybill,'oldwaybill'=>$oldwaybill),$fullorder['id']))
  2439. {
  2440. return array('yd'=>'data/pdf/'.$bctime.'/y-'.$Hwaybill.'.pdf');
  2441. }
  2442. }
  2443. }
  2444. else
  2445. {
  2446. $failed = $barcode['Description'];//错误提示
  2447. $this->$fullorder_name->save(array('print'=>1,'failed'=>$failed),$fullorder['id']);
  2448. return '订单存在错误,已移交店员处理中';
  2449. }
  2450. }
  2451. //扫描发货单出运单结束
  2452. public function _fhd($arg_array)
  2453. {
  2454. if(isset($arg_array[1]))
  2455. {
  2456. $fu = ($arg_array[0] == 'dlz')?'fullorder':'fullordersmt';
  2457. $a = $this->$fu->find_all("waybill = '$arg_array[1]'");
  2458. $fullorder = $this->$fu->read($a[0]['id']);
  2459. $fullorder = $this->_text($fullorder);//获取所需信息
  2460. $this->data['data'] = $fullorder;
  2461. $this->data['fu'] = $fu;
  2462. $this->_Template('apt_fhd',$this->data);
  2463. }
  2464. }
  2465. public function _fedex($arg_array)
  2466. {
  2467. if(isset($arg_array[0]))
  2468. {
  2469. $this->data['data'] = array($arg_array[0],$arg_array[1]);
  2470. $this->_Template('apt_fedex',$this->data);
  2471. }
  2472. }
  2473. public function _fhdusa($arg_array)
  2474. {
  2475. if(isset($arg_array[0]))
  2476. {
  2477. $fullorder_name = $arg_array[1];
  2478. $fullorder = $this->$fullorder_name->read($arg_array[0]);
  2479. $fullorder = $this->_text($fullorder);//获取所需信息
  2480. $fullorder['printtime'] = date('Y-m-d H:i:s',$fullorder['printtime']);
  2481. $this->data['data'] = $fullorder;
  2482. $this->_Template('apt_fhdusa',$this->data);
  2483. }
  2484. }
  2485. public function _text($fullorder)
  2486. {
  2487. /** 发票地址信息暂时无用
  2488. $fullorder['baddress'] = explode(',',$fullorder['baddress']);
  2489. $fullorder['baddress'] = array_reverse($fullorder['baddress']);
  2490. $fullorder['baddress'][1] = $country['ename'];
  2491. **/
  2492. //获取所用相关信息
  2493. $warehouse = $this->warehouse->read($fullorder['type']);
  2494. $country = $this->country->read($fullorder['country']);//订单国家信息
  2495. $fcountry = $this->country->read($warehouse['country']);//仓库国家信息
  2496. $warehouse['country'] = $fcountry['ename'];//仓库国家名
  2497. $warehouse['lb'] = $fcountry['lb'];//仓库国家编码
  2498. $fullorder['warehouse'] = $warehouse;//仓库数据加入订单
  2499. $fullorder['lb'] = $country['lb'];//订单国家编码加入
  2500. $fullorder['country'] = $country['ename'];//订单国家名
  2501. $fullorder['zhou'] = $country['continent'];//所属州
  2502. $express = $this->express->read($fullorder['express']);
  2503. $fullorder['express'] = $express['servicename'];
  2504. $fullorder['account'] = $express['account'];
  2505. $fullorder['printcode'] = $express['printcode'];
  2506. $fullorder['time'] = date('Y-m-d',time());
  2507. $fullorder['times'] = date('Y-m-d H:i',time());
  2508. $fullorder['sbbm']= ($fullorder['sbpm'] == 'Hair Sample') ? 67042000 : 67041100;
  2509. $fullorder['address'] = str_replace(array('&'),array('&#38;'),$fullorder['address']);
  2510. $fullorder['address2'] = str_replace(array('&'),array('&#38;'),$fullorder['address2']);
  2511. $shop = $this->shop->read($fullorder['shop']);
  2512. $fullorder['shop'] = $shop['shopname'];
  2513. return $fullorder;
  2514. }
  2515. public function _select()
  2516. {
  2517. $post = $this->input->post(NULL, TRUE);
  2518. if(isset($post['warehouse']))
  2519. {
  2520. $warehouse = $this->input->post('warehouse',true);
  2521. $user = $this->user->get_api($warehouse);
  2522. //店铺
  2523. $spid = '';
  2524. $user['shop'] = explode('|',trim($user['shop'],'|'));
  2525. foreach ($user['shop'] as $v)
  2526. {
  2527. $spid .= " id = '$v' or";
  2528. }
  2529. $spid = rtrim($spid,'or');
  2530. $spid = ltrim($spid,' ');
  2531. $shop = $this->shop->find_all($spid);
  2532. //花型
  2533. $lowe = $this->typeclass->find_all('classid = 15 and id != 105 and id != 107 and id != 108 and id != 112 and id != 114 and id != 115 and id != 116 and id != 117 and id != 118 and id != 119 and id != 120 and id != 121 and id != 122 and id != 123 and id != 124 and id != 125 and id != 292 and id != 63 and id != 289 and id != 290 and id != 181 and id != 273 and id != 148 and id != 38 and id != 291 and id != 55 and id != 271 and id != 285 and id != 186 and id != 187 and id != 188 and id != 189');
  2534. //仓库
  2535. $warehouse = array();
  2536. $user['warehouse'] = explode('|',trim($user['warehouse'],'|'));
  2537. $user['warehousetext'] = explode('|',trim($user['warehousetext'],'|'));
  2538. for($i=0;$i<count($user['warehouse']);$i++)
  2539. {
  2540. $warehouse[] = array('id'=>$user['warehouse'][$i],'title'=>$user['warehousetext'][$i]);
  2541. }
  2542. $type = $warehouse;
  2543. //快递
  2544. $express = $this->express->find_all('1=1','*','idsort desc');
  2545. echo json_encode(array('shop'=>$shop,'lowe'=>$lowe,'type'=>$warehouse,'express'=>$express,'success'=>true));exit;
  2546. }
  2547. }
  2548. public function _shop()
  2549. {
  2550. $post = $this->input->post(NULL, TRUE);
  2551. if(isset($post['shop']))
  2552. {
  2553. $shop = $this->shop->find_all();
  2554. echo json_encode(array('msg'=>$shop));exit;
  2555. }
  2556. }
  2557. public function _lowe()
  2558. {
  2559. $post = $this->input->post(NULL, TRUE);
  2560. if(isset($post['lowe']))
  2561. {
  2562. $lowe = $this->typeclass->find_all('classid = 15 and id != 105 and id != 107 and id != 108 and id != 112 and id != 114 and id != 115 and id != 116 and id != 117 and id != 118 and id != 119 and id != 120 and id != 121 and id != 122 and id != 123 and id != 124 and id != 125 and id != 292 and id != 63 and id != 289 and id != 290 and id != 181 and id != 273 and id != 148 and id != 38 and id != 291 and id != 55 and id != 271 and id != 285 and id != 186 and id != 187 and id != 188 and id != 189');
  2563. echo json_encode(array('msg'=>$lowe));exit;
  2564. }
  2565. }
  2566. public function _warehouse()
  2567. {
  2568. $post = $this->input->post(NULL, TRUE);
  2569. if(isset($post['warehouse']))
  2570. {
  2571. $warehouse = $this->input->post('warehouse',true);
  2572. $user = $this->user->get_api($warehouse);
  2573. $warehouse = array();
  2574. $user['warehouse'] = explode('|',trim($user['warehouse'],'|'));
  2575. $user['warehousetext'] = explode('|',trim($user['warehousetext'],'|'));
  2576. for($i=0;$i<count($user['warehouse']);$i++)
  2577. {
  2578. $warehouse[] = array('id'=>$user['warehouse'][$i],'title'=>$user['warehousetext'][$i]);
  2579. }
  2580. echo json_encode(array('msg'=>$warehouse));exit;
  2581. }
  2582. }
  2583. public function _express()
  2584. {
  2585. $post = $this->input->post(NULL, TRUE);
  2586. if(isset($post['express']))
  2587. {
  2588. $express = $this->express->find_all('1=1','*','idsort desc');
  2589. echo json_encode(array('msg'=>$express));exit;
  2590. }
  2591. }
  2592. public function _pdf($pdf,$title,$bctime)
  2593. {
  2594. $pdf_path = './data/pdf/'.$bctime.'/';
  2595. $file_base64 = $pdf;
  2596. $file_base64 = preg_replace('/data:.*;base64,/i', '', $file_base64);
  2597. $file_base64 = base64_decode($file_base64);
  2598. if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
  2599. file_put_contents($pdf_path.$title.'.pdf',$file_base64);
  2600. return $bctime;
  2601. }
  2602. public function _pdfurl($pdf,$title,$bctime)
  2603. {
  2604. $pdf_path = './data/pdf/'.$bctime.'/';
  2605. $pdf = fopen($pdf,"r");
  2606. if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
  2607. file_put_contents($pdf_path.$title.'.pdf',$pdf);
  2608. return $bctime;
  2609. }
  2610. public function _img($pdf,$title,$bctime)
  2611. {
  2612. $pdf_path = './data/img/'.$bctime.'/';
  2613. $file_base64 = $pdf;
  2614. $file_base64 = preg_replace('/data:.*;base64,/i', '', $file_base64);
  2615. $file_base64 = base64_decode($file_base64);
  2616. if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
  2617. file_put_contents($pdf_path.$title.'.png',$file_base64);
  2618. return $bctime;
  2619. }
  2620. }