Apt.php 88 KB

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