OrderController.class.php 179 KB

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