Fullorderexcel.php 119 KB

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