OrderController.class.php 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357
  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']['remain_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. if($can_refund_quantity >= 1){
  1310. $value['hx_info']['is_can_refund'] = 1;
  1311. }else{
  1312. $value['hx_info']['is_can_refund'] = 0;
  1313. }
  1314. }
  1315. $record_count = M('lionfish_comshop_order_goods_saleshexiao_record')->where(array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->count();
  1316. $value['hx_info']['record_count'] = $record_count;
  1317. }
  1318. }
  1319. $need_order_goods[$key] = $value;
  1320. }
  1321. if (defined('ROLE') && ROLE == 'agenter' )
  1322. {
  1323. $item['shipping_fare'] = $shipping_fare;
  1324. $item['fullreduction_money'] = $fullreduction_money;
  1325. $item['voucher_credit'] = $voucher_credit;
  1326. $item['total'] = $total;
  1327. }
  1328. $order_goods = $need_order_goods;
  1329. if (empty($item)) {
  1330. $this->message('抱歉,订单不存在!', $_SERVER['HTTP_REFERER'], 'error');
  1331. }
  1332. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id'] ) )->find();
  1333. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  1334. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  1335. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  1336. $express_info = array();
  1337. if( !empty($item['shipping_method']) )
  1338. {
  1339. $express_info = D('Seller/Express')->get_express_info($item['shipping_method']);
  1340. }
  1341. $this->express_info = $express_info;
  1342. $coupon = array();
  1343. //voucher_id voucher_credit
  1344. //ims_
  1345. if( $item['voucher_id'] > 0 )
  1346. {
  1347. $coupon = array();
  1348. //$coupon = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ",
  1349. //array(':uniacid' => $_W['uniacid'], ':id' => $item['voucher_id']));
  1350. }
  1351. if( $item['delivery'] == 'localtown_delivery' && ($item['order_status_id'] != 3 && $item['order_status_id'] != 5 ) )
  1352. {
  1353. $item['orderdistribution_order'] = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $item['order_id'] ) )->find();
  1354. if( !empty($item['orderdistribution_order']) && $item['orderdistribution_order'] > 0 )
  1355. {
  1356. if($item['orderdistribution_order']['orderdistribution_id'] > 0){
  1357. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('id' => $item['orderdistribution_order']['orderdistribution_id'] ) )->find();
  1358. $item['orderdistribution_order']['username'] = $orderdistribution['username'];
  1359. }else{
  1360. /*if($item['orderdistribution_order']['orderdistribution_id'] == -1){
  1361. $item['orderdistribution_order']['username'] = "系统默认配送员";
  1362. }else{*/
  1363. if($item['orderdistribution_order']['third_distribution_type'] == 'imdada'){
  1364. $item['orderdistribution_order']['username'] = "达达平台配送";
  1365. }else if($item['orderdistribution_order']['third_distribution_type'] == 'sf'){
  1366. $item['orderdistribution_order']['username'] = "顺丰同城配送";
  1367. }else if($item['orderdistribution_order']['third_distribution_type'] == 'uupt'){
  1368. $item['orderdistribution_order']['username'] = "UU跑腿配送";
  1369. }else if($item['orderdistribution_order']['third_distribution_type'] == 'dianwoda'){
  1370. $item['orderdistribution_order']['username'] = "点我达配送";
  1371. }
  1372. //}
  1373. }
  1374. }
  1375. }
  1376. if (defined('ROLE') && ROLE == 'agenter' )
  1377. {
  1378. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1379. if($supply_can_look_headinfo != 1){
  1380. if( $item['delivery'] == 'pickup' ){
  1381. $shipping_stree = D('Home/Front')->get_area_info($item['shipping_stree_id']);
  1382. $tuan_address = $province_info['name'].$city_info['name'].$area_info['name'];
  1383. $tuan_address2= str_replace($tuan_address, '',$item['shipping_address']);
  1384. $str = $tuan_address2;
  1385. strlen($str);
  1386. $i = mb_strlen($str,"UTF-8");
  1387. $tuan_address2 = D('Seller/Order')->desensitize($tuan_address2,1,$i-2);
  1388. $item['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$tuan_address2;
  1389. }
  1390. }
  1391. }
  1392. //售后期
  1393. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  1394. //天数
  1395. $open_aftersale_time = D('Home/Front')->get_config_by_name('open_aftersale_time');
  1396. $order_settlement =" ";
  1397. //订单状态
  1398. if($item['order_status_id'] ==5 || $item['order_status_id'] ==7 ){
  1399. //已失效
  1400. $order_status = 2;
  1401. }else{
  1402. //待结算
  1403. $order_status = $order_head_status;
  1404. if(($item['order_status_id'] ==6 || $item['order_status_id'] ==11) ){
  1405. if($item['order_status_id'] ==6){
  1406. $order_settlement = $item['receive_time'] + $open_aftersale_time*86400;
  1407. }
  1408. if($item['order_status_id'] ==11){
  1409. $order_settlement = $item['finishtime'] + $open_aftersale_time*86400;
  1410. }
  1411. }
  1412. }
  1413. $this->open_aftersale = $open_aftersale;
  1414. $this->order_status = $order_status;
  1415. $this->open_aftersale_time = $open_aftersale_time;
  1416. $this->order_settlement = $order_settlement;
  1417. $this->id = $id;
  1418. $this->item = $item;
  1419. $this->order_goods = $order_goods;
  1420. $this->member = $member;
  1421. $this->province_info = $province_info;
  1422. $this->city_info = $city_info;
  1423. $this->area_info = $area_info;
  1424. $history_list = M('lionfish_comshop_order_history')->where( array('order_id' => $id ) )->order('order_history_id asc')->select();
  1425. $order_status_arr = D('Seller/Order')->get_order_status_name();
  1426. //$order_history['order_status_id'] = 18;
  1427. $order_status_arr[18] = '已结算';
  1428. $order_status_arr[19] = '商品部分退款';
  1429. $order_status_arr[20] = '拒绝商品部分退款';
  1430. $order_status_arr[15] = '预售支付定金';
  1431. foreach( $history_list as &$val )
  1432. {
  1433. if( $val[''] == '订单改价' )
  1434. {
  1435. $val['order_status_name'] = 'comment';
  1436. }
  1437. else{
  1438. $val['order_status_name'] = $order_status_arr[$val['order_status_id']];
  1439. }
  1440. }
  1441. unset($val);
  1442. $this->history_list = $history_list;
  1443. $this->order_status_arr = $order_status_arr;
  1444. $is_can_look_headinfo = true;
  1445. $is_can_nowrfund_order = true;
  1446. $is_can_confirm_delivery = true;
  1447. $is_can_confirm_receipt = true;
  1448. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1449. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  1450. $supply_can_confirm_delivery = D('Home/Front')->get_config_by_name('supply_can_confirm_delivery');
  1451. $supply_can_confirm_receipt = D('Home/Front')->get_config_by_name('supply_can_confirm_receipt');
  1452. if (defined('ROLE') && ROLE == 'agenter' )
  1453. {
  1454. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1455. {
  1456. $is_can_look_headinfo = false;
  1457. }
  1458. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  1459. {
  1460. $is_can_nowrfund_order = false;
  1461. }
  1462. if( isset($supply_can_confirm_delivery) && $supply_can_confirm_delivery == 2 )
  1463. {
  1464. $is_can_confirm_delivery = false;
  1465. }
  1466. if( isset($supply_can_confirm_receipt) && $supply_can_confirm_receipt == 2 )
  1467. {
  1468. $is_can_confirm_receipt = false;
  1469. }
  1470. }
  1471. $s_id = 1 ;
  1472. if(SELLERUID != 1)
  1473. {
  1474. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  1475. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  1476. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  1477. $perms2 = explode(",", $perms1);
  1478. if(in_array("user/user/index", $perms2)){
  1479. $s_id = 1 ;
  1480. } else {
  1481. $s_id = 0 ;
  1482. }
  1483. }
  1484. $this->s_id = $s_id;
  1485. //预售判断 begin
  1486. $is_presale = 0;
  1487. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  1488. $presale_for_ordermoney = 0;
  1489. if( $presale_result['code'] == 0 )
  1490. {
  1491. if( $presale_result['data']['presale_deduction_money'] > 0 )
  1492. {
  1493. $presale_for_ordermoney = $presale_result['data']['presale_for_ordermoney'];
  1494. }
  1495. $is_presale = 1;
  1496. }
  1497. $this->is_presale = $is_presale;
  1498. $this->presale_for_ordermoney = $presale_for_ordermoney;
  1499. //预售end
  1500. //礼品卡begin
  1501. $is_virtualcard = 0;
  1502. $virtualcard_result = D('Seller/VirtualCard')->getVirtualCardOrderInfO( $id );
  1503. if( $virtualcard_result['code'] == 0 )
  1504. {
  1505. $is_virtualcard = 1;
  1506. $this->virtualcard_info = $virtualcard_result['data'];
  1507. }
  1508. $this->is_virtualcard = $is_virtualcard;
  1509. //礼品卡end
  1510. //订单表单信息
  1511. $order_form_data = D('Home/Allform')->getOrderFormInfo($id, $item['member_id']);
  1512. $this->order_form_data = $order_form_data;
  1513. $is_order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  1514. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  1515. $order_note_name = isset($order_note_name) && !empty($order_note_name) ? $order_note_name :'店名';
  1516. $open_admin_payment = D('Home/Front')->get_config_by_name('open_admin_payment');
  1517. $this->open_admin_payment = $open_admin_payment;
  1518. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  1519. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  1520. $this->is_order_note_open = $is_order_note_open;
  1521. $this->order_note_name = $order_note_name;
  1522. $this->is_can_look_headinfo = $is_can_look_headinfo;
  1523. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  1524. $this->is_can_confirm_delivery = $is_can_confirm_delivery;
  1525. $this->is_can_confirm_receipt = $is_can_confirm_receipt;
  1526. $this->localtown_modifypickingname = $localtown_modifypickingname;
  1527. $this->display();
  1528. }
  1529. //查看物流
  1530. public function express(){
  1531. $_GPC = I('request.');
  1532. $order_id = $_GPC['order_id'];
  1533. $express_list = D('Seller/Order')->goods_express($order_id);
  1534. if($express_list['code'] == 2){
  1535. $code = $express_list['code'];
  1536. $reason = $express_list['Reason'];
  1537. $this->code = $code;
  1538. $this->reason = $reason;
  1539. }
  1540. $new_array = json_decode(json_encode($express_list['order_info']['shipping_traces']), true);
  1541. $new_array = array_reverse($new_array);
  1542. $this->list = $new_array;
  1543. $this->display();
  1544. }
  1545. public function refund_mult()
  1546. {
  1547. $_GPC = I('request.');
  1548. $ids_arr = $_GPC['ids_arr'];
  1549. $cache_key = md5(time().count($ids_arr).'_sendmulutrefund');
  1550. $quene_order_list = array();
  1551. //限定配送数组
  1552. S('_multrefund_'.$cache_key, $ids_arr);
  1553. $this->_GPC = $_GPC;
  1554. $this->cache_key = $cache_key;
  1555. $this->display();
  1556. }
  1557. public function refund_mult_do()
  1558. {
  1559. $_GPC = I('request.');
  1560. $cache_key = $_GPC['cache_key'];
  1561. $quene_order_list = S('_multrefund_'.$cache_key);
  1562. $order_id = array_shift($quene_order_list);
  1563. S('_multrefund_'.$cache_key, $quene_order_list);
  1564. //...
  1565. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1566. $weixin_model = D('Home/Weixin');
  1567. $title = '订单编号:'.$order_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理";
  1568. //order_status_id
  1569. if( in_array($order_info['order_status_id'], array(1,4,6,10,11,12,14)) ){
  1570. $res = $weixin_model->refundOrder($order_id);
  1571. if( $res['code'] == 0 )
  1572. {
  1573. $title = '订单编号:'.$order_info['order_num_alias']." 退款失败,还剩余".count($quene_order_list)."个清单未处理";
  1574. }else{
  1575. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1576. $comment = '群接龙批量退款,全额退款';
  1577. $order_history = array();
  1578. $order_history['order_id'] = $order_id;
  1579. $order_history['order_status_id'] = 7;
  1580. $order_history['notify'] = 0;
  1581. $order_history['comment'] = $comment;
  1582. $order_history['date_added'] = time();
  1583. M('lionfish_comshop_order_history')->add( $order_history );
  1584. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 7) );
  1585. $refund_all = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id, 'state' => 0 ) )->select();
  1586. if( !empty($refund_all) )
  1587. {
  1588. foreach( $refund_all as $val )
  1589. {
  1590. $ins_data = array();
  1591. $ins_data['ref_id'] = $val['ref_id'];
  1592. $ins_data['order_id'] = $val['order_id'];
  1593. $ins_data['order_goods_id'] = $val['order_goods_id'];
  1594. $ins_data['message'] = '群接龙批量退款 ,退款成功';
  1595. $ins_data['type'] = 2;
  1596. $ins_data['addtime'] = time();
  1597. M('lionfish_comshop_order_refund_history')->add( $ins_data );
  1598. M('lionfish_comshop_order_refund')->where( array('ref_id' => $val['ref_id']) )->save( array('state' => 3) );
  1599. }
  1600. }
  1601. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  1602. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  1603. {
  1604. sellerLog('群接龙后台取消订单', 2);
  1605. D('Seller/Printaction')->check_print_order($id,'群接龙后台取消订单');
  1606. D('Seller/Printaction')->check_print_order2($id,'群接龙后台取消订单');
  1607. }
  1608. }
  1609. }
  1610. if( empty($quene_order_list) )
  1611. {
  1612. echo json_encode( array('code' => 2) );
  1613. die();
  1614. }
  1615. //清单编号
  1616. echo json_encode( array('code' => 0, 'msg' => $title ) );
  1617. die();
  1618. }
  1619. public function opreceive()
  1620. {
  1621. $opdata = $this->check_order_data();
  1622. extract($opdata);
  1623. //检查订单是否能确认收货(存在售后未完成无法确认收货)
  1624. $result = D('Seller/Order')->check_order_receive($item['order_id']);
  1625. if($result['status'] == 0){
  1626. show_json(0, array('msg'=>"该订单处于售后处理中,请处理后再确认收货!"));
  1627. }
  1628. if($item['delivery'] == 'localtown_delivery') {
  1629. $result = D('Seller/Order')->check_localtown_order_receive($item['order_id']);
  1630. if ($result['status'] == 0) {
  1631. show_json(0, array('msg' => "该订单未有配送员接单或还未指定配送员,无法确认收货!"));
  1632. }
  1633. }
  1634. //pdo_update('lionfish_comshop_order', array('order_status_id' => 6, 'receive_time' => time()), array('order_id' => $item['order_id'], 'uniacid' => $_W['uniacid']));
  1635. if( $item['delivery'] == 'localtown_delivery' )
  1636. {
  1637. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $item['order_id']) )->save( array('state' => 4) );
  1638. D('Home/LocaltownDelivery')->write_distribution_log( $item['order_id'], 0 , 4 , "后台操作,确认收货" );
  1639. }
  1640. D('Seller/Order')->receive_order($item['order_id']);
  1641. M('lionfish_comshop_order_history')->where( array('order_id' => $item['order_id'],'order_status_id' => 6) )->save( array( 'comment' => '后台操作,确认收货') );
  1642. if( $item['delivery'] == 'localtown_delivery' )
  1643. {
  1644. //D('Home/LocaltownDelivery')->distribution_deliverying_order( $item['order_id'] );
  1645. D('Home/LocaltownDelivery')->distribution_arrived_order( $item['order_id'] ,0 );
  1646. }
  1647. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1648. }
  1649. public function orderaftersales()
  1650. {
  1651. //$_GPC['order_status_id'] = 12;
  1652. $gpc = I('request.');
  1653. $this->gpc = $gpc;
  1654. $this->_GPC = $gpc;
  1655. $time = I('request.time');
  1656. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  1657. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  1658. $this->searchfield = I('request.searchfield','');
  1659. $this->keyword = I('request.keyword','');
  1660. $this->searchtime = I('request.searchtime','');
  1661. $this->delivery = I('request.delivery','');
  1662. $this->starttime = $starttime;
  1663. $this->endtime = $endtime;
  1664. $this->time = $time;
  1665. $order_status_arr = D('Seller/Order')->get_order_status_name();
  1666. $this->order_status_arr = $order_status_arr;
  1667. $need_data = D('Seller/Order')->load_afterorder_list();//改造原来的加载方法
  1668. $this->need_data = $need_data;
  1669. $cur_controller = 'order/order';
  1670. $total = $need_data['total'];
  1671. $total_money = $need_data['total_money'];
  1672. $list = $need_data['list'];
  1673. $pager = $need_data['pager'];
  1674. $all_count = $need_data['all_count'];
  1675. $count_status_1 = $need_data['count_status_1'];
  1676. $count_status_3 = $need_data['count_status_3'];
  1677. $count_status_4 = $need_data['count_status_4'];
  1678. $count_status_5 = $need_data['count_status_5'];
  1679. $count_status_7 = $need_data['count_status_7'];
  1680. $count_status_11 = $need_data['count_status_11'];
  1681. $count_status_14 = $need_data['count_status_14'];
  1682. $this->cur_controller = $cur_controller;
  1683. $this->total = $total;
  1684. $this->total_money = $total_money;
  1685. $this->list = $list;
  1686. $this->pager = $pager;
  1687. $this->all_count = $all_count;
  1688. $this->count_status_1 = $count_status_1;
  1689. $this->count_status_3 = $count_status_3;
  1690. $this->count_status_4 = $count_status_4;
  1691. $this->count_status_5 = $count_status_5;
  1692. $this->count_status_7 = $count_status_7;
  1693. $this->count_status_11 = $count_status_11;
  1694. $this->count_status_14 = $count_status_14;
  1695. $s_id = 1 ;
  1696. if(SELLERUID != 1)
  1697. {
  1698. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  1699. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  1700. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  1701. $perms2 = explode(",", $perms1);
  1702. if(in_array("user/user/index", $perms2)){
  1703. $s_id = 1 ;
  1704. } else {
  1705. $s_id = 0 ;
  1706. }
  1707. }
  1708. $this->s_id = $s_id;
  1709. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  1710. if( empty($open_feier_print) )
  1711. {
  1712. $open_feier_print = 0;
  1713. }
  1714. $this->open_feier_print = $open_feier_print;
  1715. //退款状态:0申请中,1商家拒绝,2平台介入,3退款成功,4退款失败,5:撤销申请
  1716. $order_refund_state = array(0=>'申请中',1=>'商家拒绝', 2=>'平台介入',3=>'退款成功',4=>'退款失败',5=>'撤销申请');
  1717. $this->order_refund_state = $order_refund_state;
  1718. $is_can_look_headinfo = true;
  1719. $is_can_nowrfund_order = true;
  1720. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1721. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  1722. if (defined('ROLE') && ROLE == 'agenter' )
  1723. {
  1724. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1725. {
  1726. $is_can_look_headinfo = false;
  1727. }
  1728. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  1729. {
  1730. $is_can_nowrfund_order = false;
  1731. }
  1732. }
  1733. $this->is_can_look_headinfo = $is_can_look_headinfo;
  1734. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  1735. $this->display();
  1736. }
  1737. public function oprefund_doform()
  1738. {
  1739. $_GPC = I('request.');
  1740. $ref_id = $_GPC['ref_id'];
  1741. $refund_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  1742. $this->ref_id = $ref_id;
  1743. $this->refund_info = $refund_info;
  1744. if (IS_POST) {
  1745. $order_history = array();
  1746. $order_history['order_id'] = $refund_info['order_id'];
  1747. $order_history['order_status_id'] = 0;
  1748. $order_history['notify'] = 0;
  1749. $order_history['comment'] = '';
  1750. $order_history['date_added'] = time();
  1751. $remarkrefund = $_GPC['remarkrefund'];
  1752. $is_forbidden = $_GPC['is_forbidden'];
  1753. $cansub = $_GPC['cansub'];
  1754. if( isset($_GPC['is_forbidden']) && $_GPC['is_forbidden'] > 0 )
  1755. {
  1756. //添加
  1757. $refund_disable = M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $ref_id ) )->find();
  1758. if( empty($refund_disable) )
  1759. {
  1760. //插入
  1761. $ins_data = array();
  1762. $ins_data['ref_id'] = $ref_id;
  1763. $ins_data['order_id'] = $refund_info['order_id'];
  1764. $ins_data['order_goods_id'] = $refund_info['order_goods_id'];
  1765. $ins_data['addtime'] = time();
  1766. M('lionfish_comshop_order_refund_disable')->add($ins_data);
  1767. }
  1768. }else{
  1769. //删除
  1770. M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $ref_id ) )->delete();
  1771. }
  1772. if($cansub == 1)
  1773. {
  1774. //确认退款 remarkrefund
  1775. $weixin_model = D('Home/Weixin');
  1776. $order_refund = M('lionfish_comshop_order_refund')->field('ref_money,real_refund_quantity,ref_shipping_fare')->where( array('ref_id' => $ref_id ) )->find();
  1777. //$order_info['total']
  1778. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->find();
  1779. if( $order_info['type'] == 'integral' || $order_info['type'] == 'normal' )
  1780. {
  1781. //M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('shipping_fare' => $order_refund['ref_shipping_fare'] ) );
  1782. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1783. {
  1784. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->find();
  1785. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->save( array('shipping_fare' => $order_refund['ref_shipping_fare'] ) );
  1786. }
  1787. }
  1788. if( $order_refund['real_refund_quantity'] > 0 )
  1789. {
  1790. //部分商品退款
  1791. $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);
  1792. }else{
  1793. $res = $weixin_model->refundOrder($refund_info['order_id'], $order_refund['ref_money'],0,$refund_info['order_goods_id']);
  1794. }
  1795. if( $order_info['type'] == 'integral' || $order_info['type'] == 'normal')
  1796. {
  1797. //M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('shipping_fare' => $order_info['shipping_fare'] ) );
  1798. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1799. {
  1800. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->save( array('shipping_fare' => $order_goods['shipping_fare'] ) );
  1801. }
  1802. }
  1803. if($res['code'] == 1)
  1804. {
  1805. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] , 'order_id' => $refund_info['order_id'] ) )->find();
  1806. if( $order_refund['real_refund_quantity'] <= 0 )
  1807. {
  1808. $order_refund['real_refund_quantity'] = $order_goods['quantity'] - $order_goods['has_refund_quantity'];
  1809. }
  1810. $pay_total_money = $order_goods['total']-$order_goods['voucher_credit']-$order_goods['fullreduction_money'] - $order_goods['score_for_money'];
  1811. $buy_usescore = D('Seller/Commonorder')->get_order_goods_buyscore($refund_info['order_id'], $refund_info['order_goods_id']);
  1812. if( !empty($buy_usescore) && $buy_usescore > 0 )
  1813. {
  1814. $res_score= ceil( $buy_usescore * ( $order_refund['real_refund_quantity']/ $order_goods['quantity']) );
  1815. D('Seller/Commonorder')->refund_order_goods_intrgral( $refund_info['order_id'], $refund_info['order_goods_id'] ,$res_score );
  1816. }
  1817. if($order_refund['ref_money']-$order_refund['ref_shipping_fare'] <= 0){
  1818. $refund_money = 0;
  1819. }else{
  1820. $refund_money = $order_refund['ref_money']-$order_refund['ref_shipping_fare'];
  1821. }
  1822. if( $order_info['type'] == 'integral'){
  1823. $refund_money = $order_refund['ref_money'];
  1824. }
  1825. //退款配送费问题
  1826. 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']);
  1827. //如果这个商品没有数量了。就改变他的状态为已退款的状态
  1828. $new_total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($refund_info['order_id'],$refund_info['order_goods_id'] );
  1829. $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $refund_info['order_id'], 'state' => 0 ) )->count();
  1830. if( $new_total_quantity <=0 && $ref_count <= 1)
  1831. {
  1832. 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,'平台同意退款,');
  1833. }else{
  1834. $order_history = array();
  1835. $order_history['uniacid'] = 0;
  1836. $order_history['order_id'] = $refund_info['order_id'];
  1837. $order_history['order_goods_id'] = $refund_info['order_goods_id'];
  1838. $order_history['notify'] = 0;
  1839. $order_history['order_status_id'] = 19;
  1840. if( $order_info['type'] == 'integral' )
  1841. {
  1842. $order_history['comment'] = '平台同意退款,子订单退款,退款商品:'.$order_refund['real_refund_quantity'] .'个,退库存/销量数量'.$order_refund['real_refund_quantity'].'个,退款积分'.$order_refund['ref_money'].'积分';
  1843. if( !empty($order_refund['ref_shipping_fare']) ){
  1844. $order_history['comment'] .= '. 退配送费:'.$order_refund['ref_shipping_fare'].'元';
  1845. }
  1846. }else{
  1847. $order_history['comment'] = '平台同意退款,子订单退款,退款商品:'.$order_refund['real_refund_quantity'] .'个,退库存/销量数量'.$order_refund['real_refund_quantity'].'个,退款金额'.$order_refund['ref_money'].'元';
  1848. }
  1849. $order_history['date_added'] = time();
  1850. M('lionfish_comshop_order_history')->add( $order_history );
  1851. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] ) )->save( array('is_refund_state' => 0 ) );
  1852. }
  1853. //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);
  1854. $order_refund_history = array();
  1855. $order_refund_history['ref_id'] = $ref_id;
  1856. $order_refund_history['order_id'] = $refund_info['order_id'];
  1857. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1858. $order_refund_history['message'] = '平台同意退款'.' '.$remarkrefund.' ,退款成功';
  1859. $order_refund_history['type'] = 2;
  1860. $order_refund_history['addtime'] = time();
  1861. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1862. //通过 lionfish_comshop_order_refund
  1863. sellerLog('同意'.$remarkrefund.'退款成功操作', 2);
  1864. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 3,'modify_time' => time(),'remarkrefund' => $remarkrefund) );
  1865. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1866. }else{
  1867. if( empty($res['msg']) )
  1868. {
  1869. $res['msg'] = '请检查商户号与cert证书';
  1870. }
  1871. $order_refund_history = array();
  1872. $order_refund_history['ref_id'] = $ref_id;
  1873. $order_refund_history['order_id'] = $refund_info['order_id'];
  1874. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1875. $order_refund_history['message'] = '平台同意退款'.' '.$remarkrefund.' ,但是退款失败:'.$res['msg'];
  1876. $order_refund_history['type'] = 2;
  1877. $order_refund_history['addtime'] = time();
  1878. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1879. show_json(0, array('message' => $res['msg']) );
  1880. }
  1881. }else if($cansub == 2){
  1882. //拒绝退款
  1883. $order_refund_history = array();
  1884. $order_refund_history['ref_id'] = $ref_id;
  1885. $order_refund_history['order_id'] = $refund_info['order_id'];
  1886. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1887. $order_refund_history['message'] = '平台拒绝退款'.' '.$remarkrefund;
  1888. $order_refund_history['type'] = 2;
  1889. $order_refund_history['addtime'] = time();
  1890. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1891. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 1,'modify_time' => time(),'remarkrefund' => $remarkrefund ) );
  1892. $item = M('lionfish_comshop_order')->field('order_status_id,last_refund_order_status_id')->where( array('order_id' => $refund_info['order_id'] ) )->find();
  1893. $order_history['order_status_id'] = 20;
  1894. //如果是部分退款,那么就不是12了
  1895. if( $item['order_status_id'] == 12)
  1896. {
  1897. $order_history['order_status_id'] = 12;
  1898. if( $item['last_refund_order_status_id'] > 0 )
  1899. {
  1900. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  1901. M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('order_status_id' => $item['last_refund_order_status_id']) );
  1902. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  1903. $order_history['comment'] = '商家拒绝退款,订单回退上一状态';
  1904. }else{
  1905. $order_history['comment'] = '商家拒绝退款';
  1906. }
  1907. }
  1908. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1909. {
  1910. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] ) )->save( array('is_refund_state' => 0) );
  1911. }
  1912. //拒绝 order_status_id
  1913. sellerLog($order_history['comment'].'操作', 2);
  1914. M('lionfish_comshop_order_history')->add( $order_history );
  1915. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1916. }
  1917. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1918. }
  1919. $this->display();
  1920. }
  1921. public function oprefund()
  1922. {
  1923. $_GPC = I('request.');
  1924. $opdata = $this->check_order_data();
  1925. extract($opdata);
  1926. $ref_id = $_GPC['ref_id'];
  1927. $ref_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  1928. $step_array = array();
  1929. $step_array[1]['step'] = 1;
  1930. $step_array[1]['title'] = '客户发起退款';
  1931. $step_array[1]['time'] = $ref_info['addtime'];
  1932. $step_array[1]['done'] = 1;
  1933. $step_array[2]['step'] = 2;
  1934. $step_array[2]['title'] = '平台处理维权申请';
  1935. $step_array[2]['done'] = 0;
  1936. $step_array[2]['time'] = '';
  1937. $step_array[3]['step'] = 3;
  1938. $step_array[3]['done'] = 0;
  1939. $step_array[3]['title'] = '商家处理退款完成';
  1940. $step_array[3]['time'] = '';
  1941. $ref_id = I('request.ref_id');
  1942. $this->ref_id = $ref_id;
  1943. $this->ref_info = $ref_info;
  1944. $order_goods_id = $ref_info['order_goods_id'];
  1945. if( !empty($order_goods_id) && $order_goods_id > 0 )
  1946. {
  1947. $goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id, 'order_id' => $id ) )->select();
  1948. }else{
  1949. $goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->select();
  1950. }
  1951. $total_fare = 0;
  1952. $total_shipping_fare = 0;
  1953. $total_voucher_credit =0;
  1954. $total_fullreduction_money = 0;
  1955. $total_total_fare = 0;
  1956. $total_score_for_money = 0;
  1957. /**
  1958. php echo number_format($item['total']+$item['shipping_fare']-$item['voucher_credit']-$item['fullreduction_money'],2)
  1959. **/
  1960. foreach($goods as &$value)
  1961. {
  1962. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($item['order_id'], $value['order_goods_id']);
  1963. $total_fare += $value['total'];
  1964. $total_shipping_fare += $value['shipping_fare'];
  1965. $total_voucher_credit += $value['voucher_credit'];
  1966. $total_fullreduction_money += $value['fullreduction_money'];
  1967. $total_score_for_money += $value['score_for_money'];
  1968. $total_total_fare += $value['total']+$value['shipping_fare']-$value['voucher_credit']-$value['fullreduction_money']-$value['score_for_money'];
  1969. }
  1970. $this->goods = $goods;
  1971. $this->total_fare = $total_fare;
  1972. $this->total_shipping_fare = $total_shipping_fare;
  1973. $this->total_voucher_credit = $total_voucher_credit;
  1974. $this->total_fullreduction_money = $total_fullreduction_money;
  1975. $this->total_score_for_money = $total_score_for_money;
  1976. $this->total_total_fare = $total_total_fare;
  1977. unset($r);
  1978. $item['goods'] = $goods;
  1979. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id']) )->find();
  1980. $this->member = $member;
  1981. $express_list = array();
  1982. $r_type = array(1=>'仅退款',2 => '退款退货');
  1983. //ims_
  1984. $this->r_type =$r_type;
  1985. $order_refund = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->find();
  1986. $this->order_refund = $order_refund;
  1987. if($order_refund['modify_time'] != 0 && $order_refund['state']== 3)
  1988. {
  1989. $step_array[3]['done'] = 1;
  1990. $step_array[3]['time'] = $order_refund['modify_time'];
  1991. }
  1992. $refund_imgs = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id'] ) )->select();
  1993. $this->refund_imgs = $refund_imgs;
  1994. /**
  1995. if( !empty($order_goods_id) && $order_goods_id > 0 )
  1996. {
  1997. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' =>$id,'order_goods_id' => $order_goods_id ) )->order('addtime asc')->select();
  1998. }
  1999. else{
  2000. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' =>$id ) )->order('addtime asc')->select();
  2001. }
  2002. **/
  2003. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('ref_id' => $ref_id ) )->order('addtime asc')->select();
  2004. $i = 1;
  2005. foreach($order_refund_history as $key => $val)
  2006. {
  2007. if( $i == 1 && $val['type'] == 2 )
  2008. {
  2009. $step_array[2]['done'] = 1;
  2010. $step_array[2]['time'] = time();
  2011. $i++;
  2012. }
  2013. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2014. switch($val['type'])
  2015. {
  2016. case 1:
  2017. $val['type'] = '用户反馈';
  2018. break;
  2019. case 2:
  2020. $val['type'] = '商家反馈';
  2021. break;
  2022. case 3:
  2023. $val['type'] = '平台反馈';
  2024. break;
  2025. }
  2026. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2027. if(!empty($order_refund_history_image))
  2028. {
  2029. foreach($order_refund_history_image as $kk => $vv)
  2030. {
  2031. $vv['thumb_image'] = resize ($vv['image'], 200,200);
  2032. $order_refund_history_image[$kk] = $vv;
  2033. }
  2034. }
  2035. $val['order_refund_history_image'] = $order_refund_history_image;
  2036. $order_refund_history[$key] = $val;
  2037. }
  2038. $this->step_array = $step_array;
  2039. $this->order_refund_history = $order_refund_history;
  2040. $this->item = $item;
  2041. $this->display();
  2042. }
  2043. public function oprefund_submit()
  2044. {
  2045. $gpc = I('request.');
  2046. $opdata = $this->check_order_data();
  2047. extract($opdata);
  2048. if (IS_POST) {
  2049. $id = $gpc['id'];
  2050. //refundstatus message refundcontent
  2051. $refundstatus = $gpc['refundstatus'];
  2052. $message = $gpc['message'];
  2053. $refundcontent = $gpc['refundcontent'];
  2054. $ref_id = $gpc['refundid'];
  2055. /**
  2056. int(37)
  2057. string(1) "1"
  2058. string(0) ""
  2059. string(15) "天天来退货"
  2060. **/
  2061. //1 ,3
  2062. $comment = '';
  2063. switch( $refundstatus )
  2064. {
  2065. case 1:
  2066. $comment = $refundcontent;
  2067. break;
  2068. case 3:
  2069. $comment = $message;
  2070. break;
  2071. }
  2072. $ref_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  2073. $result = array('code' =>1);
  2074. $order_refund_history = array();
  2075. $order_refund_history['order_id'] = $ref_info['order_id'];
  2076. $order_refund_history['order_goods_id'] = $ref_info['order_goods_id'];
  2077. $order_refund_history['message'] = htmlspecialchars($comment);
  2078. $order_refund_history['type'] = 2;
  2079. $order_refund_history['addtime'] = time();
  2080. M('lionfish_comshop_order_refund_history')->add($order_refund_history);
  2081. $order_history = array();
  2082. $order_history['order_id'] = $id;
  2083. $order_history['order_status_id'] = 0;
  2084. $order_history['notify'] = 0;
  2085. $order_history['comment'] = '';
  2086. $order_history['date_added'] = time();
  2087. if($refundstatus ==1)
  2088. {
  2089. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 1) );
  2090. //id item $order_info $item
  2091. $item = M('lionfish_comshop_order')->field('order_status_id,last_refund_order_status_id')->where( array('order_id' => $id ) )->find();
  2092. //如果是部分退款,那么就不是12了
  2093. if( $item['order_status_id'] == 12)
  2094. {
  2095. $order_history['order_status_id'] = 12;
  2096. if( $item['last_refund_order_status_id'] > 0 )
  2097. {
  2098. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  2099. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('order_status_id' =>$item['last_refund_order_status_id'] ) );
  2100. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  2101. }
  2102. }
  2103. if( !empty($ref_info['order_goods_id']) && $ref_info['order_goods_id'] > 0 )
  2104. {
  2105. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $ref_info['order_goods_id'] ) )->save( array('is_refund_state' =>0 ) );
  2106. }
  2107. //拒绝 order_status_id
  2108. $order_history['comment'] = '商家拒绝退款,订单回退上一状态';
  2109. M('lionfish_comshop_order_history')->add( $order_history );
  2110. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2111. } else {
  2112. $weixin_model = D('Home/Weixin');
  2113. $order_refund = M('lionfish_comshop_order_refund')->field('ref_money')->where( array('ref_id' => $ref_id) )->find();
  2114. $res = $weixin_model->refundOrder($id, $order_refund['ref_money'],0,$ref_info['order_goods_id']);
  2115. //array('code' => 0, 'msg' => $res['err_code_des']);
  2116. if($res['code'] == 1)
  2117. {
  2118. $order_history['order_status_id'] = 7;
  2119. $order_history['comment'] = '商家同意退款';
  2120. M('lionfish_comshop_order_history')->add( $order_history );
  2121. //通过 lionfish_comshop_order_refund
  2122. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 3) );
  2123. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2124. }else{
  2125. if( empty($res['msg']) )
  2126. {
  2127. $res['msg'] = '请检查商户号与cert证书';
  2128. }
  2129. show_json(0, array('message' => $res['msg']) );
  2130. }
  2131. }
  2132. }
  2133. $r_type = array(1=>'仅退款',2 => '退款退货');
  2134. //ims_
  2135. $order_refund = M('lionfish_comshop_order_refund')->where( array('order_id' => $id) )->find();
  2136. $refund_imgs = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->find();
  2137. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $id) )->order('addtime asc')->select();
  2138. foreach($order_refund_history as $key => $val)
  2139. {
  2140. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2141. switch($val['type'])
  2142. {
  2143. case 1:
  2144. $val['type'] = '用户反馈';
  2145. break;
  2146. case 2:
  2147. $val['type'] = '商家反馈';
  2148. break;
  2149. case 3:
  2150. $val['type'] = '平台反馈';
  2151. break;
  2152. }
  2153. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2154. if(!empty($order_refund_history_image))
  2155. {
  2156. foreach($order_refund_history_image as $kk => $vv)
  2157. {
  2158. $vv['thumb_image'] = resize ($vv['image'], 200,200);
  2159. $order_refund_history_image[$kk] = $vv;
  2160. }
  2161. }
  2162. $val['order_refund_history_image'] = $order_refund_history_image;
  2163. $order_refund_history[$key] = $val;
  2164. }
  2165. $this->order_refund = $order_refund;
  2166. $this->r_type = $r_type;
  2167. $this->item = $item;
  2168. $this->display();
  2169. }
  2170. public function ordercomment_gift()
  2171. {
  2172. if (IS_POST) {
  2173. $data = array();
  2174. $data = I('request.data');
  2175. $data['open_comment_gift'] = trim($data['open_comment_gift']);
  2176. $data['comment_gift_score'] = trim($data['comment_gift_score']);
  2177. $data['comment_gift_time'] = trim($data['comment_gift_time']);
  2178. $data['comment_gift_max_score'] = trim($data['comment_gift_max_score']);
  2179. $data['comment_gift_publish'] = trim($data['comment_gift_publish']);
  2180. D('Seller/Config')->update($data);
  2181. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2182. }
  2183. $data = D('Seller/Config')->get_all_config();
  2184. if(empty($data['comment_gift_publish'])){
  2185. $data['comment_gift_publish'] = "​参与好评有礼活动,好评成功并且后台审核通过以后可获得获得活动积分";
  2186. }
  2187. $this->data = $data;
  2188. $this->display();
  2189. }
  2190. public function ordercomment_config()
  2191. {
  2192. if (IS_POST) {
  2193. $data = array();
  2194. $data = I('request.data');
  2195. $data['open_comment_shenhe'] = trim($data['open_comment_shenhe']);
  2196. D('Seller/Config')->update($data);
  2197. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2198. }
  2199. $data = D('Seller/Config')->get_all_config();
  2200. $this->data = $data;
  2201. $this->display();
  2202. }
  2203. public function ordercomment()
  2204. {
  2205. $condition = ' 1 ';//0
  2206. $pindex = I('request.page', 1);
  2207. $psize = 20;
  2208. $keyword = I('request.keyword');
  2209. $this->keyword = $keyword;
  2210. if (!empty($keyword)) {
  2211. $condition .= ' and content like '.'"%' . $keyword . '%" ';
  2212. }
  2213. $label = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_order_comment
  2214. WHERE " . $condition . ' order by comment_id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  2215. $total = M('lionfish_comshop_order_comment')->where($condition)->count();
  2216. $pager = pagination2($total, $pindex, $psize);
  2217. $this->pager = $pager;
  2218. $this->total = $total;
  2219. $this->label = $label;
  2220. $this->display();
  2221. }
  2222. public function deletecomment()
  2223. {
  2224. $id = I('request.id');
  2225. if (empty($id)) {
  2226. $ids = I('request.ids');
  2227. $id = (is_array($ids) ? implode(',', $ids) : 0);
  2228. }
  2229. $items = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('comment_id' => array('in',$id) ) )->select();
  2230. if (empty($item)) {
  2231. $item = array();
  2232. }
  2233. foreach ($items as $item) {
  2234. M('lionfish_comshop_order_comment')->where( array('comment_id' => $item['comment_id']) )->delete();
  2235. }
  2236. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2237. }
  2238. public function commentstate()
  2239. {
  2240. $id = I('request.id');
  2241. if (empty($id)) {
  2242. $ids = I('request.ids');
  2243. $id = (is_array($ids) ? implode(',', $ids) : 0);
  2244. }
  2245. $items = pdo_fetchall('SELECT comment_id FROM ' . tablename('lionfish_comshop_order_comment') . '
  2246. WHERE comment_id in( ' . $id . ' ) ' );
  2247. $items = M('lionfish_comshop_order_comment')->where( array() )->select();
  2248. if (empty($item)) {
  2249. $item = array();
  2250. }
  2251. foreach ($items as $item) {
  2252. pdo_update('lionfish_comshop_order_comment', array('state' => intval($_GPC['state'])), array('comment_id' => $item['comment_id']));
  2253. }
  2254. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2255. }
  2256. public function config()
  2257. {
  2258. if (IS_POST) {
  2259. $data = array();
  2260. $data = I('request.data');
  2261. $data['open_admin_payment'] = trim($data['open_admin_payment']);
  2262. $data['open_auto_receive'] = trim($data['open_auto_receive']);
  2263. $data['shop_limit_buy_distance'] = trim($data['shop_limit_buy_distance']);
  2264. $data['is_open_order_message'] = trim($data['is_open_order_message']);
  2265. $data['is_hidden_orderlist_phone'] = trim($data['is_hidden_orderlist_phone']);
  2266. $data['order_pay_after_share_img'] = save_media($data['order_pay_after_share_img']);
  2267. //-----begin
  2268. if( $data['shop_limit_buy_distance'] == 1)
  2269. {
  2270. if( empty($data['shop_buy_distance']) || $data['shop_buy_distance'] <= 0 )
  2271. {
  2272. show_json(0, array('msg' => '开启限制购买距离,购买距离不能为空') );
  2273. }
  2274. }
  2275. if( $data['open_auto_delete'] == 1)
  2276. {
  2277. if( empty($data['auto_cancle_order_time']) || $data['auto_cancle_order_time'] <= 0 )
  2278. {
  2279. show_json(0, array('msg' => '开启自动取消订单,自动取消订单时间不能为空') );
  2280. }
  2281. }
  2282. //open_aftersale
  2283. if( $data['open_auto_recive_order'] == 1)
  2284. {
  2285. if( empty($data['auto_recive_order_time']) || $data['auto_recive_order_time'] <= 0 )
  2286. {
  2287. show_json(0, array('msg' => '开启系统自动签收,自动签收天数不能为空') );
  2288. }
  2289. }
  2290. $open_aftersale = isset($data['open_aftersale']) ? $data['open_aftersale']:0;
  2291. $open_aftersale_time = isset($data['open_aftersale_time']) ? $data['open_aftersale_time']:0;
  2292. if( $open_aftersale == 1 && ($open_aftersale_time ==0 || empty($open_aftersale_time) ) )
  2293. {
  2294. show_json(0, array('msg' => '开启售后期,请填写售后期天数') );
  2295. }
  2296. if( $data['open_redis_server'] == 1)
  2297. {
  2298. if( empty($data['redis_host']))
  2299. {
  2300. show_json(0, array('msg' => '开启redis服务,redis-host不能为空') );
  2301. }
  2302. if( empty($data['redis_port']))
  2303. {
  2304. show_json(0, array('msg' => '开启redis服务,redis-port不能为空') );
  2305. }
  2306. }
  2307. $open_feier_print = isset($data['open_feier_print']) ? $data['open_feier_print']:0;
  2308. if(empty($open_feier_print) || $open_feier_print == 0)
  2309. {
  2310. $data['open_feier_print'] = $open_feier_print;
  2311. }else if($open_feier_print == 1){
  2312. $feier_print_sn = isset($data['feier_print_sn']) ? $data['feier_print_sn']:'';
  2313. $feier_print_key = isset($data['feier_print_key']) ? $data['feier_print_key']:'';
  2314. $data['open_feier_print'] = $open_feier_print;
  2315. $data['feier_print_sn'] = $feier_print_sn;
  2316. $data['feier_print_key'] = $feier_print_key;
  2317. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn') )->find();
  2318. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  2319. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key') )->find();
  2320. $feier_print_key_old = $feier_print_key_old_arr['value'];
  2321. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  2322. {
  2323. //开始添加打印机
  2324. //printaction
  2325. $print_model = D('Seller/Printaction');
  2326. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  2327. $print_model->addprinter($snlist);
  2328. }
  2329. //...todo测试订单自动打印
  2330. }else if($open_feier_print == 2){
  2331. $yilian_machine_code = isset($data['yilian_machine_code']) ? $data['yilian_machine_code']:'';
  2332. $yilian_msign = isset($data['yilian_msign']) ? $data['yilian_msign']:'';
  2333. $yilian_client_id = isset($data['yilian_client_id']) ? $data['yilian_client_id']:'';
  2334. $yilian_client_key = isset($data['yilian_client_key']) ? $data['yilian_client_key']:'';
  2335. $data['open_feier_print'] = $open_feier_print;
  2336. $data['yilian_machine_code'] = $yilian_machine_code;
  2337. $data['yilian_msign'] = $yilian_msign;
  2338. $data['yilian_client_id'] = $yilian_client_id;
  2339. $data['yilian_client_key'] = $yilian_client_key;
  2340. $yilian_client_id_old = D('Home/Front')->get_config_by_name('yilian_client_id');
  2341. $yilian_machine_code_old = D('Home/Front')->get_config_by_name('yilian_machine_code');
  2342. $yilian_msign_old = D('Home/Front')->get_config_by_name('yilian_msign');
  2343. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  2344. {
  2345. //开始添加打印机
  2346. //printaction
  2347. $print_model = D('Seller/Printaction');
  2348. $res = $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  2349. if($res != 0)
  2350. {
  2351. show_json(0, array('msg' => '添加易联云打印机失败!'));
  2352. }
  2353. }
  2354. //...todo测试订单自动打印
  2355. }
  2356. //----end
  2357. $data['is_print_auto'] = $data['is_print_auto'] == 1 ? 0 : 1;
  2358. $data['is_print_cancleorder'] = isset($data['is_print_cancleorder']) ? $data['is_print_cancleorder'] : 0;
  2359. $data['is_print_admin_cancleorder'] = isset($data['is_print_admin_cancleorder']) ? $data['is_print_admin_cancleorder'] : 0;
  2360. $data['is_print_dansupply_order'] = isset($data['is_print_dansupply_order']) ? $data['is_print_dansupply_order'] : 0;
  2361. //----------redis begin
  2362. $data['open_redis_server'] = intval($data['open_redis_server']);
  2363. if($data['open_redis_server'] == 1 && !class_exists('Redis')){
  2364. $data['open_redis_server'] = 0;
  2365. }
  2366. //----------redis end
  2367. $data['is_has_refund_deliveryfree'] = isset($data['is_has_refund_deliveryfree']) ? $data['is_has_refund_deliveryfree'] : 0;
  2368. //订单自动发货
  2369. $data['is_localtown_auto_delivery'] = isset($data['is_localtown_auto_delivery']) ? $data['is_localtown_auto_delivery'] : 0;
  2370. $data['is_communityhead_auto_delivery'] = isset($data['is_communityhead_auto_delivery']) ? $data['is_communityhead_auto_delivery'] : 0;
  2371. $data['is_communityhead_auto_service'] = isset($data['is_communityhead_auto_service']) ? $data['is_communityhead_auto_service'] : 0;
  2372. $data['is_ziti_auto_delivery'] = isset($data['is_ziti_auto_delivery']) ? $data['is_ziti_auto_delivery'] : 0;
  2373. $data['is_ziti_auto_service'] = isset($data['is_ziti_auto_service']) ? $data['is_ziti_auto_service'] : 0;
  2374. D('Seller/Config')->update($data);
  2375. //将商品库存写入redis
  2376. if($data['open_redis_server'] == 1 )
  2377. D('Seller/Redisorder')->sysnc_allgoods_total();
  2378. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2379. }
  2380. $data = D('Seller/Config')->get_all_config();
  2381. $this->data = $data;
  2382. $this->display();
  2383. }
  2384. public function opclose()
  2385. {
  2386. $opdata = $this->check_order_data();
  2387. extract($opdata);
  2388. if ($item['order_status_id'] == 5) {
  2389. show_json(0, '订单已关闭,无需重复关闭!');
  2390. }
  2391. else if (3 != $item['order_status_id']) {
  2392. show_json(0, '订单已付款,不能关闭!');
  2393. }
  2394. if (IS_POST) {
  2395. //load_model_class('frontorder')->cancel_order($item['order_id']);
  2396. D('Home/Frontorder')->cancel_order($item['order_id'], false, '后台操作,取消订单');
  2397. /**
  2398. $time = time();
  2399. pdo_update('lionfish_comshop_order', array('order_status_id' => 5, 'canceltime' => $time), array('order_id' => $item['order_id'], 'uniacid' => $_W['uniacid'])) ;
  2400. //'remarkclose' => $_GPC['remark']),
  2401. $history_data = array();
  2402. $history_data['uniacid'] = $_W['uniacid'];
  2403. $history_data['order_id'] = $item['order_id'];
  2404. $history_data['order_status_id'] = 5;
  2405. $history_data['notify'] = 0;
  2406. $history_data['comment'] = '后台操作,取消订单' ;
  2407. $history_data['date_added'] = time();
  2408. pdo_insert('lionfish_comshop_order_history', $history_data);
  2409. **/
  2410. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2411. }
  2412. $this->item = $item;
  2413. $this->display();
  2414. }
  2415. //--begin
  2416. public function ordersendall()
  2417. {
  2418. $_GPC = I('request.');
  2419. $express_list = D('Seller/Express')->load_all_express();
  2420. $this->_GPC = $_GPC;
  2421. if( IS_POST )
  2422. {
  2423. $type = isset($_GPC['type']) && !empty($_GPC['type']) ? $_GPC['type']:'normal';
  2424. $fext = substr($_FILES['excelfile']['name'], strrpos($_FILES['excelfile']['name'], '.') + 1);
  2425. $express = trim($_GPC['express']);
  2426. $expresscom = trim($_GPC['expresscom']);
  2427. if( $fext == 'csv' )
  2428. {
  2429. $file_name = $_FILES['excelfile']['tmp_name'];
  2430. $file = fopen($file_name,'r');
  2431. $rows = array();
  2432. $i =0;
  2433. while ($data = fgetcsv($file)) {
  2434. $rows[] = eval('return '.iconv('gbk','utf-8',var_export($data,true)).';');
  2435. }
  2436. //var_dump( $rows );
  2437. //die();
  2438. }else{
  2439. $rows = D('Seller/Excel')->import('excelfile');
  2440. }
  2441. $num = count($rows);
  2442. $time = time();
  2443. $express_arr = array();
  2444. foreach($express_list as $val)
  2445. {
  2446. $express_arr[ $val['id'] ] = $val['name'];
  2447. }
  2448. $i = 0;
  2449. $err_array = array();
  2450. $quene_order_list = array();
  2451. $cache_key = md5(time().count($rows));
  2452. $j =0;
  2453. foreach ($rows as $rownum => $col)
  2454. {
  2455. $order_id = trim($col[0]);
  2456. if (empty($order_id)) {
  2457. $err_array[] = $order_id;
  2458. continue;
  2459. }
  2460. if($j == 0)
  2461. {
  2462. $j++;
  2463. continue;
  2464. }
  2465. $quene_order_list[] = array('order_num_alias' => $order_id , 'shipping_no' => $col[1], 'express' => $express,'expresscom' => $expresscom );
  2466. }
  2467. S('_orderquene_'.$cache_key, $quene_order_list);
  2468. $this->cache_key = $cache_key;
  2469. $this->type = $type;
  2470. $this->display('Order/oploadexcelorder');
  2471. die();
  2472. }
  2473. $this->express_list = $express_list;
  2474. $this->type = I('request.type');
  2475. $this->display();
  2476. }
  2477. public function do_order_quene()
  2478. {
  2479. $_GPC = I('request.');
  2480. $type = $_GPC['type'];
  2481. $cache_key = $_GPC['cache_key'];
  2482. $quene_order_list = S('_orderquene_'.$cache_key);
  2483. $tmp_info = array_shift($quene_order_list);
  2484. S('_orderquene_'.$cache_key, $quene_order_list);
  2485. $express = $tmp_info['express'];
  2486. $expresscom = $tmp_info['expresscom'];
  2487. $shipping_no = $tmp_info['shipping_no'];
  2488. $tmp_info['order_num_alias'] = trim($tmp_info['order_num_alias']);
  2489. $tmp_info['order_num_alias'] = preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$tmp_info['order_num_alias']);
  2490. //$rows = D('Seller/Excel')->import('excelfile');
  2491. $order_info = M('lionfish_comshop_order')->where( array('order_num_alias' => $tmp_info['order_num_alias'] ) )->find();
  2492. if(!empty($order_info) && $order_info['order_status_id'] == 1)
  2493. {
  2494. if( $type == 'mult' && $order_info['delivery'] == 'express' )
  2495. {
  2496. $ex_info = D('Seller/Express')-> get_express_info($express);
  2497. $data = array();
  2498. $data['express_time'] = time();
  2499. $data['order_status_id'] = 4;
  2500. $data['shipping_no'] = $shipping_no;
  2501. $data['shipping_method'] = $express;
  2502. $data['dispatchname'] = $ex_info['name'];
  2503. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save( $data );
  2504. $history_data = array();
  2505. $history_data['order_id'] = $order_info['order_id'];
  2506. $history_data['order_status_id'] = 4;
  2507. $history_data['notify'] = 0;
  2508. $history_data['comment'] = '订单快递已发货,后台导入批量发货';
  2509. $history_data['date_added'] = time();
  2510. M('lionfish_comshop_order_history')->add($history_data);
  2511. //TODO..发送已发货的模板消息
  2512. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2513. }
  2514. else {
  2515. if($order_info['delivery'] != 'express')
  2516. {
  2517. /*if($order_info['delivery'] == 'localtown_delivery'){
  2518. 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()) );
  2519. //todo ... send member msg goods is ing
  2520. $history_data = array();
  2521. $history_data['order_id'] = $order_info['order_id'];
  2522. $history_data['order_status_id'] = 4;
  2523. $history_data['notify'] = 0;
  2524. $history_data['comment'] = '订单配送中,使用表格发货';
  2525. $history_data['date_added'] = time();
  2526. M('lionfish_comshop_order_history')->add( $history_data );
  2527. D('Home/LocaltownDelivery')->change_distribution_order_state( $order_info['order_id'], 0, 1);
  2528. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id']) )->save( array('delivery_type' => 1) );
  2529. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2530. //给配送员发送公众号消息
  2531. $count = D('Seller/Redisorder')->set_distribution_delivery_message($order_info['order_id']);
  2532. }else{*/
  2533. if($order_info['delivery'] != 'localtown_delivery' && $order_info['delivery'] != 'hexiao') {
  2534. $data = array();
  2535. $data['express_time'] = time();
  2536. $data['order_status_id'] = 14;
  2537. M('lionfish_comshop_order')->where(array('order_id' => $order_info['order_id']))->save($data);
  2538. $history_data = array();
  2539. $history_data['order_id'] = $order_info['order_id'];
  2540. $history_data['order_status_id'] = 14;
  2541. $history_data['notify'] = 0;
  2542. $history_data['comment'] = '订单配送中,使用表格发货';
  2543. $history_data['date_added'] = time();
  2544. M('lionfish_comshop_order_history')->add($history_data);
  2545. }
  2546. //}
  2547. }
  2548. }
  2549. //TODO...发送已经发货给团长的消息通知
  2550. }
  2551. if($type =='mult_send_tuanz' && $order_info['delivery'] != 'express' && $order_info['order_status_id'] == 14 )
  2552. {
  2553. //订单批量团长签收 2019012749451499751
  2554. $history_data = array();
  2555. $history_data['order_id'] = $order_info['order_id'];
  2556. $history_data['order_status_id'] = 4;
  2557. $history_data['notify'] = 0;
  2558. $history_data['comment'] = '后台批量导入发货到团长';
  2559. $history_data['date_added'] = time();
  2560. M('lionfish_comshop_order_history')->add( $history_data );
  2561. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2562. }
  2563. if($type =='mult_member_receive_order' && $order_info['order_status_id'] == 4 )
  2564. {
  2565. /*if($order_info['delivery'] == 'localtown_delivery'){
  2566. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id']) )->save( array('state' => 4,'orderdistribution_id'=> -1) );
  2567. D('Seller/Order')->receive_order($order_info['order_id']);
  2568. M('lionfish_comshop_order_history')->where( array('order_id' => $order_info['order_id'],'order_status_id' => 6) )->save( array( 'comment' => '系统自动收货,等待结算佣金') );
  2569. }else{*/
  2570. if($order_info['delivery'] != 'localtown_delivery' && $order_info['delivery'] != 'hexiao') {
  2571. //批量用户确认收货
  2572. D('Home/Frontorder')->receive_order($order_info['order_id'], true);
  2573. }
  2574. //}
  2575. }
  2576. if( empty($quene_order_list) )
  2577. {
  2578. echo json_encode( array('code' => 2) );
  2579. die();
  2580. }
  2581. echo json_encode( array('code' => 0, 'msg' => '订单号:'.$tmp_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理") );
  2582. die();
  2583. }
  2584. //--end
  2585. public function ordersendall2()
  2586. {
  2587. if( IS_POST )
  2588. {
  2589. $type = I('request.type', 'normal');
  2590. $express = I('request.express', '');
  2591. $expresscom = I('request.expresscom', '');
  2592. $rows = D('Seller/Excel')->import('excelfile');
  2593. $num = count($rows);
  2594. $time = time();
  2595. $express_arr = array();
  2596. foreach($express_list as $val)
  2597. {
  2598. $express_arr[ $val['id'] ] = $val['name'];
  2599. }
  2600. $i = 0;
  2601. $err_array = array();
  2602. $j =0;
  2603. foreach ($rows as $rownum => $col) {
  2604. $order_id = trim($col[0]);
  2605. if (empty($order_id)) {
  2606. $err_array[] = $order_id;
  2607. continue;
  2608. }
  2609. if($j == 0)
  2610. {
  2611. $j++;
  2612. continue;
  2613. }
  2614. $order_info = M('lionfish_comshop_order')->where( array('order_num_alias' => $order_id ) )->find();
  2615. if(!empty($order_info) && $order_info['order_status_id'] == 1)
  2616. {
  2617. //判断是否快递类型 type //normal mult
  2618. if( $type == 'mult' && $order_info['delivery'] == 'express' )
  2619. {
  2620. $data = array();
  2621. $data['express_time'] = time();
  2622. $data['order_status_id'] = 4;
  2623. $data['shipping_no'] = $col[1];
  2624. $data['shipping_method'] = $express;
  2625. $data['dispatchname'] = $expresscom;
  2626. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save( $data );
  2627. $history_data = array();
  2628. $history_data['order_id'] = $order_info['order_id'];
  2629. $history_data['order_status_id'] = 4;
  2630. $history_data['notify'] = 0;
  2631. $history_data['comment'] = '订单快递已发货';
  2632. $history_data['date_added'] = time();
  2633. M('lionfish_comshop_order_history')->add($history_data);
  2634. //TODO..发送已发货的模板消息
  2635. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2636. }else {
  2637. if($order_info['delivery'] != 'express')
  2638. {
  2639. $data = array();
  2640. $data['express_time'] = time();
  2641. $data['order_status_id'] = 14;
  2642. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save($data);
  2643. $history_data = array();
  2644. $history_data['order_id'] = $order_info['order_id'];
  2645. $history_data['order_status_id'] = 14;
  2646. $history_data['notify'] = 0;
  2647. $history_data['comment'] = '订单配送中';
  2648. $history_data['date_added'] = time();
  2649. M('lionfish_comshop_order_history')->add($history_data);
  2650. }
  2651. }
  2652. //TODO...发送已经发货给团长的消息通知
  2653. ++$i;
  2654. }
  2655. if($type =='mult_send_tuanz' && $order_info['delivery'] != 'express' && $order_info['order_status_id'] == 14 )
  2656. {
  2657. //订单批量团长签收 2019012749451499751
  2658. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2659. ++$i;
  2660. }
  2661. if($type =='mult_member_receive_order' && $order_info['order_status_id'] == 4 )
  2662. {
  2663. //批量用户确认收货
  2664. D('Home/Frontorder')->receive_order($order_info['order_id'], true);
  2665. ++$i;
  2666. }
  2667. }
  2668. $tip = '';
  2669. if($type =='mult_send_tuanz')
  2670. {
  2671. $msg = $i . '个订单批量送达团长成功!';
  2672. }
  2673. else if($type == 'mult_member_receive_order')
  2674. {
  2675. $msg = $i . '个订单批量用户确认收货!';
  2676. }
  2677. else{
  2678. $msg = $i . '个订单发货成功!';
  2679. }
  2680. if ($i < $num) {
  2681. $url = '';
  2682. if (!empty($err_array)) {
  2683. $j = 1;
  2684. if($type =='mult_send_tuanz')
  2685. {
  2686. $tip .= '<br>' . count($err_array) . '个订单批量送达团长失败,失败的订单编号: <br>';
  2687. }else if($type == 'mult_member_receive_order'){
  2688. $tip .= '<br>' . count($err_array) . '个订单批量用户确认收货,失败的订单编号: <br>';
  2689. }
  2690. else{
  2691. $tip .= '<br>' . count($err_array) . '个订单发货失败,失败的订单编号: <br>';
  2692. }
  2693. foreach ($err_array as $k => $v) {
  2694. $tip .= $v . ' ';
  2695. if (($j % 2) == 0) {
  2696. $tip .= '<br>';
  2697. }
  2698. ++$j;
  2699. }
  2700. }
  2701. }
  2702. else {
  2703. $url = U('order/ordersendall', array('type' => $type) );
  2704. }
  2705. $redirect = $url;
  2706. $this->message = $msg.$tip;
  2707. $this->redirect = $redirect;
  2708. $this->display('Public/_message');
  2709. die();
  2710. }
  2711. $express_list = D('Seller/Express')->load_all_express();
  2712. $this->express_list = $express_list;
  2713. $this->type = I('request.type');
  2714. $this->display();
  2715. }
  2716. public function opchangeexpress()
  2717. {
  2718. $_GPC = I('request.');
  2719. $opdata = $this->check_order_data();
  2720. extract($opdata);
  2721. $changeexpress = 1;
  2722. $sendtype = intval($_GPC['sendtype']);
  2723. $edit_flag = 1;
  2724. if (IS_POST) {
  2725. if (!(empty($_GPC['shipping_no'])) && empty($_GPC['shipping_no'])) {
  2726. show_json(0, array('msg' => '请输入快递单号!') );
  2727. }
  2728. if (!(empty($item['transid']))) {
  2729. }
  2730. $express_info = D('Seller/Express')->get_express_info($_GPC['express']);
  2731. $time = time();
  2732. $data = array(
  2733. 'shipping_method' => trim($_GPC['express']),
  2734. 'dispatchname' => $express_info['name'],
  2735. 'shipping_no' => trim($_GPC['shipping_no']),
  2736. 'express_time' => $time
  2737. );
  2738. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( $data );
  2739. $history_data = array();
  2740. $history_data['order_id'] = $item['order_id'];
  2741. $history_data['order_status_id'] = 4;
  2742. $history_data['notify'] = 0;
  2743. $history_data['comment'] = '修改发货物流,订单发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $_GPC['shipping_no'];
  2744. $history_data['date_added'] = time();
  2745. M('lionfish_comshop_order_history')->add( $history_data );
  2746. //TODO...发送已经发货的消息通知
  2747. //m('notice')->sendOrderMessage($item['id']);
  2748. //plog('order.op.send', '订单发货 ID: ' . $item['id'] . ' 订单号: ' . $item['ordersn'] . ' <br/>快递公司: ' . $_GPC['expresscom'] . ' 快递单号: ' . $_GPC['expresssn']);
  2749. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2750. }
  2751. $noshipped = array();
  2752. $shipped = array();
  2753. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  2754. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  2755. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  2756. $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();
  2757. $express_list = D('Seller/Express')->load_all_express();
  2758. $this->id = $item['order_id'];
  2759. $this->item = $item;
  2760. $this->province_info = $province_info;
  2761. $this->city_info = $city_info;
  2762. $this->area_info = $area_info;
  2763. $this->order_goods = $order_goods;
  2764. $this->express_list = $express_list;
  2765. $this->display('Order/opsend');
  2766. }
  2767. public function batchsend_import()
  2768. {
  2769. global $_W;
  2770. global $_GPC;
  2771. $type = I('request.type','normal');
  2772. $this->type = $type;
  2773. $columns = array();
  2774. $columns[] = array('title' => '订单编号', 'field' => '', 'width' => 32);
  2775. //$columns[] = array('title' => '快递单号', 'field' => '', 'width' => 32);
  2776. if($type == 'normal')
  2777. {
  2778. D('Seller/Excel')->temp('批量发货数据模板', $columns);
  2779. }else{
  2780. $columns[] = array('title' => '快递单号', 'field' => '', 'width' => 32);
  2781. D('Seller/Excel')->temp('批量发货数据模板', $columns);
  2782. }
  2783. }
  2784. /**
  2785. * 上传订单Excel批量发货
  2786. */
  2787. function sendexpress_excel_done()
  2788. {
  2789. set_time_limit(0);
  2790. if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
  2791. $excel_dir = ROOT_PATH.'Uploads/image/'.date('Y-m-d');
  2792. $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  2793. RecursiveMkdir( $excel_dir );
  2794. $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
  2795. $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
  2796. $notify_model = D('Home/Weixinnotify');
  2797. //
  2798. $result = importExecl($path);
  2799. if(!empty($result)) {
  2800. $order_ids = array();
  2801. //开始导入数据库,并发货
  2802. foreach($result as $val){
  2803. if(empty($val[0]))
  2804. {
  2805. continue;
  2806. }
  2807. $order_info = M('order')->field('order_id,order_status_id,delivery')->where( array('order_num_alias' => trim($val[0])) )->find();
  2808. //order_status_id 1
  2809. if($order_info['order_status_id'] != 1)
  2810. {
  2811. continue;
  2812. }
  2813. //['delivery'] == 'pickup'
  2814. $order_ids[] = $order_info['order_id'];
  2815. if($order_info['delivery'] == 'pickup')
  2816. {
  2817. M('order')->where( array('order_id' => $order_info['order_id'] ) )->save( array('order_status_id' => 4) );
  2818. } else {
  2819. M('order')->where( array('order_id' => $order_info['order_id'] ) )->save( array('shipping_method' =>$val[5],'shipping_no' =>$val[6],'order_status_id' => 4) );
  2820. }
  2821. $oh = array();
  2822. $oh['order_id']=$order_info['order_id'];
  2823. $oh['order_status_id']=4;
  2824. $oh['notify'] = 0;
  2825. $oh['comment']='导入excel批量发货';
  2826. $oh['date_added']=time();
  2827. $oh_id=M('OrderHistory')->add($oh);
  2828. }
  2829. foreach($order_ids as $order_id) {
  2830. $order_info = M('order')->field('delivery')->where( array('order_id' => $order_id) )->find();
  2831. if($order_info['delivery'] == 'pickup')
  2832. {
  2833. $notify_model->sendPickupMsg($order_id);
  2834. } else {
  2835. $notify_model->sendExpressMsg($order_id);
  2836. }
  2837. }
  2838. }
  2839. }
  2840. echo json_encode( array('code' => 1) );
  2841. die();
  2842. }
  2843. function sendexpress()
  2844. {
  2845. $this->breadcrumb2='批量发货';
  2846. $this->display();
  2847. }
  2848. function print_order(){
  2849. $model=new OrderModel();
  2850. $this->order=$model->order_info(I('id'));
  2851. $this->print=true;
  2852. $this->display('./Themes/Home/default/Mail/order.html');
  2853. }
  2854. public function refunddone()
  2855. {
  2856. $id = I('get.id',0,'intval');
  2857. $comment = I('post.comment');
  2858. $order_refund_type = I('post.order_refund_type',0,'intval');
  2859. $result = array('code' =>1);
  2860. $order_refund_history = array();
  2861. $order_refund_history['order_id'] = $id;
  2862. $order_refund_history['message'] = htmlspecialchars($comment);
  2863. $order_refund_history['type'] = 2;
  2864. $order_refund_history['addtime'] = time();
  2865. M('order_refund_history')->add($order_refund_history);
  2866. $order_history = array();
  2867. $order_history['order_id'] = $id;
  2868. $order_history['order_status_id'] = 0;
  2869. $order_history['notify'] = 0;
  2870. $order_history['comment'] = '';
  2871. $order_history['date_added'] = time();
  2872. if($order_refund_type ==1)
  2873. {
  2874. //拒绝
  2875. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 1) );
  2876. $order_history['order_status_id'] = 12;
  2877. $order_history['comment'] = '商家拒绝退款';
  2878. M('order_history')->add($order_history);
  2879. } else {
  2880. $order_history['order_status_id'] = 12;
  2881. $order_history['comment'] = '商家统一退款';
  2882. M('order_history')->add($order_history);
  2883. $weixin_model = D('Home/Weixin');
  2884. //通过
  2885. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 3) );
  2886. $order_refund = M('order_refund')->where( array('order_id' => $id) )->find();
  2887. $weixin_model->refundOrder($id, $order_refund['ref_money']);
  2888. }
  2889. echo json_encode($result);
  2890. die();
  2891. }
  2892. public function show_refund()
  2893. {
  2894. $this->crumbs='订单退款详情';
  2895. $model=new OrderModel();
  2896. $data = $model->order_info(I('id'));
  2897. $order_statuses = $data['order_statuses'];
  2898. $need_status = array();
  2899. foreach($order_statuses as $key => $val)
  2900. {
  2901. if( in_array($val['order_status_id'], array(4)) )
  2902. {
  2903. $need_status[$key] = $val;
  2904. }
  2905. }
  2906. $data['order_statuses'] = $need_status;
  2907. $refund_reason = array(
  2908. '97' =>'商品有质量问题',
  2909. '98' =>'没有收到货',
  2910. '99' =>'商品少发漏发发错',
  2911. '100' =>'商品与描述不一致',
  2912. '101' =>'收到商品时有划痕或破损',
  2913. '102' =>'质疑假货',
  2914. '111' =>'其他',
  2915. );
  2916. $order_refund = M('order_refund')->where( array('order_id' =>I('id')) )->find();
  2917. //ref_type
  2918. $order_refund['ref_type'] = $order_refund['ref_type'] ==1 ? '仅退款': '退款退货';
  2919. $order_refund['ref_name'] = empty($refund_reason[$order_refund['ref_name']]) ? $order_refund['ref_name']: $refund_reason[$order_refund['ref_name']] ;
  2920. $refund_state = array(
  2921. 0 => '申请中',
  2922. 1 => '商家拒绝',
  2923. 2 => '平台介入',
  2924. 3 => '退款成功',
  2925. 4 => '退款失败',
  2926. 5 => '撤销申请',
  2927. );
  2928. $order_refund['state'] = $refund_state[$order_refund['state']];
  2929. $this->order_refund = $order_refund;
  2930. $order_refund_image = M('order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->select();
  2931. $refund_images = array();
  2932. if(!empty($order_refund_image))
  2933. {
  2934. foreach($order_refund_image as $refund_image)
  2935. {
  2936. $refund_image['thumb_image'] = resize($refund_image['image'], 100, 100);
  2937. $refund_images[] = $refund_image;
  2938. }
  2939. }
  2940. $order_refund_history = M('order_refund_history')->where( array('order_id' => I('id')) )->order('addtime asc')->select();
  2941. foreach($order_refund_history as $key => $val)
  2942. {
  2943. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2944. switch($val['type'])
  2945. {
  2946. case 1:
  2947. $val['type'] = '用户反馈';
  2948. break;
  2949. case 2:
  2950. $val['type'] = '商家反馈';
  2951. break;
  2952. case 3:
  2953. $val['type'] = '平台反馈';
  2954. break;
  2955. }
  2956. $order_refund_history_image = M('order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2957. if(!empty($order_refund_history_image))
  2958. {
  2959. foreach($order_refund_history_image as $kk => $vv)
  2960. {
  2961. $vv['thumb_image'] = resize($vv['image'], 100, 100);
  2962. $order_refund_history_image[$kk] = $vv;
  2963. }
  2964. }
  2965. $val['order_refund_history_image'] = $order_refund_history_image;
  2966. $order_refund_history[$key] = $val;
  2967. }
  2968. $this->order_refund_history = $order_refund_history;
  2969. $this->refund_images = $refund_images;
  2970. $this->data = $data;
  2971. $this->display('refund');
  2972. }
  2973. public function show_order(){
  2974. $this->crumbs='订单详情';
  2975. //is_ziti/1 commiss_list
  2976. $is_ziti = I('get.is_ziti', 0);
  2977. if($is_ziti == 1)
  2978. {
  2979. $this->breadcrumb1='自提管理';
  2980. $this->breadcrumb2='自提管理';
  2981. }
  2982. $model=new OrderModel();
  2983. $data = $model->order_info(I('id'));
  2984. $order_statuses = $data['order_statuses'];
  2985. $need_status = array();
  2986. foreach($order_statuses as $key => $val)
  2987. {
  2988. if( in_array($val['order_status_id'], array(1,2,3,4,5,6,7,8,11,12,13)) )
  2989. {
  2990. $need_status[$key] = $val;
  2991. }
  2992. }
  2993. $data['order_statuses'] = $need_status;
  2994. //$data['order']
  2995. if($data['order']['type'] == 'integral')
  2996. {
  2997. $integral_order = M('integral_order')->where( array('order_id' => I('id') ) )->find();
  2998. $this->integral_order = $integral_order;
  2999. }
  3000. $this->data = $data;
  3001. $pick_order_info = array();
  3002. $pick_up = array();
  3003. if($data['order']['delivery'] == 'pickup')
  3004. {
  3005. $pick_order_info = M('pick_order')->where( array('order_id' => $data['order']['order_id']) )->find();
  3006. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  3007. }
  3008. $this->pick_order_info = $pick_order_info;
  3009. $this->pick_up = $pick_up;
  3010. $sql="select s.* from ".C('DB_PREFIX')."seller_express as s, ".C('DB_PREFIX')."seller_express_relat as ser
  3011. where s.id = ser.express_id and ser.store_id = ".SELLERUID;
  3012. $express_list= M()->query($sql);
  3013. $this->express_list = $express_list;
  3014. //$data['order']['order_id']
  3015. $order_goods_haitao = M('order_goods_haitao')->where( array('order_id' => $data['order']['order_id']) )->find();
  3016. $this->order_goods_haitao = $order_goods_haitao;
  3017. $this->display('show');
  3018. }
  3019. function history(){
  3020. $model=new OrderModel();
  3021. if(IS_POST){
  3022. if(I('order_status_id')==C('cancel_order_status_id')){
  3023. $Order = new \Home\Model\OrderModel();
  3024. $Order->cancel_order($_GET['id']);
  3025. storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('BACKEND_USER'),'取消了订单 '.$_GET['id']);
  3026. $result=true;
  3027. }else{
  3028. //order_status_id 4
  3029. if($_POST['order_status_id'] != 4)
  3030. {
  3031. unset($_POST['shipping_no']);
  3032. unset($_POST['shipping_method']);
  3033. die();
  3034. }else {
  3035. }
  3036. $result=$model->addOrderHistory($_GET['id'],$_POST);
  3037. }
  3038. if($result){
  3039. $this->success='新增成功!!';
  3040. }else{
  3041. $this->error='新增失败!!';
  3042. }
  3043. }
  3044. $results = $model->getOrderHistories($_GET['id']);
  3045. foreach ($results as $result) {
  3046. $histories[] = array(
  3047. 'notify' => $result['notify'] ? '是' : '否',
  3048. 'status' => $result['status'],
  3049. 'comment' => nl2br($result['comment']),
  3050. 'date_added' => date('Y/m/d H:i:s', $result['date_added'])
  3051. );
  3052. }
  3053. $this->histories=$histories;
  3054. $this->display();
  3055. }
  3056. function del(){
  3057. $model=new OrderModel();
  3058. $return=$model->del_order(I('get.id'));
  3059. $this->osc_alert($return);
  3060. }
  3061. //begin
  3062. public function printconfig()
  3063. {
  3064. if (defined('ROLE') && ROLE == 'agenter' )
  3065. {
  3066. $supper_info = get_agent_logininfo();
  3067. if (IS_POST) {
  3068. $_GPC = I('request.');
  3069. $data = array();
  3070. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  3071. //$supper_info['id']
  3072. $open_feier_print = isset($data['open_feier_print'.$supper_info['id']]) ? $data['open_feier_print'.$supper_info['id']]:0;
  3073. if(empty($open_feier_print) || $open_feier_print == 0)
  3074. {
  3075. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3076. }else if($open_feier_print == 1){
  3077. $feier_print_sn = isset($data['feier_print_sn'.$supper_info['id']]) ? $data['feier_print_sn'.$supper_info['id']]:'';
  3078. $feier_print_key = isset($data['feier_print_key'.$supper_info['id']]) ? $data['feier_print_key'.$supper_info['id']]:'';
  3079. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3080. $data['feier_print_sn'.$supper_info['id']] = $feier_print_sn;
  3081. $data['feier_print_key'.$supper_info['id']] = $feier_print_key;
  3082. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn'.$supper_info['id'] ) )->find();
  3083. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  3084. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key'.$supper_info['id'] ) )->find();
  3085. $feier_print_key_old = $feier_print_key_old_arr['value'];
  3086. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  3087. {
  3088. //开始添加打印机
  3089. //printaction
  3090. $print_model = D('Seller/Printaction');
  3091. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  3092. $print_model->addprinter($snlist);
  3093. }
  3094. //...todo测试订单自动打印
  3095. }else if($open_feier_print == 2){
  3096. $yilian_machine_code = isset($data['yilian_machine_code'.$supper_info['id']]) ? $data['yilian_machine_code'.$supper_info['id']]:'';
  3097. $yilian_msign = isset($data['yilian_msign'.$supper_info['id']]) ? $data['yilian_msign'.$supper_info['id']]:'';
  3098. $yilian_client_id = isset($data['yilian_client_id'.$supper_info['id']]) ? $data['yilian_client_id'.$supper_info['id']]:'';
  3099. $yilian_client_key = isset($data['yilian_client_key'.$supper_info['id']]) ? $data['yilian_client_key'.$supper_info['id']]:'';
  3100. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3101. $data['yilian_machine_code'.$supper_info['id']] = $yilian_machine_code;
  3102. $data['yilian_msign'.$supper_info['id']] = $yilian_msign;
  3103. $data['yilian_client_id'.$supper_info['id']] = $yilian_client_id;
  3104. $data['yilian_client_key'.$supper_info['id']] = $yilian_client_key;
  3105. $yilian_client_id_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_client_id'.$supper_info['id'] ) )->find();
  3106. $yilian_client_id_old = $yilian_client_id_old_arr['value'];
  3107. $yilian_machine_code_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_machine_code'.$supper_info['id'] ) )->find();
  3108. $yilian_machine_code_old = $yilian_machine_code_old_arr['value'];
  3109. $yilian_msign_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_msign'.$supper_info['id'] ) )->find();
  3110. $yilian_msign_old = $yilian_msign_old_arr['value'];
  3111. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  3112. {
  3113. //开始添加打印机
  3114. //printaction
  3115. $print_model = D('Seller/Printaction');
  3116. $res = $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  3117. if($res != 0)
  3118. {
  3119. show_json(0, array('msg' => '添加易联云打印机失败!' ) );
  3120. }
  3121. }
  3122. //...todo测试订单自动打印
  3123. }
  3124. D('Seller/Config')->update($data);
  3125. show_json(1);
  3126. }
  3127. $data = D('Seller/Config')->get_all_config();
  3128. $this->supper_info = $supper_info;
  3129. $this->data = $data;
  3130. include $this->display();
  3131. }
  3132. }
  3133. public function express_list(){
  3134. $this->type = I('request.type','');
  3135. $this->order_id = I('request.order_id','');
  3136. $express_list = D('Seller/Express')->load_kdn_express();
  3137. $this->express_list = $express_list;
  3138. $this->display();
  3139. }
  3140. public function kdn_print_log_list(){
  3141. $log_list = M('lionfish_comshop_order_kdniao_print_log')->order('id desc')->limit(5)->select();
  3142. $this->log_list = $log_list;
  3143. $this->display();
  3144. }
  3145. /**
  3146. * 判断快递鸟寄件人信息
  3147. * @param $express_code
  3148. */
  3149. public function check_kdn_sender($express_code){
  3150. $result = array();
  3151. $result['status'] = 1;
  3152. $data = D('Seller/Config')->get_all_config();
  3153. if(empty($data['kdn_sender_name'])){
  3154. $result['status'] = 0;
  3155. $result['msg'] = '寄件人未配置';
  3156. return $result;
  3157. }
  3158. if(empty($data['kdn_sender_mobile'])){
  3159. $result['status'] = 0;
  3160. $result['msg'] = '寄件人联系电话未配置';
  3161. return $result;
  3162. }
  3163. if(empty($data['kdn_province_id'])){
  3164. $result['status'] = 0;
  3165. $result['msg'] = '寄件人省份未配置';
  3166. return $result;
  3167. }
  3168. if(empty($data['kdn_city_id'])){
  3169. $result['status'] = 0;
  3170. $result['msg'] = '寄件人城市未配置';
  3171. return $result;
  3172. }
  3173. if(empty($data['kdn_area_id'])){
  3174. $result['status'] = 0;
  3175. $result['msg'] = '寄件人区域未配置';
  3176. return $result;
  3177. }
  3178. if(empty($data['kdn_sender_address'])){
  3179. $result['status'] = 0;
  3180. $result['msg'] = '寄件人详细地址未配置';
  3181. return $result;
  3182. }
  3183. $code_list = array('EMS','YZPY','YZBK');
  3184. if(in_array($express_code,$code_list)){
  3185. if(empty($data['kdn_sender_postcode'])){
  3186. $result['status'] = 0;
  3187. $result['msg'] = '寄件人邮编未配置';
  3188. return $result;
  3189. }
  3190. }
  3191. return $result;
  3192. }
  3193. //打印面单
  3194. public function kdniao_order(){
  3195. $result = array();
  3196. $order_id = I('request.order_id','');
  3197. $express_code = I('request.express_code','');
  3198. if(empty($order_id)){
  3199. $result['status'] = 1;
  3200. $result['message'] = "订单号不存在";
  3201. }else if(empty($express_code)){
  3202. $result['status'] = 1;
  3203. $result['message'] = "快递公司不存在";
  3204. }else{
  3205. $sender_result = $this->check_kdn_sender($express_code);
  3206. if($sender_result['status'] == 1){
  3207. $kdNiao = new \Lib\KdApiEOrder();
  3208. $config_data = D('Seller/Config')->get_all_config();
  3209. $result = $kdNiao->printOrder($order_id,$express_code,$config_data);
  3210. }else{
  3211. $result['status'] = 3;
  3212. $result['message'] = $sender_result['msg'];
  3213. }
  3214. }
  3215. echo json_encode($result);
  3216. }
  3217. //打印多条订单面单
  3218. public function kdniao_print_orders(){
  3219. $print_type = I('request.print_type','');
  3220. $order_id = I('request.order_id','');
  3221. $express_code = I('request.express_code','');
  3222. $order_id_list = array();
  3223. $order_list = array();
  3224. $order_kdn_status = array();
  3225. if($print_type == "select"){
  3226. $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();
  3227. }else if($print_type == "all"){
  3228. $order_list = M('lionfish_comshop_order')->field('order_id,is_kdn_print')->where("order_status_id = 1 and delivery = 'express' ")->select();
  3229. }
  3230. foreach($order_list as $k=>$v){
  3231. $order_id_list[] = $v['order_id'];
  3232. $order_kdn_status[$v['order_id']] = $v['is_kdn_print'];
  3233. }
  3234. $time = time();
  3235. $print_count = count($order_id_list);
  3236. //保存快递鸟打印日志
  3237. $kd_data = array();
  3238. $kd_data['addtime'] = $time;
  3239. $kd_data['print_count'] = $print_count;
  3240. $kdn_id = M('lionfish_comshop_order_kdniao_print_log')->add( $kd_data );
  3241. $succ_count = 0;
  3242. $fail_count = 0;
  3243. $fail_result = array();
  3244. $kdNiao = new \Lib\KdApiEOrder();
  3245. $config_data = D('Seller/Config')->get_all_config();
  3246. $sender_result = $this->check_kdn_sender($express_code);
  3247. if($sender_result['status'] == 1){
  3248. foreach($order_id_list as $v){
  3249. if($order_kdn_status[$v] == 1){
  3250. $succ_count++;
  3251. }else{
  3252. $result = $kdNiao->printOrder($v,$express_code,$config_data);
  3253. if($result['status'] == 0){//打印成功
  3254. $succ_count++;
  3255. }else{//打印失败
  3256. $fail_count++;
  3257. $fail_result[] = $result['message'];
  3258. }
  3259. }
  3260. }
  3261. }else{
  3262. $result['status'] = 3;
  3263. $result['message'] = $sender_result['msg'];
  3264. }
  3265. $fail_reason = json_encode(array_unique($fail_result));
  3266. //打印完成更新快递鸟打印日志
  3267. $kdn_data = array();
  3268. $kdn_data['succ_count'] = $succ_count;
  3269. $kdn_data['fail_count'] = $fail_count;
  3270. $kdn_data['fail_reason'] = $fail_reason;
  3271. $kdn_data['status'] = 1;
  3272. M('lionfish_comshop_order_kdniao_print_log')->where(array('id' => $kdn_id))->save($kdn_data);
  3273. $kdn_order_ids = implode(",",$order_id_list);
  3274. echo json_encode(array('status'=>0,'order_ids'=>$kdn_order_ids));
  3275. }
  3276. //检查是否配置快递鸟接口参数
  3277. public function check_kdniao(){
  3278. $config_data = D('Seller/Config')->get_all_config();
  3279. if(isset($config_data['kdniao_id']) && !empty($config_data['kdniao_id']) && isset($config_data['kdniao_api_key']) && !empty($config_data['kdniao_api_key'])){
  3280. show_json(1);
  3281. }else{
  3282. show_json(0, array('msg' => '快递鸟未配置!' ) );
  3283. }
  3284. }
  3285. public function kdn_info(){
  3286. $this->order_id = I('request.order_id','');
  3287. $kdn_info = M('lionfish_comshop_order_kdniao_info')->where( array('order_id' => $this->order_id,'status'=>1) )->find();
  3288. $this->kdn_info = $kdn_info;
  3289. $this->display();
  3290. }
  3291. public function kdn_orders_info(){
  3292. $this->order_ids = I('request.order_ids','');
  3293. $kdn_list_info = M('lionfish_comshop_order_kdniao_info')->where("order_id in (".$this->order_ids.") and status = 1")->select();
  3294. $this->kdn_list_info = $kdn_list_info;
  3295. $this->display();
  3296. }
  3297. /**
  3298. * 快递鸟打印成功订单发货
  3299. */
  3300. public function kdn_send(){
  3301. $order_id = I('request.id','');
  3302. $order_ids = I('request.ids','');
  3303. if(!empty($order_id)){
  3304. $item = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3305. if (empty($item)) {
  3306. show_json(0, '未找到订单!');
  3307. }
  3308. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3309. if(!empty($order_info)) {
  3310. if ($order_info['order_status_id'] == 1 && $order_info['delivery'] == 'express' && $order_info['is_kdn_print'] == 1) {
  3311. $express_info = D('Seller/Express')->get_express_info($order_info['shipping_method']);
  3312. $data = array();
  3313. $data['order_status_id'] = 4;
  3314. M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save($data);
  3315. $history_data = array();
  3316. $history_data['order_id'] = $order_id;
  3317. $history_data['order_status_id'] = 4;
  3318. $history_data['notify'] = 0;
  3319. $history_data['comment'] = '订单发货 ID: ' . $order_id . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $item['shipping_no'];
  3320. $history_data['date_added'] = time();
  3321. M('lionfish_comshop_order_history')->add($history_data);
  3322. D('Home/Frontorder')->send_order_operate($item['order_id']);
  3323. } else {
  3324. show_json(0, '待发货快递订单才能发货成功!');
  3325. }
  3326. }else{
  3327. show_json(0, '未找到订单!');
  3328. }
  3329. }else if(!empty($order_ids)){
  3330. $ids = explode(",",$order_ids);
  3331. foreach($ids as $k=>$v){
  3332. $order_id = $v;
  3333. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3334. if (empty($order_info)) {
  3335. show_json(0, '未找到订单!');
  3336. }
  3337. if(!empty($order_info)) {
  3338. if ($order_info['order_status_id'] == 1 && $order_info['delivery'] == 'express' && $order_info['is_kdn_print'] == 1) {
  3339. $express_info = D('Seller/Express')->get_express_info($order_info['shipping_method']);
  3340. $data = array();
  3341. $data['order_status_id'] = 4;
  3342. M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save($data);
  3343. $history_data = array();
  3344. $history_data['order_id'] = $order_id;
  3345. $history_data['order_status_id'] = 4;
  3346. $history_data['notify'] = 0;
  3347. $history_data['comment'] = '订单发货 ID: ' . $order_id . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $item['shipping_no'];
  3348. $history_data['date_added'] = time();
  3349. M('lionfish_comshop_order_history')->add($history_data);
  3350. D('Home/Frontorder')->send_order_operate($item['order_id']);
  3351. } else {
  3352. show_json(0, '待发货快递订单才能发货成功!');
  3353. }
  3354. }else{
  3355. show_json(0, '未找到订单!');
  3356. }
  3357. }
  3358. }else{
  3359. show_json(0, '未找到订单!');
  3360. }
  3361. show_json(1);
  3362. }
  3363. /**
  3364. * 修改订单价格
  3365. */
  3366. public function change_order(){
  3367. $_GPC = I('request.');
  3368. $opdata = $this->check_order_data();
  3369. extract($opdata);
  3370. $id = I('request.id',0);
  3371. if( IS_POST )
  3372. {
  3373. $_GPC = I('request.');
  3374. $order_id = $_GPC['id'];
  3375. $order_goods_ids = $_GPC['order_goods_id'];
  3376. $change_prices = $_GPC['change_price'];
  3377. $count = 0;
  3378. foreach($change_prices as $v){
  3379. if(empty(trim($v))){
  3380. $count++;
  3381. }
  3382. }
  3383. if($count == count($change_prices)){
  3384. show_json(0, array('message' => '未填写涨价或减价金额!'));
  3385. }
  3386. //改价后的商品实付价格不能低于0.1元
  3387. foreach($order_goods_ids as $k=>$order_goods_id){
  3388. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' =>$order_goods_id ) )->find();
  3389. $total = $order_goods_info['total'];
  3390. $fullreduction_money = $order_goods_info['fullreduction_money'];
  3391. $voucher_credit = $order_goods_info['voucher_credit'];
  3392. $score_for_money = $order_goods_info['score_for_money'];
  3393. $total = round($total - $fullreduction_money - $voucher_credit - $score_for_money,2);
  3394. if(!empty($change_prices[$k])){
  3395. $change_price = $change_prices[$k];
  3396. $total = floatval($total) + floatval($change_price);
  3397. if(bccomp($total, '0.1', 2) == -1){
  3398. show_json(0, array('message' => '改价后的商品实付价格不能低于0.1元'));
  3399. }
  3400. }
  3401. }
  3402. $change_amount = 0;
  3403. foreach($order_goods_ids as $k=>$order_goods_id){
  3404. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' =>$order_goods_id ) )->find();
  3405. $total = $order_goods_info['total'];
  3406. $update_data = array();
  3407. if(!empty($change_prices[$k])){
  3408. $change_amount = $change_amount + $change_prices[$k];
  3409. $change_price = $change_prices[$k];
  3410. $update_data['total'] = round(floatval($total) + floatval($change_price),2);
  3411. $update_data['is_change_price'] = 1;
  3412. M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' => $order_goods_id ) )->save( $update_data);
  3413. }
  3414. }
  3415. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$id) )->find();
  3416. $order_total = $order_info['total'];
  3417. $order_data = array();
  3418. $order_data['total'] = round(floatval($order_total) + floatval($change_amount),2);
  3419. $order_data['is_change_price'] = 1;
  3420. M('lionfish_comshop_order')->where( array('order_id' =>$id) )->save($order_data);
  3421. $oh = array();
  3422. $oh['order_id'] = $id;
  3423. $oh['order_status_id']=15;
  3424. $oh['comment']='订单改价';
  3425. $oh['date_added']=time();
  3426. M('lionfish_comshop_order_history')->add($oh);
  3427. show_json(1);
  3428. }
  3429. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id) )->select();
  3430. foreach($order_goods as $k=>$v){
  3431. $order_goods[$k]['goods_img_url'] = tomedia($v['goods_images']);
  3432. }
  3433. $this->item = $opdata['item'];
  3434. $this->order_goods = $order_goods;
  3435. $this->display();
  3436. }
  3437. //检查是否配置第三方配送接口参数
  3438. public function check_delivery_config(){
  3439. $_GPC = I('request.');
  3440. $config_data = D('Seller/Config')->get_all_config();
  3441. $data_type = $_GPC['data_type'];
  3442. if($data_type == 'imdada'){
  3443. 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'])){
  3444. show_json(1);
  3445. }else{
  3446. show_json(0, array('msg' => '达达配送平台参数未配置!' ) );
  3447. }
  3448. }else if($data_type == 'sf'){
  3449. if(isset($config_data['localtown_sf_dev_id']) && !empty($config_data['localtown_sf_dev_key']) && isset($config_data['localtown_sf_store_id'])){
  3450. show_json(1);
  3451. }else{
  3452. show_json(0, array('msg' => '顺丰同城参数未配置!' ) );
  3453. }
  3454. }else if($data_type == 'make'){
  3455. if(isset($config_data['localtown_mk_token']) && !empty($config_data['localtown_mk_token']) ){
  3456. show_json(1);
  3457. }else{
  3458. show_json(0, array('msg' => '码科配送参数未配置!' ) );
  3459. }
  3460. }else if($data_type == 'ele'){
  3461. 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'])
  3462. && !empty($config_data['localtown_ele_transport_address']) && !empty($config_data['localtown_ele_transport_longitude']) && !empty($config_data['localtown_ele_transport_latitude'])
  3463. && !empty($config_data['localtown_ele_transport_tel']) && !empty($config_data['localtown_ele_position_source'])
  3464. ){
  3465. show_json(1);
  3466. }else{
  3467. show_json(0, array('msg' => '蜂鸟即配平台参数未配置!' ) );
  3468. }
  3469. }
  3470. }
  3471. /**
  3472. * 将订单推送给第三方配送
  3473. */
  3474. public function thirth_delivery_order(){
  3475. $_GPC = I('request.');
  3476. $data_type = $_GPC['data_type'];
  3477. $order_id = $_GPC['order_id'];
  3478. if(empty($data_type)){
  3479. show_json(0, array('msg' => '未选择第三方配送' ) );
  3480. }
  3481. if(empty($order_id)){
  3482. show_json(0, array('msg' => '订单号不存在' ) );
  3483. }
  3484. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3485. if(empty($order_info)){
  3486. show_json(0, array('msg' => '订单不存在' ) );
  3487. }
  3488. //店铺地址
  3489. if($order_info['store_id'] > 0) {
  3490. $store_data = D('Home/Order')->getOrderStoreAddress($order_info);
  3491. $order_info['store_data'] = $store_data;
  3492. }
  3493. //商品信息
  3494. $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 "
  3495. . 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 "
  3496. ." where og.order_id = ".$order_id;
  3497. $goods_list = M()->query($sql);
  3498. $goods_count = 0;
  3499. $goods_weight = 0;
  3500. $goods_type_count = 0;
  3501. foreach($goods_list as $k=>$v){
  3502. $goods_count = $goods_count + $v['quantity'];
  3503. if(!empty($v['rela_goodsoption_valueid'])){
  3504. $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();
  3505. if(!empty($goods_option_mult_value)){
  3506. $v['goods_weight'] = $goods_option_mult_value['weight'];
  3507. }
  3508. }
  3509. $goods_weight = $goods_weight + $v['quantity'] * $v['goods_weight'];
  3510. $goods_type_count = $goods_type_count + 1;
  3511. }
  3512. if(empty($goods_weight)){
  3513. $goods_weight = 100;//默认100克
  3514. }
  3515. $order_info['goods_list'] = $goods_list;
  3516. //商品种类
  3517. $order_info['goods_type_count'] = $goods_type_count;
  3518. //商品数量
  3519. $order_info['goods_count'] = $goods_count;
  3520. //商品重量
  3521. $order_info['goods_weight'] = $goods_weight;
  3522. //订单总金额
  3523. $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'];
  3524. //收货人地址
  3525. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  3526. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  3527. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  3528. $order_info['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$order_info['shipping_address'];
  3529. //收货人经纬度
  3530. $order_distribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3531. //收货人地址纬度
  3532. $order_info['shipping_lat'] = $order_distribution_info['member_lat'];
  3533. //收货人地址经度
  3534. $order_info['shipping_lng'] = $order_distribution_info['member_lon'];
  3535. //商城名称
  3536. $shoname = D('Home/Front')->get_config_by_name('shoname');
  3537. $order_info['shoname'] = $shoname;
  3538. if($data_type == 'imdada'){
  3539. $imdada = new \Lib\Localtown\Imdada();
  3540. $result = $imdada->addOrder($order_info);
  3541. if($result['status'] == 1){//成功
  3542. //配送费用
  3543. $delivery_fee = $result['result']['fee'];
  3544. $express_info = array();
  3545. $express_info['delivery_fee'] = $delivery_fee;
  3546. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3547. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3548. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3549. show_json(1);
  3550. }else{//失败
  3551. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3552. }
  3553. }else if($data_type == 'sf'){
  3554. $sfexpress = new \Lib\Localtown\Sfexpress();
  3555. $result = $sfexpress->addOrder($order_info);
  3556. if($result['status'] == 1){//成功
  3557. //配送费用
  3558. $delivery_fee = round($result['result']['total_price']/100,2);
  3559. //顺丰订单号
  3560. $delivery_order_id = $result['result']['sf_order_id'];
  3561. //顺丰运单号
  3562. $delivery_bill_id = $result['result']['sf_bill_id'];
  3563. $express_info = array();
  3564. $express_info['delivery_fee'] = $delivery_fee;
  3565. $express_info['delivery_order_id'] = $delivery_order_id;
  3566. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3567. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3568. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3569. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3570. show_json(1);
  3571. }else{//失败
  3572. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3573. }
  3574. }else if( $data_type == 'make' )
  3575. {
  3576. //$store_data = D('Home/Make')->getOrderStoreAddress($order_info);
  3577. $result = D('Home/Make')->addOrder($order_info);
  3578. if( $result['code'] == 0 )
  3579. {
  3580. //码科订单号
  3581. $delivery_order_id = $result['order_number'];
  3582. $express_info = array();
  3583. $express_info['delivery_fee'] = $order_distribution_info['shipping_money'];
  3584. $express_info['delivery_order_id'] = $delivery_order_id;
  3585. $express_info['delivery_bill_id'] = '';
  3586. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3587. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3588. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3589. show_json(1);
  3590. }else{
  3591. show_json(0, array('msg' => $result['message'] ) );
  3592. }
  3593. }else if($data_type == 'ele'){//蜂鸟即配
  3594. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3595. $order_code = build_order_no(session('user_auth.uid'));
  3596. //保存蜂鸟即配商户订单号
  3597. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(['order_code'=>$order_code]);
  3598. $order_info['order_num_alias'] = $order_code;
  3599. $result = $eleDistribution->addOrder($order_info);
  3600. if($result['status'] == 1){//成功
  3601. //配送费用
  3602. $delivery_fee = round($result['result']['total_price']/100,2);
  3603. //蜂鸟即配订单号
  3604. $delivery_order_id = $result['result']['sf_order_id'];
  3605. //蜂鸟即配运单号
  3606. $delivery_bill_id = $result['result']['sf_bill_id'];
  3607. $express_info = array();
  3608. $express_info['delivery_fee'] = $delivery_fee;
  3609. $express_info['delivery_order_id'] = $delivery_order_id;
  3610. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3611. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3612. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3613. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3614. show_json(1);
  3615. }else{//失败
  3616. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3617. }
  3618. }else{
  3619. show_json(0, array('msg' => '不存在第三方配送' ) );
  3620. }
  3621. }
  3622. /**
  3623. * 将订单重新推送给第三方配送
  3624. */
  3625. public function thirth_renew_delivery_order(){
  3626. $_GPC = I('request.');
  3627. $data_type = $_GPC['data_type'];
  3628. $order_id = $_GPC['order_id'];
  3629. if(empty($data_type)){
  3630. show_json(0, array('msg' => '未选择第三方配送' ) );
  3631. }
  3632. if(empty($order_id)){
  3633. show_json(0, array('msg' => '订单号不存在' ) );
  3634. }
  3635. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3636. if(empty($order_info)){
  3637. show_json(0, array('msg' => '订单不存在' ) );
  3638. }
  3639. //店铺地址
  3640. if($order_info['store_id'] > 0) {
  3641. $store_data = D('Home/Order')->getOrderStoreAddress($order_info);
  3642. $order_info['store_data'] = $store_data;
  3643. }
  3644. //商品信息
  3645. $sql = "select og.goods_id,og.name as goods_name,og.quantity,og.rela_goodsoption_valueid,g.weight as goods_weight from "
  3646. . 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 "
  3647. ." where og.order_id = ".$order_id;
  3648. $goods_list = M()->query($sql);
  3649. $goods_count = 0;
  3650. $goods_weight = 0;
  3651. $goods_type_count = 0;
  3652. foreach($goods_list as $k=>$v){
  3653. $goods_count = $goods_count + $v['quantity'];
  3654. if(!empty($v['rela_goodsoption_valueid'])){
  3655. $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();
  3656. if(!empty($goods_option_mult_value)){
  3657. $v['goods_weight'] = $goods_option_mult_value['weight'];
  3658. }
  3659. }
  3660. $goods_weight = $goods_weight + $v['quantity'] * $v['goods_weight'];
  3661. $goods_type_count = $goods_type_count + 1;
  3662. }
  3663. if(empty($goods_weight)){
  3664. $goods_weight = 100;//默认100克
  3665. }
  3666. $order_info['goods_list'] = $goods_list;
  3667. //商品种类
  3668. $order_info['goods_type_count'] = $goods_type_count;
  3669. //商品数量
  3670. $order_info['goods_count'] = $goods_count;
  3671. //商品重量
  3672. $order_info['goods_weight'] = $goods_weight;
  3673. //订单总金额
  3674. $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'];
  3675. //收货人地址
  3676. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  3677. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  3678. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  3679. $order_info['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$order_info['shipping_address'];
  3680. //收货人经纬度
  3681. $order_distribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3682. //收货人地址纬度
  3683. $order_info['shipping_lat'] = $order_distribution_info['member_lat'];
  3684. //收货人地址经度
  3685. $order_info['shipping_lng'] = $order_distribution_info['member_lon'];
  3686. //商城名称
  3687. $shoname = D('Home/Front')->get_config_by_name('shoname');
  3688. $order_info['shoname'] = $shoname;
  3689. if($data_type == 'imdada'){
  3690. $imdada = new \Lib\Localtown\Imdada();
  3691. $result = $imdada->reAddOrder($order_info);
  3692. if($result['status'] == 1){//成功
  3693. //配送费用
  3694. $delivery_fee = array();
  3695. $delivery_fee['delivery_fee'] = $result['result']['fee'];
  3696. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$delivery_fee);
  3697. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3698. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3699. show_json(1);
  3700. }else{//失败
  3701. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3702. }
  3703. }else if($data_type == 'sf'){
  3704. $sfexpress = new \Lib\Localtown\Sfexpress();
  3705. $result = $sfexpress->addOrder($order_info);
  3706. if($result['status'] == 1){//成功
  3707. //配送费用
  3708. $delivery_fee = round($result['result']['total_price']/100,2);
  3709. //顺丰订单号
  3710. $delivery_order_id = $result['result']['sf_order_id'];
  3711. //顺丰运单号
  3712. $delivery_bill_id = $result['result']['sf_bill_id'];
  3713. $express_info = array();
  3714. $express_info['delivery_fee'] = $delivery_fee;
  3715. $express_info['delivery_order_id'] = $delivery_order_id;
  3716. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3717. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3718. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3719. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3720. show_json(1);
  3721. }else{//失败
  3722. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3723. }
  3724. }else if($data_type == 'make')
  3725. {
  3726. $result = D('Home/Make')->addOrder($order_info);
  3727. if( $result['code'] == 0 )
  3728. {
  3729. //码科订单号
  3730. $delivery_order_id = $result['order_number'];
  3731. $express_info = array();
  3732. $express_info['delivery_fee'] = $order_distribution_info['shipping_money'];
  3733. $express_info['delivery_order_id'] = $delivery_order_id;
  3734. $express_info['delivery_bill_id'] = '';
  3735. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3736. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3737. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3738. show_json(1);
  3739. }else{
  3740. show_json(0, array('msg' => $result['message'] ) );
  3741. }
  3742. }else if($data_type == 'ele'){//蜂鸟即配
  3743. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3744. $order_code = build_order_no(session('user_auth.uid'));
  3745. //保存蜂鸟即配商户订单号
  3746. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(['order_code'=>$order_code]);
  3747. $order_info['order_num_alias'] = $order_code;
  3748. $result = $eleDistribution->addOrder($order_info);
  3749. if($result['status'] == 1){//成功
  3750. //配送费用
  3751. $delivery_fee = round($result['result']['total_price']/100,2);
  3752. //蜂鸟即配订单号
  3753. $delivery_order_id = $result['result']['sf_order_id'];
  3754. //蜂鸟即配运单号
  3755. $delivery_bill_id = $result['result']['sf_bill_id'];
  3756. $express_info = array();
  3757. $express_info['delivery_fee'] = $delivery_fee;
  3758. $express_info['delivery_order_id'] = $delivery_order_id;
  3759. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3760. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3761. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3762. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3763. show_json(1);
  3764. }else{//失败
  3765. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3766. }
  3767. }
  3768. else{
  3769. show_json(0, array('msg' => '不存在第三方配送' ) );
  3770. }
  3771. }
  3772. public function third_cancel_reason(){
  3773. $order_id = I('request.order_id','');
  3774. $third_distribution_type = I('request.third_distribution_type','');
  3775. $this->order_id = $order_id;
  3776. $this->third_distribution_type = $third_distribution_type;
  3777. $this->display();
  3778. }
  3779. /**
  3780. * 取消第三方配送订单
  3781. */
  3782. public function thirth_cancel_delivery_order(){
  3783. $_GPC = I('request.');
  3784. $order_id = $_GPC['order_id'];
  3785. if(empty($order_id)){
  3786. show_json(0, array('msg' => '订单号不存在' ) );
  3787. }
  3788. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3789. if(empty($order_info)){
  3790. show_json(0, array('msg' => '订单不存在' ) );
  3791. }
  3792. $orderdistribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' =>$order_id) )->find();
  3793. if(empty($orderdistribution_info)){
  3794. show_json(0, array('msg' => '配送订单不存在' ) );
  3795. }
  3796. $cancel_reason_id = $_GPC['cancel_reason_id'];
  3797. $cancel_reason = $_GPC['cancel_reason'];
  3798. $data_type = $orderdistribution_info['third_distribution_type'];
  3799. if($orderdistribution_info['state'] == 0 || $orderdistribution_info['state'] == 1 || $orderdistribution_info['state'] == 2){
  3800. if($data_type == 'imdada'){
  3801. $imdada = new \Lib\Localtown\Imdada();
  3802. $result = $imdada->cancelOrder($order_info,$cancel_reason_id,$cancel_reason);
  3803. if($result['status'] == 1){//成功
  3804. $deduct_fee = $result['result']['deduct_fee'];
  3805. $other_data = array();
  3806. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3807. $other_data['cancel_reason'] = $cancel_reason;
  3808. $other_data['now_deduct_fee'] = $deduct_fee;
  3809. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3810. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3811. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3812. show_json(1);
  3813. }else{//失败
  3814. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3815. }
  3816. }else if($data_type == 'sf'){
  3817. $sfexpress = new \Lib\Localtown\Sfexpress();
  3818. $result = $sfexpress->cancelOrder($orderdistribution_info,$cancel_reason);
  3819. if($result['status'] == 1){//成功
  3820. $other_data = array();
  3821. if(empty($cancel_reason)){
  3822. $cancel_reason = "商家取消";
  3823. }
  3824. $other_data['cancel_reason'] = $cancel_reason;
  3825. $deduct_fee = round($result['result']['deduction_detail']['deduction_fee']/100,2);
  3826. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3827. $other_data['now_deduct_fee'] = $deduct_fee;
  3828. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3829. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3830. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3831. show_json(1);
  3832. }else{//失败
  3833. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3834. }
  3835. }else if( $data_type == 'make' )
  3836. {
  3837. //$orderdistribution_info
  3838. $third_order_id = $orderdistribution_info['third_order_id'];
  3839. $result = D('Home/Make')->cancelOrder( $third_order_id );
  3840. if( $result['code'] == 0 )
  3841. {
  3842. $other_data = array();
  3843. if(empty($cancel_reason)){
  3844. $cancel_reason = "商家取消";
  3845. }
  3846. $other_data['cancel_reason'] = $cancel_reason;
  3847. $deduct_fee = 0;
  3848. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3849. $other_data['now_deduct_fee'] = $deduct_fee;
  3850. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3851. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3852. //D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3853. //load_model_class('supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3854. show_json(1);
  3855. }else{
  3856. show_json(0, array('msg' => $result['message'] ) );
  3857. }
  3858. }else if($data_type == 'ele'){
  3859. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3860. $result = $eleDistribution->cancelOrder($orderdistribution_info,$cancel_reason_id,$cancel_reason);
  3861. if($result['status'] == 1){//成功
  3862. $other_data = array();
  3863. if(empty($cancel_reason)){
  3864. $cancel_reason = "商家取消";
  3865. }
  3866. $other_data['cancel_reason'] = $cancel_reason;
  3867. $deduct_fee = round($result['result']['deduction_detail']['deduction_fee']/100,2);
  3868. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3869. $other_data['now_deduct_fee'] = $deduct_fee;
  3870. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3871. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3872. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3873. show_json(1);
  3874. }else{//失败
  3875. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3876. }
  3877. }
  3878. }else{
  3879. show_json(0, array('msg' => '配送订单无法取消' ) );
  3880. }
  3881. }
  3882. /**
  3883. * 达达平台模拟取货
  3884. */
  3885. public function orderFetch(){
  3886. $_GPC = I('request.');
  3887. $order_sn = $_GPC['order_sn'];
  3888. $type = $_GPC['type'];
  3889. $imdada = new \Lib\Localtown\Imdada();
  3890. if($type == 1){
  3891. $imdada->orderFetch($order_sn);//模拟取货
  3892. }else if($type == 2){
  3893. $imdada->orderFinish($order_sn);//完成订单
  3894. }else if($type == 3){
  3895. $imdada->orderCancel($order_sn);//取消订单
  3896. }else if($type == 4){
  3897. $imdada->orderAbnormal($order_sn);//异常妥投物品返还中
  3898. }
  3899. }
  3900. public function third_delivery_log_list(){
  3901. $order_id = I('request.order_id','');
  3902. $orderdistribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' =>$order_id) )->find();
  3903. $distribution_type = $orderdistribution_info['third_distribution_type'];
  3904. $log_list = M('lionfish_comshop_orderdistribution_thirth_log')->where( array('order_id' =>$order_id,'third_distribution_type'=>$distribution_type) )->order('addtime desc')->select();
  3905. $third_name = "";
  3906. if($distribution_type == 'imdada'){
  3907. $third_name = '达达平台';
  3908. }else if($distribution_type == 'sf'){
  3909. $third_name = '顺丰同城';
  3910. }else if($distribution_type == 'make'){
  3911. $third_name = '码科配送';
  3912. }else if($distribution_type == 'uupt'){
  3913. $third_name = 'UU跑腿';
  3914. }else if($distribution_type == 'dianwoda'){
  3915. $third_name = '点我达';
  3916. }
  3917. $this->third_name = $third_name;
  3918. $this->log_list = $log_list;
  3919. $this->orderdistribution_info = $orderdistribution_info;
  3920. $this->display();
  3921. }
  3922. //end
  3923. /**
  3924. * 订单核销
  3925. */
  3926. public function order_hexiao()
  3927. {
  3928. $opdata = $this->check_order_data();
  3929. extract($opdata);
  3930. if( $item['delivery'] == 'hexiao' )
  3931. {
  3932. D('Seller/Order')->hexiao_all_orders($item['order_id']);
  3933. }
  3934. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  3935. }
  3936. /**
  3937. * 商品按订单核销
  3938. */
  3939. public function order_goods_hexiao(){
  3940. $opdata = $this->check_order_data();
  3941. extract($opdata);
  3942. $order_goods_id = I('request.order_goods_id','');
  3943. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id, 'order_goods_id' => $order_goods_id) )->find();
  3944. if (empty($order_hexiao_info)) {
  3945. show_json(0, '未找到核销订单!');
  3946. }
  3947. D('Seller/Order')->hexiao_order_goods($order_hexiao_info,0);
  3948. D('Seller/Order')->hexiao_finished($id,'后台确认使用,订单完成');
  3949. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  3950. }
  3951. /**
  3952. * 查看核销记录
  3953. */
  3954. public function view_hexiao_history(){
  3955. $opdata = $this->get_goods_saleshexiao();
  3956. extract($opdata);
  3957. $data = D('Seller/Order')->get_goods_hexiao_record();
  3958. $this->order_hexiao_info = $order_hexiao_info;
  3959. $this->hx_list = $data['hx_list'];
  3960. $this->display("hexiao_history");
  3961. }
  3962. /**
  3963. * 按次数核销商品
  3964. */
  3965. public function hexiao_times(){
  3966. $opdata = $this->get_goods_saleshexiao();
  3967. extract($opdata);
  3968. $data = D('Seller/Order')->get_goods_hexiao_record();
  3969. $this->order_hexiao_info = $order_hexiao_info;
  3970. $this->hx_list = $data['hx_list'];
  3971. $this->hx_count = $data['hx_count'];
  3972. $this->display();
  3973. }
  3974. /**
  3975. * 获取商品核销信息
  3976. * @return
  3977. */
  3978. public function get_goods_saleshexiao(){
  3979. $opdata = $this->check_order_data();
  3980. extract($opdata);
  3981. $order_goods_id = I('request.order_goods_id','');
  3982. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id, 'order_goods_id' => $order_goods_id) )->find();
  3983. if (empty($order_hexiao_info)) {
  3984. show_json(0, '未找到核销订单!');
  3985. }
  3986. $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();
  3987. $order_hexiao_info['goods_id'] = $order_goods_info['goods_id'];
  3988. $order_hexiao_info['goods_name'] = $order_goods_info['goods_name'];
  3989. $order_hexiao_info['goods_images'] = tomedia($order_goods_info['goods_images']);
  3990. $order_hexiao_info['quantity'] = $order_goods_info['quantity'];
  3991. return array('order_hexiao_info' => $order_hexiao_info);
  3992. }
  3993. /**
  3994. * 核销商品使用
  3995. */
  3996. public function hexiao_goods(){
  3997. $hx_id = I('request.hx_id','');
  3998. $hx_count = I('request.hx_count','');
  3999. if(empty($hx_id)){
  4000. show_json(0, '核销商品数据错误!');
  4001. }
  4002. if(empty($hx_count)){
  4003. show_json(0, '核销商品数量错误!');
  4004. }
  4005. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hx_id) )->find();
  4006. if (empty($order_hexiao_info)) {
  4007. show_json(0, '未找到核销订单!');
  4008. }
  4009. D('Seller/Order')->hexiao_order_goods($order_hexiao_info,$hx_count);
  4010. D('Seller/Order')->hexiao_finished($order_hexiao_info['order_id'],'后台确认使用,订单完成');
  4011. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  4012. }
  4013. /**
  4014. * 查看商品指定核销信息
  4015. */
  4016. public function hexiao_goods_assign_salesroom(){
  4017. $goods_id = I('request.goods_id','');
  4018. $order_goods_id = I('request.order_goods_id','');
  4019. if(empty($goods_id)){
  4020. show_json(0, '商品信息错误!');
  4021. }
  4022. if(empty($order_goods_id)){
  4023. show_json(0, '核销商品信息错误!');
  4024. }
  4025. $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();
  4026. $goods_salesroom_info = D('Seller/Order')->get_goods_assign_salesroom($goods_id);
  4027. $this->salesroom_list = $goods_salesroom_info['salesroom_list'];
  4028. $this->smember_list = $goods_salesroom_info['smember_list'];
  4029. $this->goods_info = $order_goods_info;
  4030. $this->display();
  4031. }
  4032. public function checkLocalTownOrderCanRefund($item){
  4033. if($item['delivery'] == 'localtown_delivery'){//同城配送订单
  4034. if($item['order_status_id'] == 4){//已发货不能退款
  4035. return false;
  4036. }else{
  4037. return true;
  4038. }
  4039. }else{
  4040. return true;
  4041. }
  4042. }
  4043. }
  4044. ?>