Fullorderexcel.php 119 KB

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