Fullorderexcel.php 121 KB

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