OrderController.class.php 179 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. use Admin\Model\OrderModel;
  11. class OrderController extends CommonController{
  12. protected function _initialize(){
  13. parent::_initialize();
  14. }
  15. public function index(){
  16. $time = I('request.time');
  17. $s_time_start = I('request.time_start');
  18. $s_time_end = I('request.time_end');
  19. //var_dump($s_time,2);die();
  20. if( isset($s_time_start) && !empty($s_time_start) )
  21. {
  22. $time['start'] = $s_time_start;
  23. $time['end'] = $s_time_end;
  24. }
  25. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  26. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  27. $this->searchfield = I('request.searchfield','');
  28. $this->keyword = I('request.keyword','');
  29. $this->searchtime = I('request.searchtime','');
  30. $this->delivery = I('request.delivery','');
  31. $this->starttime = $starttime;
  32. $this->endtime = $endtime;
  33. $this->time = $time;
  34. //重置缓存
  35. $day_time = strtotime( date('Y-m-d '.'00:00:00') );
  36. $day_key = 'new_ordernotice_'.$day_time;
  37. S( $day_key, array() );
  38. $order_status_id = I('request.order_status_id',0);
  39. $order_status_arr = D('Seller/Order')->get_order_status_name();
  40. $this->order_status_arr = $order_status_arr;
  41. $is_soli_type = I('request.type', '');// isset($_GPC['type']) && $_GPC['type'] == 'soli' ? 1: 0;
  42. $is_soli = 0;
  43. if($is_soli_type == 'soli')
  44. {
  45. $is_soli = 1;
  46. }
  47. //soli
  48. $_GPC['is_soli'] = $is_soli;
  49. $_GET['type'] = 'normal';
  50. $is_presale_order = 0;
  51. if( isset($_GET['presale_order']) && $_GET['presale_order'] == 1 )
  52. {
  53. $is_presale_order = 1;
  54. }
  55. $is_virtualcard_order = 0;
  56. if( isset($_GET['virtualcard_order']) && $_GET['virtualcard_order'] == 1 )
  57. {
  58. $is_virtualcard_order = 1;
  59. }
  60. $this->is_soli = $is_soli;
  61. $this->is_presale_order = $is_presale_order;
  62. $this->is_virtualcard_order = $is_virtualcard_order;
  63. $need_data = D('Seller/Order')->load_order_list();
  64. $cur_controller = 'order/index';
  65. $total = $need_data['total'];
  66. $total_money = $need_data['total_money'];
  67. $list = $need_data['list'];
  68. $pager = $need_data['pager'];
  69. $all_count = $need_data['all_count'];
  70. $count_status_1 = $need_data['count_status_1'];
  71. $count_status_3 = $need_data['count_status_3'];
  72. $count_status_4 = $need_data['count_status_4'];
  73. $count_status_5 = $need_data['count_status_5'];
  74. $count_status_7 = $need_data['count_status_7'];
  75. $count_status_11 = $need_data['count_status_11'];
  76. $count_status_14 = $need_data['count_status_14'];
  77. $count_status_express = $need_data['count_status_express'];
  78. $this->cur_controller = $cur_controller;
  79. $this->total = $total;
  80. $this->total_money = $total_money;
  81. $this->list = $list;
  82. $this->pager = $pager;
  83. $this->all_count = $all_count;
  84. $this->count_status_1 = $count_status_1;
  85. $this->count_status_3 = $count_status_3;
  86. $this->count_status_4 = $count_status_4;
  87. $this->count_status_5 = $count_status_5;
  88. $this->count_status_7 = $count_status_7;
  89. $this->count_status_11 = $count_status_11;
  90. $this->count_status_14 = $count_status_14;
  91. $this->count_status_express = $count_status_express;
  92. $this->order_status_id = $order_status_id;
  93. $this->is_community = I('request.is_community', 0);
  94. $this->headid = I('request.headid', 0);
  95. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  96. if( empty($open_feier_print) )
  97. {
  98. $open_feier_print = 0;
  99. }
  100. if (defined('ROLE') && ROLE == 'agenter' )
  101. {
  102. $is_open_supply_print = D('Home/Front')->get_config_by_name('is_open_supply_print' );
  103. if( empty($is_open_supply_print) )
  104. {
  105. $open_feier_print = 0;
  106. }else{
  107. $supper_info = get_agent_logininfo();
  108. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print'.$supper_info['id'] );
  109. if( empty($open_feier_print) )
  110. {
  111. $open_feier_print = 0;
  112. }
  113. }
  114. }
  115. $this->open_feier_print = $open_feier_print;
  116. $is_can_look_headinfo = true;
  117. $is_can_nowrfund_order = true;
  118. $is_can_confirm_delivery = true;
  119. $is_can_confirm_receipt = true;
  120. $is_can_third_delivery = true;
  121. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  122. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  123. $supply_can_confirm_delivery = D('Home/Front')->get_config_by_name('supply_can_confirm_delivery');
  124. $supply_can_confirm_receipt = D('Home/Front')->get_config_by_name('supply_can_confirm_receipt');
  125. $supply_third_delivery_service = D('Home/Front')->get_config_by_name('supply_third_delivery_service');
  126. if (defined('ROLE') && ROLE == 'agenter' )
  127. {
  128. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  129. {
  130. $is_can_look_headinfo = false;
  131. }
  132. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  133. {
  134. $is_can_nowrfund_order = false;
  135. }
  136. if( isset($supply_can_confirm_delivery) && $supply_can_confirm_delivery == 2 )
  137. {
  138. $is_can_confirm_delivery = false;
  139. }
  140. if( isset($supply_can_confirm_receipt) && $supply_can_confirm_receipt == 2 )
  141. {
  142. $is_can_confirm_receipt = false;
  143. }
  144. }
  145. if( isset($supply_third_delivery_service) && $supply_third_delivery_service == 1){
  146. $is_can_third_delivery = true;
  147. }else{
  148. $is_can_third_delivery = false;
  149. }
  150. $s_id = 1 ;
  151. if(SELLERUID != 1)
  152. {
  153. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  154. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  155. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  156. $perms2 = explode(",", $perms1);
  157. if(in_array("user/user/index", $perms2)){
  158. $s_id = 1 ;
  159. } else {
  160. $s_id = 0 ;
  161. }
  162. }
  163. $this->s_id = $s_id;
  164. $is_localtown_imdada_status = D('Home/Front')->get_config_by_name('is_localtown_imdada_status');
  165. $is_localtown_sf_status = D('Home/Front')->get_config_by_name('is_localtown_sf_status');
  166. //是否开启蜂鸟即配
  167. $is_localtown_ele_status = D('Home/Front')->get_config_by_name('is_localtown_ele_status');
  168. $is_localtown_ele_status = isset($is_localtown_ele_status) ? $is_localtown_ele_status : 0;
  169. //是否开启码科配送
  170. $is_localtown_mk_status = D('Home/Front')->get_config_by_name('is_localtown_mk_status');
  171. $is_localtown_mk_status = isset($is_localtown_mk_status) ? $is_localtown_mk_status : 0;
  172. //码科预览价格
  173. $is_make_prequery_status = D('Home/Front')->get_config_by_name('is_make_prequery_status');
  174. $is_make_prequery_status = isset($is_make_prequery_status) ? $is_make_prequery_status : 0;
  175. $is_imdada_prequery_status = D('Home/Front')->get_config_by_name('is_imdada_prequery_status');
  176. $is_sf_prequery_status = D('Home/Front')->get_config_by_name('is_sf_prequery_status');
  177. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  178. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  179. $this->is_can_look_headinfo = $is_can_look_headinfo;
  180. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  181. $this->is_can_confirm_delivery = $is_can_confirm_delivery;
  182. $this->is_can_confirm_receipt = $is_can_confirm_receipt;
  183. $this->is_localtown_imdada_status = $is_localtown_imdada_status;
  184. $this->is_localtown_sf_status = $is_localtown_sf_status;
  185. $this->is_localtown_mk_status = $is_localtown_mk_status;
  186. $this->is_localtown_ele_status = $is_localtown_ele_status;
  187. $this->is_make_prequery_status = $is_make_prequery_status;
  188. $this->localtown_modifypickingname = $localtown_modifypickingname;
  189. $this->is_can_third_delivery = $is_can_third_delivery;
  190. if($is_localtown_imdada_status == 1 && $is_imdada_prequery_status == 1){
  191. $this->is_imdada_prequery_status = 1;
  192. }else{
  193. $this->is_imdada_prequery_status = 0;
  194. }
  195. if($is_localtown_sf_status == 1 && $is_sf_prequery_status == 1){
  196. $this->is_sf_prequery_status = 1;
  197. }else{
  198. $this->is_sf_prequery_status = 0;
  199. }
  200. $data = D('Seller/Config')->get_all_config();
  201. $this->data = $data;
  202. $this->display('Order/index');
  203. }
  204. public function opremarksaler()
  205. {
  206. $opdata = $this->check_order_data();
  207. extract($opdata);
  208. if (IS_POST) {
  209. $remark = I('request.remark');
  210. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( array('remarksaler' => $remark) );
  211. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  212. }
  213. $this->item = $item;
  214. $this->id = $item['order_id'];
  215. include $this->display();
  216. }
  217. private function check_order_data()
  218. {
  219. $id = I('request.id',0);
  220. $item = M('lionfish_comshop_order')->where( array('order_id' => $id) )->find();
  221. if (empty($item)) {
  222. show_json(0, '未找到订单!');
  223. }
  224. return array('id' => $id, 'item' => $item);
  225. }
  226. public function opsendcancel()
  227. {
  228. $opdata = $this->check_order_data();
  229. extract($opdata);
  230. $sendtype = I('request.sendtype','');
  231. $gpc = I('request.');
  232. if (($item['order_status_id'] != 4) ) {
  233. show_json(0, '订单未发货,不需取消发货!');
  234. }
  235. if (IS_POST) {
  236. $remark = trim($gpc['remark']);
  237. $data = array('express_time' => 0,'shipping_no' =>'','shipping_method' => 0);
  238. $data['order_status_id'] = 1;
  239. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save($data);
  240. $history_data = array();
  241. $history_data['order_id'] = $item['order_id'];
  242. $history_data['order_status_id'] = 1;
  243. $history_data['notify'] = 0;
  244. $history_data['comment'] = '订单取消发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'];
  245. $history_data['date_added'] = time();
  246. M('lionfish_comshop_order_history')->add($history_data);
  247. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  248. }
  249. $sendgoods = array();
  250. $bundles = array();
  251. $this->id = $item['order_id'];
  252. $this->item = $item;
  253. $this->sendtype = $sendtype;
  254. include $this->display();
  255. }
  256. public function opchangeaddress()
  257. {
  258. $_GPC = I('request.');
  259. $opdata = $this->check_order_data();
  260. extract($opdata);
  261. $new_area = 0;
  262. $address_street = 0;
  263. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  264. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  265. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  266. if (IS_POST) {
  267. $realname = $_GPC['realname'];
  268. $mobile = $_GPC['mobile'];
  269. $province = $_GPC['province'];
  270. $city = $_GPC['city'];
  271. $area = $_GPC['area'];
  272. $street = $_GPC['street'];
  273. $changead = intval($_GPC['changead']);
  274. $address = trim($_GPC['address']);
  275. if (!(empty($id))) {
  276. if (empty($realname)) {
  277. $ret = '请填写收件人姓名!';
  278. //show_json(0, array('msg' => $ret) );
  279. show_json(0, $ret);
  280. }
  281. if (empty($mobile)) {
  282. $ret = '请填写收件人手机!';
  283. show_json(0, $ret);
  284. }
  285. if ($changead) {
  286. if ($province == '请选择省份') {
  287. $ret = '请选择省份!';
  288. show_json(0, $ret);
  289. }
  290. if (empty($address)) {
  291. $ret = '请填写详细地址!';
  292. show_json(0, $ret);
  293. }
  294. }
  295. $address_array = array();
  296. $address_array['shipping_name'] = $realname;
  297. $address_array['shipping_tel'] = $mobile;
  298. if ($changead) {
  299. $province_info = M('lionfish_comshop_area')->where("name like '%{$province}%' ")->find();
  300. if( !empty($province_info))
  301. {
  302. $province_id = $province_info['id'];
  303. }else{
  304. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  305. $area_data = array();
  306. $area_data['name'] = $province;
  307. $area_data['pid'] = 0;
  308. $area_data['code'] = $max_dp['code']+1;
  309. $province_id = M('lionfish_comshop_area')->add($area_data);
  310. $up_data = array();
  311. $up_data['code'] = $province_id;
  312. M('lionfish_comshop_area')->where( array('id' => $province_id ) )->save($up_data);
  313. }
  314. //$city_info = M('lionfish_comshop_area')->where("name like '%{$city}%'")->find();
  315. $guding_arr = ['鞍山市'];
  316. if( in_array($city , $guding_arr) )
  317. {
  318. $city_info = M('lionfish_comshop_area')->where("name = '{$city}'")->find();
  319. }else{
  320. $city_info = M('lionfish_comshop_area')->where("name like '%{$city}%'")->find();
  321. }
  322. if( !empty($city_info))
  323. {
  324. $city_id = $city_info['id'];
  325. }else{
  326. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  327. $area_data = array();
  328. $area_data['name'] = $city;
  329. $area_data['pid'] = $province_id;
  330. $area_data['code'] = $max_dp['code']+1;
  331. $city_id = M('lionfish_comshop_area')->add( $area_data);
  332. $up_data = array();
  333. $up_data['code'] = $city_id;
  334. M('lionfish_comshop_area')->where( array('id' => $city_id ) )->save($up_data);
  335. }
  336. //city_name: 东莞市
  337. if( empty($area) )
  338. {
  339. if( $city == '东莞市' )
  340. {
  341. $area = '东莞';
  342. }
  343. if( $city == '中山市' )
  344. {
  345. $area = '中山';
  346. //453
  347. }
  348. }
  349. $country_info = M('lionfish_comshop_area')->where( "name like '%{$area}%' " )->find();
  350. if( $area == '中山' )
  351. {
  352. $country_info = M('lionfish_comshop_area')->where( array('id' => 453 ) )->find();
  353. //
  354. }
  355. if( !empty($country_info))
  356. {
  357. $country_id = $country_info['id'];
  358. }else{
  359. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  360. $area_data = array();
  361. $area_data['name'] = $area;
  362. $area_data['pid'] = $city_id;
  363. $area_data['code'] = $max_dp['code']+1;
  364. $country_id = M('lionfish_comshop_area')->add( $area_data );
  365. $up_data = array();
  366. $up_data['code'] = $country_id;
  367. M('lionfish_comshop_area')->where( array('id' => $country_id ) )->save( $up_data );
  368. }
  369. $address_array['shipping_province_id'] = $province_id;
  370. $address_array['shipping_city_id'] = $city_id;
  371. $address_array['shipping_country_id'] = $country_id;
  372. $address_array['shipping_address'] = $address;
  373. if( $item['delivery'] == 'tuanz_send' )
  374. {
  375. $address_array['tuan_send_address'] = $address;
  376. }
  377. }
  378. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( $address_array );
  379. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  380. }
  381. }
  382. $this->id = $item['order_id'];
  383. $this->item = $item;
  384. $this->province_info = $province_info;
  385. $this->city_info = $city_info;
  386. $this->area_info = $area_info;
  387. $this->display();
  388. }
  389. //确认送达团长
  390. public function opsend_tuanz_over()
  391. {
  392. $opdata = $this->check_order_data();
  393. extract($opdata);
  394. //express_tuanz_time D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  395. D('Seller/Order')->do_tuanz_over($item['order_id']);
  396. //D('Seller/Frontorder')->send_order_operate($item['order_id']);
  397. D('Home/Frontorder')->send_order_operate($item['order_id']);
  398. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  399. }
  400. public function all_opprint()
  401. {
  402. $_GPC = I('request.');
  403. $order_arr = $_GPC['order_arr'];
  404. $cache_key = md5(time().mt_rand(100,1000));
  405. S('_all_opprintquene_'.$cache_key, $order_arr);
  406. $this->cache_key = $cache_key;
  407. $this->_GPC = $_GPC;
  408. $this->display();
  409. }
  410. public function do_opprint_quene()
  411. {
  412. $_GPC = I('request.');
  413. $cache_key = $_GPC['cache_key'];
  414. $quene_order_list = S('_all_opprintquene_'.$cache_key);
  415. $order_id = array_shift($quene_order_list);
  416. S('_all_opprintquene_'.$cache_key, $quene_order_list);
  417. $order_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array( 'order_id' => $order_id ) )->find();
  418. $print_model = D('Seller/Printaction');
  419. $result = $print_model->check_print_order( $order_id );
  420. $result2 =$print_model->check_print_order2( $order_id );
  421. if( $result['code'] == 1 || $result2['code'] == 1 )
  422. {
  423. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('is_print_suc' => 1) );
  424. }
  425. if( empty($quene_order_list) )
  426. {
  427. echo json_encode( array('code' => 2) );
  428. die();
  429. }
  430. //清单编号
  431. echo json_encode( array('code' => 0, 'msg' => '订单编号:'.$order_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理") );
  432. die();
  433. }
  434. public function opprint()
  435. {
  436. $_GPC = I('request.');
  437. $order_id = $_GPC['id'];
  438. $print_model = D('Seller/Printaction');
  439. $result = $print_model->check_print_order( $order_id );
  440. $result2 = $print_model->check_print_order2( $order_id );
  441. if( $result['code'] == 1 || $result2['code'] == 1 )
  442. {
  443. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('is_print_suc' => 1) );
  444. show_json(1, array('msg' => '打印成功!' ) );
  445. }else{
  446. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  447. if(!empty($open_feier_print) && ( $open_feier_print == 2 || $open_feier_print == 1 ) )
  448. {
  449. show_json(0, array('msg' => $result['msg'] ) );
  450. }else{
  451. show_json(0, array('msg' => $result2['msg'] ) );
  452. }
  453. }
  454. }
  455. public function oprefund_goods_do()
  456. {
  457. $_GPC = I('request.');
  458. $opdata = $this->check_order_data();
  459. extract($opdata);
  460. $weixin_model = D('Home/Weixin');
  461. $id = $_GPC['id'];
  462. $order_goods_id = $_GPC['order_goods_id'];
  463. /**
  464. id : 3864
  465. order_goods_id : 4442
  466. **/
  467. //付款总额
  468. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->find();
  469. $this->order_goods_info = $order_goods_info;
  470. $goods_images = tomedia( $order_goods_info['goods_images'] );
  471. $this->goods_images = $goods_images;
  472. $free_tongji = $order_goods_info['total']-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money'] - $order_goods_info['has_refund_money'];
  473. $integral_flow = M('lionfish_comshop_member_integral_flow')->where( array('type' => 'orderbuy', 'order_goods_id' => $order_goods_id ) )->find();
  474. $use_score = 0;
  475. if( !empty($integral_flow) )
  476. {
  477. $use_score = $integral_flow['score'];
  478. }
  479. $this->use_score = $use_score;
  480. $total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($id,$order_goods_id);
  481. var_dump($total_quantity);
  482. $this->total_quantity = $total_quantity;
  483. $has_refund_quantity = D('Seller/Commonorder')->refund_order_goods_quantity($id,$order_goods_id);
  484. $this->has_refund_quantity = $has_refund_quantity;
  485. $has_refund_money = D('Seller/Commonorder')->get_order_goods_refund_money($id,$order_goods_id);
  486. $this->has_refund_money = $has_refund_money;
  487. $shipping_fare = $order_goods_info['shipping_fare'];
  488. $delivery = $opdata['item']['delivery'];
  489. $this->delivery = $delivery;
  490. //预售订单begin
  491. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  492. $presale_info = [];
  493. if( $presale_result['code'] == 0 )
  494. {
  495. $presale_info = $presale_result['data'];
  496. }
  497. $this->presale_info = $presale_info;
  498. //end
  499. $is_has_refund_deliveryfree = D('Home/Front')->get_config_by_name('is_has_refund_deliveryfree');
  500. $is_has_refund_deliveryfree = !isset($is_has_refund_deliveryfree) || $is_has_refund_deliveryfree == 1 ? 1:0;
  501. if( $is_has_refund_deliveryfree == 1 && $item['type'] != 'integral')
  502. {
  503. //后台设置退运费了
  504. //退回运费,导致佣金出错问题修改
  505. //$free_tongji += $shipping_fare;
  506. }
  507. if($item['delivery'] == 'hexiao'){
  508. $used_total = D('Home/Salesroom')->get_hexiao_order_goods_used_total($id,$order_goods_id);
  509. $free_tongji = $free_tongji - $used_total;
  510. }
  511. $this->shipping_fare = $shipping_fare;
  512. $this->is_has_refund_deliveryfree = $is_has_refund_deliveryfree;
  513. $this->free_tongji = $free_tongji;
  514. $this->_GPC = $_GPC;
  515. $commiss_state = '未结算';
  516. $commiss_info = M('lionfish_community_head_commiss_order')->where( array('order_id' => $id, 'order_goods_id' =>$order_goods_id,'type' => 'orderbuy' ) )->find();
  517. if( !empty($commiss_info) && $commiss_info['state'] == 1 )
  518. {
  519. $commiss_state = '已结算';
  520. }
  521. $this->commiss_info =$commiss_info;
  522. $this->commiss_state = $commiss_state;
  523. $this->payment_code = $item['payment_code'];
  524. if ( IS_POST ) {
  525. if(!$this->checkLocalTownOrderCanRefund($item)){
  526. show_json(0, array('message' => '同城配送订单配送中不能退款') );
  527. }
  528. $refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0 ? floatval($_GPC['refund_money']) : 0;
  529. $is_refund_shippingfare = isset($_GPC['is_refund_shippingfare']) ? $_GPC['is_refund_shippingfare'] : 0;//退运费
  530. $is_back_sellcount = isset($_GPC['is_back_sellcount']) ? $_GPC['is_back_sellcount'] : 0;//退库存
  531. $is_back_scorecount = isset($_GPC['is_back_scorecount']) ? $_GPC['is_back_scorecount'] : 0;//退积分
  532. //$free_tongji = $opdata['item']['total']-$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  533. $free_tongji = $order_goods_info['total']-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money'] - $order_goods_info['has_refund_money'];
  534. $refund_quantity = isset($_GPC['refund_quantity']) && $_GPC['refund_quantity'] >0 ? floatval($_GPC['refund_quantity']) : 0;
  535. $real_refund_quantity = isset($_GPC['real_refund_quantity']) && $_GPC['real_refund_quantity'] >0 ? intval($_GPC['real_refund_quantity']) : 0;
  536. //已退商品数量
  537. $refund_total_quantity = M('lionfish_comshop_order_goods_refund')->where( "order_id={$id} and order_goods_id={$order_goods_id} " )->sum('quantity');
  538. //部分退款计算运费
  539. if($refund_quantity + $refund_total_quantity < $order_goods_info['quantity']){
  540. $shipping_fare = round($refund_quantity/$order_goods_info['quantity']*$shipping_fare,2);
  541. }else{
  542. //$shipping_fare = round($refund_quantity/$order_goods_info['quantity']*$shipping_fare,2);
  543. $shipping_fare = $shipping_fare - $refund_total_quantity * round( 1/$order_goods_info['quantity'] * $shipping_fare,2);
  544. }
  545. $pay_total_money = $free_tongji ;
  546. $refund_shipping_fare = 0;
  547. $wx_refund_money = $refund_money;
  548. if( $is_refund_shippingfare == 1)
  549. {
  550. $free_tongji += $shipping_fare;
  551. $refund_shipping_fare = $shipping_fare;
  552. $wx_refund_money = $wx_refund_money + $shipping_fare;
  553. }
  554. $can_free_tongji = $opdata['item']['total'] + $opdata['item']['shipping_fare'] -$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  555. if( $item['type'] == 'integral' )
  556. {
  557. $can_free_tongji = $opdata['item']['total'] -$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  558. }
  559. $can_refund_quantity = 0;
  560. if($item['delivery'] == 'hexiao'){
  561. $can_refund_quantity = D('Home/Salesroom')->get_hexiao_order_goods_can_refund_quantity($id,$order_goods_id);
  562. }
  563. //以及退款了多少钱了 has_refund_money
  564. if($refund_money + $has_refund_money > $can_free_tongji){
  565. show_json(0, array('message' => '总退款金额大于可退款金额') );
  566. }
  567. else if( $refund_money < 0 )
  568. {
  569. show_json(0, array('message' => '填写正确的退款金额') );
  570. }
  571. else if( $is_back_sellcount == 1 && $refund_quantity > $total_quantity )
  572. {
  573. show_json(0, array('message' => '填写正确的退库存数量,最大'.$total_quantity.'个' ) );
  574. }else if($item['delivery'] == 'hexiao' && $can_refund_quantity < $refund_quantity){
  575. show_json(0, array('message' => '核销商品退款数量大于可退款数量'.$refund_quantity.'个' ) );
  576. }
  577. else{
  578. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  579. {
  580. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => 0) );
  581. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->save( array('shipping_fare' => 0) );
  582. }
  583. //is_back_sellcount
  584. //$res = $weixin_model->refundOrder($id,$refund_money,0,$order_goods_id,$is_back_sellcount, $refund_quantity,1);
  585. $res = $weixin_model->refundOrder($id,$wx_refund_money,0,$order_goods_id,$is_back_sellcount, $refund_quantity,1);
  586. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  587. {
  588. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => $opdata['item']['shipping_fare'] ) );
  589. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->save( array('shipping_fare' => $order_goods_info['shipping_fare']) );
  590. }
  591. if( $res['code'] == 0 )
  592. {
  593. show_json(0, array('message' => $res['msg'] ) );
  594. }else{
  595. //开始插入本次退款的情况
  596. //存储当前这笔退款 影响到的以后佣金情况
  597. //is_back_scorecount
  598. if( $is_back_scorecount == 1 )
  599. {
  600. $refund_score = 0;
  601. $refund_score = intval( ($use_score / $order_goods_info['quantity']) * $refund_quantity);
  602. D('Seller/Commonorder')->refund_order_goods_intrgral( $id, $order_goods_id ,$refund_score );
  603. }else{
  604. $refund_score = 0;
  605. D('Seller/Commonorder')->refund_order_goods_intrgral( $id, $order_goods_id ,0 );
  606. }
  607. //退回运费,导致佣金出错问题修改
  608. $order_goods_refundid = D('Seller/Commonorder')->ins_order_goods_refund($id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money,$is_back_sellcount,$refund_shipping_fare);
  609. //$order_goods_refundid = D('Seller/Commonorder')->ins_order_goods_refund($id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money,$is_back_sellcount);
  610. //如果这个商品没有数量了。就改变他的状态为已退款的状态
  611. $new_total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($id,$order_goods_id);
  612. if( $new_total_quantity <=0 )
  613. {
  614. D('Seller/Commonorder')->check_refund_order_goods_status($id, $order_goods_id, $refund_money,$is_back_sellcount,$real_refund_quantity, $refund_quantity,$is_refund_shippingfare);
  615. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->select();
  616. $is_all_refund = true;
  617. foreach($order_goods_list as $val )
  618. {
  619. if($val['is_refund_state'] != 1)
  620. {
  621. $is_all_refund = false;
  622. }
  623. }
  624. $or_gd_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->find();
  625. if(($or_gd_info['is_refund_state'] == 1) && ($is_all_refund == false) ){
  626. $or_gd_info = M('lionfish_comshop_order_goods')->field('name')->where( array('order_goods_id' => $order_goods_id ) )->find();
  627. $order_history = array();
  628. $order_history['order_id'] = $id;
  629. $order_history['order_status_id'] = 19;
  630. $order_history['notify'] = 0;
  631. if( $item['type'] == 'integral' ){
  632. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款积分'.$refund_money.'积分';
  633. }else{
  634. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款金额'.$refund_money.'元';
  635. }
  636. $order_history['date_added'] = time();
  637. M('lionfish_comshop_order_history')->add( $order_history );
  638. }
  639. }else{
  640. $or_gd_info = M('lionfish_comshop_order_goods')->field('name')->where( array('order_goods_id' => $order_goods_id ) )->find();
  641. $order_history = array();
  642. $order_history['order_id'] = $id;
  643. $order_history['order_status_id'] = 19;
  644. $order_history['notify'] = 0;
  645. if( $item['type'] == 'integral' ){
  646. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款积分'.$refund_money.'积分,';
  647. }else{
  648. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款金额'.$refund_money.'元,';
  649. }
  650. if($is_refund_shippingfare == 1)
  651. {
  652. $order_history['comment'] .= '. 退配送费:'.$refund_shipping_fare.'元';
  653. }
  654. $order_history['date_added'] = time();
  655. M('lionfish_comshop_order_history')->add( $order_history );
  656. }
  657. //核销订单操作
  658. if($item['delivery'] == 'hexiao'){
  659. //核销商品订单退款
  660. D('Home/Salesroom')->hexiao_refund_action($id,$order_goods_id,$refund_quantity);
  661. //操作核销订单是否完成
  662. D('Seller/Order')->hexiao_finished($id, '未核销商品退款,订单完成');
  663. }
  664. //礼品卡退款
  665. D('Seller/VirtualCard')->refundOrder($id);
  666. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  667. }
  668. }
  669. }
  670. if( $item['type'] == 'integral' )
  671. {
  672. include $this->display('Order/oprefund_goods_dointegral');
  673. }else{
  674. include $this->display();
  675. }
  676. }
  677. public function oprefund_do()
  678. {
  679. $_GPC = I('request.');
  680. $opdata = $this->check_order_data();
  681. extract($opdata);
  682. $id = $_GPC['id'];
  683. //付款总额
  684. $free_tongji = $opdata['item']['total']-$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  685. $total_quantity = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->sum('quantity');
  686. $has_refud_money = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $id ) )->sum('money');
  687. $this->has_refud_money = $has_refud_money;
  688. $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $id ) )->sum('quantity');
  689. $total_quantity = $total_quantity - $has_refund_quantity;
  690. $buy_score_total = M('lionfish_comshop_member_integral_flow')->where( array('type' => 'orderbuy' , 'order_id' => $id ) )->sum('score');
  691. $has_refund_buy_score_total = M('lionfish_comshop_member_integral_flow')->where(array('type' => 'refundorder' , 'order_id' => $id ))->sum('score');
  692. if(!empty($has_refund_buy_score_total) && $has_refund_buy_score_total > 0)
  693. $buy_score_total = $buy_score_total - $has_refund_buy_score_total;
  694. $this->buy_score_total = $buy_score_total;
  695. $shipping_fare = $opdata['item']['shipping_fare'];
  696. $delivery = $opdata['item']['delivery'];
  697. $is_has_refund_deliveryfree = D('Home/Front')->get_config_by_name('is_has_refund_deliveryfree');
  698. $is_has_refund_deliveryfree = !isset($is_has_refund_deliveryfree) || $is_has_refund_deliveryfree == 1 ? 1:0;
  699. if( $is_has_refund_deliveryfree == 1)
  700. {
  701. //后台设置退运费了
  702. //退回运费,导致佣金出错问题修改
  703. $free_tongji += $opdata['item']['shipping_fare'];
  704. }
  705. $hx_used_total = 0;
  706. if($item['delivery'] == 'hexiao'){
  707. $used_quantity = D('Home/Salesroom')->get_hexiao_order_used_quantity($id);
  708. $hx_used_total = D('Home/Salesroom')->get_hexiao_order_used_total($id);
  709. $total_quantity = $total_quantity - $used_quantity;
  710. $free_tongji = $free_tongji - $hx_used_total;
  711. }
  712. //判断是否有预售 begin
  713. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  714. $presale_info = [];
  715. if( $presale_result['code'] == 0 )
  716. {
  717. $presale_info = $presale_result['data'];
  718. $free_tongji = $free_tongji - $presale_info['presale_for_ordermoney'];
  719. }
  720. //end
  721. $this->presale_info = $presale_info;
  722. $this->is_has_refund_deliveryfree = $is_has_refund_deliveryfree;
  723. $this->shipping_fare = $shipping_fare;
  724. $this->total_quantity = $total_quantity;
  725. $this->delivery = $delivery;
  726. $this->hx_used_total = $hx_used_total;
  727. if( IS_POST )
  728. {
  729. if(!$this->checkLocalTownOrderCanRefund($item)){
  730. show_json(0, array('message' => '同城配送订单配送中不能退款') );
  731. }
  732. $refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0 ? floatval($_GPC['refund_money']) : 0;
  733. $is_refund_shippingfare = isset($_GPC['is_refund_shippingfare']) ? $_GPC['is_refund_shippingfare'] : 0;//退运费
  734. $is_back_sellcount = isset($_GPC['is_back_sellcount']) ? $_GPC['is_back_sellcount'] : 0;//退库存
  735. $is_back_buyscore = isset($_GPC['is_back_buyscore']) ? $_GPC['is_back_buyscore'] : 0;//退积分
  736. $wx_refund_money = $refund_money;
  737. $free_tongji = $opdata['item']['total']-$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  738. //已经退款运费
  739. $refund_shipping_fare_amount = M('lionfish_comshop_order_goods_refund')->where( array('order_id' =>$id ) )->sum('refund_shipping_fare');
  740. if( empty($refund_shipping_fare_amount) )
  741. {
  742. $refund_shipping_fare_amount = 0;
  743. }
  744. if( $is_refund_shippingfare == 1 && $opdata['item']['type'] != 'integral' )
  745. {
  746. if($refund_shipping_fare_amount < $shipping_fare) {
  747. $shipping_fare = $shipping_fare - $refund_shipping_fare_amount;
  748. $this->shipping_fare = $shipping_fare;
  749. //$free_tongji += $shipping_fare;
  750. $wx_refund_money += $shipping_fare - $opdata['item']['fare_shipping_free'];
  751. $is_back_buyscore = 2;//退运费
  752. }
  753. }
  754. $free_tongji = $free_tongji - $has_refud_money;
  755. if( $refund_money - $free_tongji >= 0.01 ){
  756. show_json(0, array('message' => '填写金额大于总退款金额' ) );
  757. }
  758. else if( $refund_money < 0 )
  759. {
  760. show_json(0, array('message' => '填写正确的退款金额' ) );
  761. }
  762. else{
  763. $weixin_model = D('Home/Weixin');
  764. $id = $_GPC['id'];
  765. $model = M('lionfish_comshop_order');
  766. //$model->startTrans(); // 开启事务
  767. $order_info = $model->where(array('order_id'=>$id))->find();
  768. if( $order_info['order_status_id'] != 7 )
  769. {
  770. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  771. {
  772. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => 0) );
  773. }
  774. //$res = $weixin_model->refundOrder($id,$refund_money,0,0,$is_back_sellcount);
  775. $res = $weixin_model->refundOrder($id,$wx_refund_money,0,0,$is_back_sellcount);
  776. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  777. {
  778. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => $opdata['item']['shipping_fare'] ) );
  779. }
  780. $model->commit(); // 开启事务
  781. if( $res['code'] == 0 )
  782. {
  783. show_json(0, array('message' => $res['msg']) );
  784. }else{
  785. //integral
  786. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $id ) )->find();
  787. $comment = '后台操作立即退款,退款金额:'.$refund_money.'元';
  788. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  789. {
  790. $comment = '后台操作立即退款,退款积分:'.$refund_money.'积分';
  791. }
  792. if( $order_info['type'] == 'integral' )
  793. {
  794. $comment = '后台操作立即退款,退还积分:'.$refund_money.'积分';
  795. //$comment = '后台操作立即退款,退款金额:'.$refund_money.'元';
  796. }
  797. if($is_refund_shippingfare == 1)
  798. {
  799. if( $order_info['type'] == 'integral' ){
  800. $refund_shipping_fare_amount2 = M('lionfish_comshop_order_goods_refund')->where( array('order_id' =>$id ) )->sum('refund_shipping_fare');
  801. if( empty($refund_shipping_fare_amount2) )
  802. {
  803. $refund_shipping_fare_amount2 = 0;
  804. }
  805. $new_shipping_fare = $opdata['item']['shipping_fare'] - $refund_shipping_fare_amount2;
  806. $comment .= '. 退配送费:'.$new_shipping_fare.'元';
  807. }else{
  808. $comment .= '. 退配送费:'.$opdata['item']['shipping_fare'].'元';
  809. }
  810. }
  811. if($is_back_sellcount == 1)
  812. {
  813. $comment .= '. 退库存:'.$total_quantity;
  814. }else{
  815. $comment .= '. 不退库存,不减销量';
  816. }
  817. $history_data = array();
  818. $history_data['order_id'] = $id;
  819. $history_data['order_status_id'] = 7;
  820. $history_data['notify'] = 0;
  821. $history_data['comment'] = $comment;
  822. $history_data['date_added'] = time();
  823. M('lionfish_comshop_order_history')->add($history_data);
  824. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('order_status_id' => 7) );
  825. //将所有在退款中的状态,全部重置成已退款成功
  826. M('lionfish_comshop_order_refund')->where( array('order_id' => $id, 'state' => 0) )->save( array('state' => 3) );
  827. //将退款中的 申请订单,全部改成已退款
  828. $refund_all = M('lionfish_comshop_order_refund')->where( array('order_id' =>$id, 'state' => 0 ) )->select();
  829. if( !empty($refund_all) )
  830. {
  831. foreach( $refund_all as $val )
  832. {
  833. $ins_data = array();
  834. $ins_data['ref_id'] = $val['ref_id'];
  835. $ins_data['order_id'] = $val['order_id'];
  836. $ins_data['order_goods_id'] = $val['order_goods_id'];
  837. $ins_data['message'] = '平台同意退款   ,退款成功';
  838. $ins_data['type'] = 2;
  839. $ins_data['addtime'] = time();
  840. M('lionfish_comshop_order_refund_history')->add( $ins_data );
  841. M('lionfish_comshop_order_refund')->where( array('ref_id' => $val['ref_id']) )->save( array('state' => 3) );
  842. }
  843. }
  844. //$data[''] = isset($data['is_print_admin_cancleorder']) ? $data['is_print_admin_cancleorder'] : 0;
  845. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  846. D('Seller/Commonorder')->refund_one_order( $id , $is_back_buyscore);
  847. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  848. {
  849. D('Seller/Printaction')->check_print_order($id,'后台操作取消订单');
  850. D('Seller/Printaction')->check_print_order2($id,'后台操作取消订单');
  851. }
  852. sellerLog('订单['.$order_info['order_num_alias'].']退款成功操作', 2);
  853. //核销订单操作
  854. if($item['delivery'] == 'hexiao'){
  855. D('Home/Salesroom')->hexiao_order_refund_action($id);
  856. }
  857. //礼品卡退款
  858. D('Seller/VirtualCard')->refundOrder($id);
  859. show_json(1, array('message' => '退款成功!') );
  860. }
  861. }else{
  862. //$model->rollback(); // 回滚
  863. show_json(0, array('message' => '请勿重复提交'));
  864. }
  865. }
  866. }
  867. $this->id = $id;
  868. $this->free_tongji = $free_tongji;
  869. $this->item = $item;
  870. $commiss_state = '未结算';
  871. $commiss_info = M('lionfish_community_head_commiss_order')->where( array('order_id' => $id, 'type' => 'orderbuy' ) )->find();
  872. if( !empty($commiss_info) && $commiss_info['state'] == 1 )
  873. {
  874. $commiss_state = '已结算';
  875. }
  876. $this->commiss_state = $commiss_state;
  877. if( $item['type'] == 'integral' )
  878. {
  879. $this->display('Order/oprefund_do_integral');
  880. }else{
  881. $this->display();
  882. }
  883. }
  884. function test()
  885. {
  886. //D('Seller/Printaction')->check_print_order(63);
  887. // lionfish_comshop_order
  888. $shop_name = D('Home/Front')->get_config_by_name('shoname');
  889. $this->shop_name = $shop_name;
  890. $order_id = 174;
  891. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  892. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->select();
  893. $need_order_goods = array();
  894. foreach($order_goods as $key => $value)
  895. {
  896. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($order_id, $value['order_goods_id']);
  897. $need_order_goods[$key] = $value;
  898. }
  899. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  900. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  901. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  902. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id'] ) )->find();
  903. $this->province_info = $province_info;
  904. $this->city_info = $city_info;
  905. $this->area_info = $area_info;
  906. $this->member = $member;
  907. $this->order_info = $order_info;
  908. $this->need_order_goods = $need_order_goods;
  909. $this->display('forms');
  910. }
  911. /**
  912. 打印配送单
  913. **/
  914. public function order_print_dan()
  915. {
  916. $order_id = I('get.id');
  917. $shop_name = D('Home/Front')->get_config_by_name('shoname');
  918. $this->shop_name = $shop_name;
  919. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  920. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->select();
  921. $need_order_goods = array();
  922. $total = 0;
  923. foreach($order_goods as $key => $value)
  924. {
  925. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($order_id, $value['order_goods_id']);
  926. $need_order_goods[$key] = $value;
  927. }
  928. $total = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->sum('total');
  929. $legal_amount = D('Seller/Order')->num_to_rmb($total);
  930. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  931. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  932. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  933. $member = M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id'] ) )->find();
  934. sellerLog('订单['.$order_info['order_num_alias'].']打印配送单', 2);
  935. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  936. $order_note_name = isset($order_note_name) && !empty($order_note_name) ? $order_note_name :'店名';
  937. $this->order_note_name = $order_note_name;
  938. $this->legal_amount = $legal_amount;
  939. $this->province_info = $province_info;
  940. $this->city_info = $city_info;
  941. $this->area_info = $area_info;
  942. $this->member = $member;
  943. $this->order_info = $order_info;
  944. $this->need_order_goods = $need_order_goods;
  945. $this->display('forms');
  946. }
  947. //配送团长
  948. public function opsend_tuanz()
  949. {
  950. $opdata = $this->check_order_data();
  951. extract($opdata);
  952. D('Seller/Order')->do_send_tuanz($item['order_id']);
  953. $order_num_alias = M('lionfish_comshop_order')->where( array('order_id' => $item['order_id'] ) )->find();
  954. D('Seller/Operatelog')->addOperateLog('detailed_list','配送团长--订单编号'.$order_num_alias['order_num_alias']);
  955. //后台自动送达团长
  956. D('Seller/Order')->order_auto_service($item,'后台自动确认送达团长');
  957. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  958. }
  959. //同城配送,确认开始配送流程
  960. public function opsend_localtown()
  961. {
  962. $opdata = $this->check_order_data();
  963. extract($opdata);
  964. $count = D('Seller/Order')->do_send_localtown($item['order_id']);
  965. show_json(1, array('url' => $_SERVER['HTTP_REFERER'], 'count' => $count));
  966. }
  967. public function opsend()
  968. {
  969. $_GPC = I('request.');
  970. $opdata = $this->check_order_data();
  971. extract($opdata);
  972. if (empty($item['address_id'])) {
  973. show_json(0, array('message' => '无收货地址,无法发货!'));
  974. }
  975. if ($item['order_status_id'] == 3) {
  976. show_json(0, array('message' => '订单未付款,无法发货!'));
  977. }
  978. if (IS_POST) {
  979. //express shipping_no $express_info['name'] dispatchname
  980. if (!(empty($_GPC['shipping_no'])) && empty($_GPC['shipping_no'])) {
  981. show_json(0, array('message' => '请输入快递单号!') );
  982. }
  983. if ( empty($_GPC['express']) ) {
  984. show_json(0, array('message' => '请选择快递公司!'));
  985. }
  986. if (!(empty($item['transid']))) {
  987. }
  988. $express_info = D('Seller/Express')->get_express_info($_GPC['express']);
  989. $time = time();
  990. $data = array(
  991. 'shipping_method' => trim($_GPC['express']),
  992. 'shipping_no' => trim($_GPC['shipping_no']),
  993. 'dispatchname' => $express_info['name'],
  994. 'express_time' => $time
  995. );
  996. $data['order_status_id'] = 4;
  997. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( $data );
  998. $history_data = array();
  999. $history_data['order_id'] = $item['order_id'];
  1000. $history_data['order_status_id'] = 4;
  1001. $history_data['notify'] = 0;
  1002. $history_data['comment'] = '订单发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $_GPC['shipping_no'];
  1003. $history_data['date_added'] = time();
  1004. M('lionfish_comshop_order_history')->add($history_data);
  1005. D('Home/Frontorder')->send_order_operate($item['order_id']);
  1006. sellerLog('订单['.$item['order_num_alias'].']订单发货操作', 2);
  1007. //TODO...发送已经发货的消息通知
  1008. //m('notice')->sendOrderMessage($item['id']);
  1009. //plog('order.op.send', '订单发货 ID: ' . $item['id'] . ' 订单号: ' . $item['ordersn'] . ' <br/>快递公司: ' . $_GPC['expresscom'] . ' 快递单号: ' . $_GPC['expresssn']);
  1010. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1011. }
  1012. $noshipped = array();
  1013. $shipped = array();
  1014. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  1015. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  1016. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  1017. $order_goods = M()->query('select og.order_goods_id as id,og.name as title,og.goods_images as thumb from ' .
  1018. C('DB_PREFIX'). 'lionfish_comshop_order_goods as og where og.order_id= '.$item['order_id']);
  1019. $express_list = D('Seller/Express')->load_all_express();
  1020. $this->province_info = $province_info;
  1021. $this->city_info = $city_info;
  1022. $this->area_info = $area_info;
  1023. $this->order_goods = $order_goods;
  1024. $this->item = $item;
  1025. $this->express_list = $express_list;
  1026. $this->id = $item['order_id'];
  1027. $this->display();
  1028. }
  1029. // 11 已完成
  1030. public function opfinish()
  1031. {
  1032. $opdata = $this->check_order_data();
  1033. extract($opdata);
  1034. M('lionfish_comshop_order')->where(array('order_id' => $item['order_id']) )->save( array('order_status_id' => 11,
  1035. 'finishtime' => time()) );
  1036. $history_data = array();
  1037. $history_data['order_id'] = $item['order_id'];
  1038. $history_data['order_status_id'] = 11;
  1039. $history_data['notify'] = 0;
  1040. $history_data['comment'] = '后台操作,已完成' ;
  1041. $history_data['date_added'] = time();
  1042. sellerLog('订单['.$item['order_num_alias'].']订单完成操作', 2);
  1043. M('lionfish_comshop_order_history')->add($history_data);
  1044. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1045. }
  1046. public function export_form()
  1047. {
  1048. $_GPC = I('request.');
  1049. /**
  1050. order_status_id:
  1051. type: normal
  1052. searchtime:
  1053. time[start]: 2019-12-23 00:00:00
  1054. time[end]: 2019-12-23 23:59:59
  1055. delivery:
  1056. searchfield: ordersn
  1057. keyword:
  1058. export: 0
  1059. **/
  1060. unset($_GPC['controller']);
  1061. unset($_GPC['export']);
  1062. $post_data = array();
  1063. $post_data['order_status_id'] = $_GPC['order_status_id'];
  1064. $post_data['type'] = $_GPC['type'];
  1065. $post_data['searchtime'] = $_GPC['searchtime'];
  1066. $post_data['time[start]'] = $_GPC['time']['start'];
  1067. $post_data['time[end]'] = $_GPC['time']['end'];
  1068. $post_data['headid'] = $_GPC['headid'];
  1069. $post_data['delivery'] = $_GPC['delivery'];
  1070. $post_data['searchfield'] = $_GPC['searchfield'];
  1071. $post_data['keyword'] = $_GPC['keyword'];
  1072. $post_data['export'] = 1;
  1073. $note_content = D('Home/Front')->get_config_by_name('order_note_name');
  1074. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  1075. $columns = array(
  1076. array('title' => '订单流水号', 'field' => 'day_paixu', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1077. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1078. array('title' => '会员昵称', 'field' => 'name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1079. array('title' => '会员手机号', 'field' => 'telephone', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1080. array('title' => '会员备注', 'field' => 'member_content', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1081. array('title' => '收货姓名(或自提人)', 'field' => 'shipping_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1082. array('title' => '联系电话', 'field' => 'shipping_tel', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1083. array('title' => '收货地址', 'field' => 'address_province_city_area', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1084. array('title' => '供应商名称/类型', 'field' => 'supply_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1085. array('title' => '提货详细地址', 'field' => 'address_address', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1086. array('title' => '商品名称', 'field' => 'goods_title', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1087. array('title' => '商品分类', 'field' => 'goods_category', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1088. array('title' => '商品价格', 'field' => 'goods_rprice2', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1089. array('title' => '商品数量', 'field' => 'quantity', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1090. array('title' => '支付方式', 'field' => 'paytype', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1091. array('title' => '配送方式', 'field' => 'delivery', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1092. array('title' => '预计送达时间', 'field' => 'expected_delivery_time', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1093. array('title' => '团长配送送货详细地址', 'field' => 'tuan_send_address', 'width' => 22, 'sort' => 0, 'is_check' => 1),
  1094. array('title' => '商品规格', 'field' => 'goods_optiontitle', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1095. array('title' => '商品单价', 'field' => 'goods_price1', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1096. array('title' => '收货时间', 'field' => 'receive_time', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1097. array('title' => '快递单号', 'field' => 'expresssn', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1098. array('title' => '下单时间', 'field' => 'createtime', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1099. array('title' => '小区名称', 'field' => 'community_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1100. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1101. array('title' => '团长电话', 'field' => 'head_mobile', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1102. array('title' => '退款商品数量', 'field' => 'has_refund_quantity', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1103. array('title' => '退款金额', 'field' => 'has_refund_money', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1104. array('title' => '微信支付交易单号', 'field' => 'transaction_id', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1105. array('title' => '商品编码', 'field' => 'goods_goodssn', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1106. array('title' => 'openid', 'field' => 'openid', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1107. array('title' => '运费', 'field' => 'dispatchprice', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1108. array('title' => '积分抵扣', 'field' => 'score_for_money', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1109. array('title' => '满额立减', 'field' => 'fullreduction_money', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1110. array('title' => '优惠券优惠', 'field' => 'voucher_credit', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1111. array('title' => '应收款(该笔订单总款)', 'field' => 'price', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1112. array('title' => '状态', 'field' => 'status', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1113. array('title' => '团长佣金', 'field' => 'head_money', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1114. array('title' => '会员佣金', 'field' => 'member_commissmoney', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1115. array('title' => '付款时间', 'field' => 'paytime', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1116. array('title' => '发货时间', 'field' => 'sendtime', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1117. array('title' => '完成时间', 'field' => 'finishtime', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1118. array('title' => '快递公司', 'field' => 'expresscom', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1119. array('title' => '完整地址', 'field' => 'fullAddress', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1120. array('title' => '订单备注', 'field' => 'remark', 'width' => 36, 'sort' => 0, 'is_check' => 0),
  1121. array('title' => '卖家订单备注', 'field' => 'remarksaler', 'width' => 36, 'sort' => 0, 'is_check' => 0),
  1122. array('title' => '商品成本价', 'field' => 'costprice', 'width' => 36, 'sort' => 0, 'is_check' => 0),
  1123. array('title' => '省市区', 'field' => 'province', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1124. array('title' => '商品重量', 'field' => 'goods_weight', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1125. );
  1126. if($order_note_open == 1){
  1127. if(empty($note_content)){
  1128. $note_content= '店名';
  1129. }
  1130. $columns[] = array('title' => $note_content, 'field' => 'note_content', 'width' => 24, 'sort' => 0, 'is_check' => 0);
  1131. }
  1132. //load_model_class('config')->update( array('modify_export_fields' => $modify_explode_arr ) );
  1133. sellerLog('订单excel导出操作', 2);
  1134. $modify_explode_json = D('Home/Front')->get_config_by_name('modify_export_fields');
  1135. if( !empty($modify_explode_json) )
  1136. {
  1137. $modify_explode_arr = json_decode($modify_explode_json, true);
  1138. foreach( $columns as $key => $val )
  1139. {
  1140. if( in_array($val['field'], array_keys($modify_explode_arr) ) )
  1141. {
  1142. $val['is_check'] =1;
  1143. $val['sort'] = $modify_explode_arr[$val['field']];
  1144. }else{
  1145. $val['is_check'] =0;
  1146. $val['sort'] = 0;
  1147. }
  1148. $columns[$key] = $val;
  1149. }
  1150. $last_index_sort = array_column($columns,'sort');
  1151. array_multisort($last_index_sort,SORT_DESC,$columns);
  1152. }
  1153. $this->post_data = $post_data;
  1154. $this->columns = $columns;
  1155. $this->_GPC = $_GPC;
  1156. $this->display();
  1157. }
  1158. public function oppay()
  1159. {
  1160. if (defined('ROLE') && ROLE == 'agenter' )
  1161. {
  1162. show_json(0, array('message' => '您无此权限') );
  1163. }
  1164. $order_id = I('request.id');
  1165. $res_arr = D('Seller/Order')->admin_pay_order($order_id);
  1166. if( $res_arr['code'] == 0)
  1167. {
  1168. show_json(0, array('message' => $res_arr['msg']) );
  1169. }else{
  1170. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1171. }
  1172. }
  1173. public function detail()
  1174. {
  1175. $id = I('get.id');
  1176. $item = M('lionfish_comshop_order')->where( array('order_id' => $id ) )->find();
  1177. if (defined('ROLE') && ROLE == 'agenter' )
  1178. {
  1179. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1180. if($supply_can_look_headinfo != 1){
  1181. $item['ziti_name'] = D('Seller/Order')->desensitize($item['ziti_name'],1,1);
  1182. $item['ziti_mobile'] = D('Seller/Order')->desensitize($item['ziti_mobile'],3,4);
  1183. }
  1184. }
  1185. switch ($item['delivery']){
  1186. case 'pickup':$item['delivery_text'] = '社区自提';break;
  1187. case 'express':$item['delivery_text'] = '快递';break;
  1188. case 'tuanz_send':$item['delivery_text'] = '团长配送';break;
  1189. case 'hexiao':$item['delivery_text'] = '到店核销';break;
  1190. }
  1191. //预收订单信息begin
  1192. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  1193. if( $presale_result['code'] == 0 )
  1194. {
  1195. $item['presale_info'] = $presale_result['data'];
  1196. }else{
  1197. $item['presale_info'] = [];
  1198. }
  1199. //预收订单信息end
  1200. if($item['type'] == 'pintuan'){
  1201. $pin_order = M('lionfish_comshop_pin_order')->field('pin_id')->where( array('order_id' => $id ) )->find();
  1202. $pin_id = $pin_order['pin_id'];
  1203. $this->pin_id = $pin_id;
  1204. }
  1205. $order_goods = array();
  1206. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id) )->select();
  1207. $need_order_goods = array();
  1208. $shipping_fare = 0;
  1209. $fullreduction_money = 0;
  1210. $voucher_credit = 0;
  1211. $total = 0;
  1212. $order_head_status = 0 ;
  1213. foreach($order_goods as $key => $value)
  1214. {
  1215. // lionfish_community_head_commiss_order
  1216. $value['name'] = htmlspecialchars_decode(stripslashes($value['name']));
  1217. $head_commission_order_info = M('lionfish_community_head_commiss_order')->where( array('order_goods_id' => $value['order_goods_id'],'order_id' => $item['order_id']) )->select();
  1218. if( !empty($head_commission_order_info) )
  1219. {
  1220. foreach( $head_commission_order_info as &$vv)
  1221. {
  1222. if($vv['state'] == 1){
  1223. $order_head_status =1;
  1224. }
  1225. $head_info_tp = M('lionfish_community_head')->field('head_name')->where( array('id' => $vv['head_id'] ) )->find();
  1226. $vv['head_name'] = $head_info_tp['head_name'];
  1227. if (defined('ROLE') && ROLE == 'agenter' )
  1228. {
  1229. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1230. if($supply_can_look_headinfo != 1){
  1231. $vv['head_name'] = D('Seller/Order')->desensitize($vv['head_name'],1,1);
  1232. }
  1233. }
  1234. //退配送费
  1235. $refund_shipping_fare = 0;
  1236. if($vv['type'] == 'orderbuy' && $vv['add_shipping_fare'] > 0){
  1237. $refund_shipping_sql = "SELECT sum(refund_shipping_fare) as refund_shipping_fare "
  1238. . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund "
  1239. . " WHERE order_id=".$vv['order_id'].' and order_goods_id='.$vv['order_goods_id'];
  1240. $refund_shippings = M()->query($refund_shipping_sql);
  1241. if(!empty($refund_shippings)){
  1242. $refund_shipping_fare = $refund_shippings[0]['refund_shipping_fare'];
  1243. }
  1244. $vv['add_shipping_fare'] = $vv['add_shipping_fare'] - $refund_shipping_fare;
  1245. $vv['money'] = $vv['money'];
  1246. }else{
  1247. $vv['add_shipping_fare'] = $vv['add_shipping_fare'];
  1248. }
  1249. if($vv['state'] == 2){//分佣订单已取消,分佣金额为0
  1250. $vv['money'] = 0;
  1251. }
  1252. }
  1253. unset($vv);
  1254. }
  1255. if( $value['is_refund_state'] == 1 || $value['has_refund_money'] > 0)
  1256. {
  1257. $refund_info = M('lionfish_comshop_order_refund')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->order('ref_id desc')->find();
  1258. $value['refund_info'] = $refund_info;
  1259. $goods_refund_shipping_fare = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->sum('refund_shipping_fare');
  1260. $value['goods_refund_shipping_fare'] = $goods_refund_shipping_fare;
  1261. }
  1262. if( $item['is_commission'] == 1 )
  1263. {
  1264. $member_commission_list = M('lionfish_comshop_member_commiss_order')->where( array('order_goods_id' => $value['order_goods_id'],'order_id' => $item['order_id']) )->order('id asc')->select();
  1265. if( !empty($member_commission_list) )
  1266. {
  1267. foreach( $member_commission_list as $kk => $vv )
  1268. {
  1269. $tmp_if = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $vv['member_id'] ) )->find();
  1270. $vv['username'] = $tmp_if['username'];
  1271. $member_commission_list[$kk] = $vv;
  1272. }
  1273. }
  1274. $value['member_commission_list'] = $member_commission_list;
  1275. }
  1276. $value['head_commission_order_info'] = $head_commission_order_info;
  1277. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($item['order_id'], $value['order_goods_id']);
  1278. //退款商品价格
  1279. $has_refund_money = M('lionfish_comshop_order_goods')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->find();
  1280. $value['has_refund_money'] = $has_refund_money['has_refund_money'];
  1281. if (defined('ROLE') && ROLE == 'agenter' )
  1282. {
  1283. $supper_info = get_agent_logininfo();
  1284. if($supper_info['id'] != $value['supply_id'])
  1285. {
  1286. continue;
  1287. }
  1288. }
  1289. if( $value['supply_id'] > 0 )
  1290. {
  1291. $supply_info = D('Home/Front')->get_supply_info($value['supply_id']);
  1292. $value['supply_name'] = $supply_info['shopname'];
  1293. $value['supply_type'] = $supply_info['type'] == 1 ? '独立' :'自营';
  1294. }else{
  1295. $value['supply_name'] = '平台自营';
  1296. $value['supply_type'] = '自营';
  1297. }
  1298. $shipping_fare += $value['shipping_fare'];
  1299. $fullreduction_money += $value['fullreduction_money'];
  1300. $voucher_credit += $value['voucher_credit'];
  1301. $total += $value['total'];
  1302. if($item['delivery'] == 'hexiao'){
  1303. $value['hx_info'] = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->find();
  1304. if(!empty($value['hx_info'])){
  1305. if($value['hx_info']['is_hexiao_over'] == 1 || $value['hx_info']['is_hexiao_over'] == 2){
  1306. $value['hx_info']['is_can_refund'] = 0;
  1307. }else if($value['hx_info']['is_hexiao_over'] == 0){
  1308. //$can_refund_quantity = floor($value['hx_info']['remain_hexiao_count']/$value['hx_info']['one_hexiao_count']);
  1309. $can_refund_quantity = floor($value['hx_info']['hexiao_count']/$value['hx_info']['one_hexiao_count']);
  1310. // var_dump($can_refund_quantity);
  1311. if($can_refund_quantity >= 1){
  1312. $value['hx_info']['is_can_refund'] = 1;
  1313. }else{
  1314. $value['hx_info']['is_can_refund'] = 0;
  1315. }
  1316. }
  1317. $record_count = M('lionfish_comshop_order_goods_saleshexiao_record')->where(array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->count();
  1318. $value['hx_info']['record_count'] = $record_count;
  1319. }
  1320. }
  1321. $need_order_goods[$key] = $value;
  1322. }
  1323. if (defined('ROLE') && ROLE == 'agenter' )
  1324. {
  1325. $item['shipping_fare'] = $shipping_fare;
  1326. $item['fullreduction_money'] = $fullreduction_money;
  1327. $item['voucher_credit'] = $voucher_credit;
  1328. $item['total'] = $total;
  1329. }
  1330. $order_goods = $need_order_goods;
  1331. if (empty($item)) {
  1332. $this->message('抱歉,订单不存在!', $_SERVER['HTTP_REFERER'], 'error');
  1333. }
  1334. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id'] ) )->find();
  1335. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  1336. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  1337. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  1338. $express_info = array();
  1339. if( !empty($item['shipping_method']) )
  1340. {
  1341. $express_info = D('Seller/Express')->get_express_info($item['shipping_method']);
  1342. }
  1343. $this->express_info = $express_info;
  1344. $coupon = array();
  1345. //voucher_id voucher_credit
  1346. //ims_
  1347. if( $item['voucher_id'] > 0 )
  1348. {
  1349. $coupon = array();
  1350. //$coupon = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ",
  1351. //array(':uniacid' => $_W['uniacid'], ':id' => $item['voucher_id']));
  1352. }
  1353. if( $item['delivery'] == 'localtown_delivery' && ($item['order_status_id'] != 3 && $item['order_status_id'] != 5 ) )
  1354. {
  1355. $item['orderdistribution_order'] = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $item['order_id'] ) )->find();
  1356. if( !empty($item['orderdistribution_order']) && $item['orderdistribution_order'] > 0 )
  1357. {
  1358. if($item['orderdistribution_order']['orderdistribution_id'] > 0){
  1359. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('id' => $item['orderdistribution_order']['orderdistribution_id'] ) )->find();
  1360. $item['orderdistribution_order']['username'] = $orderdistribution['username'];
  1361. }else{
  1362. /*if($item['orderdistribution_order']['orderdistribution_id'] == -1){
  1363. $item['orderdistribution_order']['username'] = "系统默认配送员";
  1364. }else{*/
  1365. if($item['orderdistribution_order']['third_distribution_type'] == 'imdada'){
  1366. $item['orderdistribution_order']['username'] = "达达平台配送";
  1367. }else if($item['orderdistribution_order']['third_distribution_type'] == 'sf'){
  1368. $item['orderdistribution_order']['username'] = "顺丰同城配送";
  1369. }else if($item['orderdistribution_order']['third_distribution_type'] == 'uupt'){
  1370. $item['orderdistribution_order']['username'] = "UU跑腿配送";
  1371. }else if($item['orderdistribution_order']['third_distribution_type'] == 'dianwoda'){
  1372. $item['orderdistribution_order']['username'] = "点我达配送";
  1373. }
  1374. //}
  1375. }
  1376. }
  1377. }
  1378. if (defined('ROLE') && ROLE == 'agenter' )
  1379. {
  1380. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1381. if($supply_can_look_headinfo != 1){
  1382. if( $item['delivery'] == 'pickup' ){
  1383. $shipping_stree = D('Home/Front')->get_area_info($item['shipping_stree_id']);
  1384. $tuan_address = $province_info['name'].$city_info['name'].$area_info['name'];
  1385. $tuan_address2= str_replace($tuan_address, '',$item['shipping_address']);
  1386. $str = $tuan_address2;
  1387. strlen($str);
  1388. $i = mb_strlen($str,"UTF-8");
  1389. $tuan_address2 = D('Seller/Order')->desensitize($tuan_address2,1,$i-2);
  1390. $item['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$tuan_address2;
  1391. }
  1392. }
  1393. }
  1394. //售后期
  1395. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  1396. //天数
  1397. $open_aftersale_time = D('Home/Front')->get_config_by_name('open_aftersale_time');
  1398. $order_settlement =" ";
  1399. //订单状态
  1400. if($item['order_status_id'] ==5 || $item['order_status_id'] ==7 ){
  1401. //已失效
  1402. $order_status = 2;
  1403. }else{
  1404. //待结算
  1405. $order_status = $order_head_status;
  1406. if(($item['order_status_id'] ==6 || $item['order_status_id'] ==11) ){
  1407. if($item['order_status_id'] ==6){
  1408. $order_settlement = $item['receive_time'] + $open_aftersale_time*86400;
  1409. }
  1410. if($item['order_status_id'] ==11){
  1411. $order_settlement = $item['finishtime'] + $open_aftersale_time*86400;
  1412. }
  1413. }
  1414. }
  1415. $this->open_aftersale = $open_aftersale;
  1416. $this->order_status = $order_status;
  1417. $this->open_aftersale_time = $open_aftersale_time;
  1418. $this->order_settlement = $order_settlement;
  1419. $this->id = $id;
  1420. $this->item = $item;
  1421. $this->order_goods = $order_goods;
  1422. $this->member = $member;
  1423. $this->province_info = $province_info;
  1424. $this->city_info = $city_info;
  1425. $this->area_info = $area_info;
  1426. $history_list = M('lionfish_comshop_order_history')->where( array('order_id' => $id ) )->order('order_history_id asc')->select();
  1427. $order_status_arr = D('Seller/Order')->get_order_status_name();
  1428. //$order_history['order_status_id'] = 18;
  1429. $order_status_arr[18] = '已结算';
  1430. $order_status_arr[19] = '商品部分退款';
  1431. $order_status_arr[20] = '拒绝商品部分退款';
  1432. $order_status_arr[15] = '预售支付定金';
  1433. foreach( $history_list as &$val )
  1434. {
  1435. if( $val[''] == '订单改价' )
  1436. {
  1437. $val['order_status_name'] = 'comment';
  1438. }
  1439. else{
  1440. $val['order_status_name'] = $order_status_arr[$val['order_status_id']];
  1441. }
  1442. }
  1443. unset($val);
  1444. $this->history_list = $history_list;
  1445. $this->order_status_arr = $order_status_arr;
  1446. $is_can_look_headinfo = true;
  1447. $is_can_nowrfund_order = true;
  1448. $is_can_confirm_delivery = true;
  1449. $is_can_confirm_receipt = true;
  1450. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1451. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  1452. $supply_can_confirm_delivery = D('Home/Front')->get_config_by_name('supply_can_confirm_delivery');
  1453. $supply_can_confirm_receipt = D('Home/Front')->get_config_by_name('supply_can_confirm_receipt');
  1454. if (defined('ROLE') && ROLE == 'agenter' )
  1455. {
  1456. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1457. {
  1458. $is_can_look_headinfo = false;
  1459. }
  1460. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  1461. {
  1462. $is_can_nowrfund_order = false;
  1463. }
  1464. if( isset($supply_can_confirm_delivery) && $supply_can_confirm_delivery == 2 )
  1465. {
  1466. $is_can_confirm_delivery = false;
  1467. }
  1468. if( isset($supply_can_confirm_receipt) && $supply_can_confirm_receipt == 2 )
  1469. {
  1470. $is_can_confirm_receipt = false;
  1471. }
  1472. }
  1473. $s_id = 1 ;
  1474. if(SELLERUID != 1)
  1475. {
  1476. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  1477. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  1478. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  1479. $perms2 = explode(",", $perms1);
  1480. if(in_array("user/user/index", $perms2)){
  1481. $s_id = 1 ;
  1482. } else {
  1483. $s_id = 0 ;
  1484. }
  1485. }
  1486. $this->s_id = $s_id;
  1487. //预售判断 begin
  1488. $is_presale = 0;
  1489. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  1490. $presale_for_ordermoney = 0;
  1491. if( $presale_result['code'] == 0 )
  1492. {
  1493. if( $presale_result['data']['presale_deduction_money'] > 0 )
  1494. {
  1495. $presale_for_ordermoney = $presale_result['data']['presale_for_ordermoney'];
  1496. }
  1497. $is_presale = 1;
  1498. }
  1499. $this->is_presale = $is_presale;
  1500. $this->presale_for_ordermoney = $presale_for_ordermoney;
  1501. //预售end
  1502. //礼品卡begin
  1503. $is_virtualcard = 0;
  1504. $virtualcard_result = D('Seller/VirtualCard')->getVirtualCardOrderInfO( $id );
  1505. if( $virtualcard_result['code'] == 0 )
  1506. {
  1507. $is_virtualcard = 1;
  1508. $this->virtualcard_info = $virtualcard_result['data'];
  1509. }
  1510. $this->is_virtualcard = $is_virtualcard;
  1511. //礼品卡end
  1512. //订单表单信息
  1513. $order_form_data = D('Home/Allform')->getOrderFormInfo($id, $item['member_id']);
  1514. $this->order_form_data = $order_form_data;
  1515. $is_order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  1516. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  1517. $order_note_name = isset($order_note_name) && !empty($order_note_name) ? $order_note_name :'店名';
  1518. $open_admin_payment = D('Home/Front')->get_config_by_name('open_admin_payment');
  1519. $this->open_admin_payment = $open_admin_payment;
  1520. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  1521. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  1522. $this->is_order_note_open = $is_order_note_open;
  1523. $this->order_note_name = $order_note_name;
  1524. $this->is_can_look_headinfo = $is_can_look_headinfo;
  1525. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  1526. $this->is_can_confirm_delivery = $is_can_confirm_delivery;
  1527. $this->is_can_confirm_receipt = $is_can_confirm_receipt;
  1528. $this->localtown_modifypickingname = $localtown_modifypickingname;
  1529. $this->display();
  1530. }
  1531. //查看物流
  1532. public function express(){
  1533. $_GPC = I('request.');
  1534. $order_id = $_GPC['order_id'];
  1535. $express_list = D('Seller/Order')->goods_express($order_id);
  1536. if($express_list['code'] == 2){
  1537. $code = $express_list['code'];
  1538. $reason = $express_list['Reason'];
  1539. $this->code = $code;
  1540. $this->reason = $reason;
  1541. }
  1542. $new_array = json_decode(json_encode($express_list['order_info']['shipping_traces']), true);
  1543. $new_array = array_reverse($new_array);
  1544. $this->list = $new_array;
  1545. $this->display();
  1546. }
  1547. public function refund_mult()
  1548. {
  1549. $_GPC = I('request.');
  1550. $ids_arr = $_GPC['ids_arr'];
  1551. $cache_key = md5(time().count($ids_arr).'_sendmulutrefund');
  1552. $quene_order_list = array();
  1553. //限定配送数组
  1554. S('_multrefund_'.$cache_key, $ids_arr);
  1555. $this->_GPC = $_GPC;
  1556. $this->cache_key = $cache_key;
  1557. $this->display();
  1558. }
  1559. public function refund_mult_do()
  1560. {
  1561. $_GPC = I('request.');
  1562. $cache_key = $_GPC['cache_key'];
  1563. $quene_order_list = S('_multrefund_'.$cache_key);
  1564. $order_id = array_shift($quene_order_list);
  1565. S('_multrefund_'.$cache_key, $quene_order_list);
  1566. //...
  1567. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1568. $weixin_model = D('Home/Weixin');
  1569. $title = '订单编号:'.$order_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理";
  1570. //order_status_id
  1571. if( in_array($order_info['order_status_id'], array(1,4,6,10,11,12,14)) ){
  1572. $res = $weixin_model->refundOrder($order_id);
  1573. if( $res['code'] == 0 )
  1574. {
  1575. $title = '订单编号:'.$order_info['order_num_alias']." 退款失败,还剩余".count($quene_order_list)."个清单未处理";
  1576. }else{
  1577. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1578. $comment = '群接龙批量退款,全额退款';
  1579. $order_history = array();
  1580. $order_history['order_id'] = $order_id;
  1581. $order_history['order_status_id'] = 7;
  1582. $order_history['notify'] = 0;
  1583. $order_history['comment'] = $comment;
  1584. $order_history['date_added'] = time();
  1585. M('lionfish_comshop_order_history')->add( $order_history );
  1586. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 7) );
  1587. $refund_all = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id, 'state' => 0 ) )->select();
  1588. if( !empty($refund_all) )
  1589. {
  1590. foreach( $refund_all as $val )
  1591. {
  1592. $ins_data = array();
  1593. $ins_data['ref_id'] = $val['ref_id'];
  1594. $ins_data['order_id'] = $val['order_id'];
  1595. $ins_data['order_goods_id'] = $val['order_goods_id'];
  1596. $ins_data['message'] = '群接龙批量退款 ,退款成功';
  1597. $ins_data['type'] = 2;
  1598. $ins_data['addtime'] = time();
  1599. M('lionfish_comshop_order_refund_history')->add( $ins_data );
  1600. M('lionfish_comshop_order_refund')->where( array('ref_id' => $val['ref_id']) )->save( array('state' => 3) );
  1601. }
  1602. }
  1603. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  1604. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  1605. {
  1606. sellerLog('群接龙后台取消订单', 2);
  1607. D('Seller/Printaction')->check_print_order($id,'群接龙后台取消订单');
  1608. D('Seller/Printaction')->check_print_order2($id,'群接龙后台取消订单');
  1609. }
  1610. }
  1611. }
  1612. if( empty($quene_order_list) )
  1613. {
  1614. echo json_encode( array('code' => 2) );
  1615. die();
  1616. }
  1617. //清单编号
  1618. echo json_encode( array('code' => 0, 'msg' => $title ) );
  1619. die();
  1620. }
  1621. public function opreceive()
  1622. {
  1623. $opdata = $this->check_order_data();
  1624. extract($opdata);
  1625. //检查订单是否能确认收货(存在售后未完成无法确认收货)
  1626. $result = D('Seller/Order')->check_order_receive($item['order_id']);
  1627. if($result['status'] == 0){
  1628. show_json(0, array('msg'=>"该订单处于售后处理中,请处理后再确认收货!"));
  1629. }
  1630. if($item['delivery'] == 'localtown_delivery') {
  1631. $result = D('Seller/Order')->check_localtown_order_receive($item['order_id']);
  1632. if ($result['status'] == 0) {
  1633. show_json(0, array('msg' => "该订单未有配送员接单或还未指定配送员,无法确认收货!"));
  1634. }
  1635. }
  1636. //pdo_update('lionfish_comshop_order', array('order_status_id' => 6, 'receive_time' => time()), array('order_id' => $item['order_id'], 'uniacid' => $_W['uniacid']));
  1637. if( $item['delivery'] == 'localtown_delivery' )
  1638. {
  1639. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $item['order_id']) )->save( array('state' => 4) );
  1640. D('Home/LocaltownDelivery')->write_distribution_log( $item['order_id'], 0 , 4 , "后台操作,确认收货" );
  1641. }
  1642. D('Seller/Order')->receive_order($item['order_id']);
  1643. M('lionfish_comshop_order_history')->where( array('order_id' => $item['order_id'],'order_status_id' => 6) )->save( array( 'comment' => '后台操作,确认收货') );
  1644. if( $item['delivery'] == 'localtown_delivery' )
  1645. {
  1646. //D('Home/LocaltownDelivery')->distribution_deliverying_order( $item['order_id'] );
  1647. D('Home/LocaltownDelivery')->distribution_arrived_order( $item['order_id'] ,0 );
  1648. }
  1649. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1650. }
  1651. public function orderaftersales()
  1652. {
  1653. //$_GPC['order_status_id'] = 12;
  1654. $gpc = I('request.');
  1655. $this->gpc = $gpc;
  1656. $this->_GPC = $gpc;
  1657. $time = I('request.time');
  1658. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  1659. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  1660. $this->searchfield = I('request.searchfield','');
  1661. $this->keyword = I('request.keyword','');
  1662. $this->searchtime = I('request.searchtime','');
  1663. $this->delivery = I('request.delivery','');
  1664. $this->starttime = $starttime;
  1665. $this->endtime = $endtime;
  1666. $this->time = $time;
  1667. $order_status_arr = D('Seller/Order')->get_order_status_name();
  1668. $this->order_status_arr = $order_status_arr;
  1669. $need_data = D('Seller/Order')->load_afterorder_list();//改造原来的加载方法
  1670. $this->need_data = $need_data;
  1671. $cur_controller = 'order/order';
  1672. $total = $need_data['total'];
  1673. $total_money = $need_data['total_money'];
  1674. $list = $need_data['list'];
  1675. $pager = $need_data['pager'];
  1676. $all_count = $need_data['all_count'];
  1677. $count_status_1 = $need_data['count_status_1'];
  1678. $count_status_3 = $need_data['count_status_3'];
  1679. $count_status_4 = $need_data['count_status_4'];
  1680. $count_status_5 = $need_data['count_status_5'];
  1681. $count_status_7 = $need_data['count_status_7'];
  1682. $count_status_11 = $need_data['count_status_11'];
  1683. $count_status_14 = $need_data['count_status_14'];
  1684. $this->cur_controller = $cur_controller;
  1685. $this->total = $total;
  1686. $this->total_money = $total_money;
  1687. $this->list = $list;
  1688. $this->pager = $pager;
  1689. $this->all_count = $all_count;
  1690. $this->count_status_1 = $count_status_1;
  1691. $this->count_status_3 = $count_status_3;
  1692. $this->count_status_4 = $count_status_4;
  1693. $this->count_status_5 = $count_status_5;
  1694. $this->count_status_7 = $count_status_7;
  1695. $this->count_status_11 = $count_status_11;
  1696. $this->count_status_14 = $count_status_14;
  1697. $s_id = 1 ;
  1698. if(SELLERUID != 1)
  1699. {
  1700. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  1701. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  1702. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  1703. $perms2 = explode(",", $perms1);
  1704. if(in_array("user/user/index", $perms2)){
  1705. $s_id = 1 ;
  1706. } else {
  1707. $s_id = 0 ;
  1708. }
  1709. }
  1710. $this->s_id = $s_id;
  1711. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  1712. if( empty($open_feier_print) )
  1713. {
  1714. $open_feier_print = 0;
  1715. }
  1716. $this->open_feier_print = $open_feier_print;
  1717. //退款状态:0申请中,1商家拒绝,2平台介入,3退款成功,4退款失败,5:撤销申请
  1718. $order_refund_state = array(0=>'申请中',1=>'商家拒绝', 2=>'平台介入',3=>'退款成功',4=>'退款失败',5=>'撤销申请');
  1719. $this->order_refund_state = $order_refund_state;
  1720. $is_can_look_headinfo = true;
  1721. $is_can_nowrfund_order = true;
  1722. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1723. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  1724. if (defined('ROLE') && ROLE == 'agenter' )
  1725. {
  1726. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1727. {
  1728. $is_can_look_headinfo = false;
  1729. }
  1730. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  1731. {
  1732. $is_can_nowrfund_order = false;
  1733. }
  1734. }
  1735. $this->is_can_look_headinfo = $is_can_look_headinfo;
  1736. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  1737. $this->display();
  1738. }
  1739. public function oprefund_doform()
  1740. {
  1741. $_GPC = I('request.');
  1742. $ref_id = $_GPC['ref_id'];
  1743. $refund_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  1744. $this->ref_id = $ref_id;
  1745. $this->refund_info = $refund_info;
  1746. if (IS_POST) {
  1747. $order_history = array();
  1748. $order_history['order_id'] = $refund_info['order_id'];
  1749. $order_history['order_status_id'] = 0;
  1750. $order_history['notify'] = 0;
  1751. $order_history['comment'] = '';
  1752. $order_history['date_added'] = time();
  1753. $remarkrefund = $_GPC['remarkrefund'];
  1754. $is_forbidden = $_GPC['is_forbidden'];
  1755. $cansub = $_GPC['cansub'];
  1756. if( isset($_GPC['is_forbidden']) && $_GPC['is_forbidden'] > 0 )
  1757. {
  1758. //添加
  1759. $refund_disable = M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $ref_id ) )->find();
  1760. if( empty($refund_disable) )
  1761. {
  1762. //插入
  1763. $ins_data = array();
  1764. $ins_data['ref_id'] = $ref_id;
  1765. $ins_data['order_id'] = $refund_info['order_id'];
  1766. $ins_data['order_goods_id'] = $refund_info['order_goods_id'];
  1767. $ins_data['addtime'] = time();
  1768. M('lionfish_comshop_order_refund_disable')->add($ins_data);
  1769. }
  1770. }else{
  1771. //删除
  1772. M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $ref_id ) )->delete();
  1773. }
  1774. if($cansub == 1)
  1775. {
  1776. //确认退款 remarkrefund
  1777. $weixin_model = D('Home/Weixin');
  1778. $order_refund = M('lionfish_comshop_order_refund')->field('ref_money,real_refund_quantity,ref_shipping_fare')->where( array('ref_id' => $ref_id ) )->find();
  1779. //$order_info['total']
  1780. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->find();
  1781. if( $order_info['type'] == 'integral' || $order_info['type'] == 'normal' )
  1782. {
  1783. //M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('shipping_fare' => $order_refund['ref_shipping_fare'] ) );
  1784. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1785. {
  1786. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->find();
  1787. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->save( array('shipping_fare' => $order_refund['ref_shipping_fare'] ) );
  1788. }
  1789. }
  1790. if( $order_refund['real_refund_quantity'] > 0 )
  1791. {
  1792. //部分商品退款
  1793. $res = $weixin_model->refundOrder($refund_info['order_id'], $order_refund['ref_money'],0,$refund_info['order_goods_id'],1, $order_refund['real_refund_quantity'],1);
  1794. }else{
  1795. $res = $weixin_model->refundOrder($refund_info['order_id'], $order_refund['ref_money'],0,$refund_info['order_goods_id']);
  1796. }
  1797. if( $order_info['type'] == 'integral' || $order_info['type'] == 'normal')
  1798. {
  1799. //M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('shipping_fare' => $order_info['shipping_fare'] ) );
  1800. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1801. {
  1802. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->save( array('shipping_fare' => $order_goods['shipping_fare'] ) );
  1803. }
  1804. }
  1805. if($res['code'] == 1)
  1806. {
  1807. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] , 'order_id' => $refund_info['order_id'] ) )->find();
  1808. if( $order_refund['real_refund_quantity'] <= 0 )
  1809. {
  1810. $order_refund['real_refund_quantity'] = $order_goods['quantity'] - $order_goods['has_refund_quantity'];
  1811. }
  1812. $pay_total_money = $order_goods['total']-$order_goods['voucher_credit']-$order_goods['fullreduction_money'] - $order_goods['score_for_money'];
  1813. $buy_usescore = D('Seller/Commonorder')->get_order_goods_buyscore($refund_info['order_id'], $refund_info['order_goods_id']);
  1814. if( !empty($buy_usescore) && $buy_usescore > 0 )
  1815. {
  1816. $res_score= ceil( $buy_usescore * ( $order_refund['real_refund_quantity']/ $order_goods['quantity']) );
  1817. D('Seller/Commonorder')->refund_order_goods_intrgral( $refund_info['order_id'], $refund_info['order_goods_id'] ,$res_score );
  1818. }
  1819. if($order_refund['ref_money']-$order_refund['ref_shipping_fare'] <= 0){
  1820. $refund_money = 0;
  1821. }else{
  1822. $refund_money = $order_refund['ref_money']-$order_refund['ref_shipping_fare'];
  1823. }
  1824. if( $order_info['type'] == 'integral'){
  1825. $refund_money = $order_refund['ref_money'];
  1826. }
  1827. //退款配送费问题
  1828. D('Seller/Commonorder')->ins_order_goods_refund($refund_info['order_id'], $refund_info['order_goods_id'],$pay_total_money,$order_refund['real_refund_quantity'], $order_refund['real_refund_quantity'],$refund_money,1,$order_refund['ref_shipping_fare']);
  1829. //如果这个商品没有数量了。就改变他的状态为已退款的状态
  1830. $new_total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($refund_info['order_id'],$refund_info['order_goods_id'] );
  1831. $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $refund_info['order_id'], 'state' => 0 ) )->count();
  1832. if( $new_total_quantity <=0 && $ref_count <= 1)
  1833. {
  1834. D('Seller/Commonorder')->check_refund_order_goods_status($refund_info['order_id'],$refund_info['order_goods_id'], $order_refund['ref_money'],1,$order_refund['real_refund_quantity'], $order_refund['real_refund_quantity'],1,'平台同意退款,');
  1835. }else{
  1836. $order_history = array();
  1837. $order_history['uniacid'] = 0;
  1838. $order_history['order_id'] = $refund_info['order_id'];
  1839. $order_history['order_goods_id'] = $refund_info['order_goods_id'];
  1840. $order_history['notify'] = 0;
  1841. $order_history['order_status_id'] = 19;
  1842. if( $order_info['type'] == 'integral' )
  1843. {
  1844. $order_history['comment'] = '平台同意退款,子订单退款,退款商品:'.$order_refund['real_refund_quantity'] .'个,退库存/销量数量'.$order_refund['real_refund_quantity'].'个,退款积分'.$order_refund['ref_money'].'积分';
  1845. if( !empty($order_refund['ref_shipping_fare']) ){
  1846. $order_history['comment'] .= '. 退配送费:'.$order_refund['ref_shipping_fare'].'元';
  1847. }
  1848. }else{
  1849. $order_history['comment'] = '平台同意退款,子订单退款,退款商品:'.$order_refund['real_refund_quantity'] .'个,退库存/销量数量'.$order_refund['real_refund_quantity'].'个,退款金额'.$order_refund['ref_money'].'元';
  1850. }
  1851. $order_history['date_added'] = time();
  1852. M('lionfish_comshop_order_history')->add( $order_history );
  1853. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] ) )->save( array('is_refund_state' => 0 ) );
  1854. }
  1855. //D('Seller/Commonorder')->ins_order_goods_refund($order_id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money, $is_back_sellcount);
  1856. $order_refund_history = array();
  1857. $order_refund_history['ref_id'] = $ref_id;
  1858. $order_refund_history['order_id'] = $refund_info['order_id'];
  1859. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1860. $order_refund_history['message'] = '平台同意退款'.' '.$remarkrefund.' ,退款成功';
  1861. $order_refund_history['type'] = 2;
  1862. $order_refund_history['addtime'] = time();
  1863. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1864. //通过 lionfish_comshop_order_refund
  1865. sellerLog('同意'.$remarkrefund.'退款成功操作', 2);
  1866. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 3,'modify_time' => time(),'remarkrefund' => $remarkrefund) );
  1867. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1868. }else{
  1869. if( empty($res['msg']) )
  1870. {
  1871. $res['msg'] = '请检查商户号与cert证书';
  1872. }
  1873. $order_refund_history = array();
  1874. $order_refund_history['ref_id'] = $ref_id;
  1875. $order_refund_history['order_id'] = $refund_info['order_id'];
  1876. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1877. $order_refund_history['message'] = '平台同意退款'.' '.$remarkrefund.' ,但是退款失败:'.$res['msg'];
  1878. $order_refund_history['type'] = 2;
  1879. $order_refund_history['addtime'] = time();
  1880. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1881. show_json(0, array('message' => $res['msg']) );
  1882. }
  1883. }else if($cansub == 2){
  1884. //拒绝退款
  1885. $order_refund_history = array();
  1886. $order_refund_history['ref_id'] = $ref_id;
  1887. $order_refund_history['order_id'] = $refund_info['order_id'];
  1888. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1889. $order_refund_history['message'] = '平台拒绝退款'.' '.$remarkrefund;
  1890. $order_refund_history['type'] = 2;
  1891. $order_refund_history['addtime'] = time();
  1892. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1893. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 1,'modify_time' => time(),'remarkrefund' => $remarkrefund ) );
  1894. $item = M('lionfish_comshop_order')->field('order_status_id,last_refund_order_status_id')->where( array('order_id' => $refund_info['order_id'] ) )->find();
  1895. $order_history['order_status_id'] = 20;
  1896. //如果是部分退款,那么就不是12了
  1897. if( $item['order_status_id'] == 12)
  1898. {
  1899. $order_history['order_status_id'] = 12;
  1900. if( $item['last_refund_order_status_id'] > 0 )
  1901. {
  1902. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  1903. M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('order_status_id' => $item['last_refund_order_status_id']) );
  1904. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  1905. $order_history['comment'] = '商家拒绝退款,订单回退上一状态';
  1906. }else{
  1907. $order_history['comment'] = '商家拒绝退款';
  1908. }
  1909. }
  1910. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1911. {
  1912. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] ) )->save( array('is_refund_state' => 0) );
  1913. }
  1914. //拒绝 order_status_id
  1915. sellerLog($order_history['comment'].'操作', 2);
  1916. M('lionfish_comshop_order_history')->add( $order_history );
  1917. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1918. }
  1919. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1920. }
  1921. $this->display();
  1922. }
  1923. public function oprefund()
  1924. {
  1925. $_GPC = I('request.');
  1926. $opdata = $this->check_order_data();
  1927. extract($opdata);
  1928. $ref_id = $_GPC['ref_id'];
  1929. $ref_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  1930. $step_array = array();
  1931. $step_array[1]['step'] = 1;
  1932. $step_array[1]['title'] = '客户发起退款';
  1933. $step_array[1]['time'] = $ref_info['addtime'];
  1934. $step_array[1]['done'] = 1;
  1935. $step_array[2]['step'] = 2;
  1936. $step_array[2]['title'] = '平台处理维权申请';
  1937. $step_array[2]['done'] = 0;
  1938. $step_array[2]['time'] = '';
  1939. $step_array[3]['step'] = 3;
  1940. $step_array[3]['done'] = 0;
  1941. $step_array[3]['title'] = '商家处理退款完成';
  1942. $step_array[3]['time'] = '';
  1943. $ref_id = I('request.ref_id');
  1944. $this->ref_id = $ref_id;
  1945. $this->ref_info = $ref_info;
  1946. $order_goods_id = $ref_info['order_goods_id'];
  1947. if( !empty($order_goods_id) && $order_goods_id > 0 )
  1948. {
  1949. $goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id, 'order_id' => $id ) )->select();
  1950. }else{
  1951. $goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->select();
  1952. }
  1953. $total_fare = 0;
  1954. $total_shipping_fare = 0;
  1955. $total_voucher_credit =0;
  1956. $total_fullreduction_money = 0;
  1957. $total_total_fare = 0;
  1958. $total_score_for_money = 0;
  1959. /**
  1960. php echo number_format($item['total']+$item['shipping_fare']-$item['voucher_credit']-$item['fullreduction_money'],2)
  1961. **/
  1962. foreach($goods as &$value)
  1963. {
  1964. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($item['order_id'], $value['order_goods_id']);
  1965. $total_fare += $value['total'];
  1966. $total_shipping_fare += $value['shipping_fare'];
  1967. $total_voucher_credit += $value['voucher_credit'];
  1968. $total_fullreduction_money += $value['fullreduction_money'];
  1969. $total_score_for_money += $value['score_for_money'];
  1970. $total_total_fare += $value['total']+$value['shipping_fare']-$value['voucher_credit']-$value['fullreduction_money']-$value['score_for_money'];
  1971. }
  1972. $this->goods = $goods;
  1973. $this->total_fare = $total_fare;
  1974. $this->total_shipping_fare = $total_shipping_fare;
  1975. $this->total_voucher_credit = $total_voucher_credit;
  1976. $this->total_fullreduction_money = $total_fullreduction_money;
  1977. $this->total_score_for_money = $total_score_for_money;
  1978. $this->total_total_fare = $total_total_fare;
  1979. unset($r);
  1980. $item['goods'] = $goods;
  1981. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id']) )->find();
  1982. $this->member = $member;
  1983. $express_list = array();
  1984. $r_type = array(1=>'仅退款',2 => '退款退货');
  1985. //ims_
  1986. $this->r_type =$r_type;
  1987. $order_refund = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->find();
  1988. $this->order_refund = $order_refund;
  1989. if($order_refund['modify_time'] != 0 && $order_refund['state']== 3)
  1990. {
  1991. $step_array[3]['done'] = 1;
  1992. $step_array[3]['time'] = $order_refund['modify_time'];
  1993. }
  1994. $refund_imgs = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id'] ) )->select();
  1995. $this->refund_imgs = $refund_imgs;
  1996. /**
  1997. if( !empty($order_goods_id) && $order_goods_id > 0 )
  1998. {
  1999. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' =>$id,'order_goods_id' => $order_goods_id ) )->order('addtime asc')->select();
  2000. }
  2001. else{
  2002. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' =>$id ) )->order('addtime asc')->select();
  2003. }
  2004. **/
  2005. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('ref_id' => $ref_id ) )->order('addtime asc')->select();
  2006. $i = 1;
  2007. foreach($order_refund_history as $key => $val)
  2008. {
  2009. if( $i == 1 && $val['type'] == 2 )
  2010. {
  2011. $step_array[2]['done'] = 1;
  2012. $step_array[2]['time'] = time();
  2013. $i++;
  2014. }
  2015. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2016. switch($val['type'])
  2017. {
  2018. case 1:
  2019. $val['type'] = '用户反馈';
  2020. break;
  2021. case 2:
  2022. $val['type'] = '商家反馈';
  2023. break;
  2024. case 3:
  2025. $val['type'] = '平台反馈';
  2026. break;
  2027. }
  2028. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2029. if(!empty($order_refund_history_image))
  2030. {
  2031. foreach($order_refund_history_image as $kk => $vv)
  2032. {
  2033. $vv['thumb_image'] = resize ($vv['image'], 200,200);
  2034. $order_refund_history_image[$kk] = $vv;
  2035. }
  2036. }
  2037. $val['order_refund_history_image'] = $order_refund_history_image;
  2038. $order_refund_history[$key] = $val;
  2039. }
  2040. $this->step_array = $step_array;
  2041. $this->order_refund_history = $order_refund_history;
  2042. $this->item = $item;
  2043. $this->display();
  2044. }
  2045. public function oprefund_submit()
  2046. {
  2047. $gpc = I('request.');
  2048. $opdata = $this->check_order_data();
  2049. extract($opdata);
  2050. if (IS_POST) {
  2051. $id = $gpc['id'];
  2052. //refundstatus message refundcontent
  2053. $refundstatus = $gpc['refundstatus'];
  2054. $message = $gpc['message'];
  2055. $refundcontent = $gpc['refundcontent'];
  2056. $ref_id = $gpc['refundid'];
  2057. /**
  2058. int(37)
  2059. string(1) "1"
  2060. string(0) ""
  2061. string(15) "天天来退货"
  2062. **/
  2063. //1 ,3
  2064. $comment = '';
  2065. switch( $refundstatus )
  2066. {
  2067. case 1:
  2068. $comment = $refundcontent;
  2069. break;
  2070. case 3:
  2071. $comment = $message;
  2072. break;
  2073. }
  2074. $ref_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  2075. $result = array('code' =>1);
  2076. $order_refund_history = array();
  2077. $order_refund_history['order_id'] = $ref_info['order_id'];
  2078. $order_refund_history['order_goods_id'] = $ref_info['order_goods_id'];
  2079. $order_refund_history['message'] = htmlspecialchars($comment);
  2080. $order_refund_history['type'] = 2;
  2081. $order_refund_history['addtime'] = time();
  2082. M('lionfish_comshop_order_refund_history')->add($order_refund_history);
  2083. $order_history = array();
  2084. $order_history['order_id'] = $id;
  2085. $order_history['order_status_id'] = 0;
  2086. $order_history['notify'] = 0;
  2087. $order_history['comment'] = '';
  2088. $order_history['date_added'] = time();
  2089. if($refundstatus ==1)
  2090. {
  2091. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 1) );
  2092. //id item $order_info $item
  2093. $item = M('lionfish_comshop_order')->field('order_status_id,last_refund_order_status_id')->where( array('order_id' => $id ) )->find();
  2094. //如果是部分退款,那么就不是12了
  2095. if( $item['order_status_id'] == 12)
  2096. {
  2097. $order_history['order_status_id'] = 12;
  2098. if( $item['last_refund_order_status_id'] > 0 )
  2099. {
  2100. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  2101. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('order_status_id' =>$item['last_refund_order_status_id'] ) );
  2102. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  2103. }
  2104. }
  2105. if( !empty($ref_info['order_goods_id']) && $ref_info['order_goods_id'] > 0 )
  2106. {
  2107. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $ref_info['order_goods_id'] ) )->save( array('is_refund_state' =>0 ) );
  2108. }
  2109. //拒绝 order_status_id
  2110. $order_history['comment'] = '商家拒绝退款,订单回退上一状态';
  2111. M('lionfish_comshop_order_history')->add( $order_history );
  2112. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2113. } else {
  2114. $weixin_model = D('Home/Weixin');
  2115. $order_refund = M('lionfish_comshop_order_refund')->field('ref_money')->where( array('ref_id' => $ref_id) )->find();
  2116. $res = $weixin_model->refundOrder($id, $order_refund['ref_money'],0,$ref_info['order_goods_id']);
  2117. //array('code' => 0, 'msg' => $res['err_code_des']);
  2118. if($res['code'] == 1)
  2119. {
  2120. $order_history['order_status_id'] = 7;
  2121. $order_history['comment'] = '商家同意退款';
  2122. M('lionfish_comshop_order_history')->add( $order_history );
  2123. //通过 lionfish_comshop_order_refund
  2124. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 3) );
  2125. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2126. }else{
  2127. if( empty($res['msg']) )
  2128. {
  2129. $res['msg'] = '请检查商户号与cert证书';
  2130. }
  2131. show_json(0, array('message' => $res['msg']) );
  2132. }
  2133. }
  2134. }
  2135. $r_type = array(1=>'仅退款',2 => '退款退货');
  2136. //ims_
  2137. $order_refund = M('lionfish_comshop_order_refund')->where( array('order_id' => $id) )->find();
  2138. $refund_imgs = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->find();
  2139. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $id) )->order('addtime asc')->select();
  2140. foreach($order_refund_history as $key => $val)
  2141. {
  2142. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2143. switch($val['type'])
  2144. {
  2145. case 1:
  2146. $val['type'] = '用户反馈';
  2147. break;
  2148. case 2:
  2149. $val['type'] = '商家反馈';
  2150. break;
  2151. case 3:
  2152. $val['type'] = '平台反馈';
  2153. break;
  2154. }
  2155. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2156. if(!empty($order_refund_history_image))
  2157. {
  2158. foreach($order_refund_history_image as $kk => $vv)
  2159. {
  2160. $vv['thumb_image'] = resize ($vv['image'], 200,200);
  2161. $order_refund_history_image[$kk] = $vv;
  2162. }
  2163. }
  2164. $val['order_refund_history_image'] = $order_refund_history_image;
  2165. $order_refund_history[$key] = $val;
  2166. }
  2167. $this->order_refund = $order_refund;
  2168. $this->r_type = $r_type;
  2169. $this->item = $item;
  2170. $this->display();
  2171. }
  2172. public function ordercomment_gift()
  2173. {
  2174. if (IS_POST) {
  2175. $data = array();
  2176. $data = I('request.data');
  2177. $data['open_comment_gift'] = trim($data['open_comment_gift']);
  2178. $data['comment_gift_score'] = trim($data['comment_gift_score']);
  2179. $data['comment_gift_time'] = trim($data['comment_gift_time']);
  2180. $data['comment_gift_max_score'] = trim($data['comment_gift_max_score']);
  2181. $data['comment_gift_publish'] = trim($data['comment_gift_publish']);
  2182. D('Seller/Config')->update($data);
  2183. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2184. }
  2185. $data = D('Seller/Config')->get_all_config();
  2186. if(empty($data['comment_gift_publish'])){
  2187. $data['comment_gift_publish'] = "​参与好评有礼活动,好评成功并且后台审核通过以后可获得获得活动积分";
  2188. }
  2189. $this->data = $data;
  2190. $this->display();
  2191. }
  2192. public function ordercomment_config()
  2193. {
  2194. if (IS_POST) {
  2195. $data = array();
  2196. $data = I('request.data');
  2197. $data['open_comment_shenhe'] = trim($data['open_comment_shenhe']);
  2198. D('Seller/Config')->update($data);
  2199. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2200. }
  2201. $data = D('Seller/Config')->get_all_config();
  2202. $this->data = $data;
  2203. $this->display();
  2204. }
  2205. public function ordercomment()
  2206. {
  2207. $condition = ' 1 ';//0
  2208. $pindex = I('request.page', 1);
  2209. $psize = 20;
  2210. $keyword = I('request.keyword');
  2211. $this->keyword = $keyword;
  2212. if (!empty($keyword)) {
  2213. $condition .= ' and content like '.'"%' . $keyword . '%" ';
  2214. }
  2215. $label = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_order_comment
  2216. WHERE " . $condition . ' order by comment_id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  2217. $total = M('lionfish_comshop_order_comment')->where($condition)->count();
  2218. $pager = pagination2($total, $pindex, $psize);
  2219. $this->pager = $pager;
  2220. $this->total = $total;
  2221. $this->label = $label;
  2222. $this->display();
  2223. }
  2224. public function deletecomment()
  2225. {
  2226. $id = I('request.id');
  2227. if (empty($id)) {
  2228. $ids = I('request.ids');
  2229. $id = (is_array($ids) ? implode(',', $ids) : 0);
  2230. }
  2231. $items = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('comment_id' => array('in',$id) ) )->select();
  2232. if (empty($item)) {
  2233. $item = array();
  2234. }
  2235. foreach ($items as $item) {
  2236. M('lionfish_comshop_order_comment')->where( array('comment_id' => $item['comment_id']) )->delete();
  2237. }
  2238. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2239. }
  2240. public function commentstate()
  2241. {
  2242. $id = I('request.id');
  2243. if (empty($id)) {
  2244. $ids = I('request.ids');
  2245. $id = (is_array($ids) ? implode(',', $ids) : 0);
  2246. }
  2247. $items = pdo_fetchall('SELECT comment_id FROM ' . tablename('lionfish_comshop_order_comment') . '
  2248. WHERE comment_id in( ' . $id . ' ) ' );
  2249. $items = M('lionfish_comshop_order_comment')->where( array() )->select();
  2250. if (empty($item)) {
  2251. $item = array();
  2252. }
  2253. foreach ($items as $item) {
  2254. pdo_update('lionfish_comshop_order_comment', array('state' => intval($_GPC['state'])), array('comment_id' => $item['comment_id']));
  2255. }
  2256. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2257. }
  2258. public function config()
  2259. {
  2260. if (IS_POST) {
  2261. $data = array();
  2262. $data = I('request.data');
  2263. $data['open_admin_payment'] = trim($data['open_admin_payment']);
  2264. $data['open_auto_receive'] = trim($data['open_auto_receive']);
  2265. $data['shop_limit_buy_distance'] = trim($data['shop_limit_buy_distance']);
  2266. $data['is_open_order_message'] = trim($data['is_open_order_message']);
  2267. $data['is_hidden_orderlist_phone'] = trim($data['is_hidden_orderlist_phone']);
  2268. $data['order_pay_after_share_img'] = save_media($data['order_pay_after_share_img']);
  2269. //-----begin
  2270. if( $data['shop_limit_buy_distance'] == 1)
  2271. {
  2272. if( empty($data['shop_buy_distance']) || $data['shop_buy_distance'] <= 0 )
  2273. {
  2274. show_json(0, array('msg' => '开启限制购买距离,购买距离不能为空') );
  2275. }
  2276. }
  2277. if( $data['open_auto_delete'] == 1)
  2278. {
  2279. if( empty($data['auto_cancle_order_time']) || $data['auto_cancle_order_time'] <= 0 )
  2280. {
  2281. show_json(0, array('msg' => '开启自动取消订单,自动取消订单时间不能为空') );
  2282. }
  2283. }
  2284. //open_aftersale
  2285. if( $data['open_auto_recive_order'] == 1)
  2286. {
  2287. if( empty($data['auto_recive_order_time']) || $data['auto_recive_order_time'] <= 0 )
  2288. {
  2289. show_json(0, array('msg' => '开启系统自动签收,自动签收天数不能为空') );
  2290. }
  2291. }
  2292. $open_aftersale = isset($data['open_aftersale']) ? $data['open_aftersale']:0;
  2293. $open_aftersale_time = isset($data['open_aftersale_time']) ? $data['open_aftersale_time']:0;
  2294. if( $open_aftersale == 1 && ($open_aftersale_time ==0 || empty($open_aftersale_time) ) )
  2295. {
  2296. show_json(0, array('msg' => '开启售后期,请填写售后期天数') );
  2297. }
  2298. if( $data['open_redis_server'] == 1)
  2299. {
  2300. if( empty($data['redis_host']))
  2301. {
  2302. show_json(0, array('msg' => '开启redis服务,redis-host不能为空') );
  2303. }
  2304. if( empty($data['redis_port']))
  2305. {
  2306. show_json(0, array('msg' => '开启redis服务,redis-port不能为空') );
  2307. }
  2308. }
  2309. $open_feier_print = isset($data['open_feier_print']) ? $data['open_feier_print']:0;
  2310. if(empty($open_feier_print) || $open_feier_print == 0)
  2311. {
  2312. $data['open_feier_print'] = $open_feier_print;
  2313. }else if($open_feier_print == 1){
  2314. $feier_print_sn = isset($data['feier_print_sn']) ? $data['feier_print_sn']:'';
  2315. $feier_print_key = isset($data['feier_print_key']) ? $data['feier_print_key']:'';
  2316. $data['open_feier_print'] = $open_feier_print;
  2317. $data['feier_print_sn'] = $feier_print_sn;
  2318. $data['feier_print_key'] = $feier_print_key;
  2319. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn') )->find();
  2320. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  2321. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key') )->find();
  2322. $feier_print_key_old = $feier_print_key_old_arr['value'];
  2323. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  2324. {
  2325. //开始添加打印机
  2326. //printaction
  2327. $print_model = D('Seller/Printaction');
  2328. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  2329. $print_model->addprinter($snlist);
  2330. }
  2331. //...todo测试订单自动打印
  2332. }else if($open_feier_print == 2){
  2333. $yilian_machine_code = isset($data['yilian_machine_code']) ? $data['yilian_machine_code']:'';
  2334. $yilian_msign = isset($data['yilian_msign']) ? $data['yilian_msign']:'';
  2335. $yilian_client_id = isset($data['yilian_client_id']) ? $data['yilian_client_id']:'';
  2336. $yilian_client_key = isset($data['yilian_client_key']) ? $data['yilian_client_key']:'';
  2337. $data['open_feier_print'] = $open_feier_print;
  2338. $data['yilian_machine_code'] = $yilian_machine_code;
  2339. $data['yilian_msign'] = $yilian_msign;
  2340. $data['yilian_client_id'] = $yilian_client_id;
  2341. $data['yilian_client_key'] = $yilian_client_key;
  2342. $yilian_client_id_old = D('Home/Front')->get_config_by_name('yilian_client_id');
  2343. $yilian_machine_code_old = D('Home/Front')->get_config_by_name('yilian_machine_code');
  2344. $yilian_msign_old = D('Home/Front')->get_config_by_name('yilian_msign');
  2345. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  2346. {
  2347. //开始添加打印机
  2348. //printaction
  2349. $print_model = D('Seller/Printaction');
  2350. $res = $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  2351. if($res != 0)
  2352. {
  2353. show_json(0, array('msg' => '添加易联云打印机失败!'));
  2354. }
  2355. }
  2356. //...todo测试订单自动打印
  2357. }
  2358. //----end
  2359. $data['is_print_auto'] = $data['is_print_auto'] == 1 ? 0 : 1;
  2360. $data['is_print_cancleorder'] = isset($data['is_print_cancleorder']) ? $data['is_print_cancleorder'] : 0;
  2361. $data['is_print_admin_cancleorder'] = isset($data['is_print_admin_cancleorder']) ? $data['is_print_admin_cancleorder'] : 0;
  2362. $data['is_print_dansupply_order'] = isset($data['is_print_dansupply_order']) ? $data['is_print_dansupply_order'] : 0;
  2363. //----------redis begin
  2364. $data['open_redis_server'] = intval($data['open_redis_server']);
  2365. if($data['open_redis_server'] == 1 && !class_exists('Redis')){
  2366. $data['open_redis_server'] = 0;
  2367. }
  2368. //----------redis end
  2369. $data['is_has_refund_deliveryfree'] = isset($data['is_has_refund_deliveryfree']) ? $data['is_has_refund_deliveryfree'] : 0;
  2370. //订单自动发货
  2371. $data['is_localtown_auto_delivery'] = isset($data['is_localtown_auto_delivery']) ? $data['is_localtown_auto_delivery'] : 0;
  2372. $data['is_communityhead_auto_delivery'] = isset($data['is_communityhead_auto_delivery']) ? $data['is_communityhead_auto_delivery'] : 0;
  2373. $data['is_communityhead_auto_service'] = isset($data['is_communityhead_auto_service']) ? $data['is_communityhead_auto_service'] : 0;
  2374. $data['is_ziti_auto_delivery'] = isset($data['is_ziti_auto_delivery']) ? $data['is_ziti_auto_delivery'] : 0;
  2375. $data['is_ziti_auto_service'] = isset($data['is_ziti_auto_service']) ? $data['is_ziti_auto_service'] : 0;
  2376. D('Seller/Config')->update($data);
  2377. //将商品库存写入redis
  2378. if($data['open_redis_server'] == 1 )
  2379. D('Seller/Redisorder')->sysnc_allgoods_total();
  2380. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2381. }
  2382. $data = D('Seller/Config')->get_all_config();
  2383. $this->data = $data;
  2384. $this->display();
  2385. }
  2386. public function opclose()
  2387. {
  2388. $opdata = $this->check_order_data();
  2389. extract($opdata);
  2390. if ($item['order_status_id'] == 5) {
  2391. show_json(0, '订单已关闭,无需重复关闭!');
  2392. }
  2393. else if (3 != $item['order_status_id']) {
  2394. show_json(0, '订单已付款,不能关闭!');
  2395. }
  2396. if (IS_POST) {
  2397. //load_model_class('frontorder')->cancel_order($item['order_id']);
  2398. D('Home/Frontorder')->cancel_order($item['order_id'], false, '后台操作,取消订单');
  2399. /**
  2400. $time = time();
  2401. pdo_update('lionfish_comshop_order', array('order_status_id' => 5, 'canceltime' => $time), array('order_id' => $item['order_id'], 'uniacid' => $_W['uniacid'])) ;
  2402. //'remarkclose' => $_GPC['remark']),
  2403. $history_data = array();
  2404. $history_data['uniacid'] = $_W['uniacid'];
  2405. $history_data['order_id'] = $item['order_id'];
  2406. $history_data['order_status_id'] = 5;
  2407. $history_data['notify'] = 0;
  2408. $history_data['comment'] = '后台操作,取消订单' ;
  2409. $history_data['date_added'] = time();
  2410. pdo_insert('lionfish_comshop_order_history', $history_data);
  2411. **/
  2412. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2413. }
  2414. $this->item = $item;
  2415. $this->display();
  2416. }
  2417. //--begin
  2418. public function ordersendall()
  2419. {
  2420. $_GPC = I('request.');
  2421. $express_list = D('Seller/Express')->load_all_express();
  2422. $this->_GPC = $_GPC;
  2423. if( IS_POST )
  2424. {
  2425. $type = isset($_GPC['type']) && !empty($_GPC['type']) ? $_GPC['type']:'normal';
  2426. $fext = substr($_FILES['excelfile']['name'], strrpos($_FILES['excelfile']['name'], '.') + 1);
  2427. $express = trim($_GPC['express']);
  2428. $expresscom = trim($_GPC['expresscom']);
  2429. if( $fext == 'csv' )
  2430. {
  2431. $file_name = $_FILES['excelfile']['tmp_name'];
  2432. $file = fopen($file_name,'r');
  2433. $rows = array();
  2434. $i =0;
  2435. while ($data = fgetcsv($file)) {
  2436. $rows[] = eval('return '.iconv('gbk','utf-8',var_export($data,true)).';');
  2437. }
  2438. //var_dump( $rows );
  2439. //die();
  2440. }else{
  2441. $rows = D('Seller/Excel')->import('excelfile');
  2442. }
  2443. $num = count($rows);
  2444. $time = time();
  2445. $express_arr = array();
  2446. foreach($express_list as $val)
  2447. {
  2448. $express_arr[ $val['id'] ] = $val['name'];
  2449. }
  2450. $i = 0;
  2451. $err_array = array();
  2452. $quene_order_list = array();
  2453. $cache_key = md5(time().count($rows));
  2454. $j =0;
  2455. foreach ($rows as $rownum => $col)
  2456. {
  2457. $order_id = trim($col[0]);
  2458. if (empty($order_id)) {
  2459. $err_array[] = $order_id;
  2460. continue;
  2461. }
  2462. if($j == 0)
  2463. {
  2464. $j++;
  2465. continue;
  2466. }
  2467. $quene_order_list[] = array('order_num_alias' => $order_id , 'shipping_no' => $col[1], 'express' => $express,'expresscom' => $expresscom );
  2468. }
  2469. S('_orderquene_'.$cache_key, $quene_order_list);
  2470. $this->cache_key = $cache_key;
  2471. $this->type = $type;
  2472. $this->display('Order/oploadexcelorder');
  2473. die();
  2474. }
  2475. $this->express_list = $express_list;
  2476. $this->type = I('request.type');
  2477. $this->display();
  2478. }
  2479. public function do_order_quene()
  2480. {
  2481. $_GPC = I('request.');
  2482. $type = $_GPC['type'];
  2483. $cache_key = $_GPC['cache_key'];
  2484. $quene_order_list = S('_orderquene_'.$cache_key);
  2485. $tmp_info = array_shift($quene_order_list);
  2486. S('_orderquene_'.$cache_key, $quene_order_list);
  2487. $express = $tmp_info['express'];
  2488. $expresscom = $tmp_info['expresscom'];
  2489. $shipping_no = $tmp_info['shipping_no'];
  2490. $tmp_info['order_num_alias'] = trim($tmp_info['order_num_alias']);
  2491. $tmp_info['order_num_alias'] = preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$tmp_info['order_num_alias']);
  2492. //$rows = D('Seller/Excel')->import('excelfile');
  2493. $order_info = M('lionfish_comshop_order')->where( array('order_num_alias' => $tmp_info['order_num_alias'] ) )->find();
  2494. if(!empty($order_info) && $order_info['order_status_id'] == 1)
  2495. {
  2496. if( $type == 'mult' && $order_info['delivery'] == 'express' )
  2497. {
  2498. $ex_info = D('Seller/Express')-> get_express_info($express);
  2499. $data = array();
  2500. $data['express_time'] = time();
  2501. $data['order_status_id'] = 4;
  2502. $data['shipping_no'] = $shipping_no;
  2503. $data['shipping_method'] = $express;
  2504. $data['dispatchname'] = $ex_info['name'];
  2505. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save( $data );
  2506. $history_data = array();
  2507. $history_data['order_id'] = $order_info['order_id'];
  2508. $history_data['order_status_id'] = 4;
  2509. $history_data['notify'] = 0;
  2510. $history_data['comment'] = '订单快递已发货,后台导入批量发货';
  2511. $history_data['date_added'] = time();
  2512. M('lionfish_comshop_order_history')->add($history_data);
  2513. //TODO..发送已发货的模板消息
  2514. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2515. }
  2516. else {
  2517. if($order_info['delivery'] != 'express')
  2518. {
  2519. /*if($order_info['delivery'] == 'localtown_delivery'){
  2520. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 4,'express_time' => time(), 'express_tuanz_time' => time()) );
  2521. //todo ... send member msg goods is ing
  2522. $history_data = array();
  2523. $history_data['order_id'] = $order_info['order_id'];
  2524. $history_data['order_status_id'] = 4;
  2525. $history_data['notify'] = 0;
  2526. $history_data['comment'] = '订单配送中,使用表格发货';
  2527. $history_data['date_added'] = time();
  2528. M('lionfish_comshop_order_history')->add( $history_data );
  2529. D('Home/LocaltownDelivery')->change_distribution_order_state( $order_info['order_id'], 0, 1);
  2530. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id']) )->save( array('delivery_type' => 1) );
  2531. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2532. //给配送员发送公众号消息
  2533. $count = D('Seller/Redisorder')->set_distribution_delivery_message($order_info['order_id']);
  2534. }else{*/
  2535. if($order_info['delivery'] != 'localtown_delivery' && $order_info['delivery'] != 'hexiao') {
  2536. $data = array();
  2537. $data['express_time'] = time();
  2538. $data['order_status_id'] = 14;
  2539. M('lionfish_comshop_order')->where(array('order_id' => $order_info['order_id']))->save($data);
  2540. $history_data = array();
  2541. $history_data['order_id'] = $order_info['order_id'];
  2542. $history_data['order_status_id'] = 14;
  2543. $history_data['notify'] = 0;
  2544. $history_data['comment'] = '订单配送中,使用表格发货';
  2545. $history_data['date_added'] = time();
  2546. M('lionfish_comshop_order_history')->add($history_data);
  2547. }
  2548. //}
  2549. }
  2550. }
  2551. //TODO...发送已经发货给团长的消息通知
  2552. }
  2553. if($type =='mult_send_tuanz' && $order_info['delivery'] != 'express' && $order_info['order_status_id'] == 14 )
  2554. {
  2555. //订单批量团长签收 2019012749451499751
  2556. $history_data = array();
  2557. $history_data['order_id'] = $order_info['order_id'];
  2558. $history_data['order_status_id'] = 4;
  2559. $history_data['notify'] = 0;
  2560. $history_data['comment'] = '后台批量导入发货到团长';
  2561. $history_data['date_added'] = time();
  2562. M('lionfish_comshop_order_history')->add( $history_data );
  2563. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2564. }
  2565. if($type =='mult_member_receive_order' && $order_info['order_status_id'] == 4 )
  2566. {
  2567. /*if($order_info['delivery'] == 'localtown_delivery'){
  2568. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id']) )->save( array('state' => 4,'orderdistribution_id'=> -1) );
  2569. D('Seller/Order')->receive_order($order_info['order_id']);
  2570. M('lionfish_comshop_order_history')->where( array('order_id' => $order_info['order_id'],'order_status_id' => 6) )->save( array( 'comment' => '系统自动收货,等待结算佣金') );
  2571. }else{*/
  2572. if($order_info['delivery'] != 'localtown_delivery' && $order_info['delivery'] != 'hexiao') {
  2573. //批量用户确认收货
  2574. D('Home/Frontorder')->receive_order($order_info['order_id'], true);
  2575. }
  2576. //}
  2577. }
  2578. if( empty($quene_order_list) )
  2579. {
  2580. echo json_encode( array('code' => 2) );
  2581. die();
  2582. }
  2583. echo json_encode( array('code' => 0, 'msg' => '订单号:'.$tmp_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理") );
  2584. die();
  2585. }
  2586. //--end
  2587. public function ordersendall2()
  2588. {
  2589. if( IS_POST )
  2590. {
  2591. $type = I('request.type', 'normal');
  2592. $express = I('request.express', '');
  2593. $expresscom = I('request.expresscom', '');
  2594. $rows = D('Seller/Excel')->import('excelfile');
  2595. $num = count($rows);
  2596. $time = time();
  2597. $express_arr = array();
  2598. foreach($express_list as $val)
  2599. {
  2600. $express_arr[ $val['id'] ] = $val['name'];
  2601. }
  2602. $i = 0;
  2603. $err_array = array();
  2604. $j =0;
  2605. foreach ($rows as $rownum => $col) {
  2606. $order_id = trim($col[0]);
  2607. if (empty($order_id)) {
  2608. $err_array[] = $order_id;
  2609. continue;
  2610. }
  2611. if($j == 0)
  2612. {
  2613. $j++;
  2614. continue;
  2615. }
  2616. $order_info = M('lionfish_comshop_order')->where( array('order_num_alias' => $order_id ) )->find();
  2617. if(!empty($order_info) && $order_info['order_status_id'] == 1)
  2618. {
  2619. //判断是否快递类型 type //normal mult
  2620. if( $type == 'mult' && $order_info['delivery'] == 'express' )
  2621. {
  2622. $data = array();
  2623. $data['express_time'] = time();
  2624. $data['order_status_id'] = 4;
  2625. $data['shipping_no'] = $col[1];
  2626. $data['shipping_method'] = $express;
  2627. $data['dispatchname'] = $expresscom;
  2628. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save( $data );
  2629. $history_data = array();
  2630. $history_data['order_id'] = $order_info['order_id'];
  2631. $history_data['order_status_id'] = 4;
  2632. $history_data['notify'] = 0;
  2633. $history_data['comment'] = '订单快递已发货';
  2634. $history_data['date_added'] = time();
  2635. M('lionfish_comshop_order_history')->add($history_data);
  2636. //TODO..发送已发货的模板消息
  2637. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2638. }else {
  2639. if($order_info['delivery'] != 'express')
  2640. {
  2641. $data = array();
  2642. $data['express_time'] = time();
  2643. $data['order_status_id'] = 14;
  2644. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save($data);
  2645. $history_data = array();
  2646. $history_data['order_id'] = $order_info['order_id'];
  2647. $history_data['order_status_id'] = 14;
  2648. $history_data['notify'] = 0;
  2649. $history_data['comment'] = '订单配送中';
  2650. $history_data['date_added'] = time();
  2651. M('lionfish_comshop_order_history')->add($history_data);
  2652. }
  2653. }
  2654. //TODO...发送已经发货给团长的消息通知
  2655. ++$i;
  2656. }
  2657. if($type =='mult_send_tuanz' && $order_info['delivery'] != 'express' && $order_info['order_status_id'] == 14 )
  2658. {
  2659. //订单批量团长签收 2019012749451499751
  2660. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2661. ++$i;
  2662. }
  2663. if($type =='mult_member_receive_order' && $order_info['order_status_id'] == 4 )
  2664. {
  2665. //批量用户确认收货
  2666. D('Home/Frontorder')->receive_order($order_info['order_id'], true);
  2667. ++$i;
  2668. }
  2669. }
  2670. $tip = '';
  2671. if($type =='mult_send_tuanz')
  2672. {
  2673. $msg = $i . '个订单批量送达团长成功!';
  2674. }
  2675. else if($type == 'mult_member_receive_order')
  2676. {
  2677. $msg = $i . '个订单批量用户确认收货!';
  2678. }
  2679. else{
  2680. $msg = $i . '个订单发货成功!';
  2681. }
  2682. if ($i < $num) {
  2683. $url = '';
  2684. if (!empty($err_array)) {
  2685. $j = 1;
  2686. if($type =='mult_send_tuanz')
  2687. {
  2688. $tip .= '<br>' . count($err_array) . '个订单批量送达团长失败,失败的订单编号: <br>';
  2689. }else if($type == 'mult_member_receive_order'){
  2690. $tip .= '<br>' . count($err_array) . '个订单批量用户确认收货,失败的订单编号: <br>';
  2691. }
  2692. else{
  2693. $tip .= '<br>' . count($err_array) . '个订单发货失败,失败的订单编号: <br>';
  2694. }
  2695. foreach ($err_array as $k => $v) {
  2696. $tip .= $v . ' ';
  2697. if (($j % 2) == 0) {
  2698. $tip .= '<br>';
  2699. }
  2700. ++$j;
  2701. }
  2702. }
  2703. }
  2704. else {
  2705. $url = U('order/ordersendall', array('type' => $type) );
  2706. }
  2707. $redirect = $url;
  2708. $this->message = $msg.$tip;
  2709. $this->redirect = $redirect;
  2710. $this->display('Public/_message');
  2711. die();
  2712. }
  2713. $express_list = D('Seller/Express')->load_all_express();
  2714. $this->express_list = $express_list;
  2715. $this->type = I('request.type');
  2716. $this->display();
  2717. }
  2718. public function opchangeexpress()
  2719. {
  2720. $_GPC = I('request.');
  2721. $opdata = $this->check_order_data();
  2722. extract($opdata);
  2723. $changeexpress = 1;
  2724. $sendtype = intval($_GPC['sendtype']);
  2725. $edit_flag = 1;
  2726. if (IS_POST) {
  2727. if (!(empty($_GPC['shipping_no'])) && empty($_GPC['shipping_no'])) {
  2728. show_json(0, array('msg' => '请输入快递单号!') );
  2729. }
  2730. if (!(empty($item['transid']))) {
  2731. }
  2732. $express_info = D('Seller/Express')->get_express_info($_GPC['express']);
  2733. $time = time();
  2734. $data = array(
  2735. 'shipping_method' => trim($_GPC['express']),
  2736. 'dispatchname' => $express_info['name'],
  2737. 'shipping_no' => trim($_GPC['shipping_no']),
  2738. 'express_time' => $time
  2739. );
  2740. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( $data );
  2741. $history_data = array();
  2742. $history_data['order_id'] = $item['order_id'];
  2743. $history_data['order_status_id'] = 4;
  2744. $history_data['notify'] = 0;
  2745. $history_data['comment'] = '修改发货物流,订单发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $_GPC['shipping_no'];
  2746. $history_data['date_added'] = time();
  2747. M('lionfish_comshop_order_history')->add( $history_data );
  2748. //TODO...发送已经发货的消息通知
  2749. //m('notice')->sendOrderMessage($item['id']);
  2750. //plog('order.op.send', '订单发货 ID: ' . $item['id'] . ' 订单号: ' . $item['ordersn'] . ' <br/>快递公司: ' . $_GPC['expresscom'] . ' 快递单号: ' . $_GPC['expresssn']);
  2751. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2752. }
  2753. $noshipped = array();
  2754. $shipped = array();
  2755. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  2756. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  2757. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  2758. $order_goods = M('lionfish_comshop_order_goods')->field('order_goods_id as id,name as title,goods_images as thumb')->where( array('order_id' => $item['order_id']) )->select();
  2759. $express_list = D('Seller/Express')->load_all_express();
  2760. $this->id = $item['order_id'];
  2761. $this->item = $item;
  2762. $this->province_info = $province_info;
  2763. $this->city_info = $city_info;
  2764. $this->area_info = $area_info;
  2765. $this->order_goods = $order_goods;
  2766. $this->express_list = $express_list;
  2767. $this->display('Order/opsend');
  2768. }
  2769. public function batchsend_import()
  2770. {
  2771. global $_W;
  2772. global $_GPC;
  2773. $type = I('request.type','normal');
  2774. $this->type = $type;
  2775. $columns = array();
  2776. $columns[] = array('title' => '订单编号', 'field' => '', 'width' => 32);
  2777. //$columns[] = array('title' => '快递单号', 'field' => '', 'width' => 32);
  2778. if($type == 'normal')
  2779. {
  2780. D('Seller/Excel')->temp('批量发货数据模板', $columns);
  2781. }else{
  2782. $columns[] = array('title' => '快递单号', 'field' => '', 'width' => 32);
  2783. D('Seller/Excel')->temp('批量发货数据模板', $columns);
  2784. }
  2785. }
  2786. /**
  2787. * 上传订单Excel批量发货
  2788. */
  2789. function sendexpress_excel_done()
  2790. {
  2791. set_time_limit(0);
  2792. if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
  2793. $excel_dir = ROOT_PATH.'Uploads/image/'.date('Y-m-d');
  2794. $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  2795. RecursiveMkdir( $excel_dir );
  2796. $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
  2797. $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
  2798. $notify_model = D('Home/Weixinnotify');
  2799. //
  2800. $result = importExecl($path);
  2801. if(!empty($result)) {
  2802. $order_ids = array();
  2803. //开始导入数据库,并发货
  2804. foreach($result as $val){
  2805. if(empty($val[0]))
  2806. {
  2807. continue;
  2808. }
  2809. $order_info = M('order')->field('order_id,order_status_id,delivery')->where( array('order_num_alias' => trim($val[0])) )->find();
  2810. //order_status_id 1
  2811. if($order_info['order_status_id'] != 1)
  2812. {
  2813. continue;
  2814. }
  2815. //['delivery'] == 'pickup'
  2816. $order_ids[] = $order_info['order_id'];
  2817. if($order_info['delivery'] == 'pickup')
  2818. {
  2819. M('order')->where( array('order_id' => $order_info['order_id'] ) )->save( array('order_status_id' => 4) );
  2820. } else {
  2821. M('order')->where( array('order_id' => $order_info['order_id'] ) )->save( array('shipping_method' =>$val[5],'shipping_no' =>$val[6],'order_status_id' => 4) );
  2822. }
  2823. $oh = array();
  2824. $oh['order_id']=$order_info['order_id'];
  2825. $oh['order_status_id']=4;
  2826. $oh['notify'] = 0;
  2827. $oh['comment']='导入excel批量发货';
  2828. $oh['date_added']=time();
  2829. $oh_id=M('OrderHistory')->add($oh);
  2830. }
  2831. foreach($order_ids as $order_id) {
  2832. $order_info = M('order')->field('delivery')->where( array('order_id' => $order_id) )->find();
  2833. if($order_info['delivery'] == 'pickup')
  2834. {
  2835. $notify_model->sendPickupMsg($order_id);
  2836. } else {
  2837. $notify_model->sendExpressMsg($order_id);
  2838. }
  2839. }
  2840. }
  2841. }
  2842. echo json_encode( array('code' => 1) );
  2843. die();
  2844. }
  2845. function sendexpress()
  2846. {
  2847. $this->breadcrumb2='批量发货';
  2848. $this->display();
  2849. }
  2850. function print_order(){
  2851. $model=new OrderModel();
  2852. $this->order=$model->order_info(I('id'));
  2853. $this->print=true;
  2854. $this->display('./Themes/Home/default/Mail/order.html');
  2855. }
  2856. public function refunddone()
  2857. {
  2858. $id = I('get.id',0,'intval');
  2859. $comment = I('post.comment');
  2860. $order_refund_type = I('post.order_refund_type',0,'intval');
  2861. $result = array('code' =>1);
  2862. $order_refund_history = array();
  2863. $order_refund_history['order_id'] = $id;
  2864. $order_refund_history['message'] = htmlspecialchars($comment);
  2865. $order_refund_history['type'] = 2;
  2866. $order_refund_history['addtime'] = time();
  2867. M('order_refund_history')->add($order_refund_history);
  2868. $order_history = array();
  2869. $order_history['order_id'] = $id;
  2870. $order_history['order_status_id'] = 0;
  2871. $order_history['notify'] = 0;
  2872. $order_history['comment'] = '';
  2873. $order_history['date_added'] = time();
  2874. if($order_refund_type ==1)
  2875. {
  2876. //拒绝
  2877. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 1) );
  2878. $order_history['order_status_id'] = 12;
  2879. $order_history['comment'] = '商家拒绝退款';
  2880. M('order_history')->add($order_history);
  2881. } else {
  2882. $order_history['order_status_id'] = 12;
  2883. $order_history['comment'] = '商家统一退款';
  2884. M('order_history')->add($order_history);
  2885. $weixin_model = D('Home/Weixin');
  2886. //通过
  2887. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 3) );
  2888. $order_refund = M('order_refund')->where( array('order_id' => $id) )->find();
  2889. $weixin_model->refundOrder($id, $order_refund['ref_money']);
  2890. }
  2891. echo json_encode($result);
  2892. die();
  2893. }
  2894. public function show_refund()
  2895. {
  2896. $this->crumbs='订单退款详情';
  2897. $model=new OrderModel();
  2898. $data = $model->order_info(I('id'));
  2899. $order_statuses = $data['order_statuses'];
  2900. $need_status = array();
  2901. foreach($order_statuses as $key => $val)
  2902. {
  2903. if( in_array($val['order_status_id'], array(4)) )
  2904. {
  2905. $need_status[$key] = $val;
  2906. }
  2907. }
  2908. $data['order_statuses'] = $need_status;
  2909. $refund_reason = array(
  2910. '97' =>'商品有质量问题',
  2911. '98' =>'没有收到货',
  2912. '99' =>'商品少发漏发发错',
  2913. '100' =>'商品与描述不一致',
  2914. '101' =>'收到商品时有划痕或破损',
  2915. '102' =>'质疑假货',
  2916. '111' =>'其他',
  2917. );
  2918. $order_refund = M('order_refund')->where( array('order_id' =>I('id')) )->find();
  2919. //ref_type
  2920. $order_refund['ref_type'] = $order_refund['ref_type'] ==1 ? '仅退款': '退款退货';
  2921. $order_refund['ref_name'] = empty($refund_reason[$order_refund['ref_name']]) ? $order_refund['ref_name']: $refund_reason[$order_refund['ref_name']] ;
  2922. $refund_state = array(
  2923. 0 => '申请中',
  2924. 1 => '商家拒绝',
  2925. 2 => '平台介入',
  2926. 3 => '退款成功',
  2927. 4 => '退款失败',
  2928. 5 => '撤销申请',
  2929. );
  2930. $order_refund['state'] = $refund_state[$order_refund['state']];
  2931. $this->order_refund = $order_refund;
  2932. $order_refund_image = M('order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->select();
  2933. $refund_images = array();
  2934. if(!empty($order_refund_image))
  2935. {
  2936. foreach($order_refund_image as $refund_image)
  2937. {
  2938. $refund_image['thumb_image'] = resize($refund_image['image'], 100, 100);
  2939. $refund_images[] = $refund_image;
  2940. }
  2941. }
  2942. $order_refund_history = M('order_refund_history')->where( array('order_id' => I('id')) )->order('addtime asc')->select();
  2943. foreach($order_refund_history as $key => $val)
  2944. {
  2945. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2946. switch($val['type'])
  2947. {
  2948. case 1:
  2949. $val['type'] = '用户反馈';
  2950. break;
  2951. case 2:
  2952. $val['type'] = '商家反馈';
  2953. break;
  2954. case 3:
  2955. $val['type'] = '平台反馈';
  2956. break;
  2957. }
  2958. $order_refund_history_image = M('order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2959. if(!empty($order_refund_history_image))
  2960. {
  2961. foreach($order_refund_history_image as $kk => $vv)
  2962. {
  2963. $vv['thumb_image'] = resize($vv['image'], 100, 100);
  2964. $order_refund_history_image[$kk] = $vv;
  2965. }
  2966. }
  2967. $val['order_refund_history_image'] = $order_refund_history_image;
  2968. $order_refund_history[$key] = $val;
  2969. }
  2970. $this->order_refund_history = $order_refund_history;
  2971. $this->refund_images = $refund_images;
  2972. $this->data = $data;
  2973. $this->display('refund');
  2974. }
  2975. public function show_order(){
  2976. $this->crumbs='订单详情';
  2977. //is_ziti/1 commiss_list
  2978. $is_ziti = I('get.is_ziti', 0);
  2979. if($is_ziti == 1)
  2980. {
  2981. $this->breadcrumb1='自提管理';
  2982. $this->breadcrumb2='自提管理';
  2983. }
  2984. $model=new OrderModel();
  2985. $data = $model->order_info(I('id'));
  2986. $order_statuses = $data['order_statuses'];
  2987. $need_status = array();
  2988. foreach($order_statuses as $key => $val)
  2989. {
  2990. if( in_array($val['order_status_id'], array(1,2,3,4,5,6,7,8,11,12,13)) )
  2991. {
  2992. $need_status[$key] = $val;
  2993. }
  2994. }
  2995. $data['order_statuses'] = $need_status;
  2996. //$data['order']
  2997. if($data['order']['type'] == 'integral')
  2998. {
  2999. $integral_order = M('integral_order')->where( array('order_id' => I('id') ) )->find();
  3000. $this->integral_order = $integral_order;
  3001. }
  3002. $this->data = $data;
  3003. $pick_order_info = array();
  3004. $pick_up = array();
  3005. if($data['order']['delivery'] == 'pickup')
  3006. {
  3007. $pick_order_info = M('pick_order')->where( array('order_id' => $data['order']['order_id']) )->find();
  3008. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  3009. }
  3010. $this->pick_order_info = $pick_order_info;
  3011. $this->pick_up = $pick_up;
  3012. $sql="select s.* from ".C('DB_PREFIX')."seller_express as s, ".C('DB_PREFIX')."seller_express_relat as ser
  3013. where s.id = ser.express_id and ser.store_id = ".SELLERUID;
  3014. $express_list= M()->query($sql);
  3015. $this->express_list = $express_list;
  3016. //$data['order']['order_id']
  3017. $order_goods_haitao = M('order_goods_haitao')->where( array('order_id' => $data['order']['order_id']) )->find();
  3018. $this->order_goods_haitao = $order_goods_haitao;
  3019. $this->display('show');
  3020. }
  3021. function history(){
  3022. $model=new OrderModel();
  3023. if(IS_POST){
  3024. if(I('order_status_id')==C('cancel_order_status_id')){
  3025. $Order = new \Home\Model\OrderModel();
  3026. $Order->cancel_order($_GET['id']);
  3027. storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('BACKEND_USER'),'取消了订单 '.$_GET['id']);
  3028. $result=true;
  3029. }else{
  3030. //order_status_id 4
  3031. if($_POST['order_status_id'] != 4)
  3032. {
  3033. unset($_POST['shipping_no']);
  3034. unset($_POST['shipping_method']);
  3035. die();
  3036. }else {
  3037. }
  3038. $result=$model->addOrderHistory($_GET['id'],$_POST);
  3039. }
  3040. if($result){
  3041. $this->success='新增成功!!';
  3042. }else{
  3043. $this->error='新增失败!!';
  3044. }
  3045. }
  3046. $results = $model->getOrderHistories($_GET['id']);
  3047. foreach ($results as $result) {
  3048. $histories[] = array(
  3049. 'notify' => $result['notify'] ? '是' : '否',
  3050. 'status' => $result['status'],
  3051. 'comment' => nl2br($result['comment']),
  3052. 'date_added' => date('Y/m/d H:i:s', $result['date_added'])
  3053. );
  3054. }
  3055. $this->histories=$histories;
  3056. $this->display();
  3057. }
  3058. function del(){
  3059. $model=new OrderModel();
  3060. $return=$model->del_order(I('get.id'));
  3061. $this->osc_alert($return);
  3062. }
  3063. //begin
  3064. public function printconfig()
  3065. {
  3066. if (defined('ROLE') && ROLE == 'agenter' )
  3067. {
  3068. $supper_info = get_agent_logininfo();
  3069. if (IS_POST) {
  3070. $_GPC = I('request.');
  3071. $data = array();
  3072. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  3073. //$supper_info['id']
  3074. $open_feier_print = isset($data['open_feier_print'.$supper_info['id']]) ? $data['open_feier_print'.$supper_info['id']]:0;
  3075. if(empty($open_feier_print) || $open_feier_print == 0)
  3076. {
  3077. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3078. }else if($open_feier_print == 1){
  3079. $feier_print_sn = isset($data['feier_print_sn'.$supper_info['id']]) ? $data['feier_print_sn'.$supper_info['id']]:'';
  3080. $feier_print_key = isset($data['feier_print_key'.$supper_info['id']]) ? $data['feier_print_key'.$supper_info['id']]:'';
  3081. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3082. $data['feier_print_sn'.$supper_info['id']] = $feier_print_sn;
  3083. $data['feier_print_key'.$supper_info['id']] = $feier_print_key;
  3084. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn'.$supper_info['id'] ) )->find();
  3085. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  3086. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key'.$supper_info['id'] ) )->find();
  3087. $feier_print_key_old = $feier_print_key_old_arr['value'];
  3088. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  3089. {
  3090. //开始添加打印机
  3091. //printaction
  3092. $print_model = D('Seller/Printaction');
  3093. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  3094. $print_model->addprinter($snlist);
  3095. }
  3096. //...todo测试订单自动打印
  3097. }else if($open_feier_print == 2){
  3098. $yilian_machine_code = isset($data['yilian_machine_code'.$supper_info['id']]) ? $data['yilian_machine_code'.$supper_info['id']]:'';
  3099. $yilian_msign = isset($data['yilian_msign'.$supper_info['id']]) ? $data['yilian_msign'.$supper_info['id']]:'';
  3100. $yilian_client_id = isset($data['yilian_client_id'.$supper_info['id']]) ? $data['yilian_client_id'.$supper_info['id']]:'';
  3101. $yilian_client_key = isset($data['yilian_client_key'.$supper_info['id']]) ? $data['yilian_client_key'.$supper_info['id']]:'';
  3102. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3103. $data['yilian_machine_code'.$supper_info['id']] = $yilian_machine_code;
  3104. $data['yilian_msign'.$supper_info['id']] = $yilian_msign;
  3105. $data['yilian_client_id'.$supper_info['id']] = $yilian_client_id;
  3106. $data['yilian_client_key'.$supper_info['id']] = $yilian_client_key;
  3107. $yilian_client_id_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_client_id'.$supper_info['id'] ) )->find();
  3108. $yilian_client_id_old = $yilian_client_id_old_arr['value'];
  3109. $yilian_machine_code_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_machine_code'.$supper_info['id'] ) )->find();
  3110. $yilian_machine_code_old = $yilian_machine_code_old_arr['value'];
  3111. $yilian_msign_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_msign'.$supper_info['id'] ) )->find();
  3112. $yilian_msign_old = $yilian_msign_old_arr['value'];
  3113. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  3114. {
  3115. //开始添加打印机
  3116. //printaction
  3117. $print_model = D('Seller/Printaction');
  3118. $res = $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  3119. if($res != 0)
  3120. {
  3121. show_json(0, array('msg' => '添加易联云打印机失败!' ) );
  3122. }
  3123. }
  3124. //...todo测试订单自动打印
  3125. }
  3126. D('Seller/Config')->update($data);
  3127. show_json(1);
  3128. }
  3129. $data = D('Seller/Config')->get_all_config();
  3130. $this->supper_info = $supper_info;
  3131. $this->data = $data;
  3132. include $this->display();
  3133. }
  3134. }
  3135. public function express_list(){
  3136. $this->type = I('request.type','');
  3137. $this->order_id = I('request.order_id','');
  3138. $express_list = D('Seller/Express')->load_kdn_express();
  3139. $this->express_list = $express_list;
  3140. $this->display();
  3141. }
  3142. public function kdn_print_log_list(){
  3143. $log_list = M('lionfish_comshop_order_kdniao_print_log')->order('id desc')->limit(5)->select();
  3144. $this->log_list = $log_list;
  3145. $this->display();
  3146. }
  3147. /**
  3148. * 判断快递鸟寄件人信息
  3149. * @param $express_code
  3150. */
  3151. public function check_kdn_sender($express_code){
  3152. $result = array();
  3153. $result['status'] = 1;
  3154. $data = D('Seller/Config')->get_all_config();
  3155. if(empty($data['kdn_sender_name'])){
  3156. $result['status'] = 0;
  3157. $result['msg'] = '寄件人未配置';
  3158. return $result;
  3159. }
  3160. if(empty($data['kdn_sender_mobile'])){
  3161. $result['status'] = 0;
  3162. $result['msg'] = '寄件人联系电话未配置';
  3163. return $result;
  3164. }
  3165. if(empty($data['kdn_province_id'])){
  3166. $result['status'] = 0;
  3167. $result['msg'] = '寄件人省份未配置';
  3168. return $result;
  3169. }
  3170. if(empty($data['kdn_city_id'])){
  3171. $result['status'] = 0;
  3172. $result['msg'] = '寄件人城市未配置';
  3173. return $result;
  3174. }
  3175. if(empty($data['kdn_area_id'])){
  3176. $result['status'] = 0;
  3177. $result['msg'] = '寄件人区域未配置';
  3178. return $result;
  3179. }
  3180. if(empty($data['kdn_sender_address'])){
  3181. $result['status'] = 0;
  3182. $result['msg'] = '寄件人详细地址未配置';
  3183. return $result;
  3184. }
  3185. $code_list = array('EMS','YZPY','YZBK');
  3186. if(in_array($express_code,$code_list)){
  3187. if(empty($data['kdn_sender_postcode'])){
  3188. $result['status'] = 0;
  3189. $result['msg'] = '寄件人邮编未配置';
  3190. return $result;
  3191. }
  3192. }
  3193. return $result;
  3194. }
  3195. //打印面单
  3196. public function kdniao_order(){
  3197. $result = array();
  3198. $order_id = I('request.order_id','');
  3199. $express_code = I('request.express_code','');
  3200. if(empty($order_id)){
  3201. $result['status'] = 1;
  3202. $result['message'] = "订单号不存在";
  3203. }else if(empty($express_code)){
  3204. $result['status'] = 1;
  3205. $result['message'] = "快递公司不存在";
  3206. }else{
  3207. $sender_result = $this->check_kdn_sender($express_code);
  3208. if($sender_result['status'] == 1){
  3209. $kdNiao = new \Lib\KdApiEOrder();
  3210. $config_data = D('Seller/Config')->get_all_config();
  3211. $result = $kdNiao->printOrder($order_id,$express_code,$config_data);
  3212. }else{
  3213. $result['status'] = 3;
  3214. $result['message'] = $sender_result['msg'];
  3215. }
  3216. }
  3217. echo json_encode($result);
  3218. }
  3219. //打印多条订单面单
  3220. public function kdniao_print_orders(){
  3221. $print_type = I('request.print_type','');
  3222. $order_id = I('request.order_id','');
  3223. $express_code = I('request.express_code','');
  3224. $order_id_list = array();
  3225. $order_list = array();
  3226. $order_kdn_status = array();
  3227. if($print_type == "select"){
  3228. $order_list = M('lionfish_comshop_order')->field('order_id,is_kdn_print')->where("order_status_id = 1 and delivery = 'express' and order_id in (".$order_id.")")->select();
  3229. }else if($print_type == "all"){
  3230. $order_list = M('lionfish_comshop_order')->field('order_id,is_kdn_print')->where("order_status_id = 1 and delivery = 'express' ")->select();
  3231. }
  3232. foreach($order_list as $k=>$v){
  3233. $order_id_list[] = $v['order_id'];
  3234. $order_kdn_status[$v['order_id']] = $v['is_kdn_print'];
  3235. }
  3236. $time = time();
  3237. $print_count = count($order_id_list);
  3238. //保存快递鸟打印日志
  3239. $kd_data = array();
  3240. $kd_data['addtime'] = $time;
  3241. $kd_data['print_count'] = $print_count;
  3242. $kdn_id = M('lionfish_comshop_order_kdniao_print_log')->add( $kd_data );
  3243. $succ_count = 0;
  3244. $fail_count = 0;
  3245. $fail_result = array();
  3246. $kdNiao = new \Lib\KdApiEOrder();
  3247. $config_data = D('Seller/Config')->get_all_config();
  3248. $sender_result = $this->check_kdn_sender($express_code);
  3249. if($sender_result['status'] == 1){
  3250. foreach($order_id_list as $v){
  3251. if($order_kdn_status[$v] == 1){
  3252. $succ_count++;
  3253. }else{
  3254. $result = $kdNiao->printOrder($v,$express_code,$config_data);
  3255. if($result['status'] == 0){//打印成功
  3256. $succ_count++;
  3257. }else{//打印失败
  3258. $fail_count++;
  3259. $fail_result[] = $result['message'];
  3260. }
  3261. }
  3262. }
  3263. }else{
  3264. $result['status'] = 3;
  3265. $result['message'] = $sender_result['msg'];
  3266. }
  3267. $fail_reason = json_encode(array_unique($fail_result));
  3268. //打印完成更新快递鸟打印日志
  3269. $kdn_data = array();
  3270. $kdn_data['succ_count'] = $succ_count;
  3271. $kdn_data['fail_count'] = $fail_count;
  3272. $kdn_data['fail_reason'] = $fail_reason;
  3273. $kdn_data['status'] = 1;
  3274. M('lionfish_comshop_order_kdniao_print_log')->where(array('id' => $kdn_id))->save($kdn_data);
  3275. $kdn_order_ids = implode(",",$order_id_list);
  3276. echo json_encode(array('status'=>0,'order_ids'=>$kdn_order_ids));
  3277. }
  3278. //检查是否配置快递鸟接口参数
  3279. public function check_kdniao(){
  3280. $config_data = D('Seller/Config')->get_all_config();
  3281. if(isset($config_data['kdniao_id']) && !empty($config_data['kdniao_id']) && isset($config_data['kdniao_api_key']) && !empty($config_data['kdniao_api_key'])){
  3282. show_json(1);
  3283. }else{
  3284. show_json(0, array('msg' => '快递鸟未配置!' ) );
  3285. }
  3286. }
  3287. public function kdn_info(){
  3288. $this->order_id = I('request.order_id','');
  3289. $kdn_info = M('lionfish_comshop_order_kdniao_info')->where( array('order_id' => $this->order_id,'status'=>1) )->find();
  3290. $this->kdn_info = $kdn_info;
  3291. $this->display();
  3292. }
  3293. public function kdn_orders_info(){
  3294. $this->order_ids = I('request.order_ids','');
  3295. $kdn_list_info = M('lionfish_comshop_order_kdniao_info')->where("order_id in (".$this->order_ids.") and status = 1")->select();
  3296. $this->kdn_list_info = $kdn_list_info;
  3297. $this->display();
  3298. }
  3299. /**
  3300. * 快递鸟打印成功订单发货
  3301. */
  3302. public function kdn_send(){
  3303. $order_id = I('request.id','');
  3304. $order_ids = I('request.ids','');
  3305. if(!empty($order_id)){
  3306. $item = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3307. if (empty($item)) {
  3308. show_json(0, '未找到订单!');
  3309. }
  3310. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3311. if(!empty($order_info)) {
  3312. if ($order_info['order_status_id'] == 1 && $order_info['delivery'] == 'express' && $order_info['is_kdn_print'] == 1) {
  3313. $express_info = D('Seller/Express')->get_express_info($order_info['shipping_method']);
  3314. $data = array();
  3315. $data['order_status_id'] = 4;
  3316. M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save($data);
  3317. $history_data = array();
  3318. $history_data['order_id'] = $order_id;
  3319. $history_data['order_status_id'] = 4;
  3320. $history_data['notify'] = 0;
  3321. $history_data['comment'] = '订单发货 ID: ' . $order_id . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $item['shipping_no'];
  3322. $history_data['date_added'] = time();
  3323. M('lionfish_comshop_order_history')->add($history_data);
  3324. D('Home/Frontorder')->send_order_operate($item['order_id']);
  3325. } else {
  3326. show_json(0, '待发货快递订单才能发货成功!');
  3327. }
  3328. }else{
  3329. show_json(0, '未找到订单!');
  3330. }
  3331. }else if(!empty($order_ids)){
  3332. $ids = explode(",",$order_ids);
  3333. foreach($ids as $k=>$v){
  3334. $order_id = $v;
  3335. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3336. if (empty($order_info)) {
  3337. show_json(0, '未找到订单!');
  3338. }
  3339. if(!empty($order_info)) {
  3340. if ($order_info['order_status_id'] == 1 && $order_info['delivery'] == 'express' && $order_info['is_kdn_print'] == 1) {
  3341. $express_info = D('Seller/Express')->get_express_info($order_info['shipping_method']);
  3342. $data = array();
  3343. $data['order_status_id'] = 4;
  3344. M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save($data);
  3345. $history_data = array();
  3346. $history_data['order_id'] = $order_id;
  3347. $history_data['order_status_id'] = 4;
  3348. $history_data['notify'] = 0;
  3349. $history_data['comment'] = '订单发货 ID: ' . $order_id . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $item['shipping_no'];
  3350. $history_data['date_added'] = time();
  3351. M('lionfish_comshop_order_history')->add($history_data);
  3352. D('Home/Frontorder')->send_order_operate($item['order_id']);
  3353. } else {
  3354. show_json(0, '待发货快递订单才能发货成功!');
  3355. }
  3356. }else{
  3357. show_json(0, '未找到订单!');
  3358. }
  3359. }
  3360. }else{
  3361. show_json(0, '未找到订单!');
  3362. }
  3363. show_json(1);
  3364. }
  3365. /**
  3366. * 修改订单价格
  3367. */
  3368. public function change_order(){
  3369. $_GPC = I('request.');
  3370. $opdata = $this->check_order_data();
  3371. extract($opdata);
  3372. $id = I('request.id',0);
  3373. if( IS_POST )
  3374. {
  3375. $_GPC = I('request.');
  3376. $order_id = $_GPC['id'];
  3377. $order_goods_ids = $_GPC['order_goods_id'];
  3378. $change_prices = $_GPC['change_price'];
  3379. $count = 0;
  3380. foreach($change_prices as $v){
  3381. if(empty(trim($v))){
  3382. $count++;
  3383. }
  3384. }
  3385. if($count == count($change_prices)){
  3386. show_json(0, array('message' => '未填写涨价或减价金额!'));
  3387. }
  3388. //改价后的商品实付价格不能低于0.1元
  3389. foreach($order_goods_ids as $k=>$order_goods_id){
  3390. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' =>$order_goods_id ) )->find();
  3391. $total = $order_goods_info['total'];
  3392. $fullreduction_money = $order_goods_info['fullreduction_money'];
  3393. $voucher_credit = $order_goods_info['voucher_credit'];
  3394. $score_for_money = $order_goods_info['score_for_money'];
  3395. $total = round($total - $fullreduction_money - $voucher_credit - $score_for_money,2);
  3396. if(!empty($change_prices[$k])){
  3397. $change_price = $change_prices[$k];
  3398. $total = floatval($total) + floatval($change_price);
  3399. if(bccomp($total, '0.1', 2) == -1){
  3400. show_json(0, array('message' => '改价后的商品实付价格不能低于0.1元'));
  3401. }
  3402. }
  3403. }
  3404. $change_amount = 0;
  3405. foreach($order_goods_ids as $k=>$order_goods_id){
  3406. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' =>$order_goods_id ) )->find();
  3407. $total = $order_goods_info['total'];
  3408. $update_data = array();
  3409. if(!empty($change_prices[$k])){
  3410. $change_amount = $change_amount + $change_prices[$k];
  3411. $change_price = $change_prices[$k];
  3412. $update_data['total'] = round(floatval($total) + floatval($change_price),2);
  3413. $update_data['is_change_price'] = 1;
  3414. M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' => $order_goods_id ) )->save( $update_data);
  3415. }
  3416. }
  3417. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$id) )->find();
  3418. $order_total = $order_info['total'];
  3419. $order_data = array();
  3420. $order_data['total'] = round(floatval($order_total) + floatval($change_amount),2);
  3421. $order_data['is_change_price'] = 1;
  3422. M('lionfish_comshop_order')->where( array('order_id' =>$id) )->save($order_data);
  3423. $oh = array();
  3424. $oh['order_id'] = $id;
  3425. $oh['order_status_id']=15;
  3426. $oh['comment']='订单改价';
  3427. $oh['date_added']=time();
  3428. M('lionfish_comshop_order_history')->add($oh);
  3429. show_json(1);
  3430. }
  3431. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id) )->select();
  3432. foreach($order_goods as $k=>$v){
  3433. $order_goods[$k]['goods_img_url'] = tomedia($v['goods_images']);
  3434. }
  3435. $this->item = $opdata['item'];
  3436. $this->order_goods = $order_goods;
  3437. $this->display();
  3438. }
  3439. //检查是否配置第三方配送接口参数
  3440. public function check_delivery_config(){
  3441. $_GPC = I('request.');
  3442. $config_data = D('Seller/Config')->get_all_config();
  3443. $data_type = $_GPC['data_type'];
  3444. if($data_type == 'imdada'){
  3445. if(isset($config_data['localtown_imdada_merchant_id']) && !empty($config_data['localtown_imdada_shop_no']) && isset($config_data['localtown_imdada_appkey']) && !empty($config_data['localtown_imdada_appsecret'])){
  3446. show_json(1);
  3447. }else{
  3448. show_json(0, array('msg' => '达达配送平台参数未配置!' ) );
  3449. }
  3450. }else if($data_type == 'sf'){
  3451. if(isset($config_data['localtown_sf_dev_id']) && !empty($config_data['localtown_sf_dev_key']) && isset($config_data['localtown_sf_store_id'])){
  3452. show_json(1);
  3453. }else{
  3454. show_json(0, array('msg' => '顺丰同城参数未配置!' ) );
  3455. }
  3456. }else if($data_type == 'make'){
  3457. if(isset($config_data['localtown_mk_token']) && !empty($config_data['localtown_mk_token']) ){
  3458. show_json(1);
  3459. }else{
  3460. show_json(0, array('msg' => '码科配送参数未配置!' ) );
  3461. }
  3462. }else if($data_type == 'ele'){
  3463. if(isset($config_data['localtown_ele_app_id']) && !empty($config_data['localtown_ele_secret_key']) && isset($config_data['localtown_ele_store_code']) && !empty($config_data['localtown_ele_transport_name'])
  3464. && !empty($config_data['localtown_ele_transport_address']) && !empty($config_data['localtown_ele_transport_longitude']) && !empty($config_data['localtown_ele_transport_latitude'])
  3465. && !empty($config_data['localtown_ele_transport_tel']) && !empty($config_data['localtown_ele_position_source'])
  3466. ){
  3467. show_json(1);
  3468. }else{
  3469. show_json(0, array('msg' => '蜂鸟即配平台参数未配置!' ) );
  3470. }
  3471. }
  3472. }
  3473. /**
  3474. * 将订单推送给第三方配送
  3475. */
  3476. public function thirth_delivery_order(){
  3477. $_GPC = I('request.');
  3478. $data_type = $_GPC['data_type'];
  3479. $order_id = $_GPC['order_id'];
  3480. if(empty($data_type)){
  3481. show_json(0, array('msg' => '未选择第三方配送' ) );
  3482. }
  3483. if(empty($order_id)){
  3484. show_json(0, array('msg' => '订单号不存在' ) );
  3485. }
  3486. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3487. if(empty($order_info)){
  3488. show_json(0, array('msg' => '订单不存在' ) );
  3489. }
  3490. //店铺地址
  3491. if($order_info['store_id'] > 0) {
  3492. $store_data = D('Home/Order')->getOrderStoreAddress($order_info);
  3493. $order_info['store_data'] = $store_data;
  3494. }
  3495. //商品信息
  3496. $sql = "select og.goods_id,og.name as goods_name,og.quantity,og.price,og.total,og.rela_goodsoption_valueid,g.weight as goods_weight from "
  3497. . C('DB_PREFIX')."lionfish_comshop_order_goods as og left join ".C('DB_PREFIX')."lionfish_comshop_goods as g on og.goods_id=g.id "
  3498. ." where og.order_id = ".$order_id;
  3499. $goods_list = M()->query($sql);
  3500. $goods_count = 0;
  3501. $goods_weight = 0;
  3502. $goods_type_count = 0;
  3503. foreach($goods_list as $k=>$v){
  3504. $goods_count = $goods_count + $v['quantity'];
  3505. if(!empty($v['rela_goodsoption_valueid'])){
  3506. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' => $v['rela_goodsoption_valueid'],'goods_id' => $v['goods_id']) )->find();
  3507. if(!empty($goods_option_mult_value)){
  3508. $v['goods_weight'] = $goods_option_mult_value['weight'];
  3509. }
  3510. }
  3511. $goods_weight = $goods_weight + $v['quantity'] * $v['goods_weight'];
  3512. $goods_type_count = $goods_type_count + 1;
  3513. }
  3514. if(empty($goods_weight)){
  3515. $goods_weight = 100;//默认100克
  3516. }
  3517. $order_info['goods_list'] = $goods_list;
  3518. //商品种类
  3519. $order_info['goods_type_count'] = $goods_type_count;
  3520. //商品数量
  3521. $order_info['goods_count'] = $goods_count;
  3522. //商品重量
  3523. $order_info['goods_weight'] = $goods_weight;
  3524. //订单总金额
  3525. $order_info['order_total'] = $order_info['total']+$order_info['packing_fare']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']-$order_info['score_for_money']+$order_info['localtown_add_shipping_fare']-$order_info['fare_shipping_free'];
  3526. //收货人地址
  3527. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  3528. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  3529. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  3530. $order_info['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$order_info['shipping_address'];
  3531. //收货人经纬度
  3532. $order_distribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3533. //收货人地址纬度
  3534. $order_info['shipping_lat'] = $order_distribution_info['member_lat'];
  3535. //收货人地址经度
  3536. $order_info['shipping_lng'] = $order_distribution_info['member_lon'];
  3537. //商城名称
  3538. $shoname = D('Home/Front')->get_config_by_name('shoname');
  3539. $order_info['shoname'] = $shoname;
  3540. if($data_type == 'imdada'){
  3541. $imdada = new \Lib\Localtown\Imdada();
  3542. $result = $imdada->addOrder($order_info);
  3543. if($result['status'] == 1){//成功
  3544. //配送费用
  3545. $delivery_fee = $result['result']['fee'];
  3546. $express_info = array();
  3547. $express_info['delivery_fee'] = $delivery_fee;
  3548. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3549. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3550. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3551. show_json(1);
  3552. }else{//失败
  3553. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3554. }
  3555. }else if($data_type == 'sf'){
  3556. $sfexpress = new \Lib\Localtown\Sfexpress();
  3557. $result = $sfexpress->addOrder($order_info);
  3558. if($result['status'] == 1){//成功
  3559. //配送费用
  3560. $delivery_fee = round($result['result']['total_price']/100,2);
  3561. //顺丰订单号
  3562. $delivery_order_id = $result['result']['sf_order_id'];
  3563. //顺丰运单号
  3564. $delivery_bill_id = $result['result']['sf_bill_id'];
  3565. $express_info = array();
  3566. $express_info['delivery_fee'] = $delivery_fee;
  3567. $express_info['delivery_order_id'] = $delivery_order_id;
  3568. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3569. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3570. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3571. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3572. show_json(1);
  3573. }else{//失败
  3574. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3575. }
  3576. }else if( $data_type == 'make' )
  3577. {
  3578. //$store_data = D('Home/Make')->getOrderStoreAddress($order_info);
  3579. $result = D('Home/Make')->addOrder($order_info);
  3580. if( $result['code'] == 0 )
  3581. {
  3582. //码科订单号
  3583. $delivery_order_id = $result['order_number'];
  3584. $express_info = array();
  3585. $express_info['delivery_fee'] = $order_distribution_info['shipping_money'];
  3586. $express_info['delivery_order_id'] = $delivery_order_id;
  3587. $express_info['delivery_bill_id'] = '';
  3588. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3589. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3590. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3591. show_json(1);
  3592. }else{
  3593. show_json(0, array('msg' => $result['message'] ) );
  3594. }
  3595. }else if($data_type == 'ele'){//蜂鸟即配
  3596. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3597. $order_code = build_order_no(session('user_auth.uid'));
  3598. //保存蜂鸟即配商户订单号
  3599. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(['order_code'=>$order_code]);
  3600. $order_info['order_num_alias'] = $order_code;
  3601. $result = $eleDistribution->addOrder($order_info);
  3602. if($result['status'] == 1){//成功
  3603. //配送费用
  3604. $delivery_fee = round($result['result']['total_price']/100,2);
  3605. //蜂鸟即配订单号
  3606. $delivery_order_id = $result['result']['sf_order_id'];
  3607. //蜂鸟即配运单号
  3608. $delivery_bill_id = $result['result']['sf_bill_id'];
  3609. $express_info = array();
  3610. $express_info['delivery_fee'] = $delivery_fee;
  3611. $express_info['delivery_order_id'] = $delivery_order_id;
  3612. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3613. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3614. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3615. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3616. show_json(1);
  3617. }else{//失败
  3618. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3619. }
  3620. }else{
  3621. show_json(0, array('msg' => '不存在第三方配送' ) );
  3622. }
  3623. }
  3624. /**
  3625. * 将订单重新推送给第三方配送
  3626. */
  3627. public function thirth_renew_delivery_order(){
  3628. $_GPC = I('request.');
  3629. $data_type = $_GPC['data_type'];
  3630. $order_id = $_GPC['order_id'];
  3631. if(empty($data_type)){
  3632. show_json(0, array('msg' => '未选择第三方配送' ) );
  3633. }
  3634. if(empty($order_id)){
  3635. show_json(0, array('msg' => '订单号不存在' ) );
  3636. }
  3637. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3638. if(empty($order_info)){
  3639. show_json(0, array('msg' => '订单不存在' ) );
  3640. }
  3641. //店铺地址
  3642. if($order_info['store_id'] > 0) {
  3643. $store_data = D('Home/Order')->getOrderStoreAddress($order_info);
  3644. $order_info['store_data'] = $store_data;
  3645. }
  3646. //商品信息
  3647. $sql = "select og.goods_id,og.name as goods_name,og.quantity,og.rela_goodsoption_valueid,g.weight as goods_weight from "
  3648. . C('DB_PREFIX')."lionfish_comshop_order_goods as og left join ".C('DB_PREFIX')."lionfish_comshop_goods as g on og.goods_id=g.id "
  3649. ." where og.order_id = ".$order_id;
  3650. $goods_list = M()->query($sql);
  3651. $goods_count = 0;
  3652. $goods_weight = 0;
  3653. $goods_type_count = 0;
  3654. foreach($goods_list as $k=>$v){
  3655. $goods_count = $goods_count + $v['quantity'];
  3656. if(!empty($v['rela_goodsoption_valueid'])){
  3657. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' => $v['rela_goodsoption_valueid'],'goods_id' => $v['goods_id']) )->find();
  3658. if(!empty($goods_option_mult_value)){
  3659. $v['goods_weight'] = $goods_option_mult_value['weight'];
  3660. }
  3661. }
  3662. $goods_weight = $goods_weight + $v['quantity'] * $v['goods_weight'];
  3663. $goods_type_count = $goods_type_count + 1;
  3664. }
  3665. if(empty($goods_weight)){
  3666. $goods_weight = 100;//默认100克
  3667. }
  3668. $order_info['goods_list'] = $goods_list;
  3669. //商品种类
  3670. $order_info['goods_type_count'] = $goods_type_count;
  3671. //商品数量
  3672. $order_info['goods_count'] = $goods_count;
  3673. //商品重量
  3674. $order_info['goods_weight'] = $goods_weight;
  3675. //订单总金额
  3676. $order_info['order_total'] = $order_info['total']+$order_info['packing_fare']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']-$order_info['score_for_money']+$order_info['localtown_add_shipping_fare']-$order_info['fare_shipping_free'];
  3677. //收货人地址
  3678. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  3679. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  3680. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  3681. $order_info['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$order_info['shipping_address'];
  3682. //收货人经纬度
  3683. $order_distribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3684. //收货人地址纬度
  3685. $order_info['shipping_lat'] = $order_distribution_info['member_lat'];
  3686. //收货人地址经度
  3687. $order_info['shipping_lng'] = $order_distribution_info['member_lon'];
  3688. //商城名称
  3689. $shoname = D('Home/Front')->get_config_by_name('shoname');
  3690. $order_info['shoname'] = $shoname;
  3691. if($data_type == 'imdada'){
  3692. $imdada = new \Lib\Localtown\Imdada();
  3693. $result = $imdada->reAddOrder($order_info);
  3694. if($result['status'] == 1){//成功
  3695. //配送费用
  3696. $delivery_fee = array();
  3697. $delivery_fee['delivery_fee'] = $result['result']['fee'];
  3698. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$delivery_fee);
  3699. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3700. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3701. show_json(1);
  3702. }else{//失败
  3703. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3704. }
  3705. }else if($data_type == 'sf'){
  3706. $sfexpress = new \Lib\Localtown\Sfexpress();
  3707. $result = $sfexpress->addOrder($order_info);
  3708. if($result['status'] == 1){//成功
  3709. //配送费用
  3710. $delivery_fee = round($result['result']['total_price']/100,2);
  3711. //顺丰订单号
  3712. $delivery_order_id = $result['result']['sf_order_id'];
  3713. //顺丰运单号
  3714. $delivery_bill_id = $result['result']['sf_bill_id'];
  3715. $express_info = array();
  3716. $express_info['delivery_fee'] = $delivery_fee;
  3717. $express_info['delivery_order_id'] = $delivery_order_id;
  3718. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3719. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3720. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3721. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3722. show_json(1);
  3723. }else{//失败
  3724. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3725. }
  3726. }else if($data_type == 'make')
  3727. {
  3728. $result = D('Home/Make')->addOrder($order_info);
  3729. if( $result['code'] == 0 )
  3730. {
  3731. //码科订单号
  3732. $delivery_order_id = $result['order_number'];
  3733. $express_info = array();
  3734. $express_info['delivery_fee'] = $order_distribution_info['shipping_money'];
  3735. $express_info['delivery_order_id'] = $delivery_order_id;
  3736. $express_info['delivery_bill_id'] = '';
  3737. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3738. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3739. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3740. show_json(1);
  3741. }else{
  3742. show_json(0, array('msg' => $result['message'] ) );
  3743. }
  3744. }else if($data_type == 'ele'){//蜂鸟即配
  3745. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3746. $order_code = build_order_no(session('user_auth.uid'));
  3747. //保存蜂鸟即配商户订单号
  3748. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(['order_code'=>$order_code]);
  3749. $order_info['order_num_alias'] = $order_code;
  3750. $result = $eleDistribution->addOrder($order_info);
  3751. if($result['status'] == 1){//成功
  3752. //配送费用
  3753. $delivery_fee = round($result['result']['total_price']/100,2);
  3754. //蜂鸟即配订单号
  3755. $delivery_order_id = $result['result']['sf_order_id'];
  3756. //蜂鸟即配运单号
  3757. $delivery_bill_id = $result['result']['sf_bill_id'];
  3758. $express_info = array();
  3759. $express_info['delivery_fee'] = $delivery_fee;
  3760. $express_info['delivery_order_id'] = $delivery_order_id;
  3761. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3762. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3763. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3764. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3765. show_json(1);
  3766. }else{//失败
  3767. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3768. }
  3769. }
  3770. else{
  3771. show_json(0, array('msg' => '不存在第三方配送' ) );
  3772. }
  3773. }
  3774. public function third_cancel_reason(){
  3775. $order_id = I('request.order_id','');
  3776. $third_distribution_type = I('request.third_distribution_type','');
  3777. $this->order_id = $order_id;
  3778. $this->third_distribution_type = $third_distribution_type;
  3779. $this->display();
  3780. }
  3781. /**
  3782. * 取消第三方配送订单
  3783. */
  3784. public function thirth_cancel_delivery_order(){
  3785. $_GPC = I('request.');
  3786. $order_id = $_GPC['order_id'];
  3787. if(empty($order_id)){
  3788. show_json(0, array('msg' => '订单号不存在' ) );
  3789. }
  3790. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3791. if(empty($order_info)){
  3792. show_json(0, array('msg' => '订单不存在' ) );
  3793. }
  3794. $orderdistribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' =>$order_id) )->find();
  3795. if(empty($orderdistribution_info)){
  3796. show_json(0, array('msg' => '配送订单不存在' ) );
  3797. }
  3798. $cancel_reason_id = $_GPC['cancel_reason_id'];
  3799. $cancel_reason = $_GPC['cancel_reason'];
  3800. $data_type = $orderdistribution_info['third_distribution_type'];
  3801. if($orderdistribution_info['state'] == 0 || $orderdistribution_info['state'] == 1 || $orderdistribution_info['state'] == 2){
  3802. if($data_type == 'imdada'){
  3803. $imdada = new \Lib\Localtown\Imdada();
  3804. $result = $imdada->cancelOrder($order_info,$cancel_reason_id,$cancel_reason);
  3805. if($result['status'] == 1){//成功
  3806. $deduct_fee = $result['result']['deduct_fee'];
  3807. $other_data = array();
  3808. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3809. $other_data['cancel_reason'] = $cancel_reason;
  3810. $other_data['now_deduct_fee'] = $deduct_fee;
  3811. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3812. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3813. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3814. show_json(1);
  3815. }else{//失败
  3816. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3817. }
  3818. }else if($data_type == 'sf'){
  3819. $sfexpress = new \Lib\Localtown\Sfexpress();
  3820. $result = $sfexpress->cancelOrder($orderdistribution_info,$cancel_reason);
  3821. if($result['status'] == 1){//成功
  3822. $other_data = array();
  3823. if(empty($cancel_reason)){
  3824. $cancel_reason = "商家取消";
  3825. }
  3826. $other_data['cancel_reason'] = $cancel_reason;
  3827. $deduct_fee = round($result['result']['deduction_detail']['deduction_fee']/100,2);
  3828. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3829. $other_data['now_deduct_fee'] = $deduct_fee;
  3830. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3831. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3832. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3833. show_json(1);
  3834. }else{//失败
  3835. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3836. }
  3837. }else if( $data_type == 'make' )
  3838. {
  3839. //$orderdistribution_info
  3840. $third_order_id = $orderdistribution_info['third_order_id'];
  3841. $result = D('Home/Make')->cancelOrder( $third_order_id );
  3842. if( $result['code'] == 0 )
  3843. {
  3844. $other_data = array();
  3845. if(empty($cancel_reason)){
  3846. $cancel_reason = "商家取消";
  3847. }
  3848. $other_data['cancel_reason'] = $cancel_reason;
  3849. $deduct_fee = 0;
  3850. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3851. $other_data['now_deduct_fee'] = $deduct_fee;
  3852. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3853. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3854. //D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3855. //load_model_class('supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3856. show_json(1);
  3857. }else{
  3858. show_json(0, array('msg' => $result['message'] ) );
  3859. }
  3860. }else if($data_type == 'ele'){
  3861. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3862. $result = $eleDistribution->cancelOrder($orderdistribution_info,$cancel_reason_id,$cancel_reason);
  3863. if($result['status'] == 1){//成功
  3864. $other_data = array();
  3865. if(empty($cancel_reason)){
  3866. $cancel_reason = "商家取消";
  3867. }
  3868. $other_data['cancel_reason'] = $cancel_reason;
  3869. $deduct_fee = round($result['result']['deduction_detail']['deduction_fee']/100,2);
  3870. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3871. $other_data['now_deduct_fee'] = $deduct_fee;
  3872. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3873. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3874. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3875. show_json(1);
  3876. }else{//失败
  3877. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3878. }
  3879. }
  3880. }else{
  3881. show_json(0, array('msg' => '配送订单无法取消' ) );
  3882. }
  3883. }
  3884. /**
  3885. * 达达平台模拟取货
  3886. */
  3887. public function orderFetch(){
  3888. $_GPC = I('request.');
  3889. $order_sn = $_GPC['order_sn'];
  3890. $type = $_GPC['type'];
  3891. $imdada = new \Lib\Localtown\Imdada();
  3892. if($type == 1){
  3893. $imdada->orderFetch($order_sn);//模拟取货
  3894. }else if($type == 2){
  3895. $imdada->orderFinish($order_sn);//完成订单
  3896. }else if($type == 3){
  3897. $imdada->orderCancel($order_sn);//取消订单
  3898. }else if($type == 4){
  3899. $imdada->orderAbnormal($order_sn);//异常妥投物品返还中
  3900. }
  3901. }
  3902. public function third_delivery_log_list(){
  3903. $order_id = I('request.order_id','');
  3904. $orderdistribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' =>$order_id) )->find();
  3905. $distribution_type = $orderdistribution_info['third_distribution_type'];
  3906. $log_list = M('lionfish_comshop_orderdistribution_thirth_log')->where( array('order_id' =>$order_id,'third_distribution_type'=>$distribution_type) )->order('addtime desc')->select();
  3907. $third_name = "";
  3908. if($distribution_type == 'imdada'){
  3909. $third_name = '达达平台';
  3910. }else if($distribution_type == 'sf'){
  3911. $third_name = '顺丰同城';
  3912. }else if($distribution_type == 'make'){
  3913. $third_name = '码科配送';
  3914. }else if($distribution_type == 'uupt'){
  3915. $third_name = 'UU跑腿';
  3916. }else if($distribution_type == 'dianwoda'){
  3917. $third_name = '点我达';
  3918. }
  3919. $this->third_name = $third_name;
  3920. $this->log_list = $log_list;
  3921. $this->orderdistribution_info = $orderdistribution_info;
  3922. $this->display();
  3923. }
  3924. //end
  3925. /**
  3926. * 订单核销
  3927. */
  3928. public function order_hexiao()
  3929. {
  3930. $opdata = $this->check_order_data();
  3931. extract($opdata);
  3932. if( $item['delivery'] == 'hexiao' )
  3933. {
  3934. D('Seller/Order')->hexiao_all_orders($item['order_id']);
  3935. }
  3936. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  3937. }
  3938. /**
  3939. * 商品按订单核销
  3940. */
  3941. public function order_goods_hexiao(){
  3942. $opdata = $this->check_order_data();
  3943. extract($opdata);
  3944. $order_goods_id = I('request.order_goods_id','');
  3945. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id, 'order_goods_id' => $order_goods_id) )->find();
  3946. if (empty($order_hexiao_info)) {
  3947. show_json(0, '未找到核销订单!');
  3948. }
  3949. D('Seller/Order')->hexiao_order_goods($order_hexiao_info,0);
  3950. D('Seller/Order')->hexiao_finished($id,'后台确认使用,订单完成');
  3951. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  3952. }
  3953. /**
  3954. * 查看核销记录
  3955. */
  3956. public function view_hexiao_history(){
  3957. $opdata = $this->get_goods_saleshexiao();
  3958. extract($opdata);
  3959. $data = D('Seller/Order')->get_goods_hexiao_record();
  3960. $this->order_hexiao_info = $order_hexiao_info;
  3961. $this->hx_list = $data['hx_list'];
  3962. $this->display("hexiao_history");
  3963. }
  3964. /**
  3965. * 按次数核销商品
  3966. */
  3967. public function hexiao_times(){
  3968. $opdata = $this->get_goods_saleshexiao();
  3969. extract($opdata);
  3970. $data = D('Seller/Order')->get_goods_hexiao_record();
  3971. $this->order_hexiao_info = $order_hexiao_info;
  3972. $this->hx_list = $data['hx_list'];
  3973. $this->hx_count = $data['hx_count'];
  3974. $this->display();
  3975. }
  3976. /**
  3977. * 获取商品核销信息
  3978. * @return
  3979. */
  3980. public function get_goods_saleshexiao(){
  3981. $opdata = $this->check_order_data();
  3982. extract($opdata);
  3983. $order_goods_id = I('request.order_goods_id','');
  3984. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id, 'order_goods_id' => $order_goods_id) )->find();
  3985. if (empty($order_hexiao_info)) {
  3986. show_json(0, '未找到核销订单!');
  3987. }
  3988. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('order_goods_id'=>$order_hexiao_info['order_goods_id']))->field('goods_id,name as goods_name,goods_images,quantity')->find();
  3989. $order_hexiao_info['goods_id'] = $order_goods_info['goods_id'];
  3990. $order_hexiao_info['goods_name'] = $order_goods_info['goods_name'];
  3991. $order_hexiao_info['goods_images'] = tomedia($order_goods_info['goods_images']);
  3992. $order_hexiao_info['quantity'] = $order_goods_info['quantity'];
  3993. return array('order_hexiao_info' => $order_hexiao_info);
  3994. }
  3995. /**
  3996. * 核销商品使用
  3997. */
  3998. public function hexiao_goods(){
  3999. $hx_id = I('request.hx_id','');
  4000. $hx_count = I('request.hx_count','');
  4001. if(empty($hx_id)){
  4002. show_json(0, '核销商品数据错误!');
  4003. }
  4004. if(empty($hx_count)){
  4005. show_json(0, '核销商品数量错误!');
  4006. }
  4007. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hx_id) )->find();
  4008. if (empty($order_hexiao_info)) {
  4009. show_json(0, '未找到核销订单!');
  4010. }
  4011. D('Seller/Order')->hexiao_order_goods($order_hexiao_info,$hx_count);
  4012. D('Seller/Order')->hexiao_finished($order_hexiao_info['order_id'],'后台确认使用,订单完成');
  4013. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  4014. }
  4015. /**
  4016. * 查看商品指定核销信息
  4017. */
  4018. public function hexiao_goods_assign_salesroom(){
  4019. $goods_id = I('request.goods_id','');
  4020. $order_goods_id = I('request.order_goods_id','');
  4021. if(empty($goods_id)){
  4022. show_json(0, '商品信息错误!');
  4023. }
  4024. if(empty($order_goods_id)){
  4025. show_json(0, '核销商品信息错误!');
  4026. }
  4027. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('order_goods_id'=>$order_goods_id))->field('goods_id,name as goods_name,goods_images,quantity')->find();
  4028. $goods_salesroom_info = D('Seller/Order')->get_goods_assign_salesroom($goods_id);
  4029. $this->salesroom_list = $goods_salesroom_info['salesroom_list'];
  4030. $this->smember_list = $goods_salesroom_info['smember_list'];
  4031. $this->goods_info = $order_goods_info;
  4032. $this->display();
  4033. }
  4034. public function checkLocalTownOrderCanRefund($item){
  4035. if($item['delivery'] == 'localtown_delivery'){//同城配送订单
  4036. if($item['order_status_id'] == 4){//已发货不能退款
  4037. return false;
  4038. }else{
  4039. return true;
  4040. }
  4041. }else{
  4042. return true;
  4043. }
  4044. }
  4045. }
  4046. ?>