Fullorderexcel.php 119 KB

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