Fullorderexcel.php 119 KB

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