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