Fullorderexcel.php 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Fullorderexcel extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_fullorder','fullorder');
  7. $this->load->_model('Model_fullordertt','fullordertt');
  8. $this->load->_model('Model_fullorderxw','fullorderxw');
  9. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  10. $this->load->_model('Model_fullordersmt','fullordersmt');
  11. $this->load->_model('Model_fullorderamz','fullorderamz');
  12. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  13. $this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid');
  14. $this->load->_model('Model_shop','shop');
  15. $this->load->_model('Model_country','country');
  16. $this->load->_model('Model_warehouse','warehouse');
  17. $this->load->_model('Model_excel','excel');
  18. $this->load->_model('Model_notice','notice');
  19. $this->load->_model('Model_express','express');
  20. $this->load->_model('Model_api','api');
  21. $this->load->_model('Model_apismt','apismt');
  22. $this->load->_model('Model_usps','usps');
  23. $this->load->_model('Model_typeclass','typeclass');
  24. $this->load->_model('Model_systemwigsout','systemwigsout');
  25. $this->load->_model('Model_setting','setting');
  26. $this->load->_model('Model_customer','customer');
  27. $this->load->_model('Model_customersmt','customersmt');
  28. $this->load->_model('Model_orderurl','orderurl');
  29. $this->load->_model('Model_whlabel','whlabel');
  30. $this->load->_model('Model_whlabel_bh','whlabel_bh');
  31. $this->load->_model('Model_apiyy','apiyy');
  32. $this->load->_model('Model_classid','classid');
  33. $this->load->_model('Model_systemtransfer','systemtransfer');
  34. $this->load->_model('Model_transfer','transfer');
  35. $this->load->_model('Model_classid','classid');
  36. $this->load->_model('Model_whlabel_type','whlabel_type');
  37. $this->load->_model('Model_power','power');
  38. $this->load->_model('Model_productdescribe','productdescribe');
  39. $this->load->_model('Model_shopsku','shopsku');
  40. $this->load->_model('Model_is','is');
  41. $this->load->_model('Model_whlabel_qh','whlabel_qh');
  42. $this->load->_model('Model_emaildata','emaildata');
  43. $this->load->_model('Model_afspaypal','afspaypal');
  44. $this->load->_model('Model_producttitle','producttitle');
  45. $this->load->_model('Model_message','message');
  46. $this->load->_model("Model_logic_ding","logic_ding");
  47. }
  48. //定义方法的调用规则 获取URI第二段值
  49. public function _remap($arg,$arg_array)
  50. {
  51. if($arg == 'excel')
  52. {
  53. $this->_excel();
  54. }
  55. else if($arg == 'excelhz')
  56. {
  57. $this->_excelhz();
  58. }
  59. else if($arg == 'add')
  60. {
  61. $this->_add();
  62. }
  63. else if($arg == 'edit')
  64. {
  65. $this->_edit($arg_array);
  66. }
  67. else if($arg == 'copy'){
  68. $this->_copy($arg_array);
  69. }
  70. else if($arg == 'del')
  71. {
  72. $this->_del();
  73. }
  74. else if($arg == 'rows')
  75. {
  76. $this->_rows();
  77. }
  78. else if($arg == 'waybill')
  79. {
  80. $this->_waybill($arg_array);
  81. }
  82. else if($arg == 'order')
  83. {
  84. $this->_order($arg_array);
  85. }
  86. else if($arg == 'xxpl')//线下批量导入
  87. {
  88. $this->_xxpl();
  89. }
  90. else if($arg == 'skuzh')//sku转中文
  91. {
  92. $this->_skuzh();
  93. }
  94. else if($arg == 'cs')
  95. {
  96. $this->_cs();
  97. }
  98. else if($arg == 'scwd')
  99. {
  100. $this->_scwd();
  101. }
  102. else if($arg == 'jmexcel')
  103. {
  104. $this->_jmexcel();
  105. }
  106. else if($arg == 'classid')
  107. {
  108. $this->_classid();
  109. }
  110. else if($arg == 'classidadd')
  111. {
  112. $this->_classidadd();
  113. }
  114. else if($arg == 'classidedit')
  115. {
  116. $this->_classidedit($arg_array);
  117. }
  118. else
  119. {
  120. $this->_index();
  121. }
  122. }
  123. //管理
  124. public function _index()
  125. {
  126. $post = $this->input->post(NULL, TRUE);
  127. if(isset($post['page']))
  128. {
  129. $page = $this->input->post('page',true);
  130. $perpage = $this->input->post('perpage',true);
  131. $type = $this->input->post('type',true);
  132. $where = "1=1 ";
  133. //数据排序
  134. $order_str = "id asc";
  135. if(empty($page))
  136. {
  137. $start = 0;
  138. $perpage = 1;
  139. }
  140. else
  141. {
  142. $start = ($page - 1)*$perpage;
  143. }
  144. if($type)
  145. {
  146. $where .= " and type = '$type'";
  147. }
  148. //取得信息列表
  149. $info_list = $this->fullorderexcel->find_all($where,'id,type,title',$order_str,$start,$perpage);
  150. foreach ($info_list as $k=>$v)
  151. {
  152. $classid = $this->fullorderexcelclassid->read($v['type']);
  153. $info_list[$k]['type'] = $classid['title'];
  154. $info_list[$k]['action'] = "<h9 class='window' data-h='/fullorderexcel/copy/".$v['id']."' style='color:#000'><span>复制表格</span></h9>";
  155. }
  156. $total = $this->fullorderexcel->find_count($where);
  157. $pagenum = ceil($total/$perpage);
  158. $over = $total-($start+$perpage);
  159. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  160. echo json_encode($rows);exit;
  161. }
  162. $classid = $this->fullorderexcelclassid->find_all();
  163. $this->data['classid'] = $classid;
  164. $this->_Template('fullorderexcel',$this->data);
  165. }
  166. //添加
  167. public function _add()
  168. {
  169. $post = $this->input->post(NULL, TRUE);
  170. if(isset($post['title']))
  171. {
  172. $post['title'] = $this->input->post('title',true);
  173. $post['type'] = $this->input->post('type',true);
  174. $post['content'] = $this->input->post('content',true);
  175. $post['contentzh'] = $this->input->post('contentzh',true);
  176. $addid = $this->fullorderexcel->insert($post);
  177. if($addid)
  178. {
  179. $adminid = $this->power->read(1);
  180. $this->power->save(array("excelid"=>$adminid['excelid'].$addid.'|',"exceltext"=>$adminid['exceltext'].$post['title'].'|'),$adminid['id']);
  181. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  182. }
  183. else
  184. {
  185. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  186. }
  187. }
  188. $classid = $this->fullorderexcelclassid->find_all();
  189. $this->data['classid'] = $classid;
  190. $this->_Template('fullorderexcel_add',$this->data);
  191. }
  192. //修改
  193. public function _edit($arg_array)
  194. {
  195. $post = $this->input->post(NULL, TRUE);
  196. if(isset($post['id']))
  197. {
  198. $id = $this->input->post('id',true);
  199. $post['title'] = $this->input->post('title',true);
  200. $post['type'] = $this->input->post('type',true);
  201. $post['content'] = $this->input->post('content',true);
  202. $post['contentzh'] = $this->input->post('contentzh',true);
  203. if($this->fullorderexcel->save($post,$id))
  204. {
  205. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  206. }
  207. else
  208. {
  209. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  210. }
  211. }
  212. $arg_array = $arg_array[0];
  213. $fullorderexcel = $this->fullorderexcel->read($arg_array);
  214. $this->data['fullorderexcel'] = $fullorderexcel;
  215. $classid = $this->fullorderexcelclassid->find_all();
  216. $this->data['classid'] = $classid;
  217. $this->_Template('fullorderexcel_edit',$this->data);
  218. }
  219. public function _copy($arg_array)
  220. {
  221. $post = $this->input->post(NULL, TRUE);
  222. if(isset($post['id']))
  223. {
  224. $post['title'] = $this->input->post('title',true);
  225. $post['type'] = $this->input->post('type',true);
  226. $post['content'] = $this->input->post('content',true);
  227. $post['contentzh'] = $this->input->post('contentzh',true);
  228. unset($post['id']);
  229. $addid =$this->fullorderexcel->insert($post);
  230. if($addid)
  231. {
  232. $adminid = $this->power->read(1);
  233. $this->power->save(array("excelid"=>$adminid['excelid'].$addid.'|',"exceltext"=>$adminid['exceltext'].$post['title'].'|'),$adminid['id']);
  234. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  235. }
  236. else
  237. {
  238. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  239. }
  240. }
  241. $arg_array = $arg_array[0];
  242. $fullorderexcel = $this->fullorderexcel->read($arg_array);
  243. $this->data['fullorderexcel'] = $fullorderexcel;
  244. $classid = $this->fullorderexcelclassid->find_all();
  245. $this->data['classid'] = $classid;
  246. $this->_Template('fullorderexcel_copy',$this->data);
  247. }
  248. //删除
  249. public function _del()
  250. {
  251. $post = $this->input->post(NULL, TRUE);
  252. if(isset($post['s']))
  253. {
  254. $id_arr = $this->input->post('s');
  255. $id_arr = explode(',',$id_arr);
  256. if(!$id_arr)
  257. {
  258. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  259. }
  260. //循环删除记录
  261. foreach ($id_arr as $v)
  262. {
  263. $this->fullorderexcel->remove($v);
  264. }
  265. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  266. }
  267. }
  268. //获取数据
  269. public function _rows()
  270. {
  271. $post = $this->input->post(NULL, TRUE);
  272. if(isset($post['id']))
  273. {
  274. $id = $this->input->post('id',true);
  275. $fullorderexcel = $this->fullorderexcel->read($id);
  276. $content = explode('|',rtrim($fullorderexcel['content'],'|'));
  277. $contentzh = explode('|',rtrim($fullorderexcel['contentzh'],'|'));
  278. $data = array();
  279. for($i=0;$i<count($content);$i++)
  280. {
  281. $a = explode('-',$content[$i]);
  282. $b = explode('-',$contentzh[$i]);
  283. $data[] = array(0=>$a[1],1=>$b[1]);
  284. }
  285. echo json_encode(array('rows'=>($data),'success'=>true));
  286. }
  287. }
  288. //导出订单excel
  289. public function _excel()
  290. {
  291. $fgshop = "";$sid = "";$excelshop="";
  292. if(isset($_SESSION['api']))
  293. {
  294. $user = $this->user->get_api($_SESSION['api']);
  295. $usp = $user;
  296. $usersp = explode('|',trim($user['shop'],'|'));
  297. foreach ($usersp as $value)
  298. {
  299. $fgshop .= " shop = ".$value." or";
  300. $sid .= " id = ".$value." or";
  301. }
  302. $userexcel = explode('|',trim($user['excelshop'],'|'));
  303. if($user['excelshop'] == '')
  304. {
  305. echo "没有下载权限";exit;
  306. }
  307. foreach ($userexcel as $value)
  308. {
  309. $excelshop .= " shop = ".$value." or";
  310. }
  311. if($excelshop != "")
  312. {
  313. $excelshop = "(".rtrim($excelshop,'or').")";
  314. }
  315. }
  316. if(isset($_GET['fexcel']))
  317. {
  318. $typeclass = array();
  319. $tclass = $this->typeclass->find_all();
  320. foreach ($tclass as $v)
  321. {
  322. $typeclass[$v['id']] = $v;
  323. }
  324. $dowid = $this->input->get('a');
  325. $wid = "";
  326. if($dowid != "")
  327. {
  328. $id_arr = explode(',',rtrim($dowid,','));
  329. $wid .= " id = 0 or";
  330. foreach ($id_arr as $v)
  331. {
  332. $wid .= " id = '$v' or";
  333. }
  334. $wid = " and".rtrim($wid,'or');
  335. }
  336. $fexcel = $this->input->get('fexcel',true);
  337. $page = $this->input->get('page',true);
  338. $perpage = $this->input->get('perpage',true);
  339. $warehouse = $this->input->get('warehouse',true);
  340. $timetk = $this->input->get('timetk',true);
  341. $timetj = $this->input->get('timetj',true);
  342. $shop = $this->input->get('shop',true);
  343. $source = $this->input->get('source',true);
  344. $state = $this->input->get('state',true);
  345. $review = $this->input->get('review',true);
  346. $type = $this->input->get('type',true);
  347. $express = $this->input->get('express',true);
  348. $orderinfo = $this->input->get('orderinfo',true);
  349. $user = $this->input->get('user',true);
  350. $client = $this->input->get('name',true);
  351. $waybill = $this->input->get('waybill',true);
  352. $number = $this->input->get('number',true);
  353. $email = $this->input->get('email',true);
  354. $dlz = $this->input->get('dlz',true);
  355. $library = $this->input->get('library',true);
  356. $libraryconfirm = $this->input->get('libraryconfirm',true);
  357. $print = $this->input->get('print',true);
  358. $timetkk = $this->input->get('timetkk',true);
  359. $timetjj = $this->input->get('timetjj',true);
  360. $xztime = $this->input->get('xztime',true);
  361. $country = $this->input->get('country',true);
  362. $zf = $this->input->get('zf',true);
  363. $pay = $this->input->get('pay',true);
  364. $phone = $this->input->get('phone',true);
  365. $so = $this->input->get('so',true);
  366. $sfxh = $this->input->get('sfxh',true);
  367. $xdcs = $this->input->get('xdcs',true);
  368. $xdcs = $this->input->get('xdcs',true);
  369. $dbapi = $this->input->get('dbapi',true);
  370. $orderurl = $this->input->get('orderurl',true);
  371. $timetk = strtotime($timetk);
  372. $timetj = strtotime($timetj);
  373. $timetkk = strtotime($timetkk);
  374. $timetjj = strtotime($timetjj);
  375. $px = $this->input->get('px',true);
  376. $fexcel = $this->fullorderexcel->read($fexcel);
  377. $classid = $this->fullorderexcelclassid->read($fexcel['type']);
  378. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  379. if($warehouse)
  380. {
  381. $where .= " and type = '$warehouse'";
  382. }
  383. if($xztime)
  384. {
  385. if($timetk && $timetj)
  386. {
  387. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  388. }
  389. if($timetkk && $timetjj)
  390. {
  391. $where .= " and ".$xztime." > '$timetkk' and ".$xztime." < '$timetjj'";
  392. }
  393. }
  394. else
  395. {
  396. $where .= " and dtime > '$timetk' and dtime < '$timetj'";
  397. }
  398. if($library)
  399. {
  400. $where .= " and library = '$library'";
  401. }
  402. if($print)
  403. {
  404. $where .= " and print = '$print'";
  405. }
  406. if($shop)
  407. {
  408. $where .= " and shop = '$shop'";
  409. }
  410. if($source)
  411. {
  412. if($source == '2d')
  413. {
  414. $where .= " and source >= '2'";
  415. }
  416. else
  417. {
  418. $where .= " and source = '$source'";
  419. }
  420. }
  421. if($state)
  422. {
  423. $where .= " and state = '$state'";
  424. }
  425. if($review)
  426. {
  427. $where .= " and review = '$review'";
  428. }
  429. if($type)
  430. {
  431. $where .= " and type = '$type'";
  432. }
  433. if($express)
  434. {
  435. $where .= " and express = '$express'";
  436. }
  437. if($orderinfo)
  438. {
  439. $where .= " and orderinfo = '$orderinfo'";
  440. }
  441. if($user)
  442. {
  443. $where .= " and user = '$user'";
  444. }
  445. if($client)
  446. {
  447. $where .= " and client like '%$client%'";
  448. }
  449. if($waybill)
  450. {
  451. $where .= " and waybill = '$waybill'";
  452. }
  453. if($number)
  454. {
  455. $where .= " and number = '$number'";
  456. }
  457. if($email)
  458. {
  459. $where .= " and email = '$email'";
  460. }
  461. if($country)
  462. {
  463. $where .= " and country = '$country'";
  464. }
  465. if($dlz)
  466. {
  467. $where .= " and waybill != '' and dlz = 0";
  468. }
  469. if($libraryconfirm)
  470. {
  471. $where .= " and libraryconfirm = '$libraryconfirm'";
  472. }
  473. if($so)
  474. {
  475. $where .= " and shipremarks like '%$so%'";
  476. }
  477. if($pay)
  478. {
  479. $where .= " and pay = '$pay'";
  480. }
  481. if($phone)
  482. {
  483. $where .= " and phone = '$phone'";
  484. }
  485. if($sfxh != '')
  486. {
  487. $where .= " and sfxh = '$sfxh'";
  488. }
  489. if($orderurl)
  490. {
  491. $url = $this->orderurl->read($orderurl);
  492. $where .= " and link like '%".$url['url']."%'";
  493. }
  494. if($zf)
  495. {
  496. if($zf == 1)
  497. {
  498. $where .= " and paypal not like '%-%-%-%'";
  499. }
  500. else
  501. {
  502. $where .= " and paypal like '%-%-%-%'";
  503. }
  504. }
  505. $sj = $this->input->get('sj',true);
  506. if($sj)
  507. {
  508. $sj = $this->input->get('sj',true);
  509. }
  510. else
  511. {
  512. $sj = $classid['type'];
  513. }
  514. $fexceleq = explode("|",rtrim($fexcel['content'],'|'));
  515. foreach ($fexceleq as $k=>$v)
  516. {
  517. $fexceleq[$k] = explode('-',$v);
  518. $num[$k] = $fexceleq[$k][0];
  519. }
  520. //array_multisort($num,SORT_ASC,$fexceleq);//重新排序
  521. $feq = "";$kong = array();$sku9610 = '';
  522. foreach ($fexceleq as $k=>$v)
  523. {
  524. if(isset($v[1]))
  525. {
  526. if($v[1] == 'klarnabill' || $v[1] == 'klarnaship' || $v[1] == 'PPname' || $v[1] == 'PPaddress' || $v[1] == 'PPemail' || $v[1] == 'afterpayship' || $v[1] == 'afterpaybill')
  527. {
  528. $feq .= 'klarnadata,';
  529. }
  530. if($v[1] == 'ccfpdata' || $v[1] == 'cpfpdata' || $v[1] == 'dbapi' || $v[1] == 'scapi')
  531. {
  532. $feq .= 'fpdata,';
  533. }
  534. if($v[1] != 'kong')//空值去除
  535. {
  536. if($v[1] == '9610sku' || $v[1] == 'issku' || $v[1] == 'sku')
  537. {
  538. if($v[1] == '9610sku')
  539. {
  540. $sku9610 = 1;
  541. }
  542. if($sj == 'fullordersmt')
  543. {
  544. $v[1] = 'sku';
  545. }
  546. else
  547. {
  548. $v[1] = 'issku';
  549. }
  550. }
  551. $feq .= $v[1].',';
  552. }
  553. else
  554. {
  555. $kong[$v[0]] = 1;
  556. }
  557. }
  558. }
  559. //处理额外加上的subtotal和rowtoal 但是不想在表中加太多字段 想着以后有关金额的都给怼到extra_price字段中
  560. if((strpos($feq,'subtotal')!= false)||(strpos($feq,'rowtotal')!= false) ||(strpos($feq,'product_id')!= false)){
  561. if(strpos($feq,'subtotal')!= false){
  562. $feq = str_replace('subtotal,',"extra_price as subtotal,",$feq);
  563. }
  564. if(strpos($feq,'rowtotal')!= false){
  565. $feq = str_replace('rowtotal,',"extra_price as rowtotal,",$feq);
  566. }
  567. if(strpos($feq,'product_id')!= false){
  568. $feq = str_replace('product_id,',"extra_price as product_id,",$feq);
  569. }
  570. }
  571. $typeclass_lpdl = [];
  572. //料品大类
  573. if(strpos($feq,'lpdl')!= false){
  574. $feq = str_replace('lpdl,',"fpdata as lpdl,",$feq);
  575. $tmp_typeclass_lpdl = $this->db->from('typeclass')->select("id,title,zh,classid")->where('classid',16)->get()->result_array();
  576. $typeclass_lpdl = array_column($tmp_typeclass_lpdl,'zh','id');
  577. }
  578. $typeclass_lhdycc = [];
  579. //料号对应尺寸
  580. if(strpos($feq,'lhdycc')!= false){
  581. $feq = str_replace('lhdycc,',"fpdata as lhdycc,",$feq);
  582. $tmp_typeclass_lhdycc = $this->db->from('typeclass')->select("id,title,zh,classid")->where('classid',14)->get()->result_array();
  583. $typeclass_lhdycc = array_column($tmp_typeclass_lhdycc,'zh','id');
  584. }
  585. $feq = rtrim($feq,',');
  586. $fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
  587. foreach ($fexcelzhw as $k=>$v)
  588. {
  589. $fexcelzhw[$k] = explode('-',$v);
  590. $numb[$k] = $fexcelzhw[$k][0];
  591. }
  592. //array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
  593. $fexcelzh = array();
  594. foreach ($fexcelzhw as $k=>$v)
  595. {
  596. $fexcelzh[] = $v[1];
  597. }
  598. if($px)
  599. {
  600. $order_str = $px." desc";
  601. }
  602. else
  603. {
  604. $order_str = "id desc";
  605. }
  606. // if($_GET['fexcel'] == '157'){
  607. // $this->logic_ding->sendToDing("excel导出的【".$where.$wid.' and '.$excelshop);
  608. // $this->logic_ding->sendToDing("excel导出的【".'id,'.$feq);
  609. // $this->logic_ding->sendToDing("excel导出的【".$order_str);
  610. // $this->logic_ding->sendToDing("excel导出的SJ【".$sj);
  611. // }
  612. //取得信息列表
  613. $info_list = $this->$sj->find_all($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str);
  614. //格式化数据
  615. $i = 1;$shouldmoney = 0;$hl=1;
  616. foreach ($info_list as $key=>$value)
  617. {
  618. $data = $this->$sj->read($value['id']);
  619. $data = str_replace(array("'"),array("’"),$data);
  620. if(isset($value['email']) && $usp['excelpass'] == '1')
  621. {
  622. $emailpass = $this->setting->get_excelpass($value['email']);
  623. $info_list[$key]['email'] = $emailpass;
  624. }
  625. if(isset($value['phone']) && $usp['excelpass'] == '1')
  626. {
  627. $phonepass = $this->setting->get_excelpass($value['phone']);
  628. $info_list[$key]['phone'] = $phonepass;
  629. }
  630. if(isset($value['currencytitle']))
  631. {
  632. if($value['currencytitle'] != "CNY")
  633. {
  634. $hl=$value['hl'];
  635. }
  636. $shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
  637. $budget=$budget+($value['budget']*$hl);
  638. $currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);
  639. $refund=$refund+($value['refund']*$hl);
  640. }
  641. if(isset($value['shop']))
  642. {
  643. $shop = $this->shop->read($value['shop']);
  644. $info_list[$key]['shop'] = $shop['shopname'];
  645. }
  646. if(isset($value['dtime']))
  647. {
  648. $info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
  649. }
  650. if(isset($value['printtime']))
  651. {
  652. if($value['printtime'] > 0)
  653. {
  654. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  655. }
  656. }
  657. if(isset($value['sku']))
  658. {
  659. if($sku9610 == '1')
  660. {
  661. $aesku = explode(';',$value['sku']);
  662. $aesku = $aesku[0];
  663. $aesku = explode(':',$aesku);
  664. if(count($aesku) > 1)
  665. {
  666. $aesku = $aesku[1];
  667. $aesku = str_replace('--','~',$aesku);
  668. $aesku = explode('-',$aesku);
  669. $aesku = $aesku[0];
  670. $aesku = str_replace('~','--',$aesku);
  671. $info_list[$key]['sku'] = $aesku;
  672. }
  673. else
  674. {
  675. $info_list[$key]['sku'] = '';
  676. }
  677. }
  678. else
  679. {
  680. $info_list[$key]['sku'] = $value['sku'];
  681. }
  682. }
  683. if(isset($value['issku']))
  684. {
  685. $value['issku'] = str_replace(array('&lt;','&gt;'),array('<','>'),$value['issku']);
  686. if($sku9610 == '1')
  687. {
  688. $aesku = explode(';',$value['issku']);
  689. $aesku = $aesku[0];
  690. $aesku = str_replace('--','~',$aesku);
  691. $aesku = explode('-',$aesku);
  692. $aesku = $aesku[0];
  693. $aesku = str_replace('~','--',$aesku);
  694. $aesku = str_replace(array('<','>'),array('&lt;','&gt;'),$aesku);
  695. $info_list[$key]['issku'] = $aesku;
  696. }
  697. else
  698. {
  699. $value['issku'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['issku']);
  700. $info_list[$key]['issku'] = $value['issku'];
  701. }
  702. }
  703. if(isset($value['subtotal'])){
  704. $tmp_sub_str = "";
  705. $subtotal_list = json_decode($value['subtotal'],true);
  706. foreach($subtotal_list as $v){
  707. if(isset($v['sub_total'])){
  708. $tmp_sub_str .= sprintf( "%.2f",$v['sub_total'])."<br>";
  709. }else{
  710. $tmp_sub_str .= "0<br>";
  711. }
  712. }
  713. $info_list[$key]['subtotal'] = $tmp_sub_str;
  714. }
  715. if(isset($value['rowtotal'])){
  716. $tmp_sub_str = "";
  717. $subtotal_list = json_decode($value['rowtotal'],true);
  718. foreach($subtotal_list as $v){
  719. if(isset($v['row_total'])){
  720. $tmp_sub_str .= sprintf( "%.2f",$v['row_total'])."<br>";
  721. }else{
  722. $tmp_sub_str .= "0<br>";
  723. }
  724. }
  725. $info_list[$key]['rowtotal'] = $tmp_sub_str;
  726. }
  727. if(isset($value['lpdl'])){
  728. $tmp_lpdl_str ="";
  729. $tmp_fpdata_arr = explode(';',trim($value['fpdata'],';'));
  730. $tmp_fpdata_arr = array_filter($tmp_fpdata_arr);
  731. foreach($tmp_fpdata_arr as $v){
  732. if(empty($v)){
  733. continue;
  734. }
  735. $tmp_arr = explode('-',$v);
  736. if(isset($typeclass_lpdl[$tmp_arr[1]])){
  737. $tmp_lpdl_str .= $typeclass_lpdl[$tmp_arr[1]]."<br>";
  738. }else{
  739. $tmp_lpdl_str .= " ";
  740. }
  741. }
  742. $info_list[$key]['lpdl'] = trim($tmp_lpdl_str,"<br>") ;
  743. }
  744. if(isset($value['lhdycc'])){
  745. $tmp_lhdycc_str ="";
  746. $tmp_fpdata_arr = explode(';',trim($value['fpdata'],';'));
  747. $tmp_fpdata_arr = array_filter($tmp_fpdata_arr);
  748. foreach($tmp_fpdata_arr as $v){
  749. if(empty($v)){
  750. continue;
  751. }
  752. if(stripos($v,',') !== false){
  753. $tmp_arr = explode(',',$v);
  754. if(isset($typeclass_lhdycc[$tmp_arr[0]])){
  755. $tmp_lhdycc_str .= $typeclass_lhdycc[$tmp_arr[0]]."<br>";
  756. }else{
  757. $tmp_lhdycc_str .= "异常 <br>";
  758. }
  759. }else{
  760. $tmp_lhdycc_str .= "无 <br>";
  761. }
  762. }
  763. $info_list[$key]['lhdycc'] = trim($tmp_lhdycc_str,"<br>") ;
  764. }
  765. if(isset($value['product_id'])){
  766. $tmp_product_id = "";
  767. $product_ids = json_decode($value['product_id'],true);
  768. foreach($product_ids as $v){
  769. if(isset($v['product_id'])){
  770. $tmp_product_id .= $v['product_id']."<br>";
  771. }else{
  772. $tmp_product_id .= "<br>";
  773. }
  774. }
  775. $info_list[$key]['product_id'] = $tmp_product_id;
  776. }
  777. if(isset($value['librarytime']))
  778. {
  779. if($value['librarytime'] > 0)
  780. {
  781. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  782. }
  783. }
  784. if(isset($value['buytime']))
  785. {
  786. if($value['buytime'] > 0)
  787. {
  788. $info_list[$key]['buytime'] = date('Y-m-d H:i:s',$value['buytime']);
  789. }
  790. }
  791. if(isset($value['country']))
  792. {
  793. $country = $this->country->read($value['country']);
  794. $info_list[$key]['country'] = $country['name'];
  795. }
  796. if(isset($value['street']))//暂时用街道导出州二字码
  797. {
  798. if($data['country'] == 192)//如果是美国
  799. {
  800. $ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI');
  801. $data['province'] = preg_replace('/( | |\s)/',' ',$data['province']);
  802. $data['province'] = trim($data['province'],' ');
  803. if(isset($ToState[strtolower($data['province'])]))
  804. {
  805. $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])];
  806. }
  807. else
  808. {
  809. $dataprovince = '';
  810. }
  811. $info_list[$key]['street'] = $dataprovince;
  812. }
  813. else
  814. {
  815. $info_list[$key]['street'] = '';
  816. }
  817. }
  818. if(isset($value['pay']))
  819. {
  820. $pay = $this->typeclass->read($value['pay']);
  821. $info_list[$key]['pay'] = $pay['title'];
  822. }
  823. if(isset($value['type']))
  824. {
  825. $type = $this->warehouse->read($value['type']);
  826. $info_list[$key]['type'] = $type['title'];
  827. }
  828. if(isset($value['express']))
  829. {
  830. $express = $this->express->read($value['express']);
  831. if($express)
  832. {
  833. $info_list[$key]['express'] = $express['servicename'];
  834. }
  835. else
  836. {
  837. $info_list[$key]['express'] = '未选择';
  838. }
  839. }
  840. if(isset($value['ccfpdata']))
  841. {
  842. $ccfpdata = explode(';',$value['fpdata']);
  843. $inc = 0;
  844. foreach ($ccfpdata as $v)
  845. {
  846. if(stripos($v,',') !== false)
  847. {
  848. $cc = explode(',',$v);
  849. $inctype = $this->typeclass->read($cc[0]);
  850. if(is_numeric($inctype['spare']))
  851. {
  852. if($inctype['spare'] > $inc)
  853. {
  854. $inc = $inctype['spare'];
  855. }
  856. }
  857. }
  858. }
  859. $info_list[$key]['ccfpdata'] = $inc.'inch';
  860. }
  861. if(isset($value['printtype']))
  862. {
  863. if($value['printtype'] == 1)
  864. {
  865. $info_list[$key]['printtype'] = '运单';
  866. }
  867. else if($value['printtype'] == 2)
  868. {
  869. $info_list[$key]['printtype'] = '发货单';
  870. }
  871. else if($value['printtype'] == 3)
  872. {
  873. $info_list[$key]['printtype'] = '不打印单据';
  874. }
  875. else
  876. {
  877. $info_list[$key]['printtype'] = '未选择';
  878. }
  879. }
  880. if(isset($value['exstate']))
  881. {
  882. if($value['exstate'] == '99')
  883. {
  884. $info_list[$key]['exstate'] = '未获取到物流信息';
  885. }
  886. else if($value['exstate'] == '1')
  887. {
  888. $info_list[$key]['exstate'] = '已揽收';
  889. }
  890. else if($value['exstate'] == '2')
  891. {
  892. $info_list[$key]['exstate'] = '在途中';
  893. }
  894. else if($value['exstate'] == '3')
  895. {
  896. $info_list[$key]['exstate'] = '派送中';
  897. }
  898. else if($value['exstate'] == '4')
  899. {
  900. $info_list[$key]['exstate'] = '已签收';
  901. }
  902. else if($value['exstate'] == '5')
  903. {
  904. $info_list[$key]['exstate'] = '派送异常';
  905. }
  906. else
  907. {
  908. $info_list[$key]['exstate'] = '';
  909. }
  910. }
  911. if(isset($value['link']))
  912. {
  913. if($value['link'] != '')
  914. {
  915. $link = explode(',',$value['link']);
  916. $info_list[$key]['link'] = $link[0];
  917. }
  918. else
  919. {
  920. $info_list[$key]['link'] = '';
  921. }
  922. }
  923. if(isset($value['klarnabill']))
  924. {
  925. $klarnadata = explode('|',$value['klarnadata']);
  926. if(isset($klarnadata[2]))
  927. {
  928. $info_list[$key]['klarnabill'] = $klarnadata[2];
  929. }
  930. else
  931. {
  932. $info_list[$key]['klarnabill'] = '';
  933. }
  934. }
  935. if(isset($value['klarnaship']))
  936. {
  937. $klarnadata = explode('|',$value['klarnadata']);
  938. if(isset($klarnadata[3]))
  939. {
  940. $info_list[$key]['klarnaship'] = $klarnadata[3];
  941. }
  942. else
  943. {
  944. $info_list[$key]['klarnaship'] = '';
  945. }
  946. }
  947. if(isset($value['afterpaybill']))
  948. {
  949. $klarnadata = explode('|',$value['klarnadata']);
  950. if(isset($klarnadata[1]))
  951. {
  952. $info_list[$key]['afterpaybill'] = $klarnadata[1];
  953. }
  954. else
  955. {
  956. $info_list[$key]['afterpaybill'] = '';
  957. }
  958. }
  959. if(isset($value['afterpayship']))
  960. {
  961. $klarnadata = explode('|',$value['klarnadata']);
  962. if(isset($klarnadata[2]))
  963. {
  964. $info_list[$key]['afterpayship'] = $klarnadata[2];
  965. }
  966. else
  967. {
  968. $info_list[$key]['afterpayship'] = '';
  969. }
  970. }
  971. if(isset($value['PPname']))
  972. {
  973. $info_list[$key]['PPname'] = '';
  974. $klarnadata = explode('|',$value['klarnadata']);
  975. if(isset($klarnadata[1]))
  976. {
  977. $klarnadata = json_decode($klarnadata[1],true);
  978. if(isset($klarnadata['name']))
  979. {
  980. $info_list[$key]['PPname'] = $klarnadata['name'];
  981. }
  982. }
  983. }
  984. if(isset($value['PPemail']))
  985. {
  986. $info_list[$key]['PPemail'] = '';
  987. $klarnadata = explode('|',$value['klarnadata']);
  988. if(isset($klarnadata[1]))
  989. {
  990. $klarnadata = json_decode($klarnadata[1],true);
  991. if(isset($klarnadata['email']))
  992. {
  993. if($usp['excelpass'] == '1')
  994. {
  995. $ppemailpass = $this->setting->get_excelpass($klarnadata['email']);
  996. }
  997. else
  998. {
  999. $ppemailpass = $klarnadata['email'];
  1000. }
  1001. $info_list[$key]['PPemail'] = $ppemailpass;
  1002. }
  1003. }
  1004. }
  1005. if(isset($value['PPaddress']))
  1006. {
  1007. $info_list[$key]['PPaddress'] = '';
  1008. $klarnadata = explode('|',$value['klarnadata']);
  1009. if(isset($klarnadata[1]))
  1010. {
  1011. $klarnadata = json_decode($klarnadata[1],true);
  1012. if(isset($klarnadata['address']))
  1013. {
  1014. $info_list[$key]['PPaddress'] = $klarnadata['address'];
  1015. }
  1016. }
  1017. }
  1018. if(isset($value['klarnadata']))
  1019. {
  1020. unset($info_list[$key]['klarnadata']);
  1021. }
  1022. if(isset($value['shippingmethod']))
  1023. {
  1024. $tax = explode('Tax:',$value['shippingmethod']);
  1025. $info_list[$key]['shippingmethod'] = (isset($tax[1]))?trim($tax[1],';'):'';
  1026. }
  1027. if(isset($value['systemwigsout']))
  1028. {
  1029. $out = $this->systemtransfer->find_all("number = '".$data['number']."'");
  1030. $outread = '';
  1031. if($out)
  1032. {
  1033. foreach ($out as $val)
  1034. {
  1035. $list = '';
  1036. $rk = explode('|',trim($val['rk'],'|'));
  1037. $rktime = explode('|',trim($val['rktime'],'|'));
  1038. $zw = array();
  1039. $t = $this->transfer->find_all("1=1");
  1040. foreach ($t as $v)
  1041. {
  1042. $zw[$v['id']] = $v['title'];
  1043. }
  1044. if($val['rk'] != '' && count($rk) > 0)
  1045. {
  1046. for($i=0;$i<count($rk);$i++)
  1047. {
  1048. if(!isset($rktime[$i]))
  1049. {
  1050. $list .= $zw[$cz[$i]];
  1051. }
  1052. else
  1053. {
  1054. $list .= $zw[$rk[$i]].' :'.date('Y-m-d H:i',$rktime[$i]).',';
  1055. }
  1056. }
  1057. }
  1058. $outread .= '<span style="color:#f00">'.$val['pm'].'</span>:'.$list.'<br>';
  1059. }
  1060. }
  1061. else
  1062. {
  1063. $systemwigsout = $this->systemwigsout->find_all("number = '".$data['number']."'");
  1064. if($systemwigsout)
  1065. {
  1066. foreach ($systemwigsout as $v)
  1067. {
  1068. $outread = '';
  1069. if($v['czwarehouse'] == 37)
  1070. {
  1071. $outread .= '华荣厂';
  1072. }
  1073. else if($v['czwarehouse'] == 0)
  1074. {
  1075. $outread .= '龙盈厂';
  1076. }
  1077. $cz = explode('|',trim($v['cz'],'|'));
  1078. $cztime = explode('|',trim($v['cztime'],'|'));
  1079. $zw = $this->transfer->get_list();
  1080. if($v['cz'] != '' && count($cz) > 0)
  1081. {
  1082. for($i=0;$i<count($cz);$i++)
  1083. {
  1084. if(!isset($cztime[$i]))
  1085. {
  1086. $outread .= $zw[$cz[$i]].' -&gt; ';
  1087. }
  1088. else
  1089. {
  1090. $outread .= $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]).' -&gt; ';
  1091. }
  1092. }
  1093. $outread .= '<br>';
  1094. }
  1095. }
  1096. }
  1097. }
  1098. $info_list[$key]['systemwigsout'] = $outread;
  1099. }
  1100. if(isset($value['sourcetype']))
  1101. {
  1102. if($value['sourcetype'] == '1')
  1103. {
  1104. $info_list[$key]['sourcetype'] = '网红单';
  1105. }
  1106. else if($value['sourcetype'] == '2')
  1107. {
  1108. $info_list[$key]['sourcetype'] = '批发单';
  1109. }
  1110. else if($value['sourcetype'] == '3')
  1111. {
  1112. $info_list[$key]['sourcetype'] = '线下单';
  1113. }
  1114. else if($value['sourcetype'] == '4')
  1115. {
  1116. $info_list[$key]['sourcetype'] = '售后单';
  1117. }
  1118. else if($value['sourcetype'] == '5')
  1119. {
  1120. $info_list[$key]['sourcetype'] = '其它';
  1121. }
  1122. else
  1123. {
  1124. $info_list[$key]['sourcetype'] = '';
  1125. }
  1126. }
  1127. if(isset($value['js']))
  1128. {
  1129. if($value['js'] == '0')
  1130. {
  1131. $info_list[$key]['js'] = 'Ground Advantage';
  1132. }
  1133. else if($value['js'] == '1')
  1134. {
  1135. $info_list[$key]['js'] = 'PRIORITY';
  1136. }
  1137. else if($value['js'] == '2')
  1138. {
  1139. $info_list[$key]['js'] = 'EXPRESS';
  1140. }
  1141. else if($value['js'] == '3')
  1142. {
  1143. $info_list[$key]['js'] = 'IP';
  1144. }
  1145. else if($value['js'] == '4')
  1146. {
  1147. $info_list[$key]['js'] = 'FICP';
  1148. }
  1149. }
  1150. if(isset($value['type']))
  1151. {
  1152. $type = $this->warehouse->read($value['type']);
  1153. $info_list[$key]['type'] = $type['title'];
  1154. }
  1155. if(isset($value['xdcs']))
  1156. {
  1157. if($sj == 'fullorder')
  1158. {
  1159. $xdcs = $this->customer->get_email($data['email'],$data['shop']);
  1160. }
  1161. else
  1162. {
  1163. $xdcs = $this->customersmt->get_shopdata($data['shop'],$data['name'],$data['address']);
  1164. }
  1165. $info_list[$key]['xdcs'] = (isset($xdcs['num']))?(($xdcs['num']==0)?1:$xdcs['num']):1;
  1166. }
  1167. if(isset($value['dbapi']) || isset($value['scapi']))
  1168. {
  1169. $jmlist = '';$shuliang = '';
  1170. $classid = $this->classid->sku();
  1171. $dbapi = explode(';',trim($value['fpdata'],';'));
  1172. foreach ($dbapi as $va)
  1173. {
  1174. $pm = $classid;
  1175. $jm = $classid;
  1176. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  1177. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  1178. $ts = explode('|',trim($features,'|'));
  1179. if(stripos($ts[0],',') !== false)
  1180. {
  1181. $ft = explode(',',$ts[0]);
  1182. $features = explode('-',trim($ft[1],'-'));
  1183. $features[] = $ft[0];
  1184. }
  1185. else
  1186. {
  1187. $features = explode('-',trim($ts[0],'-'));
  1188. }
  1189. foreach($features as $k=>$v)
  1190. {
  1191. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  1192. {
  1193. if($typeclass[$v]['bm'] != '')
  1194. {
  1195. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  1196. }
  1197. }
  1198. if($v != 0 && isset($typeclass[$v]))
  1199. {
  1200. if($typeclass[$v]['classid'] == 13)
  1201. {
  1202. $dj = $typeclass[$v]['title'];
  1203. }
  1204. if($typeclass[$v]['classid'] == 8)
  1205. {
  1206. $ys = $typeclass[$v]['title'];
  1207. }
  1208. if($typeclass[$v]['classid'] == 15)
  1209. {
  1210. $hx = $typeclass[$v]['title'];
  1211. }
  1212. if(isset($pm[$typeclass[$v]['classid']]))
  1213. {
  1214. if($typeclass[$v]['title'] == '9A')
  1215. {
  1216. $pm[$typeclass[$v]['classid']] = '9A';
  1217. }
  1218. else if($typeclass[$v]['title'] == '10A')
  1219. {
  1220. $pm[$typeclass[$v]['classid']] = '10A';
  1221. }
  1222. else
  1223. {
  1224. $clzh = $typeclass[$v]['zh'];
  1225. if(stripos($typeclass[$v]['zh'],'|') !== false)
  1226. {
  1227. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  1228. $clzh = $clzh[0];
  1229. }
  1230. $pm[$typeclass[$v]['classid']] = $clzh;
  1231. }
  1232. }
  1233. if(isset($jm[$typeclass[$v]['classid']]))
  1234. {
  1235. if($typeclass[$v]['jm'])
  1236. {
  1237. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  1238. }
  1239. }
  1240. }
  1241. }
  1242. $jm = array_filter($jm);//去除空值
  1243. $jm = implode("-",$jm);
  1244. $jmlist .= $jm.'<br>';
  1245. $shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';
  1246. $pm = array_filter($pm);//去除空值
  1247. $zh = implode(" ",$pm);
  1248. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  1249. }
  1250. if(isset($value['dbapi']))
  1251. {
  1252. $info_list[$key]['dbapi'] = $jmlist;
  1253. }
  1254. else
  1255. {
  1256. $info_list[$key]['scapi'] = $shuliang;
  1257. }
  1258. }
  1259. if(isset($value['dbapi']) && isset($value['scapi']))
  1260. {
  1261. $jmlist = '';$shuliang = '';
  1262. $classid = $this->classid->sku();
  1263. $dbapi = explode(';',trim($value['fpdata'],';'));
  1264. foreach ($dbapi as $va)
  1265. {
  1266. $pm = $classid;
  1267. $jm = $classid;
  1268. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  1269. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  1270. $ts = explode('|',trim($features,'|'));
  1271. if(stripos($ts[0],',') !== false)
  1272. {
  1273. $ft = explode(',',$ts[0]);
  1274. $features = explode('-',trim($ft[1],'-'));
  1275. $features[] = $ft[0];
  1276. }
  1277. else
  1278. {
  1279. $features = explode('-',trim($ts[0],'-'));
  1280. }
  1281. foreach($features as $k=>$v)
  1282. {
  1283. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  1284. {
  1285. if($typeclass[$v]['bm'] != '')
  1286. {
  1287. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  1288. }
  1289. }
  1290. if($v != 0 && isset($typeclass[$v]))
  1291. {
  1292. if($typeclass[$v]['classid'] == 13)
  1293. {
  1294. $dj = $typeclass[$v]['title'];
  1295. }
  1296. if($typeclass[$v]['classid'] == 8)
  1297. {
  1298. $ys = $typeclass[$v]['title'];
  1299. }
  1300. if($typeclass[$v]['classid'] == 15)
  1301. {
  1302. $hx = $typeclass[$v]['title'];
  1303. }
  1304. if(isset($pm[$typeclass[$v]['classid']]))
  1305. {
  1306. if($typeclass[$v]['title'] == '9A')
  1307. {
  1308. $pm[$typeclass[$v]['classid']] = '9A';
  1309. }
  1310. else if($typeclass[$v]['title'] == '10A')
  1311. {
  1312. $pm[$typeclass[$v]['classid']] = '10A';
  1313. }
  1314. else
  1315. {
  1316. $clzh = $typeclass[$v]['zh'];
  1317. if(stripos($typeclass[$v]['zh'],'|') !== false)
  1318. {
  1319. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  1320. $clzh = $clzh[0];
  1321. }
  1322. $pm[$typeclass[$v]['classid']] = $clzh;
  1323. }
  1324. }
  1325. if(isset($jm[$typeclass[$v]['classid']]))
  1326. {
  1327. if($typeclass[$v]['jm'])
  1328. {
  1329. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  1330. }
  1331. }
  1332. }
  1333. }
  1334. $jm = array_filter($jm);//去除空值
  1335. $jm = implode("-",$jm);
  1336. $jmlist .= $jm.'<br>';
  1337. $shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';
  1338. $pm = array_filter($pm);//去除空值
  1339. $zh = implode(" ",$pm);
  1340. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  1341. }
  1342. $info_list[$key]['dbapi'] = $jmlist;
  1343. $info_list[$key]['scapi'] = $shuliang;
  1344. }
  1345. if(isset($value['cpfpdata']))
  1346. {
  1347. $fpread = '';
  1348. $cpfpdata = explode(';',trim($value['fpdata'],';'));
  1349. foreach ($cpfpdata as $v)
  1350. {
  1351. $va = explode('|',trim($v,'|'));
  1352. if(isset($va[1])){
  1353. $fpread .= $va[1].'; ';
  1354. }else{
  1355. $fpread .="合并单没有产品异常标记";
  1356. }
  1357. }
  1358. $info_list[$key]['cpfpdata'] = $fpread;
  1359. }
  1360. unset($info_list[$key]['id']);
  1361. unset($info_list[$key]['fpdata']);
  1362. }
  1363. $fzh = "";
  1364. foreach ($fexcelzh as $v)
  1365. {
  1366. $fzh .= "<td>".$v."</td>";
  1367. }
  1368. $data = array($shouldmoney.' CNY');
  1369. $title = $fexcel['title'].'-'.date('Ymd',time());
  1370. $titlename = "<table border=1>
  1371. <tr>"
  1372. .$fzh.
  1373. "</tr>
  1374. </table>";
  1375. $tail = "\n";
  1376. $filename = $title.".xls";
  1377. $this->excel->get_fz5($info_list,$titlename,$filename,$tail,$kong);
  1378. }
  1379. }
  1380. //导出订单excel
  1381. public function _excelhz()
  1382. {
  1383. $fgshop = "";$sid = "";$excelshop="";
  1384. if(isset($_SESSION['api']))
  1385. {
  1386. $user = $this->user->get_api($_SESSION['api']);
  1387. $usp = $user;
  1388. $usersp = explode('|',trim($user['shop'],'|'));
  1389. foreach ($usersp as $value)
  1390. {
  1391. $fgshop .= " shop = ".$value." or";
  1392. $sid .= " id = ".$value." or";
  1393. }
  1394. $userexcel = explode('|',trim($user['excelshop'],'|'));
  1395. if($user['excelshop'] == '')
  1396. {
  1397. echo "没有下载权限";exit;
  1398. }
  1399. foreach ($userexcel as $value)
  1400. {
  1401. $excelshop .= " shop = ".$value." or";
  1402. }
  1403. if($excelshop != "")
  1404. {
  1405. $excelshop = "(".rtrim($excelshop,'or').")";
  1406. }
  1407. }
  1408. if(isset($_GET['fexcel']))
  1409. {
  1410. $typeclass = array();
  1411. $tclass = $this->typeclass->find_all();
  1412. foreach ($tclass as $v)
  1413. {
  1414. $typeclass[$v['id']] = $v;
  1415. }
  1416. $dowid = $this->input->get('a');
  1417. $wid = "";
  1418. if($dowid != "")
  1419. {
  1420. $id_arr = explode(',',rtrim($dowid,','));
  1421. $wid .= " id = 0 or";
  1422. foreach ($id_arr as $v)
  1423. {
  1424. $wid .= " id = '$v' or";
  1425. }
  1426. $wid = " and".rtrim($wid,'or');
  1427. }
  1428. $fexcel = $this->input->get('fexcel',true);
  1429. $page = $this->input->get('page',true);
  1430. $perpage = $this->input->get('perpage',true);
  1431. $warehouse = $this->input->get('warehouse',true);
  1432. $timetk = $this->input->get('timetk',true);
  1433. $timetj = $this->input->get('timetj',true);
  1434. $shop = $this->input->get('shop',true);
  1435. $source = $this->input->get('source',true);
  1436. $state = $this->input->get('state',true);
  1437. $review = $this->input->get('review',true);
  1438. $type = $this->input->get('type',true);
  1439. $express = $this->input->get('express',true);
  1440. $orderinfo = $this->input->get('orderinfo',true);
  1441. $user = $this->input->get('user',true);
  1442. $client = $this->input->get('name',true);
  1443. $waybill = $this->input->get('waybill',true);
  1444. $number = $this->input->get('number',true);
  1445. $email = $this->input->get('email',true);
  1446. $dlz = $this->input->get('dlz',true);
  1447. $library = $this->input->get('library',true);
  1448. $libraryconfirm = $this->input->get('libraryconfirm',true);
  1449. $print = $this->input->get('print',true);
  1450. $timetkk = $this->input->get('timetkk',true);
  1451. $timetjj = $this->input->get('timetjj',true);
  1452. $xztime = $this->input->get('xztime',true);
  1453. $country = $this->input->get('country',true);
  1454. $zf = $this->input->get('zf',true);
  1455. $pay = $this->input->get('pay',true);
  1456. $phone = $this->input->get('phone',true);
  1457. $so = $this->input->get('so',true);
  1458. $sfxh = $this->input->get('sfxh',true);
  1459. $xdcs = $this->input->get('xdcs',true);
  1460. $xdcs = $this->input->get('xdcs',true);
  1461. $dbapi = $this->input->get('dbapi',true);
  1462. $orderurl = $this->input->get('orderurl',true);
  1463. $timetk = strtotime($timetk);
  1464. $timetj = strtotime($timetj);
  1465. $timetkk = strtotime($timetkk);
  1466. $timetjj = strtotime($timetjj);
  1467. $px = $this->input->get('px',true);
  1468. $fexcel = $this->fullorderexcel->read($fexcel);
  1469. $classid = $this->fullorderexcelclassid->read($fexcel['type']);
  1470. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  1471. if($warehouse)
  1472. {
  1473. $where .= " and type = '$warehouse'";
  1474. }
  1475. if($xztime)
  1476. {
  1477. if($timetk && $timetj)
  1478. {
  1479. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  1480. }
  1481. if($timetkk && $timetjj)
  1482. {
  1483. $where .= " and ".$xztime." > '$timetkk' and ".$xztime." < '$timetjj'";
  1484. }
  1485. }
  1486. else
  1487. {
  1488. $where .= " and dtime > '$timetk' and dtime < '$timetj'";
  1489. }
  1490. if($library)
  1491. {
  1492. $where .= " and library = '$library'";
  1493. }
  1494. if($print)
  1495. {
  1496. $where .= " and print = '$print'";
  1497. }
  1498. if($shop)
  1499. {
  1500. $where .= " and shop = '$shop'";
  1501. }
  1502. if($source)
  1503. {
  1504. if($source == '2d')
  1505. {
  1506. $where .= " and source >= '2'";
  1507. }
  1508. else
  1509. {
  1510. $where .= " and source = '$source'";
  1511. }
  1512. }
  1513. if($state)
  1514. {
  1515. $where .= " and state = '$state'";
  1516. }
  1517. if($review)
  1518. {
  1519. $where .= " and review = '$review'";
  1520. }
  1521. if($type)
  1522. {
  1523. $where .= " and type = '$type'";
  1524. }
  1525. if($express)
  1526. {
  1527. $where .= " and express = '$express'";
  1528. }
  1529. if($orderinfo)
  1530. {
  1531. $where .= " and orderinfo = '$orderinfo'";
  1532. }
  1533. if($user)
  1534. {
  1535. $where .= " and user = '$user'";
  1536. }
  1537. if($client)
  1538. {
  1539. $where .= " and client like '%$client%'";
  1540. }
  1541. if($waybill)
  1542. {
  1543. $where .= " and waybill = '$waybill'";
  1544. }
  1545. if($number)
  1546. {
  1547. $where .= " and number = '$number'";
  1548. }
  1549. if($email)
  1550. {
  1551. $where .= " and email = '$email'";
  1552. }
  1553. if($country)
  1554. {
  1555. $where .= " and country = '$country'";
  1556. }
  1557. if($dlz)
  1558. {
  1559. $where .= " and waybill != '' and dlz = 0";
  1560. }
  1561. if($libraryconfirm)
  1562. {
  1563. $where .= " and libraryconfirm = '$libraryconfirm'";
  1564. }
  1565. if($so)
  1566. {
  1567. $where .= " and shipremarks like '%$so%'";
  1568. }
  1569. if($pay)
  1570. {
  1571. $where .= " and pay = '$pay'";
  1572. }
  1573. if($phone)
  1574. {
  1575. $where .= " and phone = '$phone'";
  1576. }
  1577. if($sfxh != '')
  1578. {
  1579. $where .= " and sfxh = '$sfxh'";
  1580. }
  1581. if($orderurl)
  1582. {
  1583. $url = $this->orderurl->read($orderurl);
  1584. $where .= " and link like '%".$url['url']."%'";
  1585. }
  1586. if($zf)
  1587. {
  1588. if($zf == 1)
  1589. {
  1590. $where .= " and paypal not like '%-%-%-%'";
  1591. }
  1592. else
  1593. {
  1594. $where .= " and paypal like '%-%-%-%'";
  1595. }
  1596. }
  1597. $sj = $this->input->get('sj',true);
  1598. if($sj)
  1599. {
  1600. $sj = $this->input->get('sj',true);
  1601. }
  1602. else
  1603. {
  1604. $sj = $classid['type'];
  1605. }
  1606. $fexceleq = explode("|",rtrim($fexcel['content'],'|'));
  1607. foreach ($fexceleq as $k=>$v)
  1608. {
  1609. $fexceleq[$k] = explode('-',$v);
  1610. $num[$k] = $fexceleq[$k][0];
  1611. }
  1612. //array_multisort($num,SORT_ASC,$fexceleq);//重新排序
  1613. $feq = "";$kong = array();$sku9610 = '';
  1614. foreach ($fexceleq as $k=>$v)
  1615. {
  1616. if(isset($v[1]))
  1617. {
  1618. if($v[1] == 'klarnabill' || $v[1] == 'klarnaship' || $v[1] == 'PPname' || $v[1] == 'PPaddress' || $v[1] == 'PPemail' || $v[1] == 'afterpayship' || $v[1] == 'afterpaybill')
  1619. {
  1620. $feq .= 'klarnadata,';
  1621. }
  1622. if($v[1] == 'ccfpdata' || $v[1] == 'cpfpdata' || $v[1] == 'dbapi' || $v[1] == 'scapi')
  1623. {
  1624. $feq .= 'fpdata,';
  1625. }
  1626. if($v[1] != 'kong')//空值去除
  1627. {
  1628. if($v[1] == '9610sku' || $v[1] == 'issku' || $v[1] == 'sku')
  1629. {
  1630. if($v[1] == '9610sku')
  1631. {
  1632. $sku9610 = 1;
  1633. }
  1634. if($sj == 'fullordersmt')
  1635. {
  1636. $v[1] = 'sku';
  1637. }
  1638. else
  1639. {
  1640. $v[1] = 'issku';
  1641. }
  1642. }
  1643. $feq .= $v[1].',';
  1644. }
  1645. else
  1646. {
  1647. $kong[$v[0]] = 1;
  1648. }
  1649. }
  1650. }
  1651. //处理额外加上的subtotal和rowtoal 但是不想在表中加太多字段 想着以后有关金额的都给怼到extra_price字段中
  1652. if((strpos($feq,'subtotal')!= false)||(strpos($feq,'rowtotal')!= false) ||(strpos($feq,'product_id')!= false)){
  1653. if(strpos($feq,'subtotal')!= false){
  1654. $feq = str_replace('subtotal,',"extra_price as subtotal,",$feq);
  1655. }
  1656. if(strpos($feq,'rowtotal')!= false){
  1657. $feq = str_replace('rowtotal,',"extra_price as rowtotal,",$feq);
  1658. }
  1659. if(strpos($feq,'product_id')!= false){
  1660. $feq = str_replace('product_id,',"extra_price as product_id,",$feq);
  1661. }
  1662. }
  1663. $typeclass_lpdl = [];
  1664. //料品大类
  1665. if(strpos($feq,'lpdl')!= false){
  1666. $feq = str_replace('lpdl,',"fpdata as lpdl,",$feq);
  1667. $tmp_typeclass_lpdl = $this->db->from('typeclass')->select("id,title,zh,classid")->where('classid',16)->get()->result_array();
  1668. $typeclass_lpdl = array_column($tmp_typeclass_lpdl,'zh','id');
  1669. }
  1670. $typeclass_lhdycc = [];
  1671. //料号对应尺寸
  1672. if(strpos($feq,'lhdycc')!= false){
  1673. $feq = str_replace('lhdycc,',"fpdata as lhdycc,",$feq);
  1674. $tmp_typeclass_lhdycc = $this->db->from('typeclass')->select("id,title,zh,classid")->where('classid',14)->get()->result_array();
  1675. $typeclass_lhdycc = array_column($tmp_typeclass_lhdycc,'zh','id');
  1676. }
  1677. $feq = rtrim($feq,',');
  1678. $fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
  1679. foreach ($fexcelzhw as $k=>$v)
  1680. {
  1681. $fexcelzhw[$k] = explode('-',$v);
  1682. $numb[$k] = $fexcelzhw[$k][0];
  1683. }
  1684. //array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
  1685. $fexcelzh = array();
  1686. foreach ($fexcelzhw as $k=>$v)
  1687. {
  1688. $fexcelzh[] = $v[1];
  1689. }
  1690. if($px)
  1691. {
  1692. $order_str = $px." desc";
  1693. }
  1694. else
  1695. {
  1696. $order_str = "id desc";
  1697. }
  1698. // if($_GET['fexcel'] == '157'){
  1699. // $this->logic_ding->sendToDing("excel导出的【".$where.$wid.' and '.$excelshop);
  1700. // $this->logic_ding->sendToDing("excel导出的【".'id,'.$feq);
  1701. // $this->logic_ding->sendToDing("excel导出的【".$order_str);
  1702. // $this->logic_ding->sendToDing("excel导出的SJ【".$sj);
  1703. // }
  1704. $extra = [
  1705. 'usp'=>$usp,
  1706. 'sku9610'=>$sku9610,
  1707. ];
  1708. $dlz_ret = $this->_datahz($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str,'fullorder',$extra);
  1709. $tt_ret = $this->_datahz($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str,'fullordertt',$extra);
  1710. $smt_ret = $this->_datahz($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str,'fullordersmt',$extra);
  1711. $amz_ret = $this->_datahz($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str,'fullorderamz',$extra);
  1712. $info_list = array_merge( $dlz_ret['info_list'],$tt_ret['info_list'],$smt_ret['info_list'],$amz_ret['info_list']);
  1713. $shouldmoney = $dlz_ret['shouldmoney']+$tt_ret['shouldmoney']+$smt_ret['shouldmoney']+$amz_ret['shouldmoney'];
  1714. $fzh = "";
  1715. foreach ($fexcelzh as $v)
  1716. {
  1717. $fzh .= "<td>".$v."</td>";
  1718. }
  1719. $data = array($shouldmoney.' CNY');
  1720. $title = $fexcel['title'].'-'.date('Ymd',time());
  1721. $titlename = "<table border=1>
  1722. <tr>"
  1723. .$fzh.
  1724. "</tr>
  1725. </table>";
  1726. $tail = "\n";
  1727. $filename = $title.".xls";
  1728. $this->excel->get_fz5($info_list,$titlename,$filename,$tail,$kong);
  1729. }
  1730. }
  1731. public function _datahz($where,$field,$order_str,$sj,$extra){
  1732. //取得信息列表
  1733. $info_list = $this->$sj->find_all($where,$field,$order_str);
  1734. //格式化数据
  1735. $i = 1;$shouldmoney = 0;$hl=1;
  1736. $usp = $extra['usp'];
  1737. $sku9610 = $extra['sku9610'];
  1738. foreach ($info_list as $key=>$value)
  1739. {
  1740. $data = $this->$sj->read($value['id']);
  1741. $data = str_replace(array("'"),array("’"),$data);
  1742. if(isset($value['email']) && $usp['excelpass'] == '1')
  1743. {
  1744. $emailpass = $this->setting->get_excelpass($value['email']);
  1745. $info_list[$key]['email'] = $emailpass;
  1746. }
  1747. if(isset($value['phone']) && $usp['excelpass'] == '1')
  1748. {
  1749. $phonepass = $this->setting->get_excelpass($value['phone']);
  1750. $info_list[$key]['phone'] = $phonepass;
  1751. }
  1752. if(isset($value['currencytitle']))
  1753. {
  1754. if($value['currencytitle'] != "CNY")
  1755. {
  1756. $hl=$value['hl'];
  1757. }
  1758. $shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
  1759. }
  1760. if(isset($value['shop']))
  1761. {
  1762. $shop = $this->shop->read($value['shop']);
  1763. $info_list[$key]['shop'] = $shop['shopname'];
  1764. }
  1765. if(isset($value['dtime']))
  1766. {
  1767. $info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
  1768. }
  1769. if(isset($value['printtime']))
  1770. {
  1771. if($value['printtime'] > 0)
  1772. {
  1773. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1774. }
  1775. }
  1776. if(isset($value['sku']))
  1777. {
  1778. if($sku9610 == '1')
  1779. {
  1780. $aesku = explode(';',$value['sku']);
  1781. $aesku = $aesku[0];
  1782. $aesku = explode(':',$aesku);
  1783. if(count($aesku) > 1)
  1784. {
  1785. $aesku = $aesku[1];
  1786. $aesku = str_replace('--','~',$aesku);
  1787. $aesku = explode('-',$aesku);
  1788. $aesku = $aesku[0];
  1789. $aesku = str_replace('~','--',$aesku);
  1790. $info_list[$key]['sku'] = $aesku;
  1791. }
  1792. else
  1793. {
  1794. $info_list[$key]['sku'] = '';
  1795. }
  1796. }
  1797. else
  1798. {
  1799. $info_list[$key]['sku'] = $value['sku'];
  1800. }
  1801. }
  1802. if(isset($value['issku']))
  1803. {
  1804. $value['issku'] = str_replace(array('&lt;','&gt;'),array('<','>'),$value['issku']);
  1805. if($sku9610 == '1')
  1806. {
  1807. $aesku = explode(';',$value['issku']);
  1808. $aesku = $aesku[0];
  1809. $aesku = str_replace('--','~',$aesku);
  1810. $aesku = explode('-',$aesku);
  1811. $aesku = $aesku[0];
  1812. $aesku = str_replace('~','--',$aesku);
  1813. $aesku = str_replace(array('<','>'),array('&lt;','&gt;'),$aesku);
  1814. $info_list[$key]['issku'] = $aesku;
  1815. }
  1816. else
  1817. {
  1818. $value['issku'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['issku']);
  1819. $info_list[$key]['issku'] = $value['issku'];
  1820. }
  1821. }
  1822. if(isset($value['subtotal'])){
  1823. $tmp_sub_str = "";
  1824. $subtotal_list = json_decode($value['subtotal'],true);
  1825. foreach($subtotal_list as $v){
  1826. if(isset($v['sub_total'])){
  1827. $tmp_sub_str .= sprintf( "%.2f",$v['sub_total'])."<br>";
  1828. }else{
  1829. $tmp_sub_str .= "0<br>";
  1830. }
  1831. }
  1832. $info_list[$key]['subtotal'] = $tmp_sub_str;
  1833. }
  1834. if(isset($value['rowtotal'])){
  1835. $tmp_sub_str = "";
  1836. $subtotal_list = json_decode($value['rowtotal'],true);
  1837. foreach($subtotal_list as $v){
  1838. if(isset($v['row_total'])){
  1839. $tmp_sub_str .= sprintf( "%.2f",$v['row_total'])."<br>";
  1840. }else{
  1841. $tmp_sub_str .= "0<br>";
  1842. }
  1843. }
  1844. $info_list[$key]['rowtotal'] = $tmp_sub_str;
  1845. }
  1846. if(isset($value['lpdl'])){
  1847. $tmp_lpdl_str ="";
  1848. $tmp_fpdata_arr = explode(';',trim($value['fpdata'],';'));
  1849. $tmp_fpdata_arr = array_filter($tmp_fpdata_arr);
  1850. foreach($tmp_fpdata_arr as $v){
  1851. if(empty($v)){
  1852. continue;
  1853. }
  1854. $tmp_arr = explode('-',$v);
  1855. if(isset($typeclass_lpdl[$tmp_arr[1]])){
  1856. $tmp_lpdl_str .= $typeclass_lpdl[$tmp_arr[1]]."<br>";
  1857. }else{
  1858. $tmp_lpdl_str .= " ";
  1859. }
  1860. }
  1861. $info_list[$key]['lpdl'] = trim($tmp_lpdl_str,"<br>") ;
  1862. }
  1863. if(isset($value['lhdycc'])){
  1864. $tmp_lhdycc_str ="";
  1865. $tmp_fpdata_arr = explode(';',trim($value['fpdata'],';'));
  1866. $tmp_fpdata_arr = array_filter($tmp_fpdata_arr);
  1867. foreach($tmp_fpdata_arr as $v){
  1868. if(empty($v)){
  1869. continue;
  1870. }
  1871. if(stripos($v,',') !== false){
  1872. $tmp_arr = explode(',',$v);
  1873. if(isset($typeclass_lhdycc[$tmp_arr[0]])){
  1874. $tmp_lhdycc_str .= $typeclass_lhdycc[$tmp_arr[0]]."<br>";
  1875. }else{
  1876. $tmp_lhdycc_str .= "异常 <br>";
  1877. }
  1878. }else{
  1879. $tmp_lhdycc_str .= "无 <br>";
  1880. }
  1881. }
  1882. $info_list[$key]['lhdycc'] = trim($tmp_lhdycc_str,"<br>") ;
  1883. }
  1884. if(isset($value['product_id'])){
  1885. $tmp_product_id = "";
  1886. $product_ids = json_decode($value['product_id'],true);
  1887. foreach($product_ids as $v){
  1888. if(isset($v['product_id'])){
  1889. $tmp_product_id .= $v['product_id']."<br>";
  1890. }else{
  1891. $tmp_product_id .= "<br>";
  1892. }
  1893. }
  1894. $info_list[$key]['product_id'] = $tmp_product_id;
  1895. }
  1896. if(isset($value['librarytime']))
  1897. {
  1898. if($value['librarytime'] > 0)
  1899. {
  1900. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  1901. }
  1902. }
  1903. if(isset($value['buytime']))
  1904. {
  1905. if($value['buytime'] > 0)
  1906. {
  1907. $info_list[$key]['buytime'] = date('Y-m-d H:i:s',$value['buytime']);
  1908. }
  1909. }
  1910. if(isset($value['country']))
  1911. {
  1912. $country = $this->country->read($value['country']);
  1913. $info_list[$key]['country'] = $country['name'];
  1914. }
  1915. if(isset($value['street']))//暂时用街道导出州二字码
  1916. {
  1917. if($data['country'] == 192)//如果是美国
  1918. {
  1919. $ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI');
  1920. $data['province'] = preg_replace('/( | |\s)/',' ',$data['province']);
  1921. $data['province'] = trim($data['province'],' ');
  1922. if(isset($ToState[strtolower($data['province'])]))
  1923. {
  1924. $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])];
  1925. }
  1926. else
  1927. {
  1928. $dataprovince = '';
  1929. }
  1930. $info_list[$key]['street'] = $dataprovince;
  1931. }
  1932. else
  1933. {
  1934. $info_list[$key]['street'] = '';
  1935. }
  1936. }
  1937. if(isset($value['pay']))
  1938. {
  1939. if($sj !='fullordersmt'){
  1940. $pay = $this->typeclass->read($value['pay']);
  1941. $info_list[$key]['pay'] = $pay['title'];
  1942. }
  1943. }
  1944. if(isset($value['type']))
  1945. {
  1946. $type = $this->warehouse->read($value['type']);
  1947. $info_list[$key]['type'] = $type['title'];
  1948. }
  1949. if(isset($value['express']))
  1950. {
  1951. $express = $this->express->read($value['express']);
  1952. if($express)
  1953. {
  1954. $info_list[$key]['express'] = $express['servicename'];
  1955. }
  1956. else
  1957. {
  1958. $info_list[$key]['express'] = '未选择';
  1959. }
  1960. }
  1961. if(isset($value['ccfpdata']))
  1962. {
  1963. $ccfpdata = explode(';',$value['fpdata']);
  1964. $inc = 0;
  1965. foreach ($ccfpdata as $v)
  1966. {
  1967. if(stripos($v,',') !== false)
  1968. {
  1969. $cc = explode(',',$v);
  1970. $inctype = $this->typeclass->read($cc[0]);
  1971. if(is_numeric($inctype['spare']))
  1972. {
  1973. if($inctype['spare'] > $inc)
  1974. {
  1975. $inc = $inctype['spare'];
  1976. }
  1977. }
  1978. }
  1979. }
  1980. $info_list[$key]['ccfpdata'] = $inc.'inch';
  1981. }
  1982. if(isset($value['printtype']))
  1983. {
  1984. if($value['printtype'] == 1)
  1985. {
  1986. $info_list[$key]['printtype'] = '运单';
  1987. }
  1988. else if($value['printtype'] == 2)
  1989. {
  1990. $info_list[$key]['printtype'] = '发货单';
  1991. }
  1992. else if($value['printtype'] == 3)
  1993. {
  1994. $info_list[$key]['printtype'] = '不打印单据';
  1995. }
  1996. else
  1997. {
  1998. $info_list[$key]['printtype'] = '未选择';
  1999. }
  2000. }
  2001. if(isset($value['exstate']))
  2002. {
  2003. if($value['exstate'] == '99')
  2004. {
  2005. $info_list[$key]['exstate'] = '未获取到物流信息';
  2006. }
  2007. else if($value['exstate'] == '1')
  2008. {
  2009. $info_list[$key]['exstate'] = '已揽收';
  2010. }
  2011. else if($value['exstate'] == '2')
  2012. {
  2013. $info_list[$key]['exstate'] = '在途中';
  2014. }
  2015. else if($value['exstate'] == '3')
  2016. {
  2017. $info_list[$key]['exstate'] = '派送中';
  2018. }
  2019. else if($value['exstate'] == '4')
  2020. {
  2021. $info_list[$key]['exstate'] = '已签收';
  2022. }
  2023. else if($value['exstate'] == '5')
  2024. {
  2025. $info_list[$key]['exstate'] = '派送异常';
  2026. }
  2027. else
  2028. {
  2029. $info_list[$key]['exstate'] = '';
  2030. }
  2031. }
  2032. if(isset($value['link']))
  2033. {
  2034. if($value['link'] != '')
  2035. {
  2036. $link = explode(',',$value['link']);
  2037. $info_list[$key]['link'] = $link[0];
  2038. }
  2039. else
  2040. {
  2041. $info_list[$key]['link'] = '';
  2042. }
  2043. }
  2044. if(isset($value['klarnabill']))
  2045. {
  2046. $klarnadata = explode('|',$value['klarnadata']);
  2047. if(isset($klarnadata[2]))
  2048. {
  2049. $info_list[$key]['klarnabill'] = $klarnadata[2];
  2050. }
  2051. else
  2052. {
  2053. $info_list[$key]['klarnabill'] = '';
  2054. }
  2055. }
  2056. if(isset($value['klarnaship']))
  2057. {
  2058. $klarnadata = explode('|',$value['klarnadata']);
  2059. if(isset($klarnadata[3]))
  2060. {
  2061. $info_list[$key]['klarnaship'] = $klarnadata[3];
  2062. }
  2063. else
  2064. {
  2065. $info_list[$key]['klarnaship'] = '';
  2066. }
  2067. }
  2068. if(isset($value['afterpaybill']))
  2069. {
  2070. $klarnadata = explode('|',$value['klarnadata']);
  2071. if(isset($klarnadata[1]))
  2072. {
  2073. $info_list[$key]['afterpaybill'] = $klarnadata[1];
  2074. }
  2075. else
  2076. {
  2077. $info_list[$key]['afterpaybill'] = '';
  2078. }
  2079. }
  2080. if(isset($value['afterpayship']))
  2081. {
  2082. $klarnadata = explode('|',$value['klarnadata']);
  2083. if(isset($klarnadata[2]))
  2084. {
  2085. $info_list[$key]['afterpayship'] = $klarnadata[2];
  2086. }
  2087. else
  2088. {
  2089. $info_list[$key]['afterpayship'] = '';
  2090. }
  2091. }
  2092. if(isset($value['PPname']))
  2093. {
  2094. $info_list[$key]['PPname'] = '';
  2095. $klarnadata = explode('|',$value['klarnadata']);
  2096. if(isset($klarnadata[1]))
  2097. {
  2098. $klarnadata = json_decode($klarnadata[1],true);
  2099. if(isset($klarnadata['name']))
  2100. {
  2101. $info_list[$key]['PPname'] = $klarnadata['name'];
  2102. }
  2103. }
  2104. }
  2105. if(isset($value['PPemail']))
  2106. {
  2107. $info_list[$key]['PPemail'] = '';
  2108. $klarnadata = explode('|',$value['klarnadata']);
  2109. if(isset($klarnadata[1]))
  2110. {
  2111. $klarnadata = json_decode($klarnadata[1],true);
  2112. if(isset($klarnadata['email']))
  2113. {
  2114. if($usp['excelpass'] == '1')
  2115. {
  2116. $ppemailpass = $this->setting->get_excelpass($klarnadata['email']);
  2117. }
  2118. else
  2119. {
  2120. $ppemailpass = $klarnadata['email'];
  2121. }
  2122. $info_list[$key]['PPemail'] = $ppemailpass;
  2123. }
  2124. }
  2125. }
  2126. if(isset($value['PPaddress']))
  2127. {
  2128. $info_list[$key]['PPaddress'] = '';
  2129. $klarnadata = explode('|',$value['klarnadata']);
  2130. if(isset($klarnadata[1]))
  2131. {
  2132. $klarnadata = json_decode($klarnadata[1],true);
  2133. if(isset($klarnadata['address']))
  2134. {
  2135. $info_list[$key]['PPaddress'] = $klarnadata['address'];
  2136. }
  2137. }
  2138. }
  2139. if(isset($value['klarnadata']))
  2140. {
  2141. unset($info_list[$key]['klarnadata']);
  2142. }
  2143. if(isset($value['shippingmethod']))
  2144. {
  2145. $tax = explode('Tax:',$value['shippingmethod']);
  2146. $info_list[$key]['shippingmethod'] = (isset($tax[1]))?trim($tax[1],';'):'';
  2147. }
  2148. if(isset($value['systemwigsout']))
  2149. {
  2150. $out = $this->systemtransfer->find_all("number = '".$data['number']."'");
  2151. $outread = '';
  2152. if($out)
  2153. {
  2154. foreach ($out as $val)
  2155. {
  2156. $list = '';
  2157. $rk = explode('|',trim($val['rk'],'|'));
  2158. $rktime = explode('|',trim($val['rktime'],'|'));
  2159. $zw = array();
  2160. $t = $this->transfer->find_all("1=1");
  2161. foreach ($t as $v)
  2162. {
  2163. $zw[$v['id']] = $v['title'];
  2164. }
  2165. if($val['rk'] != '' && count($rk) > 0)
  2166. {
  2167. for($i=0;$i<count($rk);$i++)
  2168. {
  2169. if(!isset($rktime[$i]))
  2170. {
  2171. $list .= $zw[$cz[$i]];
  2172. }
  2173. else
  2174. {
  2175. $list .= $zw[$rk[$i]].' :'.date('Y-m-d H:i',$rktime[$i]).',';
  2176. }
  2177. }
  2178. }
  2179. $outread .= '<span style="color:#f00">'.$val['pm'].'</span>:'.$list.'<br>';
  2180. }
  2181. }
  2182. else
  2183. {
  2184. $systemwigsout = $this->systemwigsout->find_all("number = '".$data['number']."'");
  2185. if($systemwigsout)
  2186. {
  2187. foreach ($systemwigsout as $v)
  2188. {
  2189. $outread = '';
  2190. if($v['czwarehouse'] == 37)
  2191. {
  2192. $outread .= '华荣厂';
  2193. }
  2194. else if($v['czwarehouse'] == 0)
  2195. {
  2196. $outread .= '龙盈厂';
  2197. }
  2198. $cz = explode('|',trim($v['cz'],'|'));
  2199. $cztime = explode('|',trim($v['cztime'],'|'));
  2200. $zw = $this->transfer->get_list();
  2201. if($v['cz'] != '' && count($cz) > 0)
  2202. {
  2203. for($i=0;$i<count($cz);$i++)
  2204. {
  2205. if(!isset($cztime[$i]))
  2206. {
  2207. $outread .= $zw[$cz[$i]].' -&gt; ';
  2208. }
  2209. else
  2210. {
  2211. $outread .= $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]).' -&gt; ';
  2212. }
  2213. }
  2214. $outread .= '<br>';
  2215. }
  2216. }
  2217. }
  2218. }
  2219. $info_list[$key]['systemwigsout'] = $outread;
  2220. }
  2221. if(isset($value['sourcetype']))
  2222. {
  2223. if($value['sourcetype'] == '1')
  2224. {
  2225. $info_list[$key]['sourcetype'] = '网红单';
  2226. }
  2227. else if($value['sourcetype'] == '2')
  2228. {
  2229. $info_list[$key]['sourcetype'] = '批发单';
  2230. }
  2231. else if($value['sourcetype'] == '3')
  2232. {
  2233. $info_list[$key]['sourcetype'] = '线下单';
  2234. }
  2235. else if($value['sourcetype'] == '4')
  2236. {
  2237. $info_list[$key]['sourcetype'] = '售后单';
  2238. }
  2239. else if($value['sourcetype'] == '5')
  2240. {
  2241. $info_list[$key]['sourcetype'] = '其它';
  2242. }
  2243. else
  2244. {
  2245. $info_list[$key]['sourcetype'] = '';
  2246. }
  2247. }
  2248. if(isset($value['js']))
  2249. {
  2250. if($value['js'] == '0')
  2251. {
  2252. $info_list[$key]['js'] = 'Ground Advantage';
  2253. }
  2254. else if($value['js'] == '1')
  2255. {
  2256. $info_list[$key]['js'] = 'PRIORITY';
  2257. }
  2258. else if($value['js'] == '2')
  2259. {
  2260. $info_list[$key]['js'] = 'EXPRESS';
  2261. }
  2262. else if($value['js'] == '3')
  2263. {
  2264. $info_list[$key]['js'] = 'IP';
  2265. }
  2266. else if($value['js'] == '4')
  2267. {
  2268. $info_list[$key]['js'] = 'FICP';
  2269. }
  2270. }
  2271. if(isset($value['type']))
  2272. {
  2273. $type = $this->warehouse->read($value['type']);
  2274. $info_list[$key]['type'] = $type['title'];
  2275. }
  2276. if(isset($value['xdcs']))
  2277. {
  2278. if($sj == 'fullorder')
  2279. {
  2280. $xdcs = $this->customer->get_email($data['email'],$data['shop']);
  2281. }
  2282. else
  2283. {
  2284. $xdcs = $this->customersmt->get_shopdata($data['shop'],$data['name'],$data['address']);
  2285. }
  2286. $info_list[$key]['xdcs'] = (isset($xdcs['num']))?(($xdcs['num']==0)?1:$xdcs['num']):1;
  2287. }
  2288. if(isset($value['dbapi']) || isset($value['scapi']))
  2289. {
  2290. $jmlist = '';$shuliang = '';
  2291. $classid = $this->classid->sku();
  2292. $dbapi = explode(';',trim($value['fpdata'],';'));
  2293. foreach ($dbapi as $va)
  2294. {
  2295. $pm = $classid;
  2296. $jm = $classid;
  2297. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  2298. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  2299. $ts = explode('|',trim($features,'|'));
  2300. if(stripos($ts[0],',') !== false)
  2301. {
  2302. $ft = explode(',',$ts[0]);
  2303. $features = explode('-',trim($ft[1],'-'));
  2304. $features[] = $ft[0];
  2305. }
  2306. else
  2307. {
  2308. $features = explode('-',trim($ts[0],'-'));
  2309. }
  2310. foreach($features as $k=>$v)
  2311. {
  2312. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  2313. {
  2314. if($typeclass[$v]['bm'] != '')
  2315. {
  2316. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  2317. }
  2318. }
  2319. if($v != 0 && isset($typeclass[$v]))
  2320. {
  2321. if($typeclass[$v]['classid'] == 13)
  2322. {
  2323. $dj = $typeclass[$v]['title'];
  2324. }
  2325. if($typeclass[$v]['classid'] == 8)
  2326. {
  2327. $ys = $typeclass[$v]['title'];
  2328. }
  2329. if($typeclass[$v]['classid'] == 15)
  2330. {
  2331. $hx = $typeclass[$v]['title'];
  2332. }
  2333. if(isset($pm[$typeclass[$v]['classid']]))
  2334. {
  2335. if($typeclass[$v]['title'] == '9A')
  2336. {
  2337. $pm[$typeclass[$v]['classid']] = '9A';
  2338. }
  2339. else if($typeclass[$v]['title'] == '10A')
  2340. {
  2341. $pm[$typeclass[$v]['classid']] = '10A';
  2342. }
  2343. else
  2344. {
  2345. $clzh = $typeclass[$v]['zh'];
  2346. if(stripos($typeclass[$v]['zh'],'|') !== false)
  2347. {
  2348. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  2349. $clzh = $clzh[0];
  2350. }
  2351. $pm[$typeclass[$v]['classid']] = $clzh;
  2352. }
  2353. }
  2354. if(isset($jm[$typeclass[$v]['classid']]))
  2355. {
  2356. if($typeclass[$v]['jm'])
  2357. {
  2358. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  2359. }
  2360. }
  2361. }
  2362. }
  2363. $jm = array_filter($jm);//去除空值
  2364. $jm = implode("-",$jm);
  2365. $jmlist .= $jm.'<br>';
  2366. $shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';
  2367. $pm = array_filter($pm);//去除空值
  2368. $zh = implode(" ",$pm);
  2369. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  2370. }
  2371. if(isset($value['dbapi']))
  2372. {
  2373. $info_list[$key]['dbapi'] = $jmlist;
  2374. }
  2375. else
  2376. {
  2377. $info_list[$key]['scapi'] = $shuliang;
  2378. }
  2379. }
  2380. if(isset($value['dbapi']) && isset($value['scapi']))
  2381. {
  2382. $jmlist = '';$shuliang = '';
  2383. $classid = $this->classid->sku();
  2384. $dbapi = explode(';',trim($value['fpdata'],';'));
  2385. foreach ($dbapi as $va)
  2386. {
  2387. $pm = $classid;
  2388. $jm = $classid;
  2389. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  2390. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  2391. $ts = explode('|',trim($features,'|'));
  2392. if(stripos($ts[0],',') !== false)
  2393. {
  2394. $ft = explode(',',$ts[0]);
  2395. $features = explode('-',trim($ft[1],'-'));
  2396. $features[] = $ft[0];
  2397. }
  2398. else
  2399. {
  2400. $features = explode('-',trim($ts[0],'-'));
  2401. }
  2402. foreach($features as $k=>$v)
  2403. {
  2404. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  2405. {
  2406. if($typeclass[$v]['bm'] != '')
  2407. {
  2408. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  2409. }
  2410. }
  2411. if($v != 0 && isset($typeclass[$v]))
  2412. {
  2413. if($typeclass[$v]['classid'] == 13)
  2414. {
  2415. $dj = $typeclass[$v]['title'];
  2416. }
  2417. if($typeclass[$v]['classid'] == 8)
  2418. {
  2419. $ys = $typeclass[$v]['title'];
  2420. }
  2421. if($typeclass[$v]['classid'] == 15)
  2422. {
  2423. $hx = $typeclass[$v]['title'];
  2424. }
  2425. if(isset($pm[$typeclass[$v]['classid']]))
  2426. {
  2427. if($typeclass[$v]['title'] == '9A')
  2428. {
  2429. $pm[$typeclass[$v]['classid']] = '9A';
  2430. }
  2431. else if($typeclass[$v]['title'] == '10A')
  2432. {
  2433. $pm[$typeclass[$v]['classid']] = '10A';
  2434. }
  2435. else
  2436. {
  2437. $clzh = $typeclass[$v]['zh'];
  2438. if(stripos($typeclass[$v]['zh'],'|') !== false)
  2439. {
  2440. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  2441. $clzh = $clzh[0];
  2442. }
  2443. $pm[$typeclass[$v]['classid']] = $clzh;
  2444. }
  2445. }
  2446. if(isset($jm[$typeclass[$v]['classid']]))
  2447. {
  2448. if($typeclass[$v]['jm'])
  2449. {
  2450. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  2451. }
  2452. }
  2453. }
  2454. }
  2455. $jm = array_filter($jm);//去除空值
  2456. $jm = implode("-",$jm);
  2457. $jmlist .= $jm.'<br>';
  2458. $shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';
  2459. $pm = array_filter($pm);//去除空值
  2460. $zh = implode(" ",$pm);
  2461. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  2462. }
  2463. $info_list[$key]['dbapi'] = $jmlist;
  2464. $info_list[$key]['scapi'] = $shuliang;
  2465. }
  2466. if(isset($value['cpfpdata']))
  2467. {
  2468. $fpread = '';
  2469. $cpfpdata = explode(';',trim($value['fpdata'],';'));
  2470. foreach ($cpfpdata as $v)
  2471. {
  2472. $va = explode('|',trim($v,'|'));
  2473. if(isset($va[1])){
  2474. $fpread .= $va[1].'; ';
  2475. }else{
  2476. $fpread .="合并单没有产品异常标记";
  2477. }
  2478. }
  2479. $info_list[$key]['cpfpdata'] = $fpread;
  2480. }
  2481. unset($info_list[$key]['id']);
  2482. unset($info_list[$key]['fpdata']);
  2483. }
  2484. return [
  2485. 'info_list'=>$info_list,
  2486. 'shouldmoney'=>$shouldmoney
  2487. ];
  2488. }
  2489. //上传运单
  2490. public function _waybill($arg_array)
  2491. {
  2492. $readid = $arg_array[0];
  2493. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  2494. /* 订单加入键值-k */
  2495. $fdata = $this->fullorder->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and dlz < 1 and state = 207');
  2496. foreach ($fdata as $v)
  2497. {
  2498. $dataorder[$v['orderinfo']] = $v;
  2499. }
  2500. $sdata = $this->fullordersmt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
  2501. foreach ($sdata as $v)
  2502. {
  2503. $dataorder[$v['orderinfo']] = $v;
  2504. }
  2505. $tdata = $this->fullordertt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
  2506. foreach ($tdata as $v)
  2507. {
  2508. $dataorder[$v['orderinfo']] = $v;
  2509. }
  2510. $xdata = $this->fullorderxw->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
  2511. foreach ($xdata as $v)
  2512. {
  2513. $dataorder[$v['orderinfo']] = $v;
  2514. }
  2515. /* 订单加入键值-j */
  2516. /* 店铺加入键值-j */
  2517. $fshop = $this->shop->find_all('1=1');
  2518. foreach ($fshop as $v)
  2519. {
  2520. $datashop[$v['id']] = $v;
  2521. }
  2522. /* 店铺加入键值-k */
  2523. /* 快递加入键值-j */
  2524. $fex = $this->express->find_all('1=1');
  2525. foreach ($fex as $v)
  2526. {
  2527. $dataex[$v['id']] = $v;
  2528. }
  2529. /* 快递加入键值-k */
  2530. /* 仓库加入键值-k */
  2531. $fwh = $this->warehouse->find_all('1=1');
  2532. foreach ($fwh as $v)
  2533. {
  2534. $datack[$v['id']] = $v;
  2535. }
  2536. /* 仓库加入键值-j */
  2537. $fs = $this->notice->get_ordertatus(216);//216成功状态
  2538. if(is_numeric($readid) == false || $readid < 1)
  2539. {
  2540. echo json_encode(array('msg'=>'店铺信息错误!','success'=>true));exit;
  2541. }
  2542. $dir = '/data/excel/'.date('Ymd',time()).'/';
  2543. $config['upload_path'] = '.'.$dir ;
  2544. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  2545. $config['allowed_types'] = 'xls|xlsx|csv';
  2546. $config['max_size'] = 10240;
  2547. $this->load->library('upload', $config);
  2548. $this->upload->initialize($config);
  2549. if ($this->upload->do_upload('userfile'))
  2550. {
  2551. $full_path = $dir.$this->upload->data('file_name');
  2552. $fileName = '.' . $full_path;
  2553. if (!file_exists($fileName))
  2554. {
  2555. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  2556. }
  2557. else
  2558. {
  2559. require_once "./data/excel/PHPExcel/IOFactory.php";
  2560. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  2561. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  2562. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  2563. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  2564. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  2565. ++$column;//如果列数大于26行
  2566. $list = array();
  2567. for ($i = 2; $i <= $row; $i++) // 行数循环
  2568. {
  2569. $data = array();
  2570. for ($c = 'A'; $c != $column; $c++) // 列数循环
  2571. {
  2572. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  2573. }
  2574. $list[] = $data;
  2575. }
  2576. }
  2577. $i = 0;$j = 0;$ed = array();$cscs = array();
  2578. $this->db->trans_begin();
  2579. foreach ($list as $key=>$value)
  2580. {
  2581. $ddh = preg_replace('/\D/s','',$value['0']);
  2582. $ydh = preg_replace('/\W/s','',$value['1']);
  2583. $shop = $datashop[$readid];
  2584. if($shop['type'] == '269')
  2585. {
  2586. $orid = $readid.$ddh;
  2587. }
  2588. else
  2589. {
  2590. $orid = $ddh;
  2591. }
  2592. if(isset($dataorder[$orid]))
  2593. {
  2594. if($shop['type'] == 269)//独立站前缀需要添加ID
  2595. {
  2596. $time = time();
  2597. $xg = $dataorder[$orid];
  2598. $oldw = $xg['waybill'];
  2599. $ex = $dataex[$xg['express']];
  2600. $warehouse = $datack[$xg['type']];
  2601. $msg = $ydh;
  2602. $xg['waybill'] = $ydh;
  2603. $fs = $this->notice->find_all("shop = '".$xg['shop']."' and message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");
  2604. if(isset($fs[0]))
  2605. {
  2606. $fs = $fs[0];
  2607. $fs['email'] = $this->emaildata->read($fs['email']);
  2608. if(($xg['dlzemail'] == 1 && $msg != $oldw) || $xg['dlzemail'] == 0)
  2609. {
  2610. $ck = $this->notice->get_god($xg,$shop,$ex,$fs);
  2611. if($ck == 1)
  2612. {
  2613. $ckemail = '邮件发送成功,';
  2614. $this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$xg['id']);
  2615. }
  2616. }
  2617. }
  2618. if($msg != $oldw)
  2619. {
  2620. if($xg['source'] != 1)
  2621. {
  2622. $ms = $this->message->find_all("express like '%,".$xg['express'].",%'");
  2623. if(!isset($ms[0]))
  2624. {
  2625. $ms = $this->message->read(2);
  2626. }
  2627. else
  2628. {
  2629. $ms = $ms[0];
  2630. }
  2631. $ddh = substr($xg['orderinfo'],1);
  2632. $shopifyid = $xg['shopify'];
  2633. //独立站地址更新订单状态、物流信息
  2634. $shopname = $shop['brandname']; //店铺名
  2635. $buyername = $xg['bname']; //Bill Name
  2636. $email_call = $shop['shopid']; //发货人邮箱;
  2637. $phone = $shop['shopphone']; //发货人电话
  2638. $track_type = $ex['title']; //快递名称
  2639. $service = $ex['title']; //快递追踪名称
  2640. $track_link = $ex['url']; //快递查询网址
  2641. $logistics_number = $ydh; //运单号
  2642. $t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%','%jtime%');
  2643. $h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone,$ex['yjtime']);
  2644. $remark = str_replace($t,$h,$ms['content']);
  2645. @$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$remark,$shopifyid);
  2646. }
  2647. else if($xg['source'] == 1)
  2648. {
  2649. $gx['res'] = 3;
  2650. $gx['state'] = 216;
  2651. }
  2652. }
  2653. else
  2654. {
  2655. $gx['res'] = $xg['dlz'];
  2656. $gx['state'] = $xg['state'];
  2657. }
  2658. $xg['iscode'] = $ex['title'];
  2659. $xg['url'] = $shop['shopname'];
  2660. @$chuanshu = $this->api->get_paypal($xg);
  2661. //$this->afspaypal->insert(array('number'=>$xg['number'],'cs'=>$chuanshu));
  2662. $this->fullorder->save(array('waybill'=>$msg,'state'=>$gx['state'],'dlz'=>$gx['res']),$xg['id']);
  2663. /**
  2664. $xg = $dataorder[$arg_array[0].$ddh];
  2665. $ex = $dataex[$xg['express']];
  2666. $warehouse = $datack[$xg['type']];
  2667. if($xg['source'] != 1 && $ex['iscode'] != 'Other' && $xg['state'] == '207')
  2668. {
  2669. //独立站地址更新订单状态、物流信息
  2670. $gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$xg['msg'],$xg['msg'],$dataorder[$orid]['shopify']);
  2671. if(!isset($gx['res']))
  2672. {
  2673. $ed[] = array($ddh.'-更新失败');
  2674. $j++;
  2675. continue;
  2676. }
  2677. $this->fullorder->save(array('waybill'=>$ydh,'dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);
  2678. if($gx['res'] == 1 && $fs)
  2679. {
  2680. $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  2681. }
  2682. }
  2683. else if($xg['source'] == 1 && $xg['state'] == '207')
  2684. {
  2685. $this->fullorder->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);
  2686. if($fs)
  2687. {
  2688. $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  2689. }
  2690. }
  2691. else
  2692. {
  2693. $ed[] = array($ddh.'-状态错误');
  2694. $j++;
  2695. continue;
  2696. }
  2697. **/
  2698. }
  2699. else if($shop['type'] == 270)//速卖通对接发货声明
  2700. {
  2701. $xg = $dataorder[$ddh];
  2702. $ex = $dataex[$xg['express']];
  2703. $warehouse = $datack[$xg['type']];
  2704. if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['library'] == 2 && ($xg['dlz'] == '0' || $xg['dlz'] == '2'))
  2705. {
  2706. $result = $this->apismt->get_out($ydh,'all',$xg['orderinfo'],$ex['aecode'],$sp['code']);
  2707. if(isset($result['result_success']) && $result['result_success'] == "true")
  2708. {
  2709. $this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$xg['id']);
  2710. /** 合并信息处理开始-发货声明 **/
  2711. if($xg['merge'] != '0')
  2712. {
  2713. $hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz = '0' and source != 1");$l=0;
  2714. foreach ($hdata as $v)
  2715. {
  2716. $result = $this->apismt->get_out($ydh,'all',$v['orderinfo'],$ex['aecode'],$sp['code']);
  2717. if(isset($result['result_success']) && $result['result_success'] == "true")
  2718. {
  2719. $this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$v['id']);
  2720. }
  2721. else
  2722. {
  2723. $ed[] = array($v['orderinfo'].'-合并单发货声明失败,请在ERP上手动操作此单');
  2724. $j++;
  2725. continue;
  2726. }
  2727. $l++;
  2728. if($l > 10)
  2729. {
  2730. break;
  2731. }
  2732. }
  2733. }
  2734. /** 合并信息处理结束开始 **/
  2735. }
  2736. else
  2737. {
  2738. $ed[] = array($ddh.'-发货声明失败');
  2739. $j++;
  2740. continue;
  2741. }
  2742. }
  2743. else if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['dlz'] == '1' && $xg['library'] == 2)//修改声明
  2744. {
  2745. $obtain = $this->apismt->get_obtain($xg['orderinfo'],$sp['code']);//修改声明先查询之前物流信息
  2746. if(isset($obtain['logistics_no']))
  2747. {
  2748. $result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$xg['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);
  2749. }
  2750. if(isset($result['result_success']) && $result['result_success'] == "true")
  2751. {
  2752. $this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);
  2753. /** 合并信息处理开始-修改声明 **/
  2754. if($xg['merge'] != '0')
  2755. {
  2756. $hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz != 1 and source != 1");$l=0;
  2757. foreach ($hdata as $v)
  2758. {
  2759. $obtain = $this->apismt->get_obtain($v['orderinfo'],$sp['code']);//修改声明先查询之前物流信息
  2760. if(isset($obtain['logistics_no']))
  2761. {
  2762. $result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$v['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);
  2763. }
  2764. if(isset($result['result_success']) && $result['result_success'] == "true")
  2765. {
  2766. $this->fullordersmt->save(array('waybill'=>$ydh),$v['id']);
  2767. }
  2768. else
  2769. {
  2770. $ed[] = array($v['orderinfo'].'-合并单修改发货声明失败,请在ERP上手动操作此单');
  2771. $j++;
  2772. continue;
  2773. }
  2774. $l++;
  2775. if($l > 10)
  2776. {
  2777. break;
  2778. }
  2779. }
  2780. }
  2781. /** 合并信息处理结束开始 **/
  2782. }
  2783. else
  2784. {
  2785. $ed[] = array($ddh.'-修改发货声明失败');
  2786. $j++;
  2787. continue;
  2788. }
  2789. }
  2790. else if($xg['source'] == 1 && $xg['state'] == '207')
  2791. {
  2792. $this->fullordersmt->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);
  2793. }
  2794. else
  2795. {
  2796. $this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);
  2797. }
  2798. }
  2799. }
  2800. else
  2801. {
  2802. $ed[] = array($ddh.'-单号错误或重复操作');
  2803. $i++;
  2804. continue;
  2805. }
  2806. sleep(1);//停留1秒
  2807. }
  2808. if ($this->db->trans_status() === FALSE)
  2809. {
  2810. $this->db->trans_rollback();
  2811. }
  2812. else
  2813. {
  2814. $this->db->trans_commit();
  2815. }
  2816. if($i+$j > 0)
  2817. {
  2818. $time = date('Ymd',time());
  2819. $title = '错误信息-'.$time;
  2820. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  2821. $tail = "\n";
  2822. $filename = $title.".xls";
  2823. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  2824. $dir = '/data/excel/'.$time.'/';
  2825. $file_name = 'error_'.$time.rand(1000,9999);
  2826. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  2827. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  2828. fwrite($myfile,$ecl);
  2829. fclose($myfile);
  2830. $error = $dir.$file_name.'.xls';
  2831. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  2832. }
  2833. else
  2834. {
  2835. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  2836. }
  2837. }
  2838. else
  2839. {
  2840. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2841. }
  2842. }
  2843. //上传速卖通订单
  2844. public function _order($arg_array)
  2845. {
  2846. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  2847. /* 订单加入键值-k */
  2848. $fdata = $this->fullorder_smt->find_all('dtime >'.(time()-5*24*3600));
  2849. foreach ($fdata as $v)
  2850. {
  2851. $dataorder[$v['orderinfo']] = $v;
  2852. }
  2853. /* 订单加入键值-j */
  2854. $dir = '/data/excel/'.date('Ymd',time()).'/';
  2855. $config['upload_path'] = '.'.$dir ;
  2856. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  2857. $config['allowed_types'] = 'xls|xlsx|csv';
  2858. $config['max_size'] = 10240;
  2859. $this->load->library('upload', $config);
  2860. $this->upload->initialize($config);
  2861. if ($this->upload->do_upload('userfile'))
  2862. {
  2863. $full_path = $dir.$this->upload->data('file_name');
  2864. $fileName = '.' . $full_path;
  2865. if (!file_exists($fileName))
  2866. {
  2867. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  2868. }
  2869. else
  2870. {
  2871. require_once "./data/excel/PHPExcel/IOFactory.php";
  2872. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  2873. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  2874. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  2875. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  2876. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  2877. ++$column;//如果列数大于26行
  2878. $list = array();
  2879. for ($i = 2; $i <= $row; $i++) // 行数循环
  2880. {
  2881. $data = array();
  2882. for ($c = 'A'; $c != $column; $c++) // 列数循环
  2883. {
  2884. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  2885. }
  2886. $list[] = $data;
  2887. }
  2888. }
  2889. $i = 0;$j = 0;$ed = array();$tytime = time();
  2890. foreach ($list as $key=>$value)
  2891. {
  2892. $value['2'] = preg_replace('/\D/s','',$value['2']);
  2893. if($value['2'] && !isset($dataorder[$value['2']]))
  2894. {
  2895. $num = $this->fullorder_smt->find_count('gtime = "'.date('Ymd',time()).'"');
  2896. $post['source'] = 2;//订单类型:1.线下订单2.PC3.手机
  2897. $post['state'] = 207;//订单状态:207等待发货
  2898. $post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  2899. $post['reviewtime'] = $tytime;//审核时间
  2900. $post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印
  2901. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  2902. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  2903. if($post['print'] != 3)
  2904. {
  2905. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  2906. }
  2907. $value['1'] = trim($value['1'],' ');
  2908. $shortname = explode('-',$value['1']);
  2909. $shortname = $this->shop->get_shortname($shortname[0]);
  2910. if(!$shortname)
  2911. {
  2912. $ed[] = array($value['1'].'-编码有问题');
  2913. $i++;
  2914. continue;
  2915. }
  2916. $post['shop'] = $shortname['id']?$shortname['id']:0;//速卖通
  2917. $post['user'] = '无';
  2918. $post['number'] = $value['1'];//编号
  2919. $post['orderinfo'] = $value['2'];//订单号
  2920. $post['client'] = preg_replace('/( | | |\s)/',' ',$value['3']);//客户名称
  2921. $post['buytime'] = $tytime;//时间转UX
  2922. $post['dtime'] = $tytime;//订单时间
  2923. $post['gtime'] = date('Ymd',$tytime);//格式化时间
  2924. //$post['pay'] = $this->input->post('pay',true);//支付方式
  2925. $post['capital'] = 3;//资金状态
  2926. $post['type'] = 5;//发货仓库
  2927. $post['currency'] = 219;//币种
  2928. $post['currencytitle'] = 'USD';//币种名称
  2929. $post['freight'] = 0;//运费
  2930. $post['expressmoney'] = 0;//物流金额
  2931. $post['shouldmoney'] = 0;//应收金额
  2932. $post['budget'] = 0;//应到金额*店铺到帐金额比
  2933. $orderremarks = '';//订单备注
  2934. $post['shipremarks'] = $value['12'];//仓库品名
  2935. $post['email'] = '';//邮箱
  2936. $post['name'] = preg_replace('/( | | |\s)/',' ',$value['3']);//名字
  2937. $post['phone'] = $value['10'];//电话
  2938. $post['country'] = 192;//国家
  2939. $ct = $this->country->get_ename($value['9']);//国家
  2940. $post['al'] = $ct['lb'];//国家二字码
  2941. $post['province'] = $value['8'];//省、州
  2942. $post['city'] = $value['6'];//城市
  2943. $post['zipcode'] = $value['7'];//邮编
  2944. $post['address'] = $value['4'];//地址1
  2945. $post['address2'] = $value['5']?$value['5']:'';//地址2
  2946. $post['express'] = 2;//快递
  2947. $post['printtype'] = 1;//打印类型
  2948. $post['fpdata'] = '';//购买产品内容
  2949. $post['sbpm'] = 'Hair Sample';//申报品名
  2950. $post['zwpm'] = '假发';//中文品名
  2951. $post['ts'] = $value['17'];//条数
  2952. $post['dtsbjz'] = 15;//单条申报价
  2953. $post['zsbjz'] = 15;//总申报价
  2954. $post['zzl'] = 0.5;//总重量
  2955. $post['zjs'] = 1;//总件数
  2956. $post['quantity'] = 1;//数量
  2957. $post['paypal'] = '';//支付号
  2958. $post['guarantee'] = '';//卖家保障
  2959. $post['zzl'] = $value['13'];//总重量
  2960. $post['bx'] = $value['14'];//总重量
  2961. $post['qm'] = $value['15'];//总重量
  2962. $post['js'] = $value['16'];//总重量
  2963. $barcode = $this->usps->get_address(array('address'=>$value['4'],'address2'=>$value['5'],'city'=>$value['6'],'province'=>$value['8'],'zipcode'=>$value['7']));
  2964. if(isset($barcode['Address']['Error']['Description']))
  2965. {
  2966. $ed[] = array($value['1'].'-'.$barcode['Address']['Error']['Description']);
  2967. $i++;
  2968. }
  2969. else
  2970. {
  2971. $this->fullorder_smt->insert($post);
  2972. }
  2973. }
  2974. else
  2975. {
  2976. $ed[] = array($value['1'].'-单号错误或重复操作');
  2977. $i++;
  2978. }
  2979. sleep(2);//停留2秒
  2980. }
  2981. if($i+$j > 0)
  2982. {
  2983. $time = date('Ymd',time());
  2984. $title = '错误信息-'.$time;
  2985. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  2986. $tail = "\n";
  2987. $filename = $title.".xls";
  2988. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  2989. $dir = '/data/excel/'.$time.'/';
  2990. $file_name = 'error_'.$time.rand(1000,9999);
  2991. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  2992. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  2993. fwrite($myfile,$ecl);
  2994. fclose($myfile);
  2995. $error = $dir.$file_name.'.xls';
  2996. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  2997. }
  2998. else
  2999. {
  3000. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  3001. }
  3002. }
  3003. else
  3004. {
  3005. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  3006. }
  3007. }
  3008. public function _email($content,$data,$shopname)
  3009. {
  3010. $express = $this->express->read($data['express']);
  3011. $t= array('$userName','$orderid','$trackingNumber','$expressCompany','$contactPerson','$mobileNo','$zip','$recipientAddress');//需要被替换的内容
  3012. $h= array($data['client'],$data['orderinfo'],$data['waybill'],$express['servicename'],$data['name'],$data['phone'],$data['zipcode'],$data['address']);//替换的内容
  3013. $content = str_replace($t,$h,$content);
  3014. $this->load->library('email');
  3015. $config['protocol'] = 'smtp';
  3016. $config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
  3017. $config['smtp_port'] = 465;
  3018. $config['smtp_user'] = 'service@email.supernovahair.com';
  3019. $config['smtp_pass'] = 'LONGyihair374';
  3020. $config['smtp_crypto'] = 'ssl';
  3021. $config['crlf'] = "\r\n";
  3022. $config['newline'] = "\r\n";
  3023. $this->email->initialize($config);
  3024. $this->email->from('service@email.supernovahair.com',$shopname);
  3025. $this->email->to($data['email']);//收件
  3026. $this->email->subject('The product you purchased has a new progress');//标题
  3027. $this->email->message($content);//内容
  3028. if ( ! $this->email->send())
  3029. {
  3030. return 2;
  3031. }
  3032. else
  3033. {
  3034. return 1;
  3035. }
  3036. }
  3037. //导出订单excel
  3038. public function _cs()
  3039. {
  3040. if(isset($_GET['fexcel']))
  3041. {
  3042. if(isset($_SESSION['api']))
  3043. {
  3044. $user = $this->user->get_api($_SESSION['api']);
  3045. $usp = $user;
  3046. $fgshop = "";$sid = "";
  3047. $user = explode('|',trim($user['shop'],'|'));
  3048. foreach ($user as $value)
  3049. {
  3050. $fgshop .= " shop = ".$value." or";
  3051. $sid .= " id = ".$value." or";
  3052. }
  3053. }
  3054. $dowid = $this->input->get('a');
  3055. $wid = "";
  3056. if($dowid != "")
  3057. {
  3058. $id_arr = explode(',',rtrim($dowid,','));
  3059. foreach ($id_arr as $v)
  3060. {
  3061. $wid .= " id = 0 or";
  3062. $wid .= " id = '$v' or";
  3063. }
  3064. $wid = " and".rtrim($wid,'or');
  3065. }
  3066. $fexcel = $this->input->get('fexcel',true);
  3067. $page = $this->input->get('page',true);
  3068. $perpage = $this->input->get('perpage',true);
  3069. $warehouse = $this->input->get('warehouse',true);
  3070. $timetk = $this->input->get('timetk',true);
  3071. $timetj = $this->input->get('timetj',true);
  3072. $shop = $this->input->get('shop',true);
  3073. $source = $this->input->get('source',true);
  3074. $state = $this->input->get('state',true);
  3075. $review = $this->input->get('review',true);
  3076. $type = $this->input->get('type',true);
  3077. $express = $this->input->get('express',true);
  3078. $orderinfo = $this->input->get('orderinfo',true);
  3079. $user = $this->input->get('user',true);
  3080. $client = $this->input->get('name',true);
  3081. $waybill = $this->input->get('waybill',true);
  3082. $number = $this->input->get('number',true);
  3083. $email = $this->input->get('email',true);
  3084. $dlz = $this->input->get('dlz',true);
  3085. $library = $this->input->get('library',true);
  3086. $libraryconfirm = $this->input->get('libraryconfirm',true);
  3087. $print = $this->input->get('print',true);
  3088. $timetkk = $this->input->get('timetkk',true);
  3089. $timetjj = $this->input->get('timetjj',true);
  3090. $timetk = strtotime($timetk);
  3091. $timetj = strtotime($timetj);
  3092. $timetkk = strtotime($timetkk);
  3093. $timetjj = strtotime($timetjj);
  3094. $where = "mergeid = 0 and (".rtrim($fgshop,'or').")";
  3095. if($warehouse)
  3096. {
  3097. $where .= " and type = '$warehouse'";
  3098. }
  3099. if($timetk && $timetj)
  3100. {
  3101. $timetj = $timetj+24*3600;
  3102. $where .= " and dtime > '$timetk' and dtime < '$timetj'";
  3103. }
  3104. if($timetkk && $timetjj)
  3105. {
  3106. $where .= " and librarytime > '$timetkk' and librarytime < '$timetjj'";
  3107. }
  3108. if($library)
  3109. {
  3110. $where .= " and library = '$library'";
  3111. }
  3112. if($print)
  3113. {
  3114. $where .= " and print = '$print'";
  3115. }
  3116. if($shop)
  3117. {
  3118. $where .= " and shop = '$shop'";
  3119. }
  3120. if($source)
  3121. {
  3122. $where .= " and source = '$source'";
  3123. }
  3124. if($state)
  3125. {
  3126. $where .= " and state = '$state'";
  3127. }
  3128. if($review)
  3129. {
  3130. $where .= " and review = '$review'";
  3131. }
  3132. if($type)
  3133. {
  3134. $where .= " and type = '$type'";
  3135. }
  3136. if($express)
  3137. {
  3138. $where .= " and express = '$express'";
  3139. }
  3140. if($orderinfo)
  3141. {
  3142. $where .= " and orderinfo = '$orderinfo'";
  3143. }
  3144. if($user)
  3145. {
  3146. $where .= " and user = '$user'";
  3147. }
  3148. if($client)
  3149. {
  3150. $where .= " and client like '%$client%'";
  3151. }
  3152. if($waybill)
  3153. {
  3154. $where .= " and waybill = '$waybill'";
  3155. }
  3156. if($number)
  3157. {
  3158. $where .= " and number = '$number'";
  3159. }
  3160. if($email)
  3161. {
  3162. $where .= " and email = '$email'";
  3163. }
  3164. if($dlz)
  3165. {
  3166. $where .= " and waybill != '' and dlz = 0";
  3167. }
  3168. if($dlz)
  3169. {
  3170. $where .= " and libraryconfirm = '$libraryconfirm'";
  3171. }
  3172. $fexcel = $this->fullorderexcel->read($fexcel);
  3173. $fexceleq = explode("|",rtrim($fexcel['content'],'|'));
  3174. foreach ($fexceleq as $k=>$v)
  3175. {
  3176. $fexceleq[$k] = explode('-',$v);
  3177. $num[$k] = $fexceleq[$k][0];
  3178. }
  3179. //array_multisort($num,SORT_ASC,$fexceleq);//重新排序
  3180. $feq = "";
  3181. foreach ($fexceleq as $k=>$v)
  3182. {
  3183. $feq .= $v[1].',';
  3184. }
  3185. $feq = rtrim($feq,',');
  3186. $fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
  3187. foreach ($fexcelzhw as $k=>$v)
  3188. {
  3189. $fexcelzhw[$k] = explode('-',$v);
  3190. $numb[$k] = $fexcelzhw[$k][0];
  3191. }
  3192. //array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
  3193. $fexcelzh = array();
  3194. foreach ($fexcelzhw as $k=>$v)
  3195. {
  3196. $fexcelzh[] = $v[1];
  3197. }
  3198. //取得信息列表
  3199. $info_list = $this->fullorder->find_all($where.$wid,$feq,'id desc');
  3200. //格式化数据
  3201. $i = 1;$shouldmoney = 0;$hl=1;
  3202. foreach ($info_list as $key=>$value)
  3203. {
  3204. if(isset($value['currencytitle']))
  3205. {
  3206. if($value['currencytitle'] != "CNY")
  3207. {
  3208. $hl=$value['hl'];
  3209. }
  3210. $shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
  3211. $budget=$budget+($value['budget']*$hl);
  3212. $currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);
  3213. $refund=$refund+($value['refund']*$hl);
  3214. }
  3215. if(isset($value['shop']))
  3216. {
  3217. $shop = $this->shop->read($value['shop']);
  3218. $info_list[$key]['shop'] = $shop['shopname'];
  3219. }
  3220. if(isset($value['dtime']))
  3221. {
  3222. $info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
  3223. }
  3224. if(isset($value['country']))
  3225. {
  3226. $country = $this->country->read($value['country']);
  3227. $info_list[$key]['country'] = $country['name'];
  3228. }
  3229. if(isset($value['type']))
  3230. {
  3231. $type = $this->warehouse->read($value['type']);
  3232. $info_list[$key]['type'] = $type['title'];
  3233. }
  3234. if(isset($value['express']))
  3235. {
  3236. $express = $this->express->read($value['express']);
  3237. if($express)
  3238. {
  3239. $info_list[$key]['express'] = $express['servicename'];
  3240. }
  3241. else
  3242. {
  3243. $info_list[$key]['express'] = '未选择';
  3244. }
  3245. }
  3246. }
  3247. echo $timetkk;
  3248. }
  3249. }
  3250. public function _gggs($sku,$s,$j,$k)
  3251. {
  3252. $companytitle = array(9=>3,10=>2,11=>1,12=>4);
  3253. $this->load->database();
  3254. $this->db->select('id');
  3255. $this->db->from('crowd_whlabel');
  3256. $this->db->where('warehouse', '5');
  3257. $this->db->where('sku', $sku);
  3258. $this->db->where('state', '0');
  3259. $this->db->limit($s,$k);
  3260. $query = $this->db->get();
  3261. $ids = array_column($query->result_array(), 'id');
  3262. if (!empty($ids))
  3263. {
  3264. // 更新
  3265. $this->db->where_in('id', $ids);
  3266. $this->db->update('crowd_whlabel', array('companytitle' => $companytitle[$j]));
  3267. return $this->db->affected_rows();
  3268. }
  3269. }
  3270. public function _xxpl()
  3271. {
  3272. $this->load->database();
  3273. $data = ['type' => ''];
  3274. $this->db->update('crowd_whlabel', $data);
  3275. $wt = array();
  3276. $whlabel_type = $this->whlabel_type->find_all();
  3277. foreach ($whlabel_type as $v)
  3278. {
  3279. $wt[$v['title']] = $v['id'];
  3280. }
  3281. /* 订单加入键值-j */
  3282. $dir = '/data/excel/'.date('Ymd',time()).'/';
  3283. $config['upload_path'] = '.'.$dir ;
  3284. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  3285. $config['allowed_types'] = 'xls|xlsx|csv';
  3286. $config['max_size'] = 10240;
  3287. $this->load->library('upload', $config);
  3288. $this->upload->initialize($config);
  3289. if ($this->upload->do_upload('userfile'))
  3290. {
  3291. $full_path = $dir.$this->upload->data('file_name');
  3292. $fileName = '.' . $full_path;
  3293. if (!file_exists($fileName))
  3294. {
  3295. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  3296. }
  3297. else
  3298. {
  3299. require_once "./data/excel/PHPExcel/IOFactory.php";
  3300. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  3301. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  3302. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  3303. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  3304. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  3305. ++$column;//如果列数大于26行
  3306. $list = array();
  3307. for ($i = 2; $i <= $row; $i++) // 行数循环
  3308. {
  3309. $data = array();
  3310. for ($c = 'A'; $c != $column; $c++) // 列数循环
  3311. {
  3312. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  3313. }
  3314. $list[] = $data;
  3315. }
  3316. }
  3317. $wt = array();
  3318. $whlabel_type = $this->whlabel_type->find_all();
  3319. foreach ($whlabel_type as $v)
  3320. {
  3321. $wt[$v['title']] = $v['id'];
  3322. }
  3323. $j = 0;$ed = array();$e = 0;$c = 0;$cs = array();
  3324. foreach ($list as $v)
  3325. {
  3326. $this->load->database();
  3327. // 设置更新数据
  3328. $data = ['type' => $wt[$v[1]]];
  3329. // 添加条件:SKU 为 123456 且 warehouse 为 5
  3330. $this->db->where('SKU', $v[0]);
  3331. $this->db->where('warehouse', '5');
  3332. // 批量更新
  3333. $this->db->update('crowd_whlabel', $data);
  3334. }
  3335. /** 导入缺货
  3336. $time = time();
  3337. $whlabel = $this->whlabel->get_sku($v[0]);
  3338. if($whlabel)
  3339. {
  3340. $this->whlabel_qh->insert(array('sku'=>$whlabel['sku'],'features'=>$whlabel['features'],'num'=>$v['1'],'gtime'=>date('Ym',$time),'gxtime'=>date('Ymd',$time)));
  3341. }
  3342. else
  3343. {
  3344. $ed[] = $v['0'];
  3345. $j++;
  3346. }
  3347. }
  3348. **/
  3349. /**
  3350. 更换等级
  3351. $this->load->database();
  3352. // 设置更新数据
  3353. $data = ['type' => $wt[$v[1]]];
  3354. // 添加条件:SKU 为 123456 且 warehouse 为 5
  3355. $this->db->where('SKU', $v[0]);
  3356. $this->db->where('warehouse', '5');
  3357. // 批量更新
  3358. $this->db->update('crowd_whlabel', $data);
  3359. **/
  3360. /**
  3361. $whlabel_type = $this->whlabel_type->find_all();
  3362. foreach ($whlabel_type as $v)
  3363. {
  3364. $wt[$v['title']] = $v['id'];
  3365. }
  3366. foreach ($list as $v)
  3367. {
  3368. $w = $this->whlabel->find_all("sku = '".$v[0]."' and warehouse = 5");
  3369. if($w && isset($wt[$v[1]]))
  3370. {
  3371. foreach ($w as $val)
  3372. {
  3373. $this->whlabel->save(array('type'=>$wt[$v[1]]),$val['id']);
  3374. }
  3375. }
  3376. else
  3377. {
  3378. $ed[] = array($v[0],$v[1]);
  3379. $j++;
  3380. }
  3381. }
  3382. **/
  3383. if($e > 0)
  3384. {
  3385. $time = date('Ymd',time());
  3386. $title = '错误信息-'.$time;
  3387. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  3388. $tail = "\n";
  3389. $filename = $title.".xls";
  3390. @$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  3391. $dir = '/data/excel/'.$time.'/';
  3392. $file_name = 'error_'.$time.rand(1000,9999);
  3393. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  3394. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  3395. fwrite($myfile,$ecl);
  3396. fclose($myfile);
  3397. $error = $dir.$file_name.'.xls';
  3398. echo json_encode(array('msg'=>$j.'条异常,','error'=>$error,'success'=>true));exit;
  3399. }
  3400. else
  3401. {
  3402. echo json_encode(array('msg'=>'添加成功!'.$c,'success'=>true));exit;
  3403. }
  3404. }
  3405. else
  3406. {
  3407. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  3408. }
  3409. }
  3410. public function _skuzh()
  3411. {
  3412. /* 订单加入键值-j */
  3413. $dir = '/data/excel/'.date('Ymd',time()).'/';
  3414. $config['upload_path'] = '.'.$dir ;
  3415. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  3416. $config['allowed_types'] = 'xls|xlsx|csv';
  3417. $config['max_size'] = 10240;
  3418. $this->load->library('upload', $config);
  3419. $this->upload->initialize($config);
  3420. if ($this->upload->do_upload('userfile'))
  3421. {
  3422. $full_path = $dir.$this->upload->data('file_name');
  3423. $fileName = '.' . $full_path;
  3424. if (!file_exists($fileName))
  3425. {
  3426. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  3427. }
  3428. else
  3429. {
  3430. require_once "./data/excel/PHPExcel/IOFactory.php";
  3431. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  3432. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  3433. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  3434. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  3435. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  3436. ++$column;//如果列数大于26行
  3437. $list = array();
  3438. for ($i = 2; $i <= $row; $i++) // 行数循环
  3439. {
  3440. $data = array();
  3441. for ($c = 'A'; $c != $column; $c++) // 列数循环
  3442. {
  3443. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  3444. }
  3445. $list[] = $data;
  3446. }
  3447. }
  3448. $dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');
  3449. $dtc = array();
  3450. foreach ($dictionaries as $v)
  3451. {
  3452. if(stripos($v['spare'],'|') !== false)//如果有多个值
  3453. {
  3454. $v['spare'] = explode('|',$v['spare']);
  3455. foreach ($v['spare'] as $k=>$vs)
  3456. {
  3457. if(stripos($v['zh'],'|') !== false)
  3458. {
  3459. $vzh = explode('|',$v['zh']);
  3460. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  3461. }
  3462. else
  3463. {
  3464. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  3465. }
  3466. }
  3467. }
  3468. else
  3469. {
  3470. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  3471. }
  3472. }
  3473. $dictionaries2 = $this->typeclass->find_all();
  3474. foreach ($dictionaries2 as $v)
  3475. {
  3476. $dtctitle[$v['id']] = $v['title'];
  3477. }
  3478. /* 匹配结束 */
  3479. /* 价格加入 */
  3480. $money = array();
  3481. $productdescribe = $this->productdescribe->find_all('1=1');
  3482. foreach ($productdescribe as $v)
  3483. {
  3484. $money[$v['number']] = array();
  3485. }
  3486. /* 价格加入 */
  3487. /* 匹配ID加入 */
  3488. $int = array();
  3489. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  3490. foreach ($intdata as $v)
  3491. {
  3492. $v['spare'] = explode('|',$v['spare']);
  3493. $int[$v['id']] = $v['spare'][0];
  3494. }
  3495. /* 匹配ID加入 */
  3496. $zjsku = array();
  3497. $shopsku = $this->shopsku->find_all();
  3498. foreach ($shopsku as $val)
  3499. {
  3500. $ss = explode(',',trim($val['shop'],','));
  3501. foreach ($ss as $v)
  3502. {
  3503. if(isset($zjsku[$v]))
  3504. {
  3505. $zjsku[$v] .= ','.trim($val['sku'],',');
  3506. }
  3507. else
  3508. {
  3509. $zjsku[$v] = trim($val['sku'],',');
  3510. }
  3511. }
  3512. }
  3513. /* 匹配ID结束 */
  3514. $q = '1;';
  3515. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  3516. $shop = $this->shop->read(19);
  3517. if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
  3518. {
  3519. $sku = rtrim($sku,',').','.$zjsku[$shop['id']];
  3520. }
  3521. $ed = array();
  3522. foreach ($list as $v)
  3523. {
  3524. $r = $this->api->matching(trim($q,';'),$v['2'],$dtc,$money,$int,$dtctitle,$shop);
  3525. $p = '';
  3526. $product = explode(';',trim($r['product'],';'));
  3527. if($r['title'] != '' && $product)
  3528. {
  3529. foreach ($product as $val)
  3530. {
  3531. $vc = explode('|',$val);
  3532. if(isset($vc[1]))
  3533. {
  3534. $p .= $vc[1].'<br>';
  3535. }
  3536. }
  3537. $r['title'] = str_replace(array('<','>'),array('&lt;','&gt;'),$r['title']);
  3538. $ed[] = array($v['0'],$v['1'],$r['title'],$v['3'],$v['4'],$v['5']);
  3539. }
  3540. else
  3541. {
  3542. $ed[] = array($v['0'],$v['1'],$v['2'].' SKU错误',$v['3'],$v['4'],$v['5']);
  3543. }
  3544. }
  3545. $time = date('Ymd',time());
  3546. $title = 'sku转换'.$time;
  3547. $titlename = "<table border=1><tr><td>退款日期</td><td>订单号</td><td>SKU</td><td退款金额</td><td退款情况具体描述</td><可用/不可用</td></tr></table>";
  3548. $tail = "\n";
  3549. $filename = $title.".xls";
  3550. @$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  3551. $dir = '/data/excel/'.$time.'/';
  3552. $file_name = 'sku转换 '.$time.rand(1000,9999);
  3553. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  3554. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  3555. fwrite($myfile,$ecl);
  3556. fclose($myfile);
  3557. $error = $dir.$file_name.'.xls';
  3558. echo json_encode(array('msg'=>'转换成功!','error'=>$error,'success'=>true));exit;
  3559. }
  3560. else
  3561. {
  3562. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  3563. }
  3564. }
  3565. public function _xxpl_b()
  3566. {
  3567. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  3568. /* 订单加入键值-k */
  3569. $fdata = $this->fullordersmt->find_all('dtime >'.(time()-10*24*3600));
  3570. foreach ($fdata as $v)
  3571. {
  3572. $dataorder[$v['orderinfo']] = $v;
  3573. }
  3574. /* 订单加入键值-j */
  3575. $dir = '/data/excel/'.date('Ymd',time()).'/';
  3576. $config['upload_path'] = '.'.$dir ;
  3577. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  3578. $config['allowed_types'] = 'xls|xlsx|csv';
  3579. $config['max_size'] = 10240;
  3580. $this->load->library('upload', $config);
  3581. $this->upload->initialize($config);
  3582. if ($this->upload->do_upload('userfile'))
  3583. {
  3584. $full_path = $dir.$this->upload->data('file_name');
  3585. $fileName = '.' . $full_path;
  3586. if (!file_exists($fileName))
  3587. {
  3588. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  3589. }
  3590. else
  3591. {
  3592. require_once "./data/excel/PHPExcel/IOFactory.php";
  3593. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  3594. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  3595. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  3596. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  3597. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  3598. ++$column;//如果列数大于26行
  3599. $list = array();
  3600. for ($i = 2; $i <= $row; $i++) // 行数循环
  3601. {
  3602. $data = array();
  3603. for ($c = 'A'; $c != $column; $c++) // 列数循环
  3604. {
  3605. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  3606. }
  3607. $list[] = $data;
  3608. }
  3609. }
  3610. $i = 0;$j = 0;$ed = array();$time = time();
  3611. foreach ($list as $key=>$value)
  3612. {
  3613. $shop = $this->shop->get_shopname($value['2']);//通过店铺名称查找店铺
  3614. if(!$shop)
  3615. {
  3616. $ed[] = array($value['0'].'-无此店铺');
  3617. $i++;continue;
  3618. }
  3619. $post['buytime'] = strtotime($value['6']);//付款时间
  3620. $value['0'] = preg_replace('/\D/s','',$value['0']);
  3621. if($value['0'] && !isset($dataorder[$value['0']]))
  3622. {
  3623. $post['source'] = 2;//订单类型:1.线下订单2.PC3.手机
  3624. $post['state'] = 207;//订单状态:207等待发货
  3625. $post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  3626. $post['reviewtime'] = $time;//审核时间
  3627. $post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印
  3628. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  3629. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  3630. $post['dtime'] = $time;//订单时间
  3631. $post['capital'] = 3;//资金状态
  3632. $post['currency'] = 219;//币种
  3633. $post['currencytitle'] = 'USD';//币种名称
  3634. $post['freight'] = 0;//运费
  3635. $post['expressmoney'] = 0;//物流金额
  3636. $post['shouldmoney'] = 0;//应收金额
  3637. if($post['print'] != 3)
  3638. {
  3639. $post['librarynot'] = "订单未打印";//不能出库原因
  3640. }
  3641. $post['gtime'] = date('Ymd',$post['buytime']);//格式化时间
  3642. $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
  3643. $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  3644. $post['user'] = $shop['shopuser'];//店铺负责人
  3645. $post['orderinfo'] = $value['0'];//订单号
  3646. $post['type'] = $value['7'];//发货仓库
  3647. $post['shop'] = $shop['id'];//店铺
  3648. $post['shouldmoney'] = $value['3'];//订单金额
  3649. $post['product'] = $value['4']?$value['4']:'';//商品名称
  3650. $post['pay'] = $value['5'];//付款方式
  3651. $post['paypal'] = $value['1']?$value['1']:'';//交易号
  3652. $post['orderremarks'] = $value['8']?$value['8']:'';//订单备注
  3653. $post['shipremarks'] = $value['9'];//仓库品名
  3654. $post['client'] = preg_replace('/( | | | |\s)/',' ',$value['10']);//公司名
  3655. $post['name'] = preg_replace('/( | | | |\s)/',' ',$value['11']);//收货人
  3656. $post['phone'] = $value['12'];//电话
  3657. $ct = $this->country->get_ename(preg_replace('/( | | | |\s)/',' ',$value['13']));//国家
  3658. if(!$ct)
  3659. {
  3660. $ed[] = array($value['0'].'-无此国家');
  3661. $i++;continue;
  3662. }
  3663. $post['country'] = $ct['id'];//国家
  3664. $post['al'] = $ct['lb'];//国家二字码
  3665. $post['province'] = $value['14'];//省、州
  3666. $post['city'] = $value['15'];//城市
  3667. $post['zipcode'] = $value['16'];//邮编
  3668. $post['address'] = $value['17'];//地址1
  3669. $post['address2'] = $value['18']?$value['18']:'';//地址2
  3670. $yga = $value['3'];$ygb = $shop['estimaterate'];
  3671. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  3672. $post['sbpm'] = $value['19'];//申报品名
  3673. $post['zwpm'] = $value['20'];//中文品名
  3674. $post['ts'] = $value['21'];//条数
  3675. $post['dtsbjz'] = $value['22'];//单条申报价
  3676. $post['zsbjz'] = $value['23'];//总申报价
  3677. $post['zzl'] = $value['24'];//总重量
  3678. $post['zjs'] = $value['25'];//总件数
  3679. $express = $this->express->get_servicename(preg_replace('/( | | | |\s)/',' ',$value['26']));
  3680. if(!$express)
  3681. {
  3682. $ed[] = array($value['0'].'-无此快递方式');
  3683. $i++;continue;
  3684. }
  3685. $post['express'] = $express['id'];//快递
  3686. $post['printtype'] = 1;//打印类型 1.运单.2.发货单
  3687. $post['fpdata'] = '';//购买产品内容
  3688. $this->fullordersmt->insert($post);
  3689. }
  3690. else
  3691. {
  3692. $ed[] = array($value['0'].'-单号错误或重复操作');
  3693. $i++;
  3694. }
  3695. sleep(2);//停留2秒
  3696. }
  3697. if($i+$j > 0)
  3698. {
  3699. $time = date('Ymd',time());
  3700. $title = '错误信息-'.$time;
  3701. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  3702. $tail = "\n";
  3703. $filename = $title.".xls";
  3704. @$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  3705. $dir = '/data/excel/'.$time.'/';
  3706. $file_name = 'error_'.$time.rand(1000,9999);
  3707. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  3708. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  3709. fwrite($myfile,$ecl);
  3710. fclose($myfile);
  3711. $error = $dir.$file_name.'.xls';
  3712. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  3713. }
  3714. else
  3715. {
  3716. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  3717. }
  3718. }
  3719. else
  3720. {
  3721. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  3722. }
  3723. }
  3724. public function _scwd()
  3725. {
  3726. $dir = '/data/excel/'.date('Ymd',time()).'/';
  3727. $config['upload_path'] = '.'.$dir ;
  3728. $config['allowed_types'] = '*';
  3729. $config['max_size'] = 102400;
  3730. $this->load->library('upload', $config);
  3731. $this->upload->initialize($config);
  3732. if ($this->upload->do_upload('userfile'))
  3733. {
  3734. $full_path = $dir.$this->upload->data('file_name');
  3735. echo json_encode(array('msg'=>'成功!','wdurl'=>$full_path,'success'=>true));exit;
  3736. }
  3737. else
  3738. {
  3739. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  3740. }
  3741. }
  3742. public function _jmexcel()
  3743. {
  3744. $setting = $this->setting->get_settings();
  3745. $excelpass = $setting['excelpass'];
  3746. $excelusernum = $setting['excelusernum'];
  3747. $exceljmnum = $setting['exceljmnum'];
  3748. $user = $this->user->get_api($_SESSION['api']);
  3749. if(!isset($user['exceltime']))
  3750. {
  3751. $this->session->sess_destroy();
  3752. header("Location:/");
  3753. }
  3754. $post = $this->input->post(NULL, TRUE);
  3755. if(isset($post['data']))
  3756. {
  3757. $data = $this->input->post('data',true);
  3758. $data = str_replace("\n",",",$data);;
  3759. $data = explode(',',trim($data,','));
  3760. $d = '';$i = 0;
  3761. foreach ($data as $v)
  3762. {
  3763. if($v == '')
  3764. {
  3765. continue;
  3766. }
  3767. $j = $this->setting->get_jmexcelpass($v);
  3768. if($j == '')
  3769. {
  3770. $j = $v.' 信息不正确';
  3771. }
  3772. $d .= $j."<br />";
  3773. $i++;
  3774. }
  3775. if($i > $exceljmnum)
  3776. {
  3777. echo json_encode(array('msg'=>'每次解密数量不可超出'.$exceljmnum.'条','success'=>false));exit;
  3778. }
  3779. if($user['exceltime'] != date('Ymd',time()))
  3780. {
  3781. $this->user->save(array('exceltime'=>date('Ymd',time()),'excelnum'=>1),$user['id']);
  3782. }
  3783. else
  3784. {
  3785. if($user['excelnum'] > $excelusernum)
  3786. {
  3787. echo json_encode(array('msg'=>'今日此账号解密次数已使用完毕','success'=>false));exit;
  3788. }
  3789. else
  3790. {
  3791. $this->user->save(array('excelnum'=>$user['excelnum']+1),$user['id']);
  3792. }
  3793. }
  3794. echo json_encode(array('msg'=>$d,'success'=>true));exit;
  3795. }
  3796. $this->data['excelpass'] = $excelpass;
  3797. $this->data['excelusernum'] = $excelusernum;
  3798. $this->data['exceljmnum'] = $exceljmnum;
  3799. $this->_Template('fullorderexcel_jmexcel',$this->data);
  3800. }
  3801. //管理
  3802. public function _classid()
  3803. {
  3804. $post = $this->input->post(NULL, TRUE);
  3805. if(isset($post['page']))
  3806. {
  3807. $page = $this->input->post('page',true);
  3808. $perpage = $this->input->post('perpage',true);
  3809. $type = $this->input->post('type',true);
  3810. $where = "1=1 ";
  3811. //数据排序
  3812. $order_str = "id asc";
  3813. if(empty($page))
  3814. {
  3815. $start = 0;
  3816. $perpage = 1;
  3817. }
  3818. else
  3819. {
  3820. $start = ($page - 1)*$perpage;
  3821. }
  3822. if($type)
  3823. {
  3824. $where .= " and type = '$type'";
  3825. }
  3826. //取得信息列表
  3827. $info_list = $this->fullorderexcelclassid->find_all($where,'id,title,type',$order_str,$start,$perpage);
  3828. $total = $this->fullorderexcelclassid->find_count($where);
  3829. $pagenum = ceil($total/$perpage);
  3830. $over = $total-($start+$perpage);
  3831. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  3832. echo json_encode($rows);exit;
  3833. }
  3834. $this->_Template('fullorderexcel_classid',$this->data);
  3835. }
  3836. //添加
  3837. public function _classidadd()
  3838. {
  3839. $post = $this->input->post(NULL, TRUE);
  3840. if(isset($post['title']))
  3841. {
  3842. if($this->fullorderexcelclassid->insert($post))
  3843. {
  3844. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  3845. }
  3846. else
  3847. {
  3848. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  3849. }
  3850. }
  3851. $this->_Template('fullorderexcel_classidadd',$this->data);
  3852. }
  3853. //修改
  3854. public function _classidedit($arg_array)
  3855. {
  3856. $post = $this->input->post(NULL, TRUE);
  3857. if(isset($post['id']))
  3858. {
  3859. $id = $this->input->post('id',true);
  3860. if($this->fullorderexcelclassid->save($post,$id))
  3861. {
  3862. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  3863. }
  3864. else
  3865. {
  3866. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  3867. }
  3868. }
  3869. $arg_array = $arg_array[0];
  3870. $fullorderexcelclassid = $this->fullorderexcelclassid->read($arg_array);
  3871. $this->data['fullorderexcelclassid'] = $fullorderexcelclassid;
  3872. $this->_Template('fullorderexcel_classidedit',$this->data);
  3873. }
  3874. }