CarController.class.php 185 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. class CarController extends CommonController {
  11. //--------begin
  12. public function reduce_car_goods()
  13. {
  14. $_GPC = I('request.');
  15. $data = array();
  16. $data['goods_id'] = $_GPC['goods_id'];
  17. $data['community_id'] = $_GPC['community_id'];
  18. $data['quantity'] = $_GPC['quantity'];
  19. $data['sku_str'] = $_GPC['sku_str'];
  20. if($_GPC['sku_str'] == 'undefined')
  21. {
  22. $_GPC['sku_str'] = '';
  23. $data['sku_str'] = '';
  24. }
  25. $data['buy_type'] = $_GPC['buy_type'];
  26. $data['pin_id'] = $_GPC['pin_id'];
  27. $data['is_just_addcar'] = $_GPC['is_just_addcar'];
  28. $data['soli_id'] = isset($_GPC['soli_id']) ? intval($_GPC['soli_id']) : '';
  29. if( !isset($data['buy_type']) || empty($data['buy_type']) )
  30. {
  31. $data['buy_type'] = 'dan';
  32. }
  33. $token = $_GPC['token'];
  34. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  35. $member_id = $weprogram_token['member_id'];
  36. $is_just_addcar = empty($data['is_just_addcar']) ? 0: 1;
  37. $goods_id = $data['goods_id'];
  38. if( empty($member_id))
  39. {
  40. $result = array('code' =>4);
  41. echo json_encode($result);
  42. die();
  43. }
  44. if (isset($data['goods_id'])) {
  45. $goods_id = $data['goods_id'];
  46. } else {
  47. $goods_id = 0;
  48. }
  49. $goods_param = array();
  50. $product = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
  51. if( $product['grounding'] != 1)
  52. {
  53. $json['code'] =6;
  54. $json['msg']='商品已下架!';
  55. echo json_encode($json);
  56. die();
  57. }
  58. $is_community = D('Seller/Communityhead')->is_community($data['community_id']);
  59. if( !$is_community )
  60. {
  61. $json['code'] =6;
  62. $json['msg']='该小区已经不存在!';
  63. echo json_encode($json);
  64. die();
  65. }
  66. //6
  67. if($is_just_addcar == 1)
  68. {
  69. if($product['pick_just'] > 0)
  70. {
  71. $json['code'] =6;
  72. $json['msg']='自提商品,请立即购买';
  73. echo json_encode($json);
  74. die();
  75. }
  76. }
  77. //商品存在
  78. if($product){
  79. $cart= D('Home/Car');
  80. if (isset($data['quantity'])) {
  81. $quantity = $data['quantity'];
  82. } else {
  83. $quantity = 1;
  84. }
  85. $option = array();
  86. if( !empty($data['sku_str'])){
  87. $option = explode('_', $data['sku_str']);
  88. }
  89. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$data['soli_id'] );
  90. $key = (int)$goods_id . ':'.$data['community_id'].':';
  91. if( !empty($data['soli_id']) )
  92. {
  93. $key .= $data['soli_id'].':';
  94. }
  95. if ($data['sku_str']) {
  96. $key.= base64_encode($data['sku_str']) . ':';
  97. } else {
  98. $key.= ':';//xx
  99. }
  100. $car_prefix = 'cart.';
  101. if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
  102. {
  103. $key = 'soitairecart.' . $key;
  104. $car_prefix = 'soitairecart.';
  105. }else{
  106. $key = 'cart.' . $key;
  107. }
  108. $json=array('code' =>0);
  109. $car_info = M('lionfish_comshop_car')->where( array('carkey' => $key,'community_id' => $data['community_id'] ) )->find();
  110. $tmp_format_data = unserialize($car_info['format_data']);
  111. //$tmp_format_data['quantity']
  112. if($tmp_format_data['quantity'] == 1 || $tmp_format_data['quantity'] <= $quantity)
  113. {
  114. $all_cart = M('lionfish_comshop_car')->where( array('carkey' => $key ,'community_id' =>$data['community_id'],'token' => $token ) )->delete();
  115. }else{
  116. $tmp_format_data['quantity'] = $tmp_format_data['quantity'] - $quantity;
  117. M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $data['community_id'] ) )->save( array('format_data' => serialize($tmp_format_data) ) );
  118. }
  119. $cart= D('Home/Car');
  120. $total=$cart->count_goodscar($token, $data['community_id']);
  121. $json ['code'] = 1;
  122. if( $data['buy_type'] != 'dan' )
  123. {
  124. $json ['code'] = 2;
  125. }
  126. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token);
  127. $json['success']='成功加入购物车!!';
  128. $json['total']=$total;
  129. $json['cur_count']=$cart_goods_quantity;
  130. $is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
  131. $json['is_limit_distance_buy']=$is_limit_distance_buy;
  132. $json['goods_total_count'] = 0;
  133. if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
  134. {
  135. $json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'],$token, $data['soli_id'] );
  136. $json['cur_count'] = $cart->get_wecart_goods($goods_id, $data['sku_str'], $data['community_id'],$token,$car_prefix,$data['soli_id'] );
  137. }
  138. echo json_encode($json);
  139. die();
  140. }
  141. }
  142. /**
  143. pintuan_newman_notice
  144. **/
  145. public function add_newcar()
  146. {
  147. $_GPC = I('request.');
  148. $data = array();
  149. $data['goods_id'] = $_GPC['goods_id'];
  150. $data['buy_type'] = 'pintuan';
  151. $data['community_id'] = $_GPC['community_id'];
  152. $community_id= $data['community_id'];
  153. $data['quantity'] = 1;
  154. $token = $_GPC['token'];
  155. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  156. $member_id = $weprogram_token['member_id'];
  157. $goods_id = $data['goods_id'];
  158. if( empty($member_id))
  159. {
  160. $result = array('code' =>4);
  161. echo json_encode($result);
  162. die();
  163. }
  164. $goods_param = array();
  165. $product = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
  166. if( $product['grounding'] != 1)
  167. {
  168. $json['code'] =6;
  169. $json['msg']='商品已下架!';
  170. echo json_encode($json);
  171. die();
  172. }
  173. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,is_new_buy');
  174. $pin_model = D('Home/Pin');
  175. $iszero_opentuan = $pin_model->check_goods_iszero_opentuan( $goods_id );
  176. if($iszero_opentuan != 1)
  177. {
  178. $json['code'] =6;
  179. $json['msg']='非邀请团商品!';
  180. echo json_encode($json);
  181. die();
  182. }
  183. $cart= D('Home/Car');
  184. if($product){
  185. if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
  186. {
  187. $car_prefix = 'pintuancart.';
  188. }
  189. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$car_prefix);
  190. $json=array('code' =>0);
  191. //$goods_model = D('Home/Goods');
  192. $goods_quantity=$cart->get_goods_quantity($goods_id);
  193. //检测商品限购 6 one_limit_count
  194. /**
  195. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  196. if(!empty($cart_goods_quantity) && $cart_goods_quantity > 0)
  197. {
  198. if($goods_description['one_limit_count'] > 0 && $cart_goods_quantity >= $goods_description['one_limit_count'] )
  199. {
  200. $json['code'] =6;
  201. //$json['msg']='已经不能再买了';
  202. $json['msg']='您本次只能购买'.$goods_description['one_limit_count'].'个';
  203. $json['max_quantity'] = $goods_description['one_limit_count'];
  204. echo json_encode($json);
  205. die();
  206. }
  207. $can_buy_count = $can_buy_count - $cart_goods_quantity;
  208. if($can_buy_count <= 0)
  209. {
  210. $can_buy_count = -1;
  211. }
  212. }
  213. if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
  214. {
  215. $json['code'] =6;
  216. //$json['msg']='已经不能再买了';
  217. $json['msg']='您本次只能购买'.$goods_description['total_limit_count'].'个';
  218. $json['max_quantity'] = $goods_description['total_limit_count'];
  219. echo json_encode($json);
  220. die();
  221. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  222. {
  223. $json['code'] =6;
  224. $json['msg']='您还能购买'.$can_buy_count.'份';
  225. $json['max_quantity'] = $can_buy_count;
  226. echo json_encode($json);
  227. die();
  228. }
  229. //已加入购物车的总数
  230. if($goods_quantity<$quantity+$cart_goods_quantity){
  231. $json['code'] =3;
  232. if ($goods_quantity==0) {
  233. $json['msg']='已抢光';
  234. }else{
  235. // $json['msg']='商品数量不足,剩余'.$goods_quantity.'个!!';
  236. $json['msg']='商品数量不足';
  237. $json['max_quantity'] = $goods_quantity;
  238. }
  239. echo json_encode($json);
  240. die();
  241. }
  242. **/
  243. //开始生产订单 TODO...
  244. $payment = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  245. $data = array();
  246. $data['member_id']=$member_id;
  247. $data['name']= $payment['username'];
  248. $data['use_score']= 0;//是否使用积分抵扣
  249. $data['telephone']= '0000';
  250. $data['shipping_name']= '0000';
  251. $data['shipping_tel']= '0000';
  252. $data['shipping_address'] = '';
  253. $data['shipping_province_id']=0;
  254. $data['shipping_city_id']=0;
  255. $data['shipping_stree_id']=0;
  256. $data['shipping_country_id']=0;
  257. $data['shipping_method'] = 0;
  258. $data['delivery']='express';
  259. $data['pick_up_id']=$community_id;
  260. $data['ziti_name']='';
  261. $data['ziti_mobile']='';
  262. $data['payment_method']='yuer';
  263. $data['address_id']= 0;
  264. $data['voucher_id'] = 0;//目前都是平台券
  265. $data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
  266. $data['date_added']=time();
  267. $data['type'] = 'pintuan';
  268. $data['shipping_fare'] = 0;
  269. $goods_data = array();
  270. $goods_data[] = array(
  271. 'goods_id' => $product['id'],
  272. 'store_id' => 0,
  273. 'name' => $product['goodsname'],
  274. 'model' => '',
  275. 'is_pin' => 1,
  276. 'pin_id' => 0,
  277. 'header_disc' => 0,
  278. 'member_disc' => 0,
  279. 'level_name' => '',
  280. 'option' => '',
  281. 'quantity' => 1,
  282. 'shipping_fare' => 0,
  283. 'price' => $product['price'],
  284. 'card_price' => 0,
  285. 'costprice' => 0,
  286. 'total' => 0,
  287. 'card_total' => 0 ,
  288. 'is_take_vipcard' => 0,
  289. 'fenbi_li' => 0,
  290. 'can_man_jian' => 0,
  291. 'comment' => ''
  292. );
  293. $data['is_free_shipping_fare']= 0;
  294. $data['store_id']= 0;
  295. $data['order_goods_total_money']= 0;
  296. $data['goodss'] = $goods_data;
  297. $data['order_num_alias']=build_order_no($member_id);
  298. $data['voucher_credit'] = 0;
  299. $data['score_for_money'] = 0;
  300. $data['reduce_money'] = 0;
  301. $data['man_total_free'] = 0;
  302. $oid = D('Home/Frontorder')->addOrder($data);// D('Order')->addOrder($data);
  303. $o = array();
  304. $o['payment_code'] = 'yuer';
  305. $o['order_status_id'] = 2;
  306. $o['date_modified']=time();
  307. $o['pay_time']=time();
  308. $o['transaction_id'] = '余额支付';
  309. $o['type'] = 'ignore';
  310. //ims_
  311. M('lionfish_comshop_order')->where( array('order_id' => $oid ) )->save( $o );
  312. //更新到0元开团订单类型
  313. echo json_encode( array('code' => 0, 'order_id' => $oid ) );
  314. die();
  315. }
  316. }
  317. //end--
  318. public function add()
  319. {
  320. $gpc = I('request.');
  321. $data = array();
  322. $data['goods_id'] = $gpc['goods_id'];
  323. $data['community_id'] = $gpc['community_id'];
  324. $data['quantity'] = $gpc['quantity'];
  325. $data['sku_str'] = $gpc['sku_str'];
  326. $data['is_just_addcar'] = $gpc['is_just_addcar'];
  327. $data['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) :'';
  328. if($gpc['sku_str'] == 'undefined')
  329. {
  330. $gpc['sku_str'] = '';
  331. $data['sku_str'] = '';
  332. }
  333. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  334. if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
  335. {
  336. $pintuan_model_buy = 0;
  337. }
  338. $data['buy_type'] = $gpc['buy_type'];
  339. $data['pin_id'] = $gpc['pin_id'];
  340. $data['is_just_addcar'] = $gpc['is_just_addcar'];
  341. if( !isset($data['buy_type']) || empty($data['buy_type']) )
  342. {
  343. $data['buy_type'] = 'dan';
  344. }
  345. else if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
  346. {
  347. $data['buy_type'] = 'soitaire';
  348. }
  349. else if( !empty($data['buy_type']) && $data['buy_type'] == 'pindan' )
  350. {
  351. $data['buy_type'] = 'pindan';
  352. }else if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
  353. {
  354. $data['buy_type'] = 'pintuan';
  355. }
  356. else if( !empty($data['buy_type']) && $data['buy_type'] == 'presale' )
  357. {
  358. $data['buy_type'] = 'presale';
  359. }
  360. else if( !empty($data['buy_type']) && $data['buy_type'] == 'virtualcard' )
  361. {
  362. $data['buy_type'] = 'virtualcard';
  363. }
  364. else if( !empty($data['buy_type']) && $data['buy_type'] == 'integral' )
  365. {
  366. $data['buy_type'] = 'integral';
  367. }
  368. $token = $gpc['token'];
  369. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  370. $member_id = $weprogram_token['member_id'];
  371. $puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
  372. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  373. if( !empty($puis_not_buy) && $puis_not_buy ==1 )
  374. {
  375. if($member_info['level_id'] == 0)
  376. {
  377. $json['code'] =6;
  378. $json['msg']='普通会员不能购买!';
  379. echo json_encode($json);
  380. die();
  381. }
  382. }
  383. //1、判断是否开启审核,2、如果开启审核,判断会员状态是否审核
  384. $is_user_shenhe = D('Home/Front')->get_config_by_name('is_user_shenhe');
  385. //1
  386. if( isset($is_user_shenhe) && $is_user_shenhe == 1 )
  387. {
  388. if( $member_info['is_apply_state'] != 1 )
  389. {
  390. $json['code'] = 6;
  391. $json['msg'] = '会员未审核不能购买';
  392. echo json_encode( $json );
  393. die();
  394. }
  395. }
  396. //团长休息
  397. $community_id = $gpc['community_id'];
  398. $group_name = D('Home/Front')->get_config_by_name('group_name');
  399. if( isset($community_id) && $community_id > 0 )
  400. {
  401. $is_can_buy = D('Seller/Communityhead')-> check_goods_can_community($gpc['goods_id'], $community_id);
  402. if( !$is_can_buy )
  403. {
  404. $json['code'] =6;
  405. $json['msg']='此商品在您所属'.$group_name.'不可参与!';
  406. echo json_encode($json);
  407. die();
  408. }
  409. // is_all_sale
  410. }
  411. $is_just_addcar = empty($data['is_just_addcar']) ? 0: 1;
  412. $goods_id = $data['goods_id'];
  413. if( empty($member_id))
  414. {
  415. $result = array('code' =>4);
  416. echo json_encode($result);
  417. die();
  418. }
  419. if (isset($data['goods_id'])) {
  420. $goods_id = $data['goods_id'];
  421. } else {
  422. $goods_id = 0;
  423. }
  424. $product = M('lionfish_comshop_goods')->where( array('id' => $goods_id ) )->find();
  425. if( $product['grounding'] != 1)
  426. {
  427. $json['code'] =6;
  428. $json['msg']='商品已下架!';
  429. echo json_encode($json);
  430. die();
  431. }
  432. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
  433. //is_limit_levelunbuy
  434. //$is_default_levellimit_buy = D('Home/Front')->get_config_by_name('is_default_levellimit_buy');
  435. //isset($is_default_levellimit_buy) && $is_default_levellimit_buy == 1 &&
  436. if( $goods_description['is_limit_levelunbuy'] == 1 )
  437. {
  438. // member_id
  439. $mb_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id ) )->find();
  440. if( $mb_info['level_id'] == 0 )
  441. {
  442. $json['code'] =6;
  443. $json['msg']='默认等级不能购买,请联系客服';
  444. echo json_encode($json);
  445. die();
  446. }
  447. }
  448. //is_limit_vipmember_buy 付费会员专享
  449. //$is_default_vipmember_buy = D('Home/Front')->get_config_by_name('is_default_vipmember_buy');
  450. //isset($is_default_vipmember_buy) && $is_default_vipmember_buy == 1 &&
  451. if( $goods_description['is_limit_vipmember_buy'] == 1 )
  452. {
  453. $mb_vip = M('lionfish_comshop_member')->field('card_id,card_begin_time,card_end_time')->where( array('member_id' => $member_id ) )->find();
  454. //当前时间
  455. $present_time = time();
  456. if( $mb_vip['card_id'] == 0 || ( $present_time > $mb_vip['card_end_time'] ) )
  457. {
  458. $is_pop_vipmember_buytip = D('Home/Front')->get_config_by_name('is_pop_vipmember_buytip');
  459. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  460. $pop_vipmember_buyimage = D('Home/Front')->get_config_by_name('pop_vipmember_buyimage');
  461. $json['has_image'] = 0;
  462. $is_open_vipcard_buy = isset($is_open_vipcard_buy) ? $is_open_vipcard_buy : 0;
  463. if( isset($is_pop_vipmember_buytip) && $is_pop_vipmember_buytip ==1 )
  464. {
  465. if( isset($pop_vipmember_buyimage) && !empty($pop_vipmember_buyimage) )
  466. {
  467. $pop_vipmember_buyimage = tomedia($pop_vipmember_buyimage);
  468. $json['has_image'] = 1;
  469. $json['pop_vipmember_buyimage'] = $pop_vipmember_buyimage;
  470. }
  471. }
  472. $json['code'] =7;
  473. $json['msg']='付费会员专享,普通会员不能购买';
  474. echo json_encode($json);
  475. die();
  476. }
  477. }
  478. if( !empty($goods_description['is_new_buy']) && $goods_description['is_new_buy'] == 1)
  479. {
  480. $ck_buy_order = M('lionfish_comshop_order')->field('order_id')->where( "member_id={$member_id} and order_status_id in (1,4,6,7,10,11,12,14)" )->find();
  481. if( !empty($ck_buy_order) )
  482. {
  483. $json['code'] =6;
  484. $json['msg']='新人专享!';
  485. echo json_encode($json);
  486. die();
  487. }
  488. $is_new_buy_limit = D('Home/Front')->get_config_by_name('is_new_buy_limit');
  489. $new_buy_limit_num = D('Home/Front')->get_config_by_name('new_buy_limit_num');
  490. if(!empty($is_new_buy_limit) && $is_new_buy_limit == 1){//新人专享限制
  491. $goods_cate_count = D('Home/Car')->get_new_goods_count($token,$goods_id,$data['sku_str']);
  492. if($goods_cate_count >= $new_buy_limit_num){
  493. $json['code'] = 6;
  494. $json['msg']='超出新人专享限制!';
  495. echo json_encode($json);
  496. die();
  497. }
  498. }
  499. }
  500. //$data['community_id']
  501. if( $data['buy_type'] == 'dan' || $data['buy_type'] =='soitaire' || ($pintuan_model_buy ==1 && $data['buy_type'] != 'dan') )
  502. {
  503. $is_community = D('Seller/Communityhead')->is_community($data['community_id']);
  504. if( !$is_community )
  505. {
  506. $json['code'] =6;
  507. $json['msg']='该小区已经不存在!';
  508. echo json_encode($json);
  509. die();
  510. }
  511. }
  512. //判断是否积分兑换
  513. if( $product['type'] == 'integral')
  514. {
  515. //判断积分是否足够 member_id 暂时关闭以下代码
  516. $integral_model = D('Home/Integral');
  517. if (isset($data['quantity'])) {
  518. $quantity = $data['quantity'];
  519. } else {
  520. $quantity = 1;
  521. }
  522. if(intval($quantity) < 1){
  523. $json['code'] =6;
  524. $json['msg']='数量不能小于1!';
  525. echo json_encode($json);
  526. die();
  527. }
  528. $check_result = $integral_model->check_user_score_quantity_can_pay($member_id, $data['sku_str'], $goods_id,$quantity);
  529. if( $check_result['code'] == 1 )
  530. {
  531. $json['code'] =6;
  532. $json['msg']='剩余'.$check_result['cur_score'].'积分,积分不足!';
  533. echo json_encode($json);
  534. die();
  535. }
  536. /****/
  537. }
  538. //6
  539. if($is_just_addcar == 1)
  540. {
  541. if($product['pick_just'] > 0)
  542. {
  543. $json['code'] =6;
  544. $json['msg']='自提商品,请立即购买';
  545. echo json_encode($json);
  546. die();
  547. }
  548. }
  549. //商品存在
  550. if($product){
  551. $cart= D('Home/Car');
  552. if (isset($data['quantity'])) {
  553. $quantity = $data['quantity'];
  554. } else {
  555. $quantity = 1;
  556. }
  557. $option = array();
  558. if( !empty($data['sku_str'])){
  559. $option = explode('_', $data['sku_str']);
  560. }
  561. $car_prefix = "cart.";
  562. if( !empty($data['buy_type']) && $data['buy_type'] == 'pindan' )
  563. {
  564. $car_prefix = 'pindancart.';//cart.
  565. }
  566. else if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
  567. {
  568. $car_prefix = 'soitairecart.';
  569. }
  570. else if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
  571. {
  572. $car_prefix = 'pintuancart.';
  573. }
  574. else if( !empty($data['buy_type']) && $data['buy_type'] == 'presale' )
  575. {
  576. $car_prefix = 'presalecart.';
  577. }
  578. else if( !empty($data['buy_type']) && $data['buy_type'] == 'virtualcard' )
  579. {
  580. $car_prefix = 'virtualcardcart.';
  581. }
  582. else if( !empty($data['buy_type']) && $data['buy_type'] == 'integral' ){
  583. $car_prefix = 'integralcart.';
  584. }
  585. //$data['soli_id']
  586. if($data['is_just_addcar'] == 0){
  587. $cart_goods_quantity = 0;
  588. }else{
  589. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$car_prefix,$data['soli_id']);
  590. }
  591. $cart_goods_all_quantity = $cart->get_wecartall_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token,$car_prefix);
  592. $json=array('code' =>0);
  593. //$goods_model = D('Home/Goods');
  594. $goods_quantity=$cart->get_goods_quantity($goods_id);
  595. if(!empty($data['sku_str'])){
  596. $goods_option_item_value = M('lionfish_comshop_goods_option_item_value')->field('stock')->where(array('goods_id' =>$goods_id,'option_item_ids'=>$data['sku_str']))->find();
  597. if(!empty($goods_option_item_value)){
  598. $goods_quantity = $goods_option_item_value['stock'];
  599. }
  600. }
  601. //rela_goodsoption_valueid
  602. if($goods_quantity < $goods_description['goods_start_count']){
  603. $json['code'] =6;
  604. $json['msg']='起售数量'.$goods_description['goods_start_count'].',库存不足,剩余'.$goods_quantity.'个';
  605. $json['max_quantity'] = $goods_description['goods_start_count'];
  606. echo json_encode($json);
  607. die();
  608. }
  609. //起售数量判断
  610. if($quantity+$cart_goods_quantity < $goods_description['goods_start_count'])
  611. {
  612. $json['code'] = 6;
  613. $json['msg'] = $goods_description['goods_start_count'].'份起售';
  614. $json['max_quantity'] = $goods_description['goods_start_count'];
  615. echo json_encode($json);
  616. die();
  617. }
  618. //$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  619. /**
  620. //单次限购
  621. if(!empty($cart_goods_all_quantity) && $cart_goods_all_quantity > 0 && $data['buy_type'] != 'pintuan' )
  622. {
  623. if($goods_description['one_limit_count'] > 0 && $cart_goods_all_quantity >= $goods_description['one_limit_count'] )
  624. {
  625. $json['code'] =6;
  626. //$json['msg']='已经不能再买了';
  627. $json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'个';
  628. $json['max_quantity'] = $goods_description['one_limit_count'];
  629. echo json_encode($json);
  630. die();
  631. }
  632. $can_buy_count = $can_buy_count - $cart_goods_all_quantity;
  633. if($can_buy_count <= 0)
  634. {
  635. $can_buy_count = -1;
  636. }
  637. }
  638. //每单限购
  639. if($can_buy_count > 0 && $quantity > $can_buy_count)
  640. {
  641. $json['code'] =6;
  642. $json['msg']='您每次只能购买'.$can_buy_count.'份';
  643. $json['max_quantity'] = $can_buy_count;
  644. echo json_encode($json);
  645. die();
  646. }
  647. //每日限购 6
  648. $can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
  649. if ($goods_description['oneday_limit_count'] >0){
  650. if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && ($cart_goods_all_quantity+$quantity) > $can_buy_day_count))
  651. {
  652. $json['code'] =6;
  653. //$json['msg']='已经不能再买了';
  654. $json['msg']='您每天只能购买'.$goods_description['oneday_limit_count'].'个';
  655. $json['max_quantity'] = $goods_description['oneday_limit_count'];
  656. echo json_encode($json);
  657. die();
  658. }
  659. }
  660. //历史限购判断
  661. if($can_buy_count == -1 && $goods_description['total_limit_count'] >0)
  662. {
  663. $json['code'] =6;
  664. //$json['msg']='已经不能再买了';
  665. $json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
  666. $json['max_quantity'] = $goods_description['total_limit_count'];
  667. echo json_encode($json);
  668. die();
  669. }
  670. **/
  671. $can_buy_one_count = D('Home/Front')->check_goods_user_canbuy_one_count($member_id, $goods_id);
  672. /*$goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
  673. if($quantity < $goods_description['goods_start_count']){
  674. $json['code'] = 6;
  675. //$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
  676. $json['msg'] = $goods_description['goods_start_count'].'件起售';
  677. $json['max_quantity'] = $goods_description['goods_start_count'];
  678. echo json_encode($json);
  679. die();
  680. }*/
  681. //单次限购判断
  682. if($goods_description['one_limit_count'] > 0 && $quantity+$cart_goods_quantity > $goods_description['one_limit_count'])
  683. {
  684. $json['code'] = 6;
  685. //$json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
  686. $json['msg'] = '购物车总数已满或超出每次购买数量';
  687. $json['max_quantity'] = $goods_description['one_limit_count']-$cart_goods_all_quantity;
  688. echo json_encode($json);
  689. die();
  690. }
  691. $can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
  692. if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity > $can_buy_day_count))
  693. {
  694. $json['code'] =6;
  695. //$json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
  696. $json['msg'] = '购物车总数已满或超出每天购买数量';
  697. $json['max_quantity'] = $can_buy_day_count-$cart_goods_all_quantity;
  698. echo json_encode($json);
  699. die();
  700. }else if($can_buy_day_count > 0 && ($quantity+$cart_goods_quantity) > $can_buy_day_count){
  701. $json['code'] =6;
  702. //$json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
  703. $json['msg'] = '购物车总数已满或超出每天购买数量';
  704. $json['max_quantity']=$can_buy_day_count-$cart_goods_all_quantity;
  705. echo json_encode($json);
  706. die();
  707. }
  708. $can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
  709. if($data['buy_type'] == 'pintuan' || $data['buy_type'] == 'pindan' || $data['buy_type'] == 'presale'){
  710. $cart_goods_all_quantity = 0;
  711. }
  712. //历史限购判断
  713. if($can_buy_all_count == -1 && $goods_description['total_limit_count'] >0)
  714. {
  715. $json['code'] =6;
  716. //$json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'份';
  717. $json['msg'] = '购物车总数已满或超出历史购买数量';
  718. $json['max_quantity'] = 1;
  719. echo json_encode($json);
  720. die();
  721. }else if($can_buy_all_count > 0 && ($cart_goods_all_quantity+$quantity) > $can_buy_all_count){
  722. $json['code'] =6;
  723. $json['msg']='购物车总数已满或超出历史购买数量';
  724. $json['max_quantity'] = $can_buy_all_count-$cart_goods_all_quantity;
  725. echo json_encode($json);
  726. die();
  727. }
  728. //已加入购物车的总数
  729. if($goods_quantity < $quantity+$cart_goods_quantity){
  730. $json['code'] =3;
  731. if ($goods_quantity==0) {
  732. $json['msg']='已抢光';
  733. }else{
  734. $json['msg']='商品数量不足';
  735. $json['max_quantity'] = $goods_quantity;
  736. }
  737. echo json_encode($json);
  738. die();
  739. }
  740. if(!empty($option))
  741. {
  742. $mul_opt_arr = array();
  743. //ims_
  744. //$goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $data['sku_str']) )->find();
  745. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  746. if(!empty($open_redis_server) && $open_redis_server == 1)
  747. {
  748. $goods_option_mult_value_stock = D('Seller/Redisorder')->get_goods_sku_quantity($goods_id, $data['sku_str']);
  749. }else{
  750. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $data['sku_str']) )->find();
  751. }
  752. if( !empty($goods_option_mult_value_stock) )
  753. {
  754. if($goods_option_mult_value_stock<$quantity+$cart_goods_quantity){
  755. $json['code'] =3;
  756. $json['msg']='商品数量不足,剩余'.$goods_option_mult_value_stock.'个!!';
  757. $json['max_quantity'] = $goods_option_mult_value['stock'];
  758. echo json_encode($json);
  759. die();
  760. }
  761. }
  762. }
  763. //buy_type
  764. // $this->clear_all_cart(); $data['community_id']
  765. $format_data_array = array(
  766. 'quantity' => $quantity,
  767. 'community_id' => $data['community_id'],
  768. 'goods_id' => $goods_id,
  769. 'sku_str'=>$data['sku_str'],
  770. 'buy_type' =>$data['buy_type'],
  771. 'soli_id' => $data['soli_id']
  772. );
  773. //区分活动商品还是普通商品。做两个购物车,活动商品是需要直接购买的,单独购买商品加入正常的购物车TODO....
  774. //is_just_addcar 0 1
  775. if($data['buy_type'] == 'dan' && $is_just_addcar == 0)
  776. {
  777. //$cart->removedancar($token);
  778. //清空一下购物车
  779. //singledel
  780. $format_data_array['is_just_addcar'] = 0;
  781. $format_data_array['singledel'] = 1;
  782. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id']);
  783. $total=$cart->count_goodscar($token ,$data['community_id']);
  784. }
  785. else if($data['buy_type'] == 'dan' && $is_just_addcar == 1)
  786. {
  787. //singledel
  788. $format_data_array['is_just_addcar'] = 1;
  789. $format_data_array['singledel'] = 1;
  790. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id']);
  791. $total=$cart->count_goodscar($token, $data['community_id']);
  792. }
  793. else if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
  794. {
  795. //清理单独购买的商品
  796. $format_data_array['is_just_addcar'] = 1;
  797. $format_data_array['singledel'] = 1;
  798. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix,$data['soli_id']);
  799. $total=0;
  800. }
  801. else if( !empty($data['buy_type']) && $data['buy_type'] == 'pindan' )
  802. {
  803. //清理单独购买的商品
  804. $cart->removeActivityAllcar($token, 'pindancart.');
  805. $format_data_array['is_just_addcar'] = 0;
  806. $format_data_array['singledel'] = 1;
  807. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
  808. $total=0;
  809. }
  810. else if( !empty($data['buy_type']) && $data['buy_type'] == 'pintuan' )
  811. {
  812. $pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
  813. if( $pin_id > 0 )
  814. {
  815. $pin_info_tmp = M('lionfish_comshop_pin')->where( array('pin_id' => $pin_id ) )->find();
  816. if( !empty($pin_info_tmp) && $pin_info_tmp['is_newman_takein'] == 1 )
  817. {
  818. //检测是否新人
  819. //检测是否购买过
  820. $od_status = "1,2,4,6,7,8,9,10,11,12,14";
  821. $od_buy_count = M('lionfish_comshop_order')->where("order_status_id in ({$od_status}) and member_id=".$member_id)->count();
  822. if( !empty($od_buy_count) && $od_buy_count >0 )
  823. {
  824. $json['code'] =3;
  825. $json['msg']='新人专享';
  826. echo json_encode($json);
  827. die();
  828. }
  829. }
  830. }
  831. //清理拼团的商品
  832. $cart->removeActivityAllcar($token, 'pintuancart.');
  833. $format_data_array['is_just_addcar'] = 0;
  834. $format_data_array['singledel'] = 1;
  835. $format_data_array['pin_id'] = $pin_id;
  836. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
  837. $total=0;
  838. }
  839. else if( !empty($data['buy_type']) && $data['buy_type'] == 'presale' )
  840. {
  841. //清理预售的商品
  842. $cart->removeActivityAllcar($token, 'presalecart.');
  843. $format_data_array['is_just_addcar'] = 0;
  844. $format_data_array['singledel'] = 1;
  845. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
  846. $total=0;
  847. }
  848. else if( !empty($data['buy_type']) && $data['buy_type'] == 'virtualcard' )
  849. {
  850. //清理预售的商品
  851. $cart->removeActivityAllcar($token, 'virtualcardcart.');
  852. $format_data_array['is_just_addcar'] = 0;
  853. $format_data_array['singledel'] = 1;
  854. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
  855. $total=0;
  856. }
  857. else if( !empty($data['buy_type']) && $data['buy_type'] == 'integral' )
  858. {
  859. //清理拼团的商品 $data['pin_id']
  860. $cart->removeActivityAllcar($token, 'integralcart.');
  861. $format_data_array['is_just_addcar'] = 0;
  862. $format_data_array['singledel'] = 1;
  863. $cart->addwecar($token,$goods_id,$format_data_array,$data['sku_str'],$data['community_id'],$car_prefix);
  864. $total=0;
  865. }
  866. else {
  867. //buy_type:pin 活动购物车。
  868. $pin_id = isset($data['pin_id']) ? $data['pin_id'] : 0;
  869. //lottery
  870. if( $product['type'] == 'lottery' && $product['type'] == 'lottery' )
  871. {
  872. /**
  873. //等待把抽奖的活动打开
  874. $now_time = time();
  875. $lottery_goods_info = M('lottery_goods')->where( array('goods_id' => $goods_id) )->find();
  876. if($lottery_goods_info['end_time'] < $now_time)
  877. {
  878. $json['code'] =6;
  879. $json['msg']='抽奖活动已结束';
  880. echo json_encode($json);
  881. die();
  882. }
  883. **/
  884. }
  885. //检测商品是否老带新,新人才能参团
  886. if($pin_id > 0 )
  887. {
  888. //等待把老带新的活动打开
  889. /**
  890. if($product['type'] == 'newman')
  891. {
  892. $new_mamn_buy = $goods_model->check_goods_new_manbug($member_id);
  893. if($new_mamn_buy>0)
  894. {
  895. $json['code'] =5;
  896. $json['msg']='该商品只能新人参团';
  897. echo json_encode($json);
  898. die();
  899. }
  900. }
  901. **/
  902. }
  903. $format_data_array['pin_id'] = $pin_id;
  904. $cart->add_activitycar($token, $goods_id,$format_data_array,$data['sku_str']);
  905. $total=$cart->count_activitycar($token);
  906. }
  907. $carts = M('lionfish_comshop_car')->where( array('token' => $token,'community_id' => $data['community_id'],'carkey' => 'cart_total') )->find();
  908. if( !empty($data['buy_type']) && $data['buy_type'] == 'dan' )
  909. {
  910. if( !empty($carts) )
  911. {
  912. $car_data = array();
  913. $car_data['format_data'] = serialize(array('quantity' => $total));
  914. $car_data['modifytime'] = 1;
  915. M('lionfish_comshop_car')->where( array('token' => $token,'community_id' => $data['community_id'],'carkey' => 'cart_total') )->save($car_data);
  916. } else{
  917. $car_data = array();
  918. $car_data['token'] = $token;
  919. $car_data['community_id'] = $data['community_id'];
  920. $car_data['carkey'] = 'cart_total';
  921. $car_data['format_data'] = serialize(array('quantity' => $total));
  922. M('lionfish_comshop_car')->add($car_data);
  923. }
  924. }
  925. //session('cart_total',$total);
  926. $json ['code'] = 1;
  927. if( $data['buy_type'] != 'dan' )
  928. {
  929. $json ['code'] = 2;
  930. }
  931. $json['success']='成功加入购物车!!';
  932. $json['total']=$total;
  933. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token , $car_prefix);
  934. $json['cur_count']=$cart_goods_quantity;
  935. //soitaire
  936. $is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
  937. $json['is_limit_distance_buy']=$is_limit_distance_buy;
  938. $json['goods_total_count'] = 0;
  939. if( !empty($data['buy_type']) && $data['buy_type'] == 'soitaire' )
  940. {
  941. $json['goods_total_count'] = $cart->get_wecart_goods_solicount($goods_id, $data['community_id'],$token, $data['soli_id'] );
  942. $cart_goods_quantity = $cart->get_wecart_goods($goods_id,$data['sku_str'],$data['community_id'] ,$token , $car_prefix, $data['soli_id']);
  943. $json['cur_count']=$cart_goods_quantity;
  944. }
  945. echo json_encode($json);
  946. die();
  947. }
  948. }
  949. //显示购物车中商品列表
  950. function show_cart_goods(){
  951. $gpc = I('request.');
  952. $token = $gpc['token'];
  953. $community_id = $gpc['community_id'];
  954. $soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
  955. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  956. $member_id = $weprogram_token['member_id'];
  957. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  958. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  959. $modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
  960. $is_vip_card_member = 0;
  961. $is_member_level_buy = 0;
  962. if( $member_id > 0 )
  963. {
  964. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  965. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  966. {
  967. $now_time = time();
  968. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  969. {
  970. $is_vip_card_member = 1;//还是会员
  971. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  972. $is_vip_card_member = 2;//已过期
  973. }
  974. }
  975. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  976. {
  977. $is_member_level_buy = 1;
  978. }
  979. }
  980. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type']: 'dan';
  981. if( empty($member_id) )
  982. {
  983. //需要登录
  984. echo json_encode( array('code' =>5) );
  985. die();
  986. }
  987. $cart = D('Home/Car');
  988. $goods = $cart->get_all_goodswecar($buy_type, $token, 0, $community_id,$soli_id);
  989. $seller_goodss = array();
  990. $seller_goodss_mult = array();
  991. //is_only_express
  992. $tp_ar = array();
  993. foreach($goods as $key => $val)
  994. {
  995. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  996. //$seller_goodss[ $goods_store_field['store_id'] ]['goods'][$key] = $val;
  997. $supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
  998. if($supply_id > 0)
  999. {
  1000. $supply_info = D('Home/Front')->get_supply_info($supply_id);
  1001. if($supply_info['type'] ==0)
  1002. {
  1003. $supply_id = 0;
  1004. }
  1005. }
  1006. $seller_goodss[ $supply_id ]['goods'][$key] = $val;
  1007. $tp_ar[] = $val['is_only_express'];
  1008. $seller_goodss_mult[$val['is_only_express']][ $supply_id ]['goods'][$key] = $val;//new 0719
  1009. }
  1010. $ck_goodstype_count = 0;
  1011. $vipcard_save_money = 0;
  1012. $level_save_money = 0;
  1013. //$max_can_orderbuy_money = 0 ;
  1014. foreach($seller_goodss_mult as $key => $seller_goodss_tp)
  1015. {
  1016. foreach($seller_goodss_tp as $store_id => $val)
  1017. {
  1018. //total
  1019. $seller_voucher_list = array();
  1020. $seller_total_fee = 0;
  1021. $total_trans_free = 0;
  1022. $tmp_goods = array();
  1023. $is_store_ck = false;
  1024. foreach($val['goods'] as $kk =>$d_goods)
  1025. {
  1026. $seller_total_fee += $d_goods['total'];
  1027. $total_trans_free += $d_goods[$kk]['trans_free'];
  1028. $val['goods'][$kk] = $d_goods;
  1029. $tp_val = array();
  1030. $tp_val['id'] = $d_goods['goods_id'];
  1031. $tp_val['key'] = $d_goods['key'];
  1032. if($d_goods['singledel'] == 1)
  1033. {
  1034. $tp_val['isselect'] = true;
  1035. $is_store_ck = true;
  1036. $ck_goodstype_count++;
  1037. if($d_goods['is_take_vipcard'] == 1)
  1038. {
  1039. $vipcard_save_money = $d_goods['total'] - $d_goods['card_total'];
  1040. }else if($d_goods['is_mb_level_buy'] == 1 ){
  1041. $level_save_money = $d_goods['total'] - $d_goods['level_total'];
  1042. }
  1043. } else {
  1044. $tp_val['isselect'] = false;
  1045. }
  1046. $tp_val['imgurl'] = $d_goods['image'];
  1047. $tp_val['edit'] = 'inline';
  1048. $tp_val['title'] = htmlspecialchars_decode($d_goods['name']);
  1049. $tp_val['finish'] = 'none';
  1050. $tp_val['description'] = 'description';
  1051. $option_arr = array();
  1052. $option_str = "";
  1053. foreach($d_goods['option'] as $option_val)
  1054. {
  1055. //$option_arr[] = $option_val['name'].':'.$option_val['value'];
  1056. $option_arr[] = $option_val['value'];
  1057. }
  1058. if(!empty($option_arr))
  1059. {
  1060. $option_str = implode(';', $option_arr);
  1061. }
  1062. $tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
  1063. $tp_val['option_can_buy'] = D('Home/Pingoods')->get_goods_option_can_buy( $d_goods['goods_id'], $d_goods['sku_str']);
  1064. $tp_val['goodstype'] = $option_str;
  1065. $tp_val['goodstypeedit'] = $option_str;
  1066. $tp_val['goodsnum'] = $d_goods['quantity'];
  1067. $tp_val['can_man_jian'] = $d_goods['can_man_jian'];
  1068. $tp_val['max_quantity'] = $d_goods['max_quantity'];
  1069. $tp_val['cartype'] = 'inline';
  1070. $tp_val['currntprice'] = $d_goods['price'];
  1071. $tp_val['card_price'] = $d_goods['card_price'];
  1072. $tp_val['levelprice'] = $d_goods['levelprice'];// 会员等级价格
  1073. $tp_val['is_mb_level_buy'] = $d_goods['is_mb_level_buy'];//是否可以会员等级价格购买
  1074. $tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
  1075. $tp_val['price'] = $d_goods['shop_price'];
  1076. $tp_val['is_new_buy'] = $d_goods['is_new_buy'];
  1077. $tp_val['goods_start_count'] = $d_goods['goods_start_count'];
  1078. $tp_val['store_id'] = $store_id;
  1079. $tmp_goods[] = $tp_val;
  1080. }
  1081. //$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
  1082. //$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
  1083. $store_info = array('s_true_name' => '','s_id' => 1);
  1084. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  1085. if( !empty($s_logo) )
  1086. {
  1087. $s_logo = tomedia($s_logo);
  1088. }
  1089. $val['store_info'] = $store_info;
  1090. $store_data = array();
  1091. $store_data['id'] = $store_info['s_id'];
  1092. if($is_store_ck)
  1093. {
  1094. $store_data['isselect'] = true;
  1095. } else {
  1096. $store_data['isselect'] = false;
  1097. }
  1098. $store_data['shopname'] = $store_info['s_true_name'];
  1099. $store_data['caredit'] = 'inline';
  1100. $store_data['finish'] = 'none';
  1101. $store_data['count'] = '0.00';
  1102. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1103. $full_money = D('Home/Front')->get_config_by_name('full_money');
  1104. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  1105. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  1106. {
  1107. $is_open_fullreduction = 0;
  1108. }
  1109. $store_data['is_open_fullreduction'] = $is_open_fullreduction;
  1110. $store_data['full_money'] = $full_money;
  1111. $store_data['full_reducemoney'] = $full_reducemoney;
  1112. $store_data['goodstype'] = 2;
  1113. $store_data['goodstypeselect'] = 0;
  1114. $store_data['shopcarts'] = $tmp_goods;
  1115. //起送价格
  1116. $localtown_moneytype_fixed_deliverymoney = 0;
  1117. //达到金额免配送费
  1118. $localtown_moneytype_fixed_freemoney = 0;
  1119. $localtown_fixed_list = array();
  1120. if($key == 3){//同城配送商品
  1121. $storename = "";
  1122. if($store_id == 0){
  1123. //配送费类型:0、固定金额,1、按距离收取
  1124. $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
  1125. if($localtown_delivery_moneytype == 0){
  1126. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
  1127. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
  1128. }
  1129. $storename = "平台";
  1130. }else{
  1131. $isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$store_id);
  1132. //配送费类型:0、固定金额,1、按距离收取
  1133. $localtown_delivery_moneytype = D('Home/Front')->get_supply_config_by_name('localtown_delivery_moneytype',$store_id);
  1134. if($isopen_localtown_delivery == 1 && $localtown_delivery_moneytype == 0){
  1135. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_deliverymoney',$store_id);
  1136. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_freemoney',$store_id);
  1137. }
  1138. $supply_info_data = M('lionfish_comshop_supply')->field('storename')->where( array('id' => $store_id) )->find();
  1139. $storename = $supply_info_data['storename'];
  1140. }
  1141. $localtown_fixed_list['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
  1142. //if($localtown_moneytype_fixed_deliverymoney > $max_can_orderbuy_money){
  1143. //获取起送最大下单金额限制
  1144. //$max_can_orderbuy_money = $localtown_moneytype_fixed_deliverymoney;
  1145. //}
  1146. $localtown_fixed_list['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
  1147. $localtown_fixed_list['store_name'] = $storename;
  1148. }else if($key == 2){
  1149. if($store_id == 0){
  1150. $storename = "平台";
  1151. }else{
  1152. $supply_info_data = M('lionfish_comshop_supply')->field('storename')->where( array('id' => $store_id) )->find();
  1153. $storename = $supply_info_data['storename'];
  1154. }
  1155. $localtown_fixed_list['store_name'] = $storename;
  1156. }
  1157. $store_data['localtown_fixed_list'] = $localtown_fixed_list;
  1158. $seller_goodss_tp[$store_id] = $store_data;
  1159. $i++;
  1160. }
  1161. $seller_goodss_mult[$key] = $seller_goodss_tp;
  1162. }
  1163. foreach($seller_goodss as $store_id => $val)
  1164. {
  1165. //total
  1166. $seller_voucher_list = array();
  1167. $seller_total_fee = 0;
  1168. $total_trans_free = 0;
  1169. $tmp_goods = array();
  1170. $is_store_ck = false;
  1171. foreach($val['goods'] as $kk =>$d_goods)
  1172. {
  1173. $seller_total_fee += $d_goods['total'];
  1174. $total_trans_free += $d_goods[$kk]['trans_free'];
  1175. $val['goods'][$kk] = $d_goods;
  1176. $tp_val = array();
  1177. $tp_val['id'] = $d_goods['goods_id'];
  1178. $tp_val['key'] = $d_goods['key'];
  1179. if($d_goods['singledel'] == 1)
  1180. {
  1181. $tp_val['isselect'] = true;
  1182. $is_store_ck = true;
  1183. $ck_goodstype_count++;
  1184. } else {
  1185. $tp_val['isselect'] = false;
  1186. }
  1187. $tp_val['imgurl'] = $d_goods['image'];
  1188. $tp_val['edit'] = 'inline';
  1189. $tp_val['title'] = $d_goods['name'];
  1190. $tp_val['finish'] = 'none';
  1191. $tp_val['description'] = 'description';
  1192. $option_arr = array();
  1193. $option_str = "";
  1194. foreach($d_goods['option'] as $option_val)
  1195. {
  1196. //$option_arr[] = $option_val['name'].':'.$option_val['value'];
  1197. $option_arr[] = $option_val['value'];
  1198. }
  1199. if(!empty($option_arr))
  1200. {
  1201. $option_str = implode(';', $option_arr);
  1202. }
  1203. $tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
  1204. $tp_val['goodstype'] = $option_str;
  1205. $tp_val['goodstypeedit'] = $option_str;
  1206. $tp_val['goodsnum'] = $d_goods['quantity'];
  1207. $tp_val['can_man_jian'] = $d_goods['can_man_jian'];
  1208. $tp_val['max_quantity'] = $d_goods['max_quantity'];
  1209. $tp_val['cartype'] = 'inline';
  1210. $tp_val['currntprice'] = $d_goods['price'];
  1211. $tp_val['price'] = $d_goods['shop_price'];
  1212. $tp_val['card_price'] = $d_goods['card_price'];
  1213. $tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
  1214. $tp_val['is_new_buy'] = $d_goods['is_new_buy'];
  1215. $tmp_goods[] = $tp_val;
  1216. }
  1217. //$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
  1218. //$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
  1219. $store_info = array('s_true_name' => '','s_id' => 1);
  1220. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  1221. if( !empty($s_logo) )
  1222. {
  1223. $s_logo = tomedia($s_logo);
  1224. }
  1225. $val['store_info'] = $store_info;
  1226. $store_data = array();
  1227. $store_data['id'] = $store_info['s_id'];
  1228. if($is_store_ck)
  1229. {
  1230. $store_data['isselect'] = true;
  1231. } else {
  1232. $store_data['isselect'] = false;
  1233. }
  1234. $store_data['shopname'] = $store_info['s_true_name'];
  1235. $store_data['caredit'] = 'inline';
  1236. $store_data['finish'] = 'none';
  1237. $store_data['count'] = '0.00';
  1238. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1239. $full_money = D('Home/Front')->get_config_by_name('full_money');
  1240. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  1241. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  1242. {
  1243. $is_open_fullreduction = 0;
  1244. }
  1245. $store_data['is_open_fullreduction'] = $is_open_fullreduction;
  1246. $store_data['full_money'] = $full_money;
  1247. $store_data['full_reducemoney'] = $full_reducemoney;
  1248. $store_data['goodstype'] = 2;
  1249. $store_data['goodstypeselect'] = 0;
  1250. $store_data['shopcarts'] = $tmp_goods;
  1251. $seller_goodss[$store_id] = $store_data;
  1252. $i++;
  1253. }
  1254. // 商家是否休息
  1255. $is_comunity_rest = D('Seller/Communityhead')->is_community_rest($community_id);
  1256. $open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
  1257. $man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
  1258. //if($man_orderbuy_money > $max_can_orderbuy_money){
  1259. //$max_can_orderbuy_money = $man_orderbuy_money;
  1260. //}
  1261. $is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_guess_like');
  1262. // 免配送 man_free_tuanzshipping>0开启
  1263. $delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
  1264. $delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
  1265. $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
  1266. $man_free_tuanzshipping = $delivery_tuanz_money = 0;
  1267. //暂时屏蔽,2020.02.13.14:57
  1268. /**
  1269. if($delivery_type_ziti!=1 && $delivery_type_express!=1 && $delivery_type_tuanz==1) {
  1270. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  1271. if($man_free_tuanzshipping>1 && !empty($man_free_tuanzshipping)) {
  1272. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  1273. }
  1274. }
  1275. **/
  1276. if($delivery_type_tuanz==1) {
  1277. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  1278. }else{
  1279. $man_free_tuanzshipping = 0;
  1280. }
  1281. $open_tuan_ship = $delivery_type_tuanz;
  1282. //团长自定义配送开关
  1283. if($community_id&&$man_free_tuanzshipping>1) {
  1284. $community_modify_shipping = M('lionfish_community_head')->field('is_modify_shipping_method')->where( array('id' => $community_id) )->find();
  1285. $is_modify_shipping_method = $community_modify_shipping['is_modify_shipping_method'];
  1286. if($is_modify_shipping_method==1) {
  1287. $open_tuan_ship = 1;
  1288. } else if($is_modify_shipping_method==2){
  1289. $open_tuan_ship = 0;
  1290. }
  1291. }
  1292. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  1293. $shopcar_tab_all_name = D('Home/Front')->get_config_by_name('shopcar_tab_all_name');
  1294. $shopcar_tab_express_name = D('Home/Front')->get_config_by_name('shopcar_tab_express_name');
  1295. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1296. if($is_open_fullreduction){
  1297. $full_list = D('Home/Front')->get_fullreduction();
  1298. }else{
  1299. $full_list[0]['full_money']= 0 ;
  1300. $full_list[0]['full_reducemoney']= 0 ;
  1301. }
  1302. //同城配送信息
  1303. //配送费类型:0、固定金额,1、按距离收取
  1304. $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
  1305. $localtown_moneytype_fixed_deliverymoney = 0;
  1306. $localtown_moneytype_fixed_freemoney = 0;
  1307. if($localtown_delivery_moneytype == 0){
  1308. //起送价格
  1309. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
  1310. //达到金额免配送费
  1311. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
  1312. }
  1313. $need_data = array();
  1314. $need_data['code'] = 0;
  1315. $need_data['carts'] = $seller_goodss;
  1316. $need_data['mult_carts'] = $seller_goodss_mult;
  1317. $need_data['is_comunity_rest'] = $is_comunity_rest;
  1318. $need_data['open_man_orderbuy'] = $open_man_orderbuy;
  1319. $need_data['man_orderbuy_money'] = $man_orderbuy_money;
  1320. //$need_data['max_can_orderbuy_money'] = $max_can_orderbuy_money;
  1321. $need_data['is_show_guess_like'] = $is_show_guess_like;
  1322. $need_data['man_free_tuanzshipping'] = $man_free_tuanzshipping;
  1323. $need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
  1324. $need_data['is_member_level_buy'] = $is_member_level_buy;//当前会员折扣 购买,1是,0否
  1325. $need_data['level_save_money'] = $level_save_money;//会员折扣省的钱
  1326. $need_data['is_vip_card_member'] = $is_vip_card_member;//当前会员是否是 会员卡会员 0 不是,1是,2已过期
  1327. $need_data['vipcard_save_money'] = $vipcard_save_money;//vip能节约的金额
  1328. $need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy;//vip能节约的金额
  1329. $need_data['modify_vipcard_name'] = $modify_vipcard_name;
  1330. $need_data['shopcar_tab_all_name'] = $shopcar_tab_all_name;
  1331. $need_data['shopcar_tab_express_name'] = $shopcar_tab_express_name;
  1332. $need_data['open_tuan_ship'] = $open_tuan_ship;
  1333. $need_data['is_open_fullreduction'] = $is_open_fullreduction;
  1334. $need_data['full_list'] = $full_list;
  1335. //平台和供应商 起送价格和免配送费价格
  1336. //$need_data['localtown_fixed_list'] = $localtown_fixed_list;
  1337. $need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;//起送价格
  1338. $need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;//达到金额免配送费
  1339. echo json_encode( $need_data );
  1340. die();
  1341. }
  1342. public function checkout_flushall()
  1343. {
  1344. $gpc = I('request.');
  1345. $token = $gpc['token'];
  1346. $community_id = $gpc['community_id'];
  1347. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1348. $member_id = $weprogram_token['member_id'];
  1349. //dan soitaire
  1350. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  1351. //$car_prefix = 'soitairecart.';
  1352. //buy_type和soli_id吗
  1353. $is_community = D('Seller/Communityhead')->is_community($community_id);
  1354. if( !$is_community )
  1355. {
  1356. $json['code'] =6;
  1357. $json['msg']='该小区已经不存在!';
  1358. echo json_encode($json);
  1359. die();
  1360. }
  1361. $data = array();
  1362. $data['car_key'] = $gpc['car_key'];
  1363. $data['all_keys_arr'] = $gpc['all_keys_arr'];
  1364. $data['cur_car_key'] = $gpc['cur_car_key'];
  1365. //car_key:cart.6:MTc0:,cart.13:MjcwXzI3Mw==:
  1366. //all_keys_arr:cart.6:MTc0:_1,cart.13:MjcwXzI3Mw==:_1
  1367. $car_key = explode(',', $data['car_key']);
  1368. $all_keys_arr = explode(',', $data['all_keys_arr']) ;
  1369. if(!empty($data['cur_car_key'])){
  1370. $car_key = array($data['cur_car_key']);
  1371. }
  1372. $save_keys = array();
  1373. if(!empty($all_keys_arr)){
  1374. foreach($all_keys_arr as $val)
  1375. {
  1376. $tmp_val = explode('_', $val);
  1377. $save_keys[ $tmp_val[0] ] = $tmp_val[1];
  1378. }
  1379. }
  1380. if( $buy_type == 'dan')
  1381. {
  1382. $all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'cart.%'")->select();
  1383. }else if( $buy_type == 'soitaire' ){
  1384. $all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'soitairecart.%'")->select();
  1385. }
  1386. if(!empty($all_cart))
  1387. {
  1388. foreach($all_cart as $val)
  1389. {
  1390. $tmp_format_data = unserialize($val['format_data']);
  1391. $tmp_format_data['singledel'] = 0;
  1392. $tmp_format_data['quantity'] = isset( $save_keys[$val['carkey']] ) ? $save_keys[$val['carkey']] : $tmp_format_data['quantity'];
  1393. M('lionfish_comshop_car')->where( array('id' => $val['id'] ,'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
  1394. }
  1395. }
  1396. if(!empty($car_key)){
  1397. foreach( $car_key as $key )
  1398. {
  1399. $car_info = M('lionfish_comshop_car')->where( array('community_id' => $community_id,'carkey' => $key ,'token' => $token) )->find();
  1400. if( !empty($car_info) )
  1401. {
  1402. $tmp_format_data = unserialize($car_info['format_data']);
  1403. $tmp_format_data['singledel'] = 1;
  1404. $quantity = $tmp_format_data['quantity'];
  1405. $sku_quantity_one = $tmp_format_data['quantity'];
  1406. $goods_id = $tmp_format_data['goods_id'];
  1407. $sku_str = $tmp_format_data['sku_str'];
  1408. //同一个商品不同规格 总数量合计
  1409. $sku_quantity = $this->_check_goods_sku_quantity($community_id,$key,$token);
  1410. if($sku_quantity > $quantity) {
  1411. $quantity = $sku_quantity;
  1412. }
  1413. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'goods_start_count');
  1414. //起售数量判断
  1415. if($sku_quantity_one < $goods_description['goods_start_count'])
  1416. {
  1417. $json['code'] = 6;
  1418. $json['msg'] = $goods_description['goods_start_count'].'份起售';
  1419. $json['max_quantity'] = $goods_description['goods_start_count'];
  1420. echo json_encode( $json );
  1421. die();
  1422. }
  1423. $check_json = $this->_check_can_buy($member_id, $goods_id,$quantity);
  1424. if($check_json['code'] != 0)
  1425. {
  1426. $tmp_format_data['quantity'] = $check_json['count'];
  1427. M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
  1428. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  1429. die();
  1430. }
  1431. //check sku is ok
  1432. $check_json = $this->_check_goods_sku_canbuy($goods_id,$sku_str);
  1433. if($check_json['code'] != 0)
  1434. {
  1435. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  1436. die();
  1437. }
  1438. $check_json = $this->_check_goods_quantity($goods_id,$sku_quantity_one,$sku_str);
  1439. if($check_json['code'] != 0)
  1440. {
  1441. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  1442. die();
  1443. }
  1444. M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
  1445. }
  1446. }
  1447. }
  1448. $is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
  1449. echo json_encode( array('code' => 0, 'data' => $is_limit_distance_buy) );
  1450. die();
  1451. }
  1452. public function _check_goods_sku_quantity($community_id,$key,$token){
  1453. $quantity = 0;
  1454. $key_array = explode(":",$key);
  1455. $key_result = "";
  1456. foreach($key_array as $k=>$v){
  1457. if($k < 2){
  1458. if(empty($key_result)){
  1459. $key_result = $v;
  1460. }else{
  1461. $key_result = $key_result.":".$v;
  1462. }
  1463. }
  1464. }
  1465. $sql = "SELECT format_data FROM ".C('DB_PREFIX')."lionfish_comshop_car "
  1466. . " WHERE carkey LIKE '".$key_result."%' and community_id = '".$community_id."' "
  1467. . " and token='".$token."'";
  1468. $cart_goods_list = M()->query($sql);
  1469. if(!empty($cart_goods_list)){
  1470. foreach($cart_goods_list as $val)
  1471. {
  1472. $tmp_format_data = unserialize($val['format_data']);
  1473. $quantity = $quantity + $tmp_format_data['quantity'];
  1474. }
  1475. }
  1476. return $quantity;
  1477. }
  1478. public function _check_goods_sku_canbuy($goods_id,$sku_str)
  1479. {
  1480. $json = array('code' => 0);
  1481. $goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where( array('id' => $goods_id ) )->find();
  1482. if(!empty($sku_str))
  1483. {
  1484. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where( array('option_item_ids' => $sku_str,'goods_id' => $goods_id) )->find();
  1485. if( empty($goods_option_mult_value) )
  1486. {
  1487. $json['code'] =3;
  1488. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').',规格已失效,删除后再结算';
  1489. }
  1490. }
  1491. return $json;
  1492. }
  1493. public function del_car_goods()
  1494. {
  1495. $gpc = I('request.');
  1496. $token = $gpc['token'];
  1497. $community_id = $gpc['community_id'];
  1498. $carkey = $gpc['carkey'];
  1499. M('lionfish_comshop_car')->where( "community_id={$community_id} and token='{$token}' and carkey='{$carkey}'" )->delete();
  1500. echo json_encode( array('code' => 0) );
  1501. die();
  1502. }
  1503. public function _check_goods_quantity($goods_id,$quantity,$sku_str)
  1504. {
  1505. $gpc = I('request.');
  1506. $goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where( array('id' => $goods_id) )->find();
  1507. $goods_quantity= D('Home/Car')->get_goods_quantity($goods_id);
  1508. $json = array('code' => 0);
  1509. if($goods_quantity<$quantity){
  1510. $json['code'] =3;
  1511. $json['msg']= mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_quantity.'个!!';
  1512. }else if(!empty($sku_str)){
  1513. $mul_opt_arr = array();
  1514. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->field('stock as quantity')->where( array('option_item_ids' => $sku_str,'goods_id' => $goods_id) )->find();
  1515. if( !empty($goods_option_mult_value) )
  1516. {
  1517. if($goods_option_mult_value['quantity']<$quantity){
  1518. $json['code'] =3;
  1519. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_option_mult_value['quantity'].'个!!';
  1520. }
  1521. }
  1522. }
  1523. return $json;
  1524. }
  1525. private function _check_can_buy($member_id, $goods_id,$quantity)
  1526. {
  1527. $gpc = I('request.');
  1528. //$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  1529. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count,oneday_limit_count,is_new_buy,is_limit_levelunbuy,is_limit_vipmember_buy,goods_start_count');
  1530. //单次限购判断
  1531. if($goods_description['one_limit_count'] > 0 && $quantity > $goods_description['one_limit_count'])
  1532. {
  1533. $json['code'] = 6;
  1534. $json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
  1535. $json['count'] = $goods_description['one_limit_count'];
  1536. return $json;
  1537. }
  1538. $can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
  1539. if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity >$can_buy_day_count))
  1540. {
  1541. $json['code'] =6;
  1542. $json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
  1543. $json['count']=1;
  1544. return $json;
  1545. }else if($can_buy_day_count > 0 && $quantity > $can_buy_day_count){
  1546. $json['code'] =6;
  1547. $json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
  1548. $json['count']=$can_buy_day_count;
  1549. return $json;
  1550. }
  1551. $can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
  1552. //历史限购判断
  1553. if($can_buy_all_count == -1 && $goods_description['total_limit_count'] >0)
  1554. {
  1555. $json['code'] =6;
  1556. $json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'个';
  1557. $json['count'] = 1;
  1558. return $json;
  1559. }else if($can_buy_all_count > 0 && $quantity > $can_buy_all_count)
  1560. {
  1561. $json['code'] =6;
  1562. $json['msg']='您还能购买'.$can_buy_all_count.'份';
  1563. $json['count'] = $can_buy_all_count;
  1564. return $json;
  1565. }
  1566. $goods_info = M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->find();
  1567. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'per_number');
  1568. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  1569. $json = array();
  1570. if($can_buy_count == -1 || $can_buy_day_count == -1)
  1571. {
  1572. $json['code'] =6;
  1573. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您本次只能购买'.$goods_description['per_number'].'个';
  1574. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  1575. {
  1576. $json['code'] =6;
  1577. //$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您还能购买'.$can_buy_count.'份';
  1578. $json['msg']='本次最多购买'.$can_buy_count.'份';
  1579. $json['count']=$can_buy_count;
  1580. }else{
  1581. $json['code'] = 0;
  1582. }
  1583. return $json;
  1584. }
  1585. private function _add_address($token,$userName,$telNumber,$provinceName,$cityName, $countyName,$detailInfo,$latitude='',$longitude='',$lou_meng_hao='')
  1586. {
  1587. $_GPC = I('request.');
  1588. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1589. $member_id = $weprogram_token['member_id'];
  1590. // lionfish_comshop_area
  1591. $province_info = M('lionfish_comshop_area')->where("name like '%{$provinceName}%' ")->find();
  1592. if( !empty($province_info))
  1593. {
  1594. $province_id = $province_info['id'];
  1595. }else{
  1596. $area_data = array();
  1597. $area_data['name'] = $provinceName;
  1598. $area_data['pid'] = 0;
  1599. $area_data['code'] = $max_dp['code']+1;
  1600. $province_id = M('lionfish_comshop_area')->add($area_data);
  1601. $up_data = array();
  1602. $up_data['code'] = $province_id;
  1603. M('lionfish_comshop_area')->where( array('id' => $province_id ) )->save($up_data);
  1604. }
  1605. $guding_arr = ['鞍山市'];
  1606. if( in_array($cityName , $guding_arr) )
  1607. {
  1608. $city_info = M('lionfish_comshop_area')->where("name = '{$cityName}'")->find();
  1609. }else{
  1610. $city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
  1611. }
  1612. //$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
  1613. if( !empty($city_info))
  1614. {
  1615. $city_id = $city_info['id'];
  1616. }else{
  1617. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  1618. $area_data = array();
  1619. $area_data['name'] = $cityName;
  1620. $area_data['pid'] = $province_id;
  1621. $area_data['code'] = $max_dp['code']+1;
  1622. $city_id = M('lionfish_comshop_area')->add( $area_data);
  1623. $up_data = array();
  1624. $up_data['code'] = $city_id;
  1625. M('lionfish_comshop_area')->where( array('id' => $city_id ) )->save($up_data);
  1626. }
  1627. //city_name: 东莞市
  1628. if( empty($countyName) )
  1629. {
  1630. if( $cityName == '东莞市' )
  1631. {
  1632. $countyName = '东莞';
  1633. }
  1634. if( $cityName == '中山市' )
  1635. {
  1636. $countyName = '中山';
  1637. //453
  1638. }
  1639. }
  1640. $country_info = M('lionfish_comshop_area')->where( "name like '%{$countyName}%' " )->find();
  1641. if( $countyName == '中山' )
  1642. {
  1643. $country_info = M('lionfish_comshop_area')->where( array('id' => 453 ) )->find();
  1644. //
  1645. }
  1646. if( !empty($country_info))
  1647. {
  1648. $country_id = $country_info['id'];
  1649. }else{
  1650. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  1651. $area_data = array();
  1652. $area_data['name'] = $countyName;
  1653. $area_data['pid'] = $city_id;
  1654. $area_data['code'] = $max_dp['code']+1;
  1655. $country_id = M('lionfish_comshop_area')->add( $area_data );
  1656. $up_data = array();
  1657. $up_data['code'] = $country_id;
  1658. M('lionfish_comshop_area')->where( array('id' => $country_id ) )->save( $up_data );
  1659. }
  1660. $address_param = array();
  1661. $address_param['member_id'] = $member_id;
  1662. $address_param['province_id'] = $province_id;
  1663. $address_param['country_id'] = $country_id;
  1664. $address_param['city_id'] = $city_id;
  1665. $address_param['address'] = $detailInfo;
  1666. $address_param['name'] = $userName;
  1667. $address_param['telephone'] = $telNumber;
  1668. $address_param['lon_lat'] = '';
  1669. $address_param['lou_meng_hao'] = $lou_meng_hao;
  1670. if(!empty($latitude))
  1671. {
  1672. $address_param['lon_lat'] = $longitude.','.$latitude;
  1673. }
  1674. $has_addre = M('lionfish_comshop_address')->where($address_param)->find();
  1675. if(empty($has_addre))
  1676. {
  1677. $has_default_address = M('lionfish_comshop_address')->where( array('is_default' => 1,'member_id' => $member_id) )->find();
  1678. $address_data = array();
  1679. $address_data['member_id'] = $member_id;
  1680. $address_data['name'] = $userName;
  1681. $address_data['telephone'] = $telNumber;
  1682. $address_data['lou_meng_hao'] = $lou_meng_hao;
  1683. if(!empty($latitude))
  1684. {
  1685. $address_data['lon_lat'] = $longitude.','.$latitude;
  1686. }else{
  1687. $address_data['lon_lat'] = '';
  1688. }
  1689. $address_data['address'] = $detailInfo;
  1690. $address_data['address_name'] = empty($data['address_name']) ? 'HOME' : $data['address_name'];
  1691. if(!empty($has_default_address) && false)
  1692. {
  1693. $address_data['is_default'] = 0;
  1694. }else{
  1695. $data = array();
  1696. $data['is_default'] = 0;
  1697. M('lionfish_comshop_address')->where( array('member_id' => $member_id ) )->save($data);
  1698. $address_data['is_default'] = 1;
  1699. }
  1700. $address_data['city_id'] = $city_id;
  1701. $address_data['country_id'] = $country_id;
  1702. $address_data['province_id'] = $province_id;
  1703. $res = M('lionfish_comshop_address')->add($address_data);
  1704. }else{
  1705. $res = $has_addre['address_id'];
  1706. }
  1707. return $res;
  1708. }
  1709. public function checkout()
  1710. {
  1711. $gpc = I('request.');
  1712. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  1713. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  1714. if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
  1715. {
  1716. $pintuan_model_buy = 0;
  1717. }
  1718. $mb_city_name = isset($gpc['mb_city_name']) ? $gpc['mb_city_name'] : '';
  1719. if($buy_type == 'undefined')
  1720. {
  1721. $buy_type = 'dan';
  1722. }
  1723. $community_id = $gpc['community_id'];
  1724. $token = $gpc['token'];
  1725. $voucher_id = isset($gpc['voucher_id']) ? $gpc['voucher_id'] : 0;
  1726. $soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
  1727. $use_quan_str = isset($gpc['use_quan_str']) ? $gpc['use_quan_str'] : '';
  1728. $use_quan_arr = array();
  1729. if($use_quan_str != '')
  1730. {
  1731. $use_quan_arr_tmp = explode('@',$use_quan_str );
  1732. foreach($use_quan_arr_tmp as $val)
  1733. {
  1734. $tmp_arr = explode('_', $val);
  1735. $use_quan_arr[$tmp_arr[0]] = $tmp_arr[1];
  1736. }
  1737. }
  1738. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1739. $member_id = $weprogram_token['member_id'];
  1740. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  1741. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  1742. $is_vip_card_member = 0;
  1743. $is_member_level_buy = 0;
  1744. if( $member_id > 0 )
  1745. {
  1746. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  1747. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  1748. {
  1749. $now_time = time();
  1750. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  1751. {
  1752. $is_vip_card_member = 1;//还是会员
  1753. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  1754. $is_vip_card_member = 2;//已过期
  1755. }
  1756. }
  1757. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  1758. {
  1759. $is_member_level_buy = 1;
  1760. }
  1761. }
  1762. //预售不开启会员卡
  1763. if($buy_type == 'pesale')
  1764. {
  1765. $is_member_level_buy = 0;
  1766. $is_vip_card_member = 0;
  1767. }
  1768. if( empty($member_id) )
  1769. {
  1770. //需要登录
  1771. echo json_encode( array('code' =>5) );
  1772. die();
  1773. }
  1774. $cart = D('Home/Car');
  1775. if ((!$cart->has_goodswecar($buy_type,$token,$community_id) ) ) {
  1776. //购物车中没有商品
  1777. echo json_encode( array('code' =>4) );
  1778. die();
  1779. }
  1780. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1781. //soitaire
  1782. $goods=$cart->get_all_goodswecar($buy_type, $token,1,$community_id,$soli_id);
  1783. $address = M('lionfish_comshop_address')->where( array('member_id' => $member_id) )->order('is_default desc,address_id desc')->find();
  1784. $add_old_order = M('lionfish_comshop_order')->field('address_id')->where( " (delivery ='localtown_delivery' or delivery = 'express') and member_id = {$member_id} " )->order('order_id desc')->find();
  1785. if( !empty($add_old_order) && $add_old_order['address_id'] > 0)
  1786. {
  1787. $address = M('lionfish_comshop_address')->where( array('address_id' => $add_old_order['address_id'],'member_id' => $member_id) )->find();
  1788. }
  1789. $mb_city_id = 0;
  1790. if(!empty($mb_city_name))
  1791. {
  1792. $mb_city_info = M('lionfish_comshop_area')->where(" name='{$mb_city_name}' ")->find();
  1793. if( !empty($mb_city_info) )
  1794. {
  1795. $mb_city_id = $mb_city_info['id'];
  1796. }
  1797. }
  1798. if($address){
  1799. //get_area_info($id)
  1800. $province_info = D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
  1801. $city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
  1802. $country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
  1803. $address['province_name'] = $province_info['name'];
  1804. $address['city_name'] = $city_info['name'];
  1805. $address['country_name'] = $country_info['name'];
  1806. }else{
  1807. $address = array();
  1808. }
  1809. $seller_goodss = array();
  1810. $show_voucher = 0;
  1811. //判断是否仅快递的配送方式 is_only_express
  1812. $is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
  1813. $is_only_express = 0;
  1814. if( !empty($is_open_only_express) && $is_open_only_express == 1)
  1815. {
  1816. $is_only_express = 1;
  1817. }
  1818. /**
  1819. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  1820. {
  1821. $is_member_level_buy = 1;
  1822. }
  1823. **/
  1824. foreach($goods as $key => $val)
  1825. {
  1826. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  1827. if( $is_only_express == 1 && $val['is_only_express'] != 1 )
  1828. {
  1829. $is_only_express = 0;
  1830. }
  1831. if($is_only_express == 0 && $val['is_only_express'] == 3 )
  1832. {
  1833. $is_only_express = 3;
  1834. }
  1835. if($is_only_express == 0 && $val['is_only_express'] == 2 )
  1836. {
  1837. $is_only_express = 2;
  1838. }
  1839. $supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
  1840. if($supply_id > 0)
  1841. {
  1842. $supply_info = D('Home/Front')->get_supply_info($supply_id);
  1843. if($supply_info['type'] ==0)
  1844. {
  1845. $supply_id = 0;
  1846. }
  1847. }
  1848. $val['name'] = htmlspecialchars_decode($val['name']);
  1849. $seller_goodss[ $supply_id ]['goods'][$key] = $val;
  1850. }
  1851. //begin 如果是同城配送 ,查一查有没有新提交的地址,如果有,按照新的来处理
  1852. $localtown_address = array();
  1853. if( $is_only_express == 3 )
  1854. {
  1855. $localtown_old_order = M('lionfish_comshop_order')->field('address_id')->where( array('delivery' => 'localtown_delivery','member_id' => $member_id) )->order('order_id desc')->find();
  1856. $localtown_id = 0;
  1857. if( !empty($localtown_old_order) && $localtown_old_order['address_id'] > 0)
  1858. {
  1859. $localtown_address = M('lionfish_comshop_address')->where( array('address_id' => $localtown_old_order['address_id'],'member_id' => $member_id) )->find();
  1860. if(!empty($localtown_address))
  1861. {
  1862. $province_info = D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
  1863. $city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
  1864. $country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
  1865. $localtown_address['province_name'] = $province_info['name'];
  1866. $localtown_address['city_name'] = $city_info['name'];
  1867. $localtown_address['country_name'] = $country_info['name'];
  1868. }else if( isset($gpc['longitude']) && isset($gpc['latitude']) )
  1869. {
  1870. $localtown_address['lon_lat'] = $gpc['longitude'].','.$gpc['latitude'];
  1871. }
  1872. }else{
  1873. $address = array();
  1874. }
  1875. }
  1876. //end同城配送
  1877. $quan_model = D('Home/Voucher');
  1878. $pin_model = D('Home/Pin');
  1879. $voucher_price = 0;
  1880. $reduce_money = 0;
  1881. $cha_reduce_money = 0;
  1882. $is_pin_over = 0;
  1883. $is_moban = false;
  1884. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1885. $full_money = D('Home/Front')->get_config_by_name('full_money');
  1886. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  1887. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  1888. {
  1889. $is_open_fullreduction = 0;
  1890. }
  1891. $show_voucher = 0;
  1892. $voucher_can_use =1;//目前都是平台券,
  1893. $man_total_free = 0;
  1894. $store_buy_total_money = 0;
  1895. $pin_id = 0;
  1896. $presale_goods_id = 0;//预售商品id
  1897. $presale_goods_total = 0;//预售商品价格
  1898. $is_zero_buy = 0;
  1899. $vipcard_save_money = 0;
  1900. $level_save_money = 0;
  1901. $today_time = time();
  1902. $arr = array('天','一','二','三','四','五','六');
  1903. //计算优惠券
  1904. foreach($seller_goodss as $store_id => $val)
  1905. {
  1906. $seller_voucher_list = array();
  1907. $seller_total_fee = 0;
  1908. $total_trans_free = 0;
  1909. $is_no_quan = false;
  1910. $total_weight = 0;
  1911. $total_quantity = 0;
  1912. $vch_goods_ids = array();
  1913. foreach($val['goods'] as $kk =>$d_goods)
  1914. {
  1915. //预售不参与会员卡
  1916. if($d_goods['is_take_vipcard'] == 1)
  1917. {
  1918. $vipcard_save_money += $d_goods['total'] - $d_goods['card_total'];
  1919. }else if( $d_goods['is_mb_level_buy'] == 1 && $d_goods['is_mb_level_buy'] == 1 && $is_member_level_buy == 1)
  1920. {
  1921. $level_save_money += $d_goods['total'] - $d_goods['level_total'];
  1922. }
  1923. if( $is_vip_card_member == 1 && $d_goods['is_take_vipcard'] == 1 )
  1924. {
  1925. $seller_total_fee += $d_goods['card_total'];
  1926. if( $store_id == 0 )
  1927. {
  1928. $store_buy_total_money += $d_goods['card_total'];
  1929. }
  1930. if( $d_goods['can_man_jian'] == 1)
  1931. {
  1932. $man_total_free += $d_goods['card_total'];
  1933. }
  1934. }
  1935. else if( $d_goods['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  1936. {
  1937. $seller_total_fee += $d_goods['level_total'];
  1938. if( $store_id == 0 )
  1939. {
  1940. $store_buy_total_money += $d_goods['level_total'];
  1941. }
  1942. if( $d_goods['can_man_jian'] == 1)
  1943. {
  1944. $man_total_free += $d_goods['level_total'];
  1945. }
  1946. }
  1947. else
  1948. {
  1949. $seller_total_fee += $d_goods['total'];
  1950. if( $store_id == 0 )
  1951. {
  1952. $store_buy_total_money += $d_goods['total'];
  1953. }
  1954. if( $d_goods['can_man_jian'] == 1)
  1955. {
  1956. $man_total_free += $d_goods['total'];
  1957. }
  1958. }
  1959. if($buy_type == 'pintuan' && $d_goods['pin_id'] > 0)
  1960. {
  1961. $is_pin_over = $pin_model->getNowPinState($d_goods['pin_id']);
  1962. if( $is_pin_over == 2 )
  1963. {
  1964. $is_zero_buy = $pin_model->check_goods_iszero_opentuan( $d_goods['goods_id'] );
  1965. }
  1966. }else if($buy_type == 'pintuan' && $d_goods['pin_id'] == 0)
  1967. {
  1968. $is_zero_buy = $pin_model->check_goods_iszero_opentuan( $d_goods['goods_id'] );
  1969. }
  1970. if( $buy_type == 'presale' )
  1971. {
  1972. $presale_goods_id = $d_goods['goods_id'];
  1973. $presale_goods_total = $seller_total_fee;
  1974. }
  1975. $tp_goods_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $d_goods['goods_id']) )->find();
  1976. $vch_goods_ids[$d_goods['goods_id']] = $vch_goods_ids[$d_goods['goods_id']] + $d_goods['total'];
  1977. //$is_no_quan = true;
  1978. //预售不开启优惠券
  1979. if($tp_goods_info['type'] == 'integral' || $tp_goods_info['type'] == 'presale' )
  1980. {
  1981. $is_no_quan = true;
  1982. }
  1983. if($d_goods['shipping']==0)
  1984. {
  1985. $is_moban = true;
  1986. $val['is_moban'] = true;
  1987. $total_weight += $d_goods['weight']*$d_goods['quantity'];
  1988. $total_quantity += $d_goods['quantity'];
  1989. }
  1990. $d_goods[$kk]['trans_free'] = 0;
  1991. /**
  1992. if($d_goods['shipping']==1)
  1993. {
  1994. //统一运费
  1995. $d_goods[$kk]['trans_free'] = $d_goods['goods_freight'];
  1996. }else {
  1997. //运费模板
  1998. if(!empty($address))
  1999. {
  2000. $trans_free = load_model_class('transport')->calc_transport($d_goods['transport_id'], $d_goods['quantity'],$d_goods['quantity']*$d_goods['weight'], $address['city_id'] );
  2001. }else{
  2002. $trans_free = 0;
  2003. }
  2004. $d_goods[$kk]['trans_free'] = $trans_free;
  2005. }
  2006. **/
  2007. $total_trans_free += $d_goods[$kk]['trans_free'];
  2008. //自提时间
  2009. $goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $d_goods['goods_id']) )->find();
  2010. $pick_up_type = -1;
  2011. if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
  2012. {
  2013. $pick_up_type = $goods_info['pick_up_type'];
  2014. if($pick_up_type == 0)
  2015. {
  2016. $pick_up_time = date('m-d', $today_time);
  2017. $pick_up_weekday = '周'.$arr[date('w',$today_time)];
  2018. }else if( $pick_up_type == 1 ){
  2019. $pick_up_time = date('m-d', $today_time+86400);
  2020. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  2021. }else if( $pick_up_type == 2 )
  2022. {
  2023. $pick_up_time = date('m-d', $today_time+86400*2);
  2024. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  2025. }else if($pick_up_type == 3)
  2026. {
  2027. $pick_up_time = $goods_info['pick_up_modify'];
  2028. }
  2029. }
  2030. $d_goods['pick_up_type'] = $pick_up_type;
  2031. $d_goods['pick_up_time'] = $pick_up_time;
  2032. $d_goods['pick_up_weekday'] = $pick_up_weekday;
  2033. $val['goods'][$kk] = $d_goods;
  2034. }
  2035. $val['reduce_money'] = 0;
  2036. //pindan (拼团商品单独购买) pintuan (拼团)
  2037. //预售关闭满减
  2038. if($buy_type == 'pindan' || $buy_type == 'pintuan' || $buy_type == 'integral' || $buy_type == 'presale')
  2039. {
  2040. $is_open_fullreduction = 0;
  2041. }
  2042. //原来满级计算man_total_free
  2043. /*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
  2044. {
  2045. $val['reduce_money'] = $full_reducemoney;
  2046. $reduce_money = $full_reducemoney;
  2047. }else if($is_open_fullreduction == 1 && $man_total_free < $full_money)
  2048. {
  2049. $cha_reduce_money = $full_money - $man_total_free;
  2050. }*/
  2051. /**
  2052. * 新满减计算
  2053. */
  2054. if($is_open_fullreduction == 1)
  2055. {
  2056. $reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
  2057. $val['reduce_money'] = $reduce_result['reduce_money'];
  2058. $reduce_money = $reduce_result['reduce_money'];
  2059. $cha_reduce_money = $reduce_result['cha_reduce_money'];
  2060. }
  2061. $chose_vouche = array();
  2062. if(!$is_no_quan)
  2063. {
  2064. $vouche_list = $quan_model->get_user_canpay_voucher($member_id,$store_id,$seller_total_fee,'',$vch_goods_ids);
  2065. $vouche_list = $quan_model->get_voucher_amout_bygoods($vouche_list,$val['goods'],$reduce_money);
  2066. //var_dump( $vouche_list );
  2067. //die();
  2068. if(!empty($vouche_list) && empty($use_quan_arr) ) {
  2069. $ling_vouche_list = $vouche_list;
  2070. if($voucher_can_use == 1)
  2071. {
  2072. $voucher_can_use++;
  2073. $show_voucher = 1;
  2074. reset($ling_vouche_list);
  2075. $chose_vouche = current($ling_vouche_list);
  2076. //$voucher_price += $chose_vouche['credit'];
  2077. $voucher_price += $chose_vouche['can_vouche_amount'];
  2078. //$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
  2079. $seller_total_fee = round( $seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
  2080. }
  2081. }else if( !empty($vouche_list) && !empty($use_quan_arr) )
  2082. {
  2083. foreach($vouche_list as $tmp_voucher)
  2084. {
  2085. if($tmp_voucher['id'] == $use_quan_arr[$store_id])
  2086. {
  2087. $show_voucher = 1;
  2088. $chose_vouche = $tmp_voucher;
  2089. //$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
  2090. //$voucher_price += $chose_vouche['credit'];
  2091. $seller_total_fee = round( $seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
  2092. $voucher_price += $chose_vouche['can_vouche_amount'];
  2093. break;
  2094. }
  2095. }
  2096. }
  2097. }
  2098. $val['chose_vouche'] = $chose_vouche;
  2099. $val['show_voucher'] = $show_voucher;
  2100. $val['voucher_list'] = $vouche_list;
  2101. $val['total'] = $seller_total_fee;
  2102. if($val['total'] < 0)
  2103. {
  2104. $val['total'] = 0;
  2105. }
  2106. $val['trans_free'] = $total_trans_free;
  2107. $val['total_weight'] = $total_weight;
  2108. $val['total_quantity'] = $total_quantity;
  2109. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  2110. $shoname = D('Home/Front')->get_config_by_name('shoname');
  2111. if( !empty($s_logo) )
  2112. {
  2113. $s_logo = tomedia( $s_logo );
  2114. }
  2115. $store_info = array('s_id' => $store_id,'s_true_name' => $shoname,'s_logo' => $s_logo );
  2116. if( !empty($store_id) && $store_id > 0 )
  2117. {
  2118. $supply_info = D('Home/Front')->get_supply_info($store_id);
  2119. //logo
  2120. if( !empty($supply_info) )
  2121. {
  2122. $store_info['s_true_name'] = $supply_info['shopname'];
  2123. $store_info['s_logo'] = tomedia( $supply_info['logo'] );
  2124. }
  2125. }
  2126. $val['store_info'] = $store_info;
  2127. $seller_goodss[$store_id] = $val;
  2128. }
  2129. $trans_free_toal = 0;//运费
  2130. //delivery_type_ziti delivery_type_express delivery_type_tuanz delivery_tuanz_money
  2131. $delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
  2132. $delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
  2133. $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
  2134. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  2135. //---
  2136. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  2137. $man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
  2138. $delivery_express_name = D('Home/Front')->get_config_by_name('delivery_express_name');
  2139. if( empty($man_free_tuanzshipping) || $buy_type == 'integral')
  2140. {
  2141. $man_free_tuanzshipping = 0;
  2142. }
  2143. //关闭团长配送费 免 预售
  2144. if( empty($man_free_tuanzshipping) || $buy_type == 'presale' )
  2145. {
  2146. $man_free_tuanzshipping = 0;
  2147. }
  2148. if( empty($man_free_shipping) || $buy_type == 'integral' )
  2149. {
  2150. $man_free_shipping = 0;
  2151. }
  2152. //关闭快递配送费 免 预售
  2153. if( empty($man_free_shipping) || $buy_type == 'presale' )
  2154. {
  2155. $man_free_shipping = 0;
  2156. }
  2157. //if( $buy_type == 'dan' )
  2158. if( $buy_type == 'dan' || $buy_type == 'soitaire' || ($pintuan_model_buy == 1 && $buy_type != 'dan' && $buy_type != 'integral' ) )
  2159. {
  2160. //...判断团长是否开启自定义的情况 store_buy_total_money
  2161. $community_info_modify = M('lionfish_community_head')->field('is_modify_shipping_method,is_modify_shipping_fare,shipping_fare')->where( array('id' => $community_id) )->find();
  2162. if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 && $delivery_type_tuanz == 1)
  2163. {
  2164. //开启配送
  2165. $delivery_type_tuanz = 1;
  2166. if( !empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0 )
  2167. {
  2168. $delivery_tuanz_money = $community_info_modify['shipping_fare'];
  2169. }
  2170. }else if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 2 )
  2171. {
  2172. //关闭配送
  2173. $delivery_type_tuanz = 0;
  2174. }
  2175. }else if( $buy_type == 'pindan' || $buy_type == 'pintuan' ){
  2176. if($pintuan_model_buy == 0)
  2177. {
  2178. $delivery_type_tuanz = 0;
  2179. $delivery_type_express = 1;
  2180. $delivery_type_ziti = 2;
  2181. }
  2182. }else if( $buy_type == 'integral' )
  2183. {
  2184. $delivery_type_tuanz = 0;
  2185. $delivery_type_express = 1;
  2186. $delivery_type_ziti = 2;
  2187. }
  2188. foreach($val['goods'] as $kk =>$d_goods)
  2189. {
  2190. if($d_goods['is_only_express'] == 1){
  2191. $delivery_type_express = 1;
  2192. }
  2193. }
  2194. $is_man_delivery_tuanz_fare = 0;//是否达到满xx减团长配送费
  2195. $fare_man_delivery_tuanz_fare_money = 0;//达到满xx减团长配送费, 减了多少钱
  2196. if( ( $buy_type == 'dan' || $buy_type == 'soitaire' ) && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $man_free_tuanzshipping <= $store_buy_total_money )
  2197. {
  2198. //$delivery_tuanz_money = 0;
  2199. $is_man_delivery_tuanz_fare = 1;
  2200. $fare_man_delivery_tuanz_fare_money = $delivery_tuanz_money;
  2201. }
  2202. $is_man_shipping_fare = 0;//是否达到满xx减运费
  2203. $fare_man_shipping_fare_money = 0;//达到满xx减运费,司机减了多少运费
  2204. //----开始计算运费 //dispatchtype
  2205. if($delivery_type_express == 1)
  2206. {
  2207. //ims_
  2208. $store_trans_free_toal = 0;
  2209. if($mb_city_id > 0){
  2210. $shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
  2211. foreach($seller_goodss as $store_id => $val)
  2212. {
  2213. //$val['is_moban'] = true;
  2214. $store_shipping_fare = 0;
  2215. if( isset($val['is_moban']) && $val['is_moban'] )
  2216. {
  2217. $store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'],$val['total_weight'], $mb_city_id );
  2218. }
  2219. $val['store_shipping_fare'] = $store_shipping_fare;
  2220. $trans_free_toal += $store_shipping_fare;
  2221. if( $store_id == 0 )
  2222. {
  2223. $store_trans_free_toal += $store_shipping_fare;
  2224. }
  2225. foreach($val['goods'] as $kk =>$d_goods)
  2226. {
  2227. if($d_goods['shipping']==1)
  2228. {
  2229. //统一运费
  2230. $trans_free_toal += $d_goods['goods_freight'];
  2231. if( $store_id == 0 )
  2232. {
  2233. $store_trans_free_toal += $d_goods['goods_freight'];
  2234. }
  2235. }
  2236. }
  2237. }
  2238. }else if(!empty($address) && $mb_city_id == 0)
  2239. {
  2240. $shipping_default = M('lionfish_comshop_shipping')->where( array('enabled' => 1) )->order('isdefault desc,id desc')->find();
  2241. foreach($seller_goodss as $store_id => $val)
  2242. {
  2243. $store_shipping_fare = 0;
  2244. if(isset($val['is_moban']) && $val['is_moban'])
  2245. {
  2246. $store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'],$val['total_weight'], $address['city_id'] );
  2247. }
  2248. $val['store_shipping_fare'] = $store_shipping_fare;
  2249. $trans_free_toal += $store_shipping_fare;
  2250. if( $store_id == 0 )
  2251. {
  2252. $store_trans_free_toal += $store_shipping_fare;
  2253. }
  2254. foreach($val['goods'] as $kk =>$d_goods)
  2255. {
  2256. if($d_goods['shipping']==1)
  2257. {
  2258. //统一运费
  2259. $trans_free_toal += $d_goods['goods_freight'];
  2260. $val['store_shipping_fare'] += $d_goods['goods_freight'];
  2261. if( $store_id == 0 )
  2262. {
  2263. $store_trans_free_toal += $d_goods['goods_freight'];
  2264. }
  2265. }
  2266. }
  2267. }
  2268. }else{
  2269. $trans_free_toal = 0;
  2270. }
  2271. //
  2272. if( !empty($man_free_shipping) && $man_free_shipping > 0 && $man_free_shipping <= $store_buy_total_money )
  2273. {
  2274. $fare_man_shipping_fare_money = $store_trans_free_toal;
  2275. $is_man_shipping_fare = 1;
  2276. //$trans_free_toal = 0;
  2277. }
  2278. }
  2279. //礼品卡配送费0
  2280. if( $buy_type == 'virtualcard' )
  2281. {
  2282. $trans_free_toal = 0;
  2283. }
  2284. //---结束结算运费
  2285. if( empty($delivery_type_ziti) )
  2286. {
  2287. $delivery_type_ziti = 1;//开启
  2288. }
  2289. if( empty($delivery_type_express) )
  2290. {
  2291. $delivery_type_express = 2;
  2292. }
  2293. if( empty($delivery_type_tuanz) )
  2294. {
  2295. $delivery_type_tuanz = 2;
  2296. }
  2297. //默认关闭同城配送
  2298. $delivery_type_localtown = 0;
  2299. //默认关闭核销商品
  2300. $delvery_type_hexiao = 0;
  2301. //is_only_express
  2302. if( $is_only_express == 1 )
  2303. {
  2304. $delivery_type_ziti = 2;
  2305. $delivery_type_express = 1;
  2306. $delivery_type_tuanz = 2;
  2307. }else if( $is_only_express == 3 )
  2308. {
  2309. //同城配送
  2310. $delivery_type_ziti = 0;
  2311. $delivery_type_express = 0;
  2312. $delivery_type_tuanz = 0;
  2313. $delivery_type_localtown = 1;
  2314. }else if( $is_only_express == 2 )
  2315. {
  2316. //核销商品
  2317. $delivery_type_ziti = 0;
  2318. $delivery_type_express = 0;
  2319. $delivery_type_tuanz = 0;
  2320. $delivery_type_localtown = 0;
  2321. $delvery_type_hexiao = 1;
  2322. }
  2323. $total_free = 0;
  2324. $is_ziti = 2;
  2325. $pick_up_time = "";
  2326. $pick_up_type = -1;
  2327. $pick_up_weekday = '';
  2328. $today_time = time();
  2329. $arr = array('天','一','二','三','四','五','六');
  2330. $pick_up_arr = array();
  2331. foreach($goods as $key => $good)
  2332. {
  2333. //暂时关闭
  2334. //ims_lionfish_comshop_goods
  2335. //ims_ lionfish_comshop_good_common
  2336. $goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $good['goods_id']) )->find();
  2337. if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
  2338. {
  2339. $pick_up_type = $goods_info['pick_up_type'];
  2340. if($pick_up_type == 0)
  2341. {
  2342. $pick_up_time = date('m-d', $today_time);
  2343. $pick_up_weekday = '周'.$arr[date('w',$today_time)];
  2344. }else if( $pick_up_type == 1 ){
  2345. $pick_up_time = date('m-d', $today_time+86400);
  2346. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  2347. }else if( $pick_up_type == 2 )
  2348. {
  2349. $pick_up_time = date('m-d', $today_time+86400*2);
  2350. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  2351. }else if($pick_up_type == 3)
  2352. {
  2353. $pick_up_time = $goods_info['pick_up_modify'];
  2354. }
  2355. }
  2356. $goods[$key]['trans_free'] = $good['goods_freight'];
  2357. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  2358. {
  2359. $total_free += $good['card_total'];
  2360. }
  2361. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  2362. {
  2363. $total_free += $good['level_total'];
  2364. }
  2365. else
  2366. {
  2367. $total_free += $good['total'];
  2368. }
  2369. }
  2370. //同城配送费
  2371. $localtown_shipping_fare = 0;
  2372. //包装费
  2373. $picking_fare = 0;
  2374. $picking_fare_arr = array();
  2375. $localtown_shipping_fare_arr = array();
  2376. $localtown_dispatchtime = 0;//预计一共需要配送多少分钟
  2377. $localtown_expected_delivery = array();//预计送达时间段
  2378. $localtown_modifypickingname = "";//包装费标题
  2379. if( $is_only_express == 3 )
  2380. {
  2381. $picking_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money( $seller_goodss );// $seller_goodss;
  2382. $picking_fare = $picking_fare_arr['total_picking_fare'];
  2383. $localtown_dispatchtime = D('Home/LocaltownDelivery')->get_order_dispatchtime($seller_goodss);
  2384. if( isset($gpc['latitude']) && !empty($gpc['latitude']) && isset($gpc['longitude']) && !empty($gpc['longitude']) )
  2385. {
  2386. $lon = $gpc['longitude'];
  2387. $lat = $gpc['latitude'];
  2388. $localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $seller_goodss );
  2389. $localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
  2390. $trans_free_toal = $localtown_shipping_fare;
  2391. }else if( !empty($localtown_address) )
  2392. {
  2393. list($lon,$lat) = explode(',', $localtown_address['lon_lat'] );
  2394. $localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $seller_goodss );
  2395. $localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
  2396. $trans_free_toal = $localtown_shipping_fare;
  2397. }
  2398. //配送时间段间隔
  2399. $localtown_expected_delivery = D('Home/LocaltownDelivery')->get_expected_delivery($localtown_dispatchtime);
  2400. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  2401. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  2402. }
  2403. //暂时关闭自提代码
  2404. /**
  2405. if(!empty($pick_up))
  2406. {
  2407. $pick_up = unserialize($pick_up);
  2408. $pick_up_ids = implode(',',$pick_up);
  2409. $pick_up_arr = M('pick_up')->where( array('id'=>array('in',$pick_up_ids)) )->select();
  2410. }
  2411. **/
  2412. $pick_up_name = '';
  2413. $pick_up_mobile = '';
  2414. $tuan_send_address = '';
  2415. $order_note_content = '';
  2416. $tuan_send_address_info = array();
  2417. $shop_limit_buy_distance = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
  2418. if($is_ziti >= 1)
  2419. {
  2420. //寻找上一个订单的自提电话 自提姓名
  2421. $last_order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'delivery' => 'pickup') )->order('order_id desc')->find();
  2422. if(empty($last_order_info)){
  2423. $last_order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'delivery' => 'hexiao') )->order('order_id desc')->find();
  2424. }
  2425. if(!empty($last_order_info))
  2426. {
  2427. $pick_up_name = $last_order_info['shipping_name'];
  2428. $pick_up_mobile = $last_order_info['telephone'];
  2429. $order_note_content = $last_order_info['note_content'];
  2430. }
  2431. //order_note_content
  2432. $last_tuanz_send_order_info = M('lionfish_comshop_order')->field('tuan_send_address,address_id,note_content,order_id')->where( array('member_id' =>$member_id,'delivery' => 'tuanz_send' ) )->order('order_id desc')->find();
  2433. if(!empty($last_tuanz_send_order_info))
  2434. {
  2435. $tuan_send_address = $last_tuanz_send_order_info['tuan_send_address'];
  2436. if( !empty($last_tuanz_send_order_info['note_content']) && $last_tuanz_send_order_info['order_id'] > $last_order_info['order_id'] )
  2437. {
  2438. $order_note_content = $last_tuanz_send_order_info['note_content'];
  2439. }
  2440. if( !empty($last_tuanz_send_order_info['address_id']) )
  2441. {
  2442. if($shop_limit_buy_distance == 1)
  2443. {
  2444. $tuan_send_address_info = M('lionfish_comshop_address')->where( "address_id=".$last_tuanz_send_order_info['address_id']." and lon_lat != '' " )->find();
  2445. }else{
  2446. $tuan_send_address_info = M('lionfish_comshop_address')->where( "address_id=".$last_tuanz_send_order_info['address_id'] )->find();
  2447. }
  2448. if( !empty($tuan_send_address) && !empty($tuan_send_address_info['lon_lat']) )
  2449. {
  2450. $province_info = D('Home/Front')->get_area_info($tuan_send_address_info['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
  2451. $city_info = D('Home/Front')->get_area_info($tuan_send_address_info['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
  2452. $country_info = D('Home/Front')->get_area_info($tuan_send_address_info['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
  2453. $tuan_send_address_info['province_name'] = $province_info['name'];
  2454. $tuan_send_address_info['city_name'] = $city_info['name'];
  2455. $tuan_send_address_info['country_name'] = $country_info['name'];
  2456. $tuan_send_address = $tuan_send_address_info['address'];
  2457. }else{
  2458. //todo...
  2459. $tuan_send_address = '';
  2460. }
  2461. }else{
  2462. $tuan_send_address = '';
  2463. }
  2464. }
  2465. }
  2466. /**
  2467. **/
  2468. /**
  2469. tuan_region
  2470. store_buy_total_money
  2471. **/
  2472. //open_score_buy_score $shop_limit_buy_distance = load_model_class('front')->get_config_by_name('shop_limit_buy_distance');
  2473. /**
  2474. $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
  2475. $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
  2476. $delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
  2477. if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
  2478. if( empty($tuan_send_address_info) )
  2479. {
  2480. $tuan_send_address_info = array();
  2481. }
  2482. //判断是否预售,给出预售的信息 begin todo
  2483. $presale_info = [];
  2484. if( $buy_type == 'presale' )
  2485. {
  2486. // $presale_goods_id
  2487. $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
  2488. if( $presale_result['code'] == 0 )
  2489. {
  2490. $presale_info = $presale_result['data'];
  2491. }
  2492. }
  2493. //end
  2494. **/
  2495. $open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
  2496. if( empty($open_score_buy_score) || $buy_type == 'integral' )
  2497. {
  2498. $open_score_buy_score = 0;
  2499. }
  2500. $score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
  2501. if( empty($score_forbuy_money_maxbi) )
  2502. {
  2503. $score_forbuy_money_maxbi = 100;
  2504. }
  2505. $score_for_money = 0;
  2506. $bue_use_score = 0;
  2507. if( $open_score_buy_score == 1 )
  2508. {
  2509. if( $member_info['score'] > 0 )
  2510. {
  2511. $score_can_max = $store_buy_total_money - $voucher_price - $reduce_money;
  2512. //计算能兑换多少钱
  2513. $score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
  2514. //只有兑换比例大于0才能允许兑换
  2515. if( !empty($score_forbuy_money) && $score_forbuy_money >0 )
  2516. {
  2517. $score_for_money = sprintf("%.2f",$member_info['score'] / $score_forbuy_money);
  2518. if( $score_can_max < $score_for_money )
  2519. {
  2520. $score_for_money = $score_can_max;
  2521. $bue_use_score = floor($score_can_max * $score_forbuy_money);
  2522. $score_for_money = round($bue_use_score/$score_forbuy_money,2);
  2523. }
  2524. $max_store_buy_total_money = sprintf("%.2f",($score_forbuy_money_maxbi * $score_can_max) /100);
  2525. if($score_for_money > $max_store_buy_total_money)
  2526. {
  2527. $score_for_money = $max_store_buy_total_money;
  2528. $bue_use_score = floor($max_store_buy_total_money * $score_forbuy_money);
  2529. $score_for_money = round($bue_use_score/$score_forbuy_money,2);
  2530. }else if($bue_use_score <= $max_store_buy_total_money){
  2531. $bue_use_score = floor($score_for_money * $score_forbuy_money);
  2532. //$bue_use_score = $member_info['score'];
  2533. if($bue_use_score > $member_info['score'] )
  2534. {
  2535. $bue_use_score = floor($member_info['score']);
  2536. }
  2537. $score_for_money = round($bue_use_score/$score_forbuy_money,2);
  2538. }
  2539. }
  2540. //预售
  2541. //if($buy_type == 'presale'){
  2542. // $sum_deduction_money = $goods[0]["quantity"] * $presale_info['deduction_money'] ;
  2543. //}
  2544. }
  2545. }
  2546. //score_forbuy_money score
  2547. $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
  2548. $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
  2549. $delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
  2550. if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
  2551. if( empty($tuan_send_address_info) )
  2552. {
  2553. $tuan_send_address_info = array();
  2554. }
  2555. //判断是否预售,给出预售的信息 begin todo
  2556. $presale_info = [];
  2557. if( $buy_type == 'presale' )
  2558. {
  2559. // $presale_goods_id
  2560. $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
  2561. if( $presale_result['code'] == 0 )
  2562. {
  2563. $presale_info = $presale_result['data'];
  2564. }
  2565. }
  2566. //end
  2567. $need_data = array();
  2568. $need_data['code'] = 1;
  2569. $need_data['open_score_buy_score'] = $open_score_buy_score;//1开启积分抵扣
  2570. $need_data['score'] = $member_info['score'];//会员持有的积分
  2571. $need_data['score_for_money'] = $score_for_money;//会员能抵扣的金额
  2572. $need_data['bue_use_score'] = $bue_use_score;//会员能抵扣的积分数
  2573. $need_data['delivery_type_ziti'] = $delivery_type_ziti;
  2574. $need_data['delivery_type_express'] = $delivery_type_express;
  2575. $need_data['delivery_type_tuanz'] = $delivery_type_tuanz;
  2576. $need_data['delivery_type_localtown'] = $delivery_type_localtown;
  2577. $need_data['delvery_type_hexiao'] = $delvery_type_hexiao;
  2578. $need_data['delivery_express_name'] = $delivery_express_name;
  2579. $need_data['delivery_ziti_name'] = $delivery_ziti_name;
  2580. $need_data['delivery_tuanzshipping_name'] = $delivery_tuanzshipping_name;
  2581. $need_data['delivery_diy_sort'] = $delivery_diy_sort;
  2582. $need_data['presale_info'] = $presale_info;//预售信息
  2583. $seller_goodss_keys = array_keys($seller_goodss);
  2584. $need_data['delivery_tuanz_money'] = round($delivery_tuanz_money * count($seller_goodss_keys) , 2);
  2585. //$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
  2586. $need_data['man_free_tuanzshipping'] = empty($man_free_tuanzshipping) ? 0 : $man_free_tuanzshipping;//团长配送,满多少免配送费,0或者为空表示不减免
  2587. $need_data['man_free_shipping'] = empty($man_free_shipping) ? 0 : $man_free_shipping;//快递配送,满多少免配送费,0或者为空表示不减免
  2588. $need_data['address'] = $address;
  2589. $need_data['pick_up_time'] = $pick_up_time;
  2590. $need_data['pick_up_type'] = $pick_up_type;
  2591. $need_data['pick_up_weekday'] = $pick_up_weekday;
  2592. $need_data['is_pin_over'] = $is_pin_over;
  2593. $need_data['is_integer'] = 0;//$is_no_quan ? 1: 0;
  2594. $need_data['pick_up_arr'] = $pick_up_arr;
  2595. $need_data['is_ziti'] = 2;
  2596. $need_data['ziti_name'] = $pick_up_name;
  2597. $need_data['ziti_mobile'] = $pick_up_mobile;
  2598. $need_data['tuan_send_address'] = $tuan_send_address;
  2599. $need_data['tuan_send_address_info'] = $tuan_send_address_info;
  2600. $need_data['seller_goodss'] = $seller_goodss;
  2601. $need_data['show_voucher'] = $show_voucher;
  2602. $need_data['buy_type'] = $buy_type;
  2603. $need_data['address'] = $address;
  2604. $need_data['trans_free_toal'] = $trans_free_toal;
  2605. $need_data['is_limit_distance_buy'] = 0;
  2606. $need_data['limit_distance'] = 100;//km
  2607. $need_data['is_member_level_buy'] = $is_member_level_buy;//km
  2608. $need_data['level_save_money'] = $level_save_money;//km
  2609. //begin
  2610. $need_data['localtown_shipping_fare'] = $localtown_shipping_fare;//同城配送配送费
  2611. $need_data['pickingup_fare'] = $picking_fare;//包装费
  2612. $need_data['localtown_dispatchtime'] = $localtown_dispatchtime;//预计一共需要配送多少分钟
  2613. $need_data['picking_fare_arr'] = $picking_fare_arr;
  2614. $need_data['localtown_shipping_fare_arr'] = $localtown_shipping_fare_arr;
  2615. $need_data['localtown_expected_delivery'] = $localtown_expected_delivery;
  2616. //end
  2617. $need_data['is_vip_card_member'] = $is_vip_card_member;//km
  2618. $need_data['vipcard_save_money'] = $vipcard_save_money;//km
  2619. $need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy;//km
  2620. if( !empty($shop_limit_buy_distance) && $shop_limit_buy_distance ==1 )
  2621. {
  2622. $latitude = 0;
  2623. $longitude = 0;
  2624. if( !empty($tuan_send_address_info) && !empty($tuan_send_address_info['lon_lat']) )
  2625. {
  2626. //lon_lat
  2627. $lon_lat_arr = explode(',', $tuan_send_address_info['lon_lat']);
  2628. $longitude = $lon_lat_arr[0];
  2629. $latitude = $lon_lat_arr[1];
  2630. }
  2631. if( isset($gpc['latitude']) && !empty($gpc['latitude']) )
  2632. {
  2633. $latitude = $gpc['latitude'];
  2634. }
  2635. if( isset($gpc['longitude']) && !empty($gpc['longitude']) )
  2636. {
  2637. $longitude = $gpc['longitude'];
  2638. }
  2639. if( !empty($latitude) && !empty($longitude) )
  2640. {
  2641. $shop_buy_distance = D('Home/Front')->get_config_by_name('shop_buy_distance');
  2642. $shop_buy_distance = $shop_buy_distance * 1000;
  2643. $community_info = M('lionfish_community_head')->field('lon,lat')->where( array('id' => $community_id ) )->find();
  2644. $distince = D('Seller/Communityhead')->GetDistance($longitude,$latitude,$community_info['lon'],$community_info['lat']);
  2645. $need_data['current_distance'] = $distince;
  2646. $need_data['shop_buy_distance'] = $shop_buy_distance;
  2647. if($distince > $shop_buy_distance )
  2648. {
  2649. $need_data['is_limit_distance_buy'] = 1;
  2650. $need_data['limit_distance'] = $distince/1000;
  2651. }
  2652. }
  2653. }
  2654. $need_data['reduce_money'] = $reduce_money;
  2655. $need_data['is_open_fullreduction'] = $is_open_fullreduction;
  2656. $need_data['cha_reduce_money'] = $cha_reduce_money;
  2657. $need_data['is_man_delivery_tuanz_fare'] = $is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
  2658. $need_data['fare_man_delivery_tuanz_fare_money'] = $fare_man_delivery_tuanz_fare_money; //达到满xx减团长配送费, 减了多少钱
  2659. $need_data['is_man_shipping_fare'] = $is_man_shipping_fare; //是否达到满xx减运费
  2660. $need_data['fare_man_shipping_fare_money'] = $fare_man_shipping_fare_money; //达到满xx减运费,司机减了多少运费
  2661. $dispatching = isset($gpc['dispatching']) ? $gpc['dispatching']:'pickup';
  2662. //is_ziti == 2
  2663. if($dispatching == 'express')
  2664. {
  2665. $need_data['total_free'] = $total_free + $trans_free_toal - $voucher_price -$reduce_money;
  2666. }
  2667. else if( $dispatching == 'localtown_delivery' )
  2668. {
  2669. $need_data['total_free'] = $total_free + $localtown_shipping_fare + $picking_fare - $voucher_price - $reduce_money;
  2670. }
  2671. else{
  2672. $need_data['total_free'] = $total_free - $voucher_price -$reduce_money;
  2673. }
  2674. if($is_ziti == 2)
  2675. {
  2676. $need_data['total_free'] = $total_free - $voucher_price -$reduce_money;
  2677. }
  2678. //积分兑换 不算总金额,但是算总积分
  2679. if( $buy_type == 'integral' )
  2680. {
  2681. $need_data['total_free'] = $trans_free_toal;
  2682. $need_data['total_integral'] = $total_free;
  2683. }
  2684. if($need_data['total_free'] < 0)
  2685. {
  2686. $need_data['total_free'] = 0;
  2687. }
  2688. //判断是否可以余额支付
  2689. //暂时关闭 会员余额功能
  2690. /**
  2691. $is_yue_open_info = M('config')->where( array('name' => 'is_yue_open') )->find();
  2692. $is_yue_open = $is_yue_open_info['value'];
  2693. **/
  2694. $is_yue_open = 0;
  2695. $is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
  2696. if( empty($is_yue_open) )
  2697. {
  2698. $is_yue_open = 0;
  2699. }
  2700. $need_data['is_yue_open'] = $is_yue_open;
  2701. $need_data['can_yupay'] = 0;
  2702. //暂时关闭 会员余额功能
  2703. if($is_yue_open == 1 && $need_data['total_free'] >=0 && $member_info['account_money'] >= $need_data['total_free'])
  2704. {
  2705. $need_data['can_yupay'] = 1;
  2706. }
  2707. //前端隐藏 团长信息
  2708. $index_hide_headdetail_address = D('Home/Front')->get_config_by_name('index_hide_headdetail_address');
  2709. if( empty($index_hide_headdetail_address) )
  2710. {
  2711. $index_hide_headdetail_address = 0;
  2712. }
  2713. $need_data['index_hide_headdetail_address'] = $index_hide_headdetail_address;
  2714. //订单留言
  2715. $is_open_order_message = D('Home/Front')->get_config_by_name('is_open_order_message');
  2716. $need_data['yu_money'] = $member_info['account_money'];
  2717. $need_data['goods'] = $goods;
  2718. $need_data['is_open_order_message'] = $is_open_order_message;
  2719. $need_data['is_zero_opentuan'] = 0;
  2720. //拼团特殊情况0元开团
  2721. if( $buy_type == 'pintuan' && $is_zero_buy == 1 )
  2722. {
  2723. //$need_data['total_free'] = 0;
  2724. //$need_data['trans_free_toal'] = 0;
  2725. //$need_data['is_zero_opentuan'] = 1;
  2726. }
  2727. //订阅消息begin
  2728. $is_need_subscript = 0;
  2729. $need_subscript_template = array();
  2730. //'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
  2731. //$member_id
  2732. if( $buy_type == 'pintuan' )
  2733. {
  2734. //pin_tuansuccess
  2735. //send_order parameter[weprogram_subtemplate_pin_tuansuccess]
  2736. //hexiao_success
  2737. $pin_tuansuccess_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'pin_tuansuccess' ) )->find();
  2738. //if( empty($pin_tuansuccess_info) )
  2739. //{
  2740. $weprogram_subtemplate_pin_tuansuccess = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
  2741. if( !empty($weprogram_subtemplate_pin_tuansuccess) )
  2742. {
  2743. $need_subscript_template['pin_tuansuccess'] = $weprogram_subtemplate_pin_tuansuccess;
  2744. }
  2745. //}
  2746. }else{
  2747. //pay_order
  2748. $pay_order_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'pay_order') )->find();
  2749. //if( empty($pay_order_info) )
  2750. //{
  2751. $weprogram_subtemplate_pay_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
  2752. if( !empty($weprogram_subtemplate_pay_order) )
  2753. {
  2754. $need_subscript_template['pay_order'] = $weprogram_subtemplate_pay_order;
  2755. }
  2756. //}
  2757. }
  2758. //send_order
  2759. $send_order_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'send_order' ) )->find();
  2760. //if( empty($send_order_info) )
  2761. //{
  2762. $weprogram_subtemplate_send_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
  2763. if( !empty($weprogram_subtemplate_send_order) )
  2764. {
  2765. $need_subscript_template['send_order'] = $weprogram_subtemplate_send_order;
  2766. }
  2767. //}
  2768. //hexiao_success
  2769. $hexiao_success_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'hexiao_success' ) )->find();
  2770. //if( empty($hexiao_success_info) )
  2771. //{
  2772. $weprogram_subtemplate_hexiao_success = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
  2773. if( !empty($weprogram_subtemplate_hexiao_success) )
  2774. {
  2775. $need_subscript_template['hexiao_success'] = $weprogram_subtemplate_hexiao_success;
  2776. }
  2777. //}
  2778. if( !empty($need_subscript_template) )
  2779. {
  2780. $is_need_subscript = 1;
  2781. }
  2782. //下单万能表单
  2783. $need_data['allform'] = D('Home/Allform')->getOrderForms();
  2784. //判断是否使用货到付款
  2785. $cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
  2786. $need_data['cashondelivery_data'] = $cashondelivery_data;
  2787. //订阅消息end
  2788. $need_data['is_need_subscript'] = $is_need_subscript;
  2789. $need_data['need_subscript_template'] = $need_subscript_template;
  2790. //订单提交页面备注信息
  2791. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  2792. $order_note_open = isset($order_note_open) && $order_note_open == 1 ? 1: 0;
  2793. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  2794. $order_note_name = !isset($order_note_name) || empty($order_note_name) ? '店名' : $order_note_name;
  2795. $need_data['order_note_open'] = $order_note_open;//开启下单页面备注,仅 自提跟 团长配送时需要
  2796. $need_data['order_note_name'] = $order_note_name;//备注名称,默认是店名
  2797. $need_data['order_note_content'] = $order_note_content;//备注名称,默认是店名
  2798. $need_data['localtown_modifypickingname'] = $localtown_modifypickingname;//备注名称,默认是店名
  2799. //配送费类型:0、固定金额,1、按距离收取
  2800. $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
  2801. //起送价格
  2802. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
  2803. //达到金额免配送费
  2804. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
  2805. //加价配送
  2806. $localtown_makeup_delivery_money = D('Home/Front')->get_config_by_name('localtown_makeup_delivery_money');
  2807. //1、固定金额,订单价格超过起送价格 无加价配送费,2、按距离收取 无加价配送费 3、固定金额,起送价格为0 无加价配送费
  2808. if(($localtown_delivery_moneytype == 0 && ($localtown_shipping_fare_arr[0]['is_can_qisong'] == 1 || $localtown_moneytype_fixed_deliverymoney == 0)) || $localtown_delivery_moneytype == 1){
  2809. $localtown_makeup_delivery_money = 0;
  2810. }else{
  2811. $localtown_makeup_delivery_money = 0;
  2812. }
  2813. $need_data['localtown_delivery_moneytype'] = $localtown_delivery_moneytype;
  2814. $need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
  2815. $need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
  2816. $need_data['localtown_makeup_delivery_money'] = $localtown_makeup_delivery_money;
  2817. $need_data['order_lou_meng_hao'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao');
  2818. $need_data['order_lou_meng_hao_placeholder'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao_placeholder');
  2819. echo json_encode($need_data);
  2820. die();
  2821. }
  2822. public function sub_order()
  2823. {
  2824. $gpc = I('request.');
  2825. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  2826. $token = $gpc['token'];
  2827. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2828. $member_id = $weprogram_token['member_id'];
  2829. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  2830. $allform_id = $gpc['allform_id'];
  2831. $allform_list = $gpc['allform_list'];
  2832. if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
  2833. {
  2834. $pintuan_model_buy = 0;
  2835. }
  2836. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  2837. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  2838. $is_vip_card_member = 0;
  2839. $is_member_level_buy = 0;
  2840. if( $member_id > 0 )
  2841. {
  2842. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  2843. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  2844. {
  2845. $now_time = time();
  2846. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  2847. {
  2848. $is_vip_card_member = 1;//还是会员
  2849. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  2850. $is_vip_card_member = 2;//已过期
  2851. }
  2852. }
  2853. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  2854. {
  2855. $is_member_level_buy = 1;
  2856. }
  2857. }
  2858. if($buy_type == 'presale')
  2859. {
  2860. $is_vip_card_member = 0;
  2861. $is_member_level_buy = 0;
  2862. }
  2863. //use_score = 1
  2864. $use_score = isset($gpc['use_score']) ? intval($gpc['use_score']) : 0;
  2865. $puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
  2866. if( !empty($puis_not_buy) && $puis_not_buy ==1 )
  2867. {
  2868. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id) )->find();
  2869. if($member_info['level_id'] == 0)
  2870. {
  2871. echo json_encode( array('code' => 2, 'msg' => '普通会员不能购买') );
  2872. die();
  2873. }
  2874. }
  2875. //$buy_type == 'presale'
  2876. $data_s = array();
  2877. $data_s['pay_method'] = $gpc['wxpay'];
  2878. $data_s['buy_type'] = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  2879. $data_s['pick_up_id'] = $gpc['pick_up_id'];
  2880. $data_s['dispatching'] = $gpc['dispatching'];
  2881. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  2882. if($order_note_open == 1){
  2883. $data_s['note_content'] = $gpc['note_content'];
  2884. }else{
  2885. $data_s['note_content'] = '';
  2886. }
  2887. $data_s['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : 0 ;
  2888. if($data_s['dispatching'] != 'express' && empty($data_s['pick_up_id']))
  2889. {
  2890. $last_community = M('lionfish_community_history')->where( array('member_id' => $member_id) )->order('id desc')->find();
  2891. if( !empty($last_community) )
  2892. {
  2893. $data_s['pick_up_id'] = $last_community['head_id'];
  2894. }
  2895. //$data_s['pick_up_id']
  2896. }
  2897. //礼品卡不用配送地址begin
  2898. if( $data_s['buy_type'] == 'virtualcard' )
  2899. {
  2900. $data_s['dispatching'] = 'express';
  2901. $data_s['address_id'] = 0;
  2902. }
  2903. //end
  2904. if( $data_s['buy_type'] == 'dan' || $data_s['buy_type'] == 'soitaire' || $data_s['buy_type'] == 'presale' || ($pintuan_model_buy == 1 && $data_s['buy_type'] != 'dan' && $data_s['buy_type'] != 'integral' ) )
  2905. {
  2906. D('Seller/Community')->in_community_history($member_id,$data_s['pick_up_id']);
  2907. }
  2908. //'express' 快递, 'pickup' 自提, 'tuanz_send' 团长配送) tuan_send_address
  2909. $data_s['ziti_name'] = $gpc['ziti_name'];
  2910. $data_s['quan_arr'] = $gpc['quan_arr'];
  2911. $data_s['comment'] = $gpc['comment'];
  2912. $data_s['ziti_mobile'] = $gpc['ziti_mobile'];
  2913. $data_s['tuan_send_address'] = $gpc['tuan_send_address'];
  2914. $data_s['ck_yupay'] = $gpc['ck_yupay'];
  2915. //是否货到付款
  2916. $data_s['cashon_delivery'] = $gpc['cashon_delivery'];
  2917. $data_s['province_name'] = isset($gpc['province_name']) ? $gpc['province_name']:'' ;
  2918. $data_s['city_name'] = isset($gpc['city_name']) ? $gpc['city_name']: '';
  2919. $data_s['country_name'] = isset($gpc['country_name']) ? $gpc['country_name']: '';
  2920. $data_s['address_name'] = isset($gpc['address_name']) ? $gpc['address_name']:'' ;
  2921. $data_s['latitude'] = isset($gpc['latitude']) ? $gpc['latitude']:'' ;
  2922. $data_s['longitude'] = isset($gpc['longitude']) ? $gpc['longitude']:'' ;
  2923. $data_s['lou_meng_hao'] = isset($gpc['lou_meng_hao']) ? $gpc['lou_meng_hao']:'' ;
  2924. $data_s['expected_delivery_time'] = isset($gpc['expected_delivery_time']) ? $gpc['expected_delivery_time']:'' ;
  2925. //$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
  2926. //$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
  2927. //tuan_send_address
  2928. $province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
  2929. $city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
  2930. $country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
  2931. $address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
  2932. //判断配送距离
  2933. /*if($data_s['dispatching'] == 'localtown_delivery'){
  2934. //服务距离
  2935. $localtown_servvice_maxdistance = D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
  2936. //商家经纬度
  2937. $localtown_shop_lon = D('Home/Front')->get_config_by_name('localtown_shop_lon');
  2938. $localtown_shop_lat = D('Home/Front')->get_config_by_name('localtown_shop_lat');
  2939. $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
  2940. $distince = round($distince/1000,2);
  2941. if($distince > $localtown_servvice_maxdistance){
  2942. //echo json_encode( array('code' => 2, 'msg' => '超出服务距离'.$localtown_servvice_maxdistance.'KM') );
  2943. echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
  2944. die();
  2945. }
  2946. }*/
  2947. $json=array();
  2948. $pay_method = $data_s['pay_method'];//支付类型
  2949. $order_msg_str = $data_s['order_msg_str'];//商品订单留言
  2950. $comment = $data_s['comment'];//商品订单留言
  2951. $comment_arr = array();
  2952. if( !empty($data_s['comment']) )
  2953. {
  2954. $comment_arr1 = explode('@EOF@', $data_s['comment']);
  2955. foreach($comment_arr1 as $var){
  2956. $count = substr_count($var, '_');
  2957. $a = explode('_', $var);
  2958. for($i=1 ; $i<$count ; $i++ ){
  2959. $comment_arr[$a[$i]] = $a[$count];
  2960. }
  2961. }
  2962. }
  2963. $pick_up_id = $data_s['pick_up_id'];
  2964. $dispatching = $data_s['dispatching'];
  2965. $ziti_name = $data_s['ziti_name'];
  2966. $ziti_mobile = $data_s['ziti_mobile'];
  2967. //新增快递
  2968. $province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
  2969. $city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
  2970. $country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
  2971. $address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
  2972. $ck_yupay = $data_s['ck_yupay'];
  2973. $cashon_delivery = $data_s['cashon_delivery'];
  2974. if($dispatching == 'express')
  2975. {
  2976. $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name);
  2977. }
  2978. else if( $dispatching == 'localtown_delivery' )
  2979. {
  2980. $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name,$data_s['latitude'],$data_s['longitude'],$data_s['lou_meng_hao'] );
  2981. }
  2982. else if($dispatching == 'tuanz_send'){
  2983. $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$data_s['tuan_send_address'],$data_s['latitude'],$data_s['longitude'],$data_s['lou_meng_hao'] );
  2984. $data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
  2985. }
  2986. /**
  2987. pick_up_id: that.data.pick_up_id,
  2988. dispatching: that.data.dispatching, //express pickup
  2989. ziti_name: t_ziti_name,
  2990. ziti_mobile: t_ziti_mobile
  2991. **/
  2992. $order_msg_arr = explode('@,@', $order_msg_str);
  2993. $quan_arr = $data_s['quan_arr'];//商品订单留言
  2994. $order_quan_arr = array();
  2995. if( !empty($quan_arr) )
  2996. {
  2997. if( !is_array($quan_arr) )
  2998. {
  2999. $quan_arr = array($quan_arr);
  3000. }
  3001. foreach($quan_arr as $q_val)
  3002. {
  3003. $tmp_q = array();
  3004. $tmp_q = explode('_',$q_val);
  3005. $voucher_info = M('lionfish_comshop_coupon_list')->where("consume='N' and id=".$tmp_q[1]." and user_id=".$member_id." and end_time >".time())->find();
  3006. if( !empty($voucher_info) )
  3007. {
  3008. //$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
  3009. $order_quan_arr[1] = $tmp_q[1];
  3010. }
  3011. }
  3012. }
  3013. $msg_arr = array();
  3014. foreach($order_msg_arr as $val)
  3015. {
  3016. $tmp_val = explode('@_@', $val);
  3017. $msg_arr[ $tmp_val[0] ] = $tmp_val[1];
  3018. }
  3019. $cart= D('Home/Car');
  3020. // 验证商品数量
  3021. //buy_type:buy_type
  3022. $buy_type = $data_s['buy_type'];//I('post.buy_type');
  3023. $is_pin = 0;
  3024. if($buy_type == 'pintuan')
  3025. {
  3026. $is_pin = 1;
  3027. }
  3028. $goodss = $cart->get_all_goodswecar($buy_type,$token,1,$data_s['pick_up_id'], $data_s['soli_id']);
  3029. //付款人
  3030. $payment = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  3031. //收货人
  3032. $addr_param = array();
  3033. $addr_param[':uniacid'] = $_W['uniacid'];
  3034. $addr_param[':member_id'] = $member_id;
  3035. //$addr_sql = "select * from ".tablename('lionfish_comshop_address')." where uniacid=:uniacid and member_id=:member_id order by is_default desc,address_id desc limit 1";
  3036. //$address = pdo_fetch($addr_sql, $addr_param);
  3037. $seller_goodss = array();
  3038. /** 计算每个订单的优惠券占比begin */
  3039. $zanbi_total_money = 0;
  3040. //是否需要校验ticket 交易组件
  3041. $scene = $gpc['scene'];
  3042. $is_need_scene_check = 0;
  3043. if(!empty($scene))
  3044. {
  3045. $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
  3046. }
  3047. foreach($goodss as $key => $val) {
  3048. //单商户先屏蔽
  3049. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  3050. $supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
  3051. if ($supply_id > 0) {
  3052. $supply_info = D('Home/Front')->get_supply_info($supply_id);
  3053. if ($supply_info['type'] == 0) {
  3054. $supply_id = 0;
  3055. }
  3056. }
  3057. if($data_s['dispatching'] == 'localtown_delivery'){
  3058. if($supply_id > 0){
  3059. $isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$supply_id);
  3060. if($isopen_localtown_delivery == 1){
  3061. //服务距离
  3062. $localtown_servvice_maxdistance = D('Home/Front')->get_supply_config_by_name('localtown_servvice_maxdistance',$supply_id);
  3063. //商家经纬度
  3064. $localtown_shop_lon = D('Home/Front')->get_supply_config_by_name('localtown_shop_lon',$supply_id);
  3065. $localtown_shop_lat = D('Home/Front')->get_supply_config_by_name('localtown_shop_lat',$supply_id);
  3066. $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
  3067. $distince = round($distince/1000,2);
  3068. if($distince > $localtown_servvice_maxdistance){
  3069. echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
  3070. die();
  3071. }
  3072. }
  3073. }else{
  3074. //服务距离
  3075. $localtown_servvice_maxdistance = D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
  3076. //商家经纬度
  3077. $localtown_shop_lon = D('Home/Front')->get_config_by_name('localtown_shop_lon');
  3078. $localtown_shop_lat = D('Home/Front')->get_config_by_name('localtown_shop_lat');
  3079. $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
  3080. $distince = round($distince/1000,2);
  3081. if($distince > $localtown_servvice_maxdistance){
  3082. echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
  3083. die();
  3084. }
  3085. }
  3086. }
  3087. $seller_goodss[$supply_id][$key] = $val;
  3088. //$cart->removecar($val['key'],$token);
  3089. if ($is_vip_card_member == 1 && $val['is_take_vipcard'] == 1) {
  3090. $zanbi_total_money += $val['card_total'];
  3091. } else if ($val['is_mb_level_buy'] > 0 && $is_member_level_buy == 1) {
  3092. $zanbi_total_money += $val['level_total'];
  3093. } else if ($val['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0){
  3094. $zanbi_total_money += $val['level_total'];
  3095. }
  3096. else
  3097. {
  3098. $zanbi_total_money += $val['total'];
  3099. }
  3100. //检测是否场景符合begin
  3101. if( $is_need_scene_check == 1 )
  3102. {
  3103. if( $val['isTradeComponts'] == 0 )
  3104. {
  3105. echo json_encode( array('code' => 2,'msg' => $val['name'].':未提交小程序交易组件' ) );
  3106. die();
  3107. }
  3108. }
  3109. //检测是否场景符合end
  3110. }
  3111. //判断是否可以货到付款
  3112. if($cashon_delivery == 1){
  3113. $cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
  3114. if($cashondelivery_data['isopen_cashondelivery'] == 1){
  3115. if($dispatching == 'express' && $cashondelivery_data['isopen_cashondelivery_express'] == 0){
  3116. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3117. die();
  3118. }else if($dispatching == 'tuanz_send' && $cashondelivery_data['isopen_cashondelivery_communityhead'] == 0){
  3119. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3120. die();
  3121. }else if($dispatching == 'localtown_delivery' && $cashondelivery_data['isopen_cashondelivery_localtown'] == 0){
  3122. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3123. die();
  3124. }else if($dispatching == 'hexiao' && $cashondelivery_data['isopen_cashondelivery_hexiao'] == 0){
  3125. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3126. die();
  3127. }else if($dispatching == 'pickup' && $cashondelivery_data['isopen_cashondelivery_ziti'] == 0){
  3128. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3129. die();
  3130. }
  3131. }else{
  3132. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3133. die();
  3134. }
  3135. }
  3136. //....看看有没有满多少才能下单begin
  3137. $open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
  3138. $man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
  3139. //pindan (拼团商品单独购买) pintuan (拼团)
  3140. if($buy_type == 'pintuan' || $buy_type == 'pindan' || $buy_type == 'integral' )
  3141. {
  3142. $open_man_orderbuy = 0;
  3143. }
  3144. if( !empty($open_man_orderbuy) && $open_man_orderbuy == 1 )
  3145. {
  3146. if( !empty($man_orderbuy_money) && $man_orderbuy_money >0 )
  3147. {
  3148. if($man_orderbuy_money > $zanbi_total_money)
  3149. {
  3150. echo json_encode( array('code' => 2,'msg' => '满'.$man_orderbuy_money.'元才可以下单' , 'is_forb' => 1) );
  3151. die();
  3152. }
  3153. }
  3154. }
  3155. //....看看有没有满多少才能下单end
  3156. //清除购物车
  3157. foreach($goodss as $key => $val)
  3158. {
  3159. $cart->removecar($val['key'],$token);
  3160. }
  3161. /** 计算每个订单的优惠券占比end */
  3162. $pay_total = 0;
  3163. //M('order_all')
  3164. $order_all_data = array();
  3165. $order_all_data['member_id'] = $member_id;
  3166. $order_all_data['order_num_alias'] = build_order_no($member_id);
  3167. $order_all_data['transaction_id'] = '';
  3168. $order_all_data['order_status_id'] = 3;
  3169. $order_all_data['is_pin'] = $is_pin;
  3170. $order_all_data['paytime'] = 0;
  3171. $order_all_data['addtime'] = time();
  3172. $order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
  3173. //暂时屏蔽积分商城模块
  3174. $integral_model = D('Home/Integral');
  3175. $order_ids_arr = array();
  3176. $del_integral = 0;
  3177. if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0 )
  3178. {
  3179. $community_info = array();
  3180. $community_detail_info = array();
  3181. }
  3182. else if( $buy_type == 'integral' )
  3183. {
  3184. $community_info = array();
  3185. $community_detail_info = array();
  3186. }
  3187. else if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1 )
  3188. {
  3189. $community_info = M('lionfish_community_head')->where( array('id' => $data_s['pick_up_id'] ) )->find();
  3190. $community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
  3191. }else{
  3192. $community_info = M('lionfish_community_head')->where( array('id' => $data_s['pick_up_id'] ) )->find();
  3193. $community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
  3194. }
  3195. $address_info = M('lionfish_comshop_address')->where( array('address_id' => $data_s['address_id'] ) )->find();
  3196. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  3197. $full_money = D('Home/Front')->get_config_by_name('full_money');
  3198. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  3199. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  3200. $man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
  3201. if( empty($man_free_tuanzshipping) )
  3202. {
  3203. $man_free_tuanzshipping = 0;
  3204. }
  3205. if( empty($man_free_shipping) )
  3206. {
  3207. $man_free_shipping = 0;
  3208. }
  3209. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  3210. {
  3211. $is_open_fullreduction = 0;
  3212. }
  3213. if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0 )
  3214. {
  3215. $man_free_tuanzshipping = 0;
  3216. $man_free_shipping = 0;
  3217. $is_open_fullreduction = 0;
  3218. }
  3219. else if( $buy_type == 'integral' )
  3220. {
  3221. $man_free_tuanzshipping = 0;
  3222. $man_free_shipping = 0;
  3223. $is_open_fullreduction = 0;
  3224. }
  3225. else if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1 )
  3226. {
  3227. $man_free_shipping = 0;
  3228. $is_open_fullreduction = 0;
  3229. }
  3230. //预售不参与满减
  3231. if($buy_type == 'presale')
  3232. {
  3233. $man_free_tuanzshipping = 0;
  3234. $man_free_shipping = 0;
  3235. $is_open_fullreduction = 0;
  3236. }
  3237. $is_moban = false;
  3238. $cart = D('Home/Car');
  3239. $is_just_1 = 0;
  3240. $index_comment = 0;
  3241. $pay_goods_name = "";
  3242. $store_buy_total_money = 0;
  3243. $open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
  3244. $score_for_money = 0;//use_score
  3245. if( $buy_type == 'integral' )
  3246. {
  3247. $open_score_buy_score = 0;
  3248. }
  3249. //预售不参与积分抵扣
  3250. if($open_score_buy_score == 1 && $use_score == 1 && $payment['score'] > 0 && $buy_type != 'presale')
  3251. {
  3252. //计算能兑换多少钱
  3253. $score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
  3254. //只有兑换比例大于0才能允许兑换
  3255. if( !empty($score_forbuy_money) && $score_forbuy_money >0 )
  3256. {
  3257. $score_for_money = sprintf('%.2f', $payment['score'] / $score_forbuy_money);
  3258. }
  3259. }
  3260. foreach($seller_goodss as $kk => $vv)
  3261. {
  3262. $is_just_1++;
  3263. $data = array();
  3264. $data['member_id']=$member_id;
  3265. $data['name']= $payment['username'];
  3266. $data['use_score']= $use_score;//是否使用积分抵扣
  3267. $data['telephone']= $data_s['ziti_mobile'];
  3268. $data['note_content']= $data_s['note_content'];
  3269. $data['shipping_name']= $data_s['ziti_name'];
  3270. $data['shipping_tel']= $data_s['ziti_mobile'];
  3271. if($dispatching == 'express' || $dispatching == 'tuanz_send' || $dispatching == 'localtown_delivery')
  3272. {
  3273. $data['shipping_address'] = $address_info['address'];
  3274. $data['shipping_province_id']=$address_info['province_id'];
  3275. $data['shipping_city_id']=$address_info['city_id'];
  3276. $data['shipping_stree_id']= 0;
  3277. $data['shipping_country_id']=$address_info['country_id'];
  3278. }else{
  3279. $data['shipping_address'] = $community_detail_info['fullAddress'];
  3280. $data['shipping_province_id']=$community_info['province_id'];
  3281. $data['shipping_city_id']=$community_info['city_id'];
  3282. $data['shipping_stree_id']=$community_info['country_id'];
  3283. $data['shipping_country_id']=$community_info['area_id'];
  3284. }
  3285. $data['shipping_method'] = 0;
  3286. $data['delivery']=$dispatching;
  3287. $data['pick_up_id']=$pick_up_id;
  3288. $data['ziti_name']=$community_info['head_name'];
  3289. $data['ziti_mobile']=$community_info['head_mobile'];
  3290. $data['payment_method']=$pay_method;
  3291. $data['address_id']= $data_s['address_id'];
  3292. $data['voucher_id'] = isset($order_quan_arr[1]) ? $order_quan_arr[1]:0;//目前都是平台券
  3293. $data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
  3294. $data['date_added']=time();
  3295. $subject='';
  3296. $fare = 0;
  3297. $order_total = 0;
  3298. $trans_free_toal = 0;//运费
  3299. $is_localtown_free_shipping_fare = 0;
  3300. $localtown_shipping_fare_total = 0;//同城配送费
  3301. $localtown_free_shipping_fare = 0;//满减的同城配送费用
  3302. $reduce_money = 0;
  3303. $man_total_free = 0;
  3304. $score_buy_money = 0;
  3305. $is_lottery = 0;
  3306. $is_integral = 0;
  3307. $is_spike = 0;
  3308. $is_hexiao = 0;
  3309. $total_weight = 0;
  3310. $total_quantity = 0;
  3311. $redis_has_add_list = array();
  3312. $is_free_shipping_fare = 0;//是否免除运费
  3313. $order_goods_total_money = 0;
  3314. $goods_data = array();
  3315. $is_moban = false;
  3316. //comment_arr comment_arr
  3317. $packing_fare = 0;
  3318. $iscan_fu_packing = 1;
  3319. if('localtown_delivery' == $dispatching)
  3320. {
  3321. $tmp_sellergd = array($kk => array('goods'=>$vv) );
  3322. $town_address = M('lionfish_comshop_address')->where( array('address_id' => $data_s['address_id'] ) )->find();
  3323. list($lon, $lat ) = explode(",",$town_address['lon_lat'] );
  3324. $localtown_shippingfare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $tmp_sellergd );
  3325. $trans_free_toal = $localtown_shippingfare_arr['total_shipping_fare'];
  3326. $localtown_shipping_fare_total = $trans_free_toal;
  3327. $packing_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money( array( $kk => array('goods' => $vv ) ) );
  3328. $packing_fare = $packing_fare_arr['total_picking_fare'];
  3329. $localtown_shipping_fare = $localtown_shippingfare_arr['total_shipping_fare'];
  3330. $localtown_yl_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
  3331. if($localtown_shipping_fare != $localtown_yl_shipping_fare && $localtown_shipping_fare == 0){
  3332. $is_localtown_free_shipping_fare = 1;
  3333. $localtown_free_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
  3334. }
  3335. $data['localtown_add_shipping_fare'] = $localtown_shippingfare_arr[$kk]['localtown_add_shipping_fare'];
  3336. }
  3337. $data['expected_delivery_time'] = $data_s['expected_delivery_time'];
  3338. $data['packing_fare'] = floatval($packing_fare);
  3339. foreach($vv as $key => $good)
  3340. {
  3341. if( $kk == 0 )
  3342. {
  3343. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3344. {
  3345. $store_buy_total_money += $good['card_total'];
  3346. }
  3347. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3348. {
  3349. $store_buy_total_money += $good['level_total'];
  3350. }
  3351. else
  3352. {
  3353. $store_buy_total_money += $good['total'];
  3354. }
  3355. }
  3356. /**
  3357. if($good['shipping']==1)
  3358. {
  3359. //统一运费
  3360. $trans_free_toal += $good['goods_freight'];
  3361. $trans_free = $good['goods_freight'];
  3362. }else {
  3363. //运费模板
  3364. $trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
  3365. //$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
  3366. $trans_free_toal +=$trans_free;
  3367. }
  3368. **/
  3369. $trans_free = 0;
  3370. //$trans_free_toal +=$trans_free;
  3371. //sku_str
  3372. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3373. {
  3374. $order_goods_total_money += $good['card_total'];
  3375. $order_total += $good['card_total'];
  3376. }
  3377. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3378. {
  3379. $order_goods_total_money += $good['level_total'];
  3380. $order_total += $good['level_total'];
  3381. }
  3382. else
  3383. {
  3384. $order_goods_total_money += $good['total'];
  3385. $order_total += $good['total'];
  3386. }
  3387. $tp_goods_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $good['goods_id']) )->find();
  3388. $tp_goods_info['store_id'] = 1;
  3389. if($tp_goods_info['type'] == 'lottery')
  3390. {
  3391. $is_lottery = 1;
  3392. }
  3393. if($tp_goods_info['type'] == 'spike')
  3394. {
  3395. $is_spike = 1;
  3396. $is_pin = 0;
  3397. }
  3398. //暂时屏蔽积分商城模块
  3399. if($tp_goods_info['type'] == 'integral')
  3400. {
  3401. $is_integral = 1;
  3402. $is_pin = 0;
  3403. $check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
  3404. if($check_result['code'] == 1)
  3405. {
  3406. echo json_encode( array('code' => 2, 'msg' => '剩余'.$check_result['cur_score'].'积分,积分不足!' , 'is_forb' => 1 ) );
  3407. die();
  3408. }
  3409. }
  3410. //is_hexiao is_only_express
  3411. if($good['is_only_express']==2)
  3412. {
  3413. $is_hexiao = 2;
  3414. $is_pin = 0;
  3415. }
  3416. if($good['shipping']==0)
  3417. {
  3418. $is_moban = true;
  3419. //统一运费
  3420. $total_weight += $good['weight']*$good['quantity'];
  3421. $total_quantity += $good['quantity'];
  3422. }
  3423. $fenbi_li = 1;
  3424. if( $zanbi_total_money > 0 )
  3425. {
  3426. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3427. {
  3428. $fenbi_li = round($good['card_total'] / $zanbi_total_money, 2);
  3429. }
  3430. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3431. {
  3432. $fenbi_li = round($good['level_total'] / $zanbi_total_money, 2);
  3433. }
  3434. else
  3435. {
  3436. $fenbi_li = round($good['total'] / $zanbi_total_money, 2);
  3437. }
  3438. }
  3439. //if( isset($comment_arr[$index_comment]) )
  3440. //{
  3441. // $comment = $comment_arr[$index_comment];
  3442. //}
  3443. //$good['goods_id']
  3444. if( isset($comment_arr) )
  3445. {
  3446. foreach($comment_arr as $key => $var){
  3447. if($good['goods_id'] == $key ){
  3448. $comment = $var;
  3449. }
  3450. }
  3451. }
  3452. //监测库存数量
  3453. $quantity_flag = D('Seller/Redisorder')->check_goods_can_buy($good['goods_id'], $good['sku_str'],$good['quantity']);
  3454. if( $quantity_flag <=0 )
  3455. {
  3456. if( !empty($redis_has_add_list) )
  3457. {
  3458. D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
  3459. }
  3460. echo json_encode( array('code' => 2, 'msg' => '已抢光' , 'is_forb' => 1) );
  3461. die();
  3462. }
  3463. //如果是下单减库存,那么用占坑法来避免超库存---begin
  3464. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
  3465. if( empty($kucun_method) )
  3466. {
  3467. $kucun_method = 0;
  3468. }
  3469. if($kucun_method == 0)
  3470. {
  3471. //$ret = $redis->rPush('city', 'guangzhou');
  3472. $check_redis_quantity = D('Seller/Redisorder')->add_goods_buy_user($good['goods_id'], $good['sku_str'],$good['quantity'],$member_id);
  3473. //注意要回滚
  3474. //$key = "user_goods_{$member_id}_{$goods_id}_{$sku_str}";
  3475. if($check_redis_quantity == 0)
  3476. {
  3477. //cancle_redis_user_list
  3478. if( !empty($redis_has_add_list) )
  3479. {
  3480. D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
  3481. }
  3482. echo json_encode( array('code' => 2, 'msg' => '已抢光' , 'is_forb' => 1) );
  3483. die();
  3484. }
  3485. $redis_has_add_list[] = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'],'quantity' => $good['quantity'] );
  3486. }
  3487. //----------------redis end
  3488. if( $good['can_man_jian'] == 1)
  3489. {
  3490. //$man_total_free += $good['total'];
  3491. //begggg
  3492. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3493. {
  3494. if( $good['can_man_jian'] == 1)
  3495. {
  3496. $man_total_free += $good['card_total'];
  3497. }
  3498. }
  3499. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3500. {
  3501. if( $good['can_man_jian'] == 1)
  3502. {
  3503. $man_total_free += $good['level_total'];
  3504. }
  3505. }
  3506. else
  3507. {
  3508. if( $good['can_man_jian'] == 1)
  3509. {
  3510. $man_total_free += $good['total'];
  3511. }
  3512. }
  3513. //eddddd
  3514. }
  3515. $pay_goods_name .= $good['name'];
  3516. if( $good['is_mb_level_buy'] == 1 && $is_vip_card_member ==0 && $member_info['level_id'] >0 )
  3517. {
  3518. $good['is_mb_level_buy'] == 1;
  3519. }else{
  3520. $good['is_mb_level_buy'] == 0;
  3521. }
  3522. $localtown_superposition_pickingmoney = 0;
  3523. $localtown_superposition_pickingmoney = isset($localtown_superposition_pickingmoney) ? $localtown_superposition_pickingmoney : 0;
  3524. $gd_packing_fare = 0;
  3525. if( $localtown_superposition_pickingmoney == 0 )
  3526. {
  3527. $gd_packing_fare = $good['packing_free'];
  3528. } else
  3529. {
  3530. if( $packing_fare == $good['packing_free'] && $iscan_fu_packing == 1)
  3531. {
  3532. $iscan_fu_packing = 0;
  3533. $gd_packing_fare = $good['packing_free'];
  3534. }
  3535. }
  3536. $goods_data[] = array(
  3537. 'goods_id' => $good['goods_id'],
  3538. 'store_id' => $tp_goods_info['store_id'],
  3539. 'name' => $good['name'],
  3540. 'model' => $good['model'],
  3541. 'is_pin' => $is_pin,
  3542. 'pin_id' => $good['pin_id'],
  3543. 'header_disc' => $good['header_disc'],
  3544. 'member_disc' => $good['member_disc'],
  3545. 'level_name' => $good['level_name'],
  3546. 'option' => $good['sku_str']== 'undefined' ? '':$good['sku_str'],
  3547. 'quantity' => $good['quantity'],
  3548. 'shipping_fare' => $trans_free,
  3549. 'price' => $good['price'],
  3550. 'costprice' => $good['costprice'],
  3551. 'card_price' => $good['card_price'],
  3552. 'levelprice' => $good['levelprice'],
  3553. 'total' => $good['total'],
  3554. 'packing_fare' => $gd_packing_fare,
  3555. 'card_total' => $good['card_total'] ,
  3556. 'level_total' => $good['level_total'] ,
  3557. 'is_mb_level_buy' => $good['is_mb_level_buy'] ,
  3558. 'is_take_vipcard' => $good['is_take_vipcard'],
  3559. 'fenbi_li' => $fenbi_li,
  3560. 'can_man_jian' => $good['can_man_jian'],
  3561. 'soli_id' => $good['soli_id'],
  3562. 'comment' => htmlspecialchars($comment)
  3563. );
  3564. }
  3565. $index_comment++;
  3566. //$total_weight = 0;
  3567. //$total_quantity = 0;
  3568. if($dispatching == 'express')
  3569. {
  3570. //结算运费新模式
  3571. $trans_free_toal = 0;//运费
  3572. //----开始计算运费
  3573. //ims_
  3574. $shipping_default = M('lionfish_comshop_shipping')->where("enabled=1")->order('isdefault desc,id desc')->find();
  3575. $seller_goodss_re = $seller_goodss;
  3576. $store_shipping_fare = 0;
  3577. if($is_moban)
  3578. {
  3579. $store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $total_quantity,$total_weight, $address_info['city_id'] );
  3580. }
  3581. $trans_free_toal += $store_shipping_fare;
  3582. foreach($vv as $kkc =>$d_goods)
  3583. {
  3584. if($d_goods['shipping']==1)
  3585. {
  3586. //统一运费
  3587. $trans_free_toal += $d_goods['goods_freight'];
  3588. }
  3589. }
  3590. if( $kk == 0 && !empty($man_free_shipping) && $man_free_shipping > 0 && $order_goods_total_money >= $man_free_shipping )
  3591. {
  3592. //$trans_free_toal = 0;
  3593. $is_free_shipping_fare = 1;
  3594. }
  3595. //---结束结算运费 address_id
  3596. $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name);
  3597. }
  3598. else if('tuanz_send' == $dispatching)
  3599. {
  3600. $trans_free_toal = 0;
  3601. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  3602. $community_info_modify = $community_info;
  3603. if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 )
  3604. {
  3605. if( !empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0 )
  3606. {
  3607. $delivery_tuanz_money = $community_info_modify['shipping_fare'];
  3608. }
  3609. }
  3610. $trans_free_toal = $delivery_tuanz_money;
  3611. $data['tuan_send_address'] = $data_s['tuan_send_address'];
  3612. if( $kk == 0 && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $order_goods_total_money >= $man_free_tuanzshipping )
  3613. {
  3614. $is_free_shipping_fare = 1;
  3615. //$trans_free_toal = 0;
  3616. }
  3617. }
  3618. //$is_pin; is_lottery
  3619. //'pintuan', 'normal', 'lottery'
  3620. $data['type'] = 'normal';
  3621. if($is_pin == 1)
  3622. {
  3623. $data['type'] = 'pintuan';
  3624. if($is_lottery == 1)
  3625. {
  3626. $data['type'] = 'lottery';
  3627. }
  3628. }
  3629. if($is_integral == 1)
  3630. {
  3631. $data['type'] = 'integral';
  3632. $is_pin = 0;
  3633. }
  3634. if($is_hexiao == 1)
  3635. {
  3636. $data['type'] = 'virtual';
  3637. $is_pin = 0;
  3638. }
  3639. if($is_spike == 1)
  3640. {
  3641. $data['type'] = 'spike';
  3642. $is_pin = 0;
  3643. }
  3644. //礼品卡配送费0
  3645. if( $buy_type == 'virtualcard' )
  3646. {
  3647. $trans_free_toal = 0;
  3648. }
  3649. $data['shipping_fare'] = floatval($trans_free_toal);
  3650. if($is_free_shipping_fare == 1)
  3651. {
  3652. $trans_free_toal = 0;
  3653. }
  3654. //原先计算满减金额
  3655. /*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
  3656. {
  3657. $reduce_money = $full_reducemoney ;
  3658. }*/
  3659. //多组满减金额计算
  3660. if($is_open_fullreduction == 1)
  3661. {
  3662. $reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
  3663. $reduce_money = $reduce_result['reduce_money'];
  3664. }
  3665. $data['is_free_shipping_fare']= $is_free_shipping_fare;
  3666. $data['store_id']= $kk;
  3667. $data['order_goods_total_money']= $order_goods_total_money;
  3668. $data['is_localtown_free_shipping_fare']= $is_localtown_free_shipping_fare;
  3669. $data['localtown_free_shipping_fare']= $localtown_free_shipping_fare;
  3670. $data['goodss'] = $goods_data;
  3671. $data['order_num_alias']=build_order_no($member_id);
  3672. $data['totals'][0]=array(
  3673. 'code'=>'sub_total',
  3674. 'title'=>'商品价格',
  3675. 'text'=>'¥'.$order_total,
  3676. 'value'=>$order_total
  3677. );
  3678. $data['totals'][1]=array(
  3679. 'code'=>'shipping',
  3680. 'title'=>'运费',
  3681. 'text'=>'¥'.$trans_free_toal,
  3682. 'value'=>$trans_free_toal
  3683. );
  3684. $data['totals'][2]=array(
  3685. 'code'=>'total',
  3686. 'title'=>'总价',
  3687. 'text'=>'¥'.($order_total+$trans_free_toal-$reduce_money),
  3688. 'value'=>($order_total+$trans_free_toal-$reduce_money)
  3689. );
  3690. $data['from_type'] = 'wepro';
  3691. //目前都是平台券
  3692. if($data['voucher_id'] > 0) {
  3693. //暂时屏蔽优惠券,等待开启
  3694. /**
  3695. $voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ",
  3696. array(':uniacid' => $_W['uniacid'],':id' => $data['voucher_id']));
  3697. $data['voucher_credit'] = $voucher_info['credit'];
  3698. pdo_update('lionfish_comshop_coupon_list', array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time()), array('id' => $data['voucher_id'] ));
  3699. **/
  3700. $voucher_info = M('lionfish_comshop_coupon_list')->where( array('id' => $data['voucher_id']) )->find();
  3701. //检查优惠券指定商品或指定商品分类 优惠金额 begin
  3702. $voucher_list[0] = $voucher_info;
  3703. $voucher_list = D('Home/Voucher')->get_voucher_amout_bygoods($voucher_list,$goods_data, 0);
  3704. $voucher_info = $voucher_list[0];
  3705. //检查优惠券指定商品或指定商品分类 优惠金额 end
  3706. $data['voucher_credit'] = $voucher_info['can_vouche_amount'];
  3707. $bili = 1;
  3708. if( $zanbi_total_money > 0 )
  3709. {
  3710. $bili = round( ($order_goods_total_money / $zanbi_total_money), 2);
  3711. }
  3712. $data['voucher_credit'] = $data['voucher_credit'] * $bili;
  3713. //判断是否超出订单商品金额,不算运费
  3714. //if($data['voucher_credit'] > $order_total+$trans_free_toal - $reduce_money )
  3715. if($data['voucher_credit'] > $order_total - $reduce_money )
  3716. {
  3717. $data['voucher_credit'] = $order_total - $reduce_money;
  3718. }
  3719. M('lionfish_comshop_coupon_list')->where( array('id' => $data['voucher_id'] ) )->save( array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time() ) );
  3720. } else {
  3721. $data['voucher_credit'] = 0;
  3722. }
  3723. $use_score_total = 0;//用掉用户多少积分了.
  3724. $data['score_for_money'] = 0;
  3725. if( $kk == 0 && $score_for_money > 0)
  3726. {
  3727. if( $order_total+$trans_free_toal - $reduce_money - $data['voucher_credit'] <= 0)
  3728. {
  3729. //没必要扣积分了,单价已经是0
  3730. }else{
  3731. //只能抵扣扣除优惠券部分的金额
  3732. $del_money = $order_total - $data['voucher_credit'] - $reduce_money;
  3733. //var_dump($del_money, $score_for_money);die();
  3734. //score_for_money 会员能抵扣的最大金额
  3735. //计算多少积分了。
  3736. $score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
  3737. $score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
  3738. if( empty($score_forbuy_money_maxbi) )
  3739. {
  3740. $score_forbuy_money_maxbi = 100;
  3741. }
  3742. //$max_dikou_money = sprintf('%.2f', ($del_money * $score_forbuy_money_maxbi) /100);
  3743. $max_dikou_score = floor($del_money * $score_forbuy_money_maxbi * $score_forbuy_money / 100 );
  3744. $max_dikou_money = sprintf('%.2f', ($max_dikou_score / $score_forbuy_money));
  3745. if($max_dikou_money < $score_for_money)
  3746. {
  3747. $score_for_money = $max_dikou_money;
  3748. }
  3749. //$score_buy_money = 0;
  3750. $data['score_for_money'] = $score_for_money;
  3751. //TODO...扣除会员积分,将积分分拆入每个商品订单,写入日志
  3752. //var_dump($data['score_for_money'], $max_dikou_money);die();
  3753. }
  3754. }
  3755. $data['comment'] = htmlspecialchars($comment);
  3756. $data['reduce_money'] = $reduce_money;
  3757. $data['man_total_free'] = $man_total_free;
  3758. //判断自提 dispatching:"pickup"
  3759. //dispatching, //express pickup
  3760. if($dispatching == 'express')
  3761. {
  3762. $data['total']=($order_total);//+$fare - $data['voucher_credit']
  3763. }else if('tuanz_send' == $dispatching){
  3764. $data['total']=($order_total);// - $data['voucher_credit']);
  3765. }
  3766. else{
  3767. $data['total'] = ($order_total );// - $data['voucher_credit']
  3768. }
  3769. //积分商城
  3770. //暂时屏蔽积分商城模块
  3771. if($data['type'] == 'integral')
  3772. {
  3773. $del_integral += $order_total;//扣除积分
  3774. $data['total'] = $order_total;
  3775. }
  3776. $data['buy_type'] = $buy_type;//判断预售使用
  3777. //万能表单数据
  3778. $data['allform_id'] = $allform_id;
  3779. $data['allform_list'] = $allform_list;
  3780. $oid= D('Home/Frontorder')->addOrder($data);// D('Order')->addOrder($data);
  3781. //暂时屏蔽自提模块
  3782. /**
  3783. if($data['delivery'] == 'pickup')
  3784. {
  3785. $verify_bool = true;
  3786. $verifycode = 0;
  3787. while($verify_bool)
  3788. {
  3789. $code = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
  3790. $verifycode = $code ? $code : rand(100000,999999);
  3791. $verifycode = str_replace('1989','9819',$verifycode);
  3792. $verifycode = str_replace('1259','9521',$verifycode);
  3793. $verifycode = str_replace('12590','95210',$verifycode);
  3794. $verifycode = str_replace('10086','68001',$verifycode);
  3795. $pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
  3796. if(empty($pick_order))
  3797. {
  3798. $verify_bool = false;
  3799. }
  3800. }
  3801. $pick_data = array();
  3802. $pick_data['pick_sn'] = $verifycode;
  3803. $pick_data['pick_id'] = $pick_up_id;
  3804. $pick_data['order_id'] = $oid;
  3805. $pick_data['state'] = 0;
  3806. $pick_data['ziti_name'] = $ziti_name;
  3807. $pick_data['ziti_mobile'] = $ziti_mobile;
  3808. $pick_data['addtime'] = time();
  3809. M('pick_order')->add($pick_data);
  3810. }
  3811. **/
  3812. $order_ids_arr[] = $oid;
  3813. //$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
  3814. if($dispatching == 'express' && $data['type'] != 'integral')
  3815. {
  3816. $pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit']- $reduce_money - $data['score_for_money'];
  3817. }
  3818. else if( $dispatching == 'express' && $data['type'] == 'integral' )
  3819. {
  3820. $pay_total = $trans_free_toal;
  3821. }
  3822. else if('localtown_delivery' == $dispatching)
  3823. {
  3824. $pay_total = $pay_total + $order_total+ $packing_fare + $trans_free_toal - $data['voucher_credit'] -$reduce_money - $data['score_for_money'] + $data['localtown_add_shipping_fare'];
  3825. }
  3826. else if('tuanz_send' == $dispatching){
  3827. $pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'] -$reduce_money - $data['score_for_money'];
  3828. }
  3829. else{
  3830. $pay_total = $pay_total + $order_total - $data['voucher_credit'] -$reduce_money - $data['score_for_money'];
  3831. }
  3832. if( $buy_type == 'presale' )
  3833. {
  3834. //如果是预售,此处支付的就是定金
  3835. $presale_order_info = M('lionfish_comshop_order_presale')->where(['order_id' => $oid ])->find();
  3836. if( $presale_order_info['presale_type'] == 1 )
  3837. {
  3838. M('lionfish_comshop_order_presale')->where( ['id' => $presale_order_info['id'] ] )->save( ['presale_ding_money' => $pay_total ] );
  3839. }else{
  3840. $pay_total = $presale_order_info['presale_ding_money'];
  3841. }
  3842. }
  3843. $pay_total = round($pay_total, 2);
  3844. $order_relate_data = array();
  3845. $order_relate_data['order_all_id'] = $order_all_id;
  3846. $order_relate_data['order_id'] = $oid;
  3847. $order_relate_data['addtime'] = time();
  3848. M('lionfish_comshop_order_relate')->add($order_relate_data);
  3849. }
  3850. $order_all_data = array();
  3851. $order_all_data['total_money'] = $pay_total;
  3852. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id) )->save($order_all_data);
  3853. if($order_all_id){
  3854. $order = M('lionfish_comshop_order')->where( array('order_id' => $oid) )->find();
  3855. $member_info = M('lionfish_comshop_member')->field('we_openid,account_money')->where( array('member_id' => $member_id ) )->find();
  3856. $is_yue_open = 0;
  3857. $is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
  3858. if( empty($is_yue_open) )
  3859. {
  3860. $is_yue_open = 0;
  3861. }
  3862. //检测是否需要扣除积分
  3863. if($data['type'] == 'integral' && $del_integral> 0 && $is_integral == 1)
  3864. {
  3865. $order_goods_tp = M('lionfish_comshop_order_goods')->field('order_goods_id')->where( array('order_id' => $oid ) )->find();
  3866. D('Admin/Member')->sendMemberPointChange($member_id,$del_integral, 1 ,'积分兑换商品', 'integral_exchange', $oid ,$order_goods_tp['order_goods_id']);
  3867. }
  3868. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  3869. if( $order['type'] == 'ignore' || $pay_total<=0 || ($is_yue_open == 1 && $ck_yupay == 1 && $member_info['account_money'] >= $pay_total) )
  3870. {
  3871. //余额支付独立方法
  3872. D('Home/OrderV2')->carOrderYuerPay( $order_all_id, $order ,$pay_total , $ck_yupay ,$buy_type, $is_integral, $is_spike , $is_just_1 );
  3873. }else if($buy_type == 'dan' && $cashon_delivery == 1){//货到付款订单
  3874. //货到付款支付独立方法
  3875. D('Home/OrderV2')->carOrderCashonPay( $order_all_id, $order ,$pay_total , $cashon_delivery , $buy_type , $is_spike , $is_just_1);
  3876. }
  3877. else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  3878. {
  3879. //begin
  3880. $fee = $pay_total;
  3881. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  3882. $body = $pay_goods_name;//'商品购买';
  3883. $body = mb_substr($body,0,32,'utf-8');
  3884. if( empty($body) )
  3885. {
  3886. $body = '商品购买';
  3887. }
  3888. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  3889. $nonce_str = nonce_str();
  3890. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  3891. $notify_url = $shop_domain.'/notify.php';
  3892. $openid = $payment['we_openid'];
  3893. $out_trade_no = $order_all_id.'-'.time();
  3894. //out_trade_no
  3895. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id ) )->save( array('out_trade_no' => $out_trade_no ) );
  3896. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  3897. $total_fee = $fee*100;
  3898. //float(0.99999999999998)
  3899. $trade_type = 'JSAPI';
  3900. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  3901. $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');// 'wx7c38e2f177e0af59';
  3902. $post['body'] = $body;
  3903. $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');//'1562705521';
  3904. $post['nonce_str'] = $nonce_str;
  3905. $post['notify_url'] = $notify_url;
  3906. //$post['openid'] = $openid;
  3907. $post['out_trade_no'] = $out_trade_no;
  3908. $post['spbill_create_ip'] = $spbill_create_ip;
  3909. $post['sub_appid'] = $appid;
  3910. $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  3911. $post['sub_openid'] = $openid;
  3912. $post['total_fee'] = $total_fee;
  3913. $post['trade_type'] = $trade_type;
  3914. $sign = sign($post,$pay_key);
  3915. //var_dump( $notify_url );die();
  3916. $post_xml = '<xml>
  3917. <appid>'.$post['appid'].'</appid>
  3918. <body>'.$body.'</body>
  3919. <mch_id>'.$post['mch_id'].'</mch_id>
  3920. <nonce_str>'.$nonce_str.'</nonce_str>
  3921. <notify_url>'.$notify_url.'</notify_url>
  3922. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  3923. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  3924. <sub_appid>'.$post['sub_appid'].'</sub_appid>
  3925. <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
  3926. <sub_openid>'.$openid.'</sub_openid>
  3927. <total_fee>'.$total_fee.'</total_fee>
  3928. <trade_type>'.$trade_type.'</trade_type>
  3929. <sign>'.$sign.'</sign>
  3930. </xml> ';
  3931. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  3932. $xml = http_request($url,$post_xml);
  3933. $array = xml($xml);
  3934. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  3935. D('Home/Pin')->insertNotifyOrder($order['order_id']);
  3936. $time = time();
  3937. $tmp=array();
  3938. $tmp['appId'] = $appid;
  3939. $tmp['nonceStr'] = $nonce_str;
  3940. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  3941. $tmp['signType'] = 'MD5';
  3942. $tmp['timeStamp'] = "$time";
  3943. $prepay_id = (string)$array['PREPAY_ID'];
  3944. M('lionfish_comshop_order')->where( array('order_id' => array('in', $order_ids_arr)) )->save( array('perpay_id' => $prepay_id) );
  3945. //M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
  3946. $data = array();
  3947. $data['code'] = 0;
  3948. $data['appid'] = $appid;
  3949. $data['timeStamp'] = "$time";
  3950. $data['nonceStr'] = $nonce_str;
  3951. $data['signType'] = 'MD5';
  3952. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  3953. $data['paySign'] = sign($tmp,$pay_key);
  3954. $data['out_trade_no'] = $out_trade_no;
  3955. $data['is_go_orderlist'] = $is_just_1;
  3956. if($is_pin == 1)
  3957. {
  3958. $data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
  3959. } else {
  3960. $data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
  3961. }
  3962. }else{
  3963. $data = array();
  3964. $data['code'] = 1;
  3965. $data['text'] = "错误";
  3966. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  3967. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  3968. }
  3969. $data['has_yupay'] = 0;
  3970. //end
  3971. }
  3972. else{
  3973. $fee = $pay_total;
  3974. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  3975. $body = $pay_goods_name;//'商品购买';
  3976. $body = mb_substr($body,0,32,'utf-8');
  3977. if( empty($body) )
  3978. {
  3979. $body = '商品购买';
  3980. }
  3981. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  3982. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  3983. $nonce_str = nonce_str();
  3984. $notify_url = $shop_domain.'/notify.php';
  3985. $openid = $payment['we_openid'];
  3986. $out_trade_no = $order_all_id.'-'.time();
  3987. //out_trade_no
  3988. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id ) )->save( array('out_trade_no' => $out_trade_no ) );
  3989. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  3990. $total_fee = $fee*100;
  3991. $trade_type = 'JSAPI';
  3992. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  3993. $post['appid'] = $appid;
  3994. $post['body'] = $body;
  3995. $post['mch_id'] = $mch_id;
  3996. $post['nonce_str'] = $nonce_str;
  3997. $post['notify_url'] = $notify_url;
  3998. $post['openid'] = $openid;
  3999. $post['out_trade_no'] = $out_trade_no;
  4000. $post['spbill_create_ip'] = $spbill_create_ip;
  4001. $post['total_fee'] = $total_fee;
  4002. $post['trade_type'] = $trade_type;
  4003. $sign = sign($post,$pay_key);
  4004. $post_xml = '<xml>
  4005. <appid>'.$appid.'</appid>
  4006. <body>'.$body.'</body>
  4007. <mch_id>'.$mch_id.'</mch_id>
  4008. <nonce_str>'.$nonce_str.'</nonce_str>
  4009. <notify_url>'.$notify_url.'</notify_url>
  4010. <openid>'.$openid.'</openid>
  4011. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4012. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4013. <total_fee>'.$total_fee.'</total_fee>
  4014. <trade_type>'.$trade_type.'</trade_type>
  4015. <sign>'.$sign.'</sign>
  4016. </xml> ';
  4017. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4018. $xml = http_request($url,$post_xml);
  4019. $array = xml($xml);
  4020. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4021. D('Home/Pin')->insertNotifyOrder($order['order_id']);
  4022. $time = time();
  4023. $tmp=array();
  4024. $tmp['appId'] = $appid;
  4025. $tmp['nonceStr'] = $nonce_str;
  4026. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4027. $tmp['signType'] = 'MD5';
  4028. $tmp['timeStamp'] = "$time";
  4029. $prepay_id = (string)$array['PREPAY_ID'];
  4030. M('lionfish_comshop_order')->where( array('order_id' => array('in', $order_ids_arr)) )->save( array('perpay_id' => $prepay_id) );
  4031. //M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
  4032. $data = array();
  4033. $data['code'] = 0;
  4034. $data['appid'] = $appid;
  4035. $data['timeStamp'] = "$time";
  4036. $data['nonceStr'] = $nonce_str;
  4037. $data['signType'] = 'MD5';
  4038. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4039. $data['paySign'] = sign($tmp,$pay_key);
  4040. $data['out_trade_no'] = $out_trade_no;
  4041. $data['is_go_orderlist'] = $is_just_1;
  4042. //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
  4043. $data['order_info'] = [];
  4044. $data['isRequestOrderPayment'] = $is_need_scene_check;
  4045. if($is_need_scene_check == 1)
  4046. {
  4047. $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $oid , $time , $pay_total );
  4048. //如果是微信小程序交易组件,提供订单信息 end
  4049. $data['order_info'] = $orderPamentResult['order_info'];
  4050. }
  4051. if($is_pin == 1)
  4052. {
  4053. $data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
  4054. } else {
  4055. $data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
  4056. }
  4057. }else{
  4058. $data = array();
  4059. $data['code'] = 1;
  4060. $data['text'] = "错误";
  4061. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4062. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4063. }
  4064. $data['has_yupay'] = 0;
  4065. }
  4066. if($is_pin == 1)
  4067. {
  4068. $data['order_id'] = $oid;
  4069. $data['order_all_id'] = $order_all_id;
  4070. }else{
  4071. $data['order_id'] = $oid;
  4072. $data['order_all_id'] = $order_all_id;
  4073. }
  4074. $data['is_go_orderlist'] = $is_just_1;
  4075. $data['is_spike'] = $is_spike;
  4076. echo json_encode($data);
  4077. die();
  4078. }else{
  4079. echo json_encode( array('code' =>1,'order_all_id' =>$order_all_id) );
  4080. die();
  4081. }
  4082. }
  4083. function requestAsHttpPOST($data, $service_url){
  4084. $HTTP_TIME_OUT= "20";
  4085. ksort(array_filter($data)); //删除数组中的空值并排序
  4086. $post_data = http_build_query($data);
  4087. $options = array(
  4088. 'http' => array(
  4089. 'method' => 'POST',
  4090. 'header' => 'Content-type:application/x-www-form-urlencoded;charset=MD5',
  4091. 'content' => $post_data,
  4092. 'timeout' => $HTTP_TIME_OUT * 1000 //超时时间,*1000将毫秒变为秒(单位:s)
  4093. )
  4094. );
  4095. $context = stream_context_create($options);
  4096. $result = file_get_contents($service_url, false, $context);
  4097. return $result;
  4098. }
  4099. /**
  4100. 微信充值
  4101. **/
  4102. public function wxcharge()
  4103. {
  4104. $_GPC = I('request.');
  4105. $token = $_GPC['token'];
  4106. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  4107. $member_id = $weprogram_token['member_id'];
  4108. if( empty($member_id) )
  4109. {
  4110. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  4111. die();
  4112. }
  4113. $money = $_GPC['money'];
  4114. $rech_id = isset($_GPC['rech_id']) && $_GPC['rech_id'] > 0 ? $_GPC['rech_id'] : 0;
  4115. $member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
  4116. $give_money = 0;
  4117. if( $rech_id > 0 )
  4118. {
  4119. $rech_info = M('lionfish_comshop_chargetype')->where( array('id' => $rech_id ) )->find();
  4120. if( !empty($rech_info) )
  4121. {
  4122. $give_money = $rech_info['send_money'];
  4123. }
  4124. $money = $rech_info['money'];
  4125. }else{
  4126. $recharge_get_money = D('Home/Front')->get_config_by_name('recharge_get_money');
  4127. if(isset($recharge_get_money) && $recharge_get_money == 1){
  4128. $rech_info = M('lionfish_comshop_chargetype')->where( "money <= ".$money )->order('money desc')->limit(1)->find();
  4129. if( !empty($rech_info) )
  4130. {
  4131. $give_money = $rech_info['send_money'];
  4132. }
  4133. }
  4134. }
  4135. $member_charge_flow_data = array();
  4136. $member_charge_flow_data['member_id'] = $member_id;
  4137. $member_charge_flow_data['money'] = $money;
  4138. $member_charge_flow_data['state'] = 0;
  4139. $member_charge_flow_data['give_money'] = $give_money;
  4140. $member_charge_flow_data['charge_time'] = 0;
  4141. $member_charge_flow_data['remark'] = '会员前台微信充值';
  4142. $member_charge_flow_data['add_time'] = time();
  4143. $order_id = M('lionfish_comshop_member_charge_flow')->add( $member_charge_flow_data );
  4144. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  4145. $fee = $money;
  4146. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  4147. $body = '会员充值';
  4148. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  4149. $nonce_str = nonce_str();
  4150. $notify_url = $shop_domain.'/notify.php';
  4151. $openid = $member_info['we_openid'];
  4152. $out_trade_no = $order_id.'-'.time().'-charge-'.$id;
  4153. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  4154. $total_fee = $fee*100;
  4155. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  4156. if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  4157. {
  4158. $trade_type = 'JSAPI';
  4159. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4160. $post = array();
  4161. $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');// 'wx7c38e2f177e0af59';
  4162. $post['body'] = $body;
  4163. $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');//'1562705521';
  4164. $post['nonce_str'] = $nonce_str;
  4165. $post['notify_url'] = $notify_url;
  4166. //$post['openid'] = $openid;
  4167. $post['out_trade_no'] = $out_trade_no;
  4168. $post['spbill_create_ip'] = $spbill_create_ip;
  4169. $post['sub_appid'] = $appid;
  4170. $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  4171. $post['sub_openid'] = $openid;
  4172. $post['total_fee'] = $total_fee;
  4173. $post['trade_type'] = $trade_type;
  4174. $sign = sign($post,$pay_key);
  4175. $post_xml = '<xml>
  4176. <appid>'.$post['appid'].'</appid>
  4177. <body>'.$body.'</body>
  4178. <mch_id>'.$post['mch_id'].'</mch_id>
  4179. <nonce_str>'.$nonce_str.'</nonce_str>
  4180. <notify_url>'.$notify_url.'</notify_url>
  4181. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4182. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4183. <sub_appid>'.$post['sub_appid'].'</sub_appid>
  4184. <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
  4185. <sub_openid>'.$openid.'</sub_openid>
  4186. <total_fee>'.$total_fee.'</total_fee>
  4187. <trade_type>'.$trade_type.'</trade_type>
  4188. <sign>'.$sign.'</sign>
  4189. </xml> ';
  4190. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4191. $xml = http_request($url,$post_xml);
  4192. $array = xml($xml);
  4193. //end
  4194. }else{
  4195. $trade_type = 'JSAPI';
  4196. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4197. $post = array();
  4198. $post['appid'] = $appid;
  4199. $post['body'] = $body;
  4200. $post['mch_id'] = $mch_id;
  4201. $post['nonce_str'] = $nonce_str;
  4202. $post['notify_url'] = $notify_url;
  4203. $post['openid'] = $openid;
  4204. $post['out_trade_no'] = $out_trade_no;
  4205. $post['spbill_create_ip'] = $spbill_create_ip;
  4206. $post['total_fee'] = $total_fee;
  4207. $post['trade_type'] = $trade_type;
  4208. $sign = sign($post,$pay_key);
  4209. //sign()
  4210. $post_xml = '<xml>
  4211. <appid>'.$appid.'</appid>
  4212. <body>'.$body.'</body>
  4213. <mch_id>'.$mch_id.'</mch_id>
  4214. <nonce_str>'.$nonce_str.'</nonce_str>
  4215. <notify_url>'.$notify_url.'</notify_url>
  4216. <openid>'.$openid.'</openid>
  4217. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4218. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4219. <total_fee>'.$total_fee.'</total_fee>
  4220. <trade_type>'.$trade_type.'</trade_type>
  4221. <sign>'.$sign.'</sign>
  4222. </xml> ';
  4223. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4224. $xml = http_request($url,$post_xml);
  4225. $array = xml($xml);
  4226. }
  4227. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4228. $time = time();
  4229. $tmp= array();
  4230. $tmp['appId'] = $appid;
  4231. $tmp['nonceStr'] = $nonce_str;
  4232. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4233. $tmp['signType'] = 'MD5';
  4234. $tmp['timeStamp'] = "$time";
  4235. M('lionfish_comshop_member_charge_flow')->where( array('id' => $order_id) )->save( array('formid' => $array['PREPAY_ID'] ) );
  4236. $data['code'] = 0;
  4237. $data['timeStamp'] = "$time";
  4238. $data['nonceStr'] = $nonce_str;
  4239. $data['signType'] = 'MD5';
  4240. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4241. $data['paySign'] = sign($tmp, $pay_key);
  4242. $data['out_trade_no'] = $out_trade_no;
  4243. $data['redirect_url'] = '../dan/me';
  4244. }else{
  4245. $data['code'] = 1;
  4246. $data['text'] = "错误";
  4247. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4248. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4249. }
  4250. echo json_encode($data);
  4251. die();
  4252. }
  4253. public function wxpay()
  4254. {
  4255. $gpc = I('request.');
  4256. $token = $gpc['token'];
  4257. $order_id = $gpc['order_id'];
  4258. $scene = $gpc['scene'];
  4259. $is_need_scene_check = 0;
  4260. if(!empty($scene))
  4261. {
  4262. $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
  4263. }
  4264. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  4265. $member_id = $weprogram_token['member_id'];
  4266. if( empty($member_id) )
  4267. {
  4268. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  4269. die();
  4270. }
  4271. $member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
  4272. $order = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  4273. //order_status_id
  4274. if( $order['order_status_id'] != 3 && $order['order_status_id'] != 15 )
  4275. {
  4276. $json = array();
  4277. $json['msg']='商品已下架!';
  4278. $json['code'] = 2;
  4279. if($order['order_status_id'] == 1)
  4280. {
  4281. $json['msg']='订单已付款,请勿重新付款!';
  4282. }
  4283. else if( $order['order_status_id'] == 5){
  4284. $json['msg']='订单已取消,请重新选择商品下单!';
  4285. }
  4286. echo json_encode($json);
  4287. die();
  4288. }
  4289. //检测商品是否下架 begin
  4290. $sql = "select name,quantity,rela_goodsoption_valueid,goods_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods
  4291. where order_id={$order_id} ";
  4292. $order_goods_list = M()->query($sql);
  4293. foreach($order_goods_list as $tp_val)
  4294. {
  4295. $tp_gd_info = M('lionfish_comshop_goods')->field('grounding')->where( array('id' => $tp_val['goods_id'] ) )->find();
  4296. if( empty($tp_gd_info) || $tp_gd_info['grounding'] != 1 )
  4297. {
  4298. $json['code'] = 2;
  4299. $json['msg']='商品已下架!';
  4300. echo json_encode($json);
  4301. die();
  4302. }
  4303. }
  4304. //检测商品是否下架end
  4305. //检测是否预售商品。预售商品不需要检测二次支付问题
  4306. $presale_info = [];
  4307. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
  4308. if( $presale_result['code'] == 0 )
  4309. {
  4310. $presale_info = $presale_result['data'];
  4311. }
  4312. //检测是否已经支付过了begin
  4313. $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
  4314. if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 && empty($presale_info) )
  4315. {
  4316. $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
  4317. if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
  4318. {
  4319. $out_trade_no = $order_all_info['out_trade_no'];
  4320. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  4321. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  4322. $nonce_str = nonce_str();
  4323. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4324. $post = array();
  4325. $post['appid'] = $appid;
  4326. $post['mch_id'] = $mch_id;
  4327. $post['nonce_str'] = $nonce_str;
  4328. $post['out_trade_no'] = $out_trade_no;
  4329. $sign = sign($post,$pay_key);
  4330. $post_xml = '<xml>
  4331. <appid>'.$appid.'</appid>
  4332. <mch_id>'.$mch_id.'</mch_id>
  4333. <nonce_str>'.$nonce_str.'</nonce_str>
  4334. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4335. <sign>'.$sign.'</sign>
  4336. </xml>';
  4337. $url = "https://api.mch.weixin.qq.com/pay/orderquery";
  4338. $result = http_request($url,$post_xml);
  4339. $array = xml($result);
  4340. if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
  4341. {
  4342. if( $array['TRADE_STATE'] == 'SUCCESS' )
  4343. {
  4344. $json = array();
  4345. $json['msg']='商品已下架!';
  4346. $json['code'] = 2;
  4347. $json['msg']='订单已付款,请勿重新付款,请刷新页面!';
  4348. echo json_encode($json);
  4349. die();
  4350. }
  4351. }
  4352. }
  4353. }
  4354. //检测是否已经支付过了end
  4355. //支付才减库存,才需要判断
  4356. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
  4357. if( empty($kucun_method) )
  4358. {
  4359. $kucun_method = 0;
  4360. }
  4361. if($kucun_method == 1 && ( empty($presale_info) || $presale_info['state'] != 1 ) )
  4362. {
  4363. /*** 检测商品库存begin **/
  4364. //goods_id
  4365. foreach($order_goods_list as $val)
  4366. {
  4367. $quantity = $val['quantity'];
  4368. $goods_id = $val['goods_id'];
  4369. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  4370. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
  4371. if($can_buy_count == -1)
  4372. {
  4373. $json['code'] = 2;
  4374. $json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
  4375. echo json_encode($json);
  4376. die();
  4377. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  4378. {
  4379. $json['code'] = 2;
  4380. $json['msg']='您还能购买'.$can_buy_count.'份';
  4381. echo json_encode($json);
  4382. die();
  4383. }
  4384. //rela_goodsoption_valueid
  4385. if(!empty($val['rela_goodsoption_valueid']))
  4386. {
  4387. $mul_opt_arr = array();
  4388. //ims_
  4389. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $goods_id,'option_item_ids' => $val['rela_goodsoption_valueid']) )->find();
  4390. if( !empty($goods_option_mult_value) )
  4391. {
  4392. if($goods_option_mult_value['stock']<$quantity){
  4393. $json['code'] =2;
  4394. $json['msg']='商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
  4395. echo json_encode($json);
  4396. die();
  4397. }
  4398. }
  4399. }
  4400. }
  4401. /*** 检测商品库存end **/
  4402. }
  4403. $pin_order = array();
  4404. if( !empty($pin_order) )
  4405. {
  4406. /**
  4407. $pin_model = load_model_class('pin');
  4408. $is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
  4409. if($is_pin_over != 0)
  4410. {
  4411. pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
  4412. pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
  4413. $order_goods_info = pdo_fetch("select goods_id from ".tablename('lionfish_comshop_order_goods')." where uniacid=:uniacid and order_id=:order_id ", array(':order_id' => $order_id,':uniacid' => $_W['uniacid']));
  4414. //新开团
  4415. $pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
  4416. //插入拼团订单
  4417. $pin_model->insertTuanOrder($pin_id,$order_id);
  4418. }
  4419. **/
  4420. }
  4421. //单独支付一个店铺的订单
  4422. //M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id) )->delete();
  4423. $order_all_data = array();
  4424. $order_all_data['member_id'] = $member_id;
  4425. $order_all_data['order_num_alias'] = build_order_no($member_id);
  4426. $order_all_data['transaction_id'] = '';
  4427. $order_all_data['order_status_id'] = 3;
  4428. $order_all_data['is_pin'] = $order['is_pin'];
  4429. $order_all_data['paytime'] = 0;
  4430. $order_all_data['total_money'] = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'];
  4431. $order_all_data['addtime'] = time();
  4432. $order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
  4433. $order_relate_data = array();
  4434. $order_relate_data['order_all_id'] = $order_all_id;
  4435. $order_relate_data['order_id'] = $order_id;
  4436. $order_relate_data['addtime'] = time();
  4437. M('lionfish_comshop_order_relate')->add($order_relate_data);
  4438. if( $order['delivery'] == 'pickup' )
  4439. {
  4440. $fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
  4441. }else if($order['delivery'] == 'localtown_delivery'){
  4442. $fee = $order['total'] + $order['packing_fare'] + $order['shipping_fare']-$order['voucher_credit'] - $order['fullreduction_money'] - $order['score_for_money'] + $order['localtown_add_shipping_fare'] - $order['fare_shipping_free'];
  4443. }else {
  4444. $fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
  4445. }
  4446. //如果是预售 begin
  4447. if( !empty($presale_info) )
  4448. {
  4449. if( $presale_info['state'] == 0 )
  4450. {
  4451. //首次支付,
  4452. $fee = $presale_info['presale_ding_money'];
  4453. }else if( $presale_info['state'] == 1 )
  4454. {
  4455. //第二次支付
  4456. if( !empty($presale_info['presale_deduction_money']) && false )
  4457. {
  4458. $fee = $fee - $presale_info['presale_deduction_money'];
  4459. }else{
  4460. $fee = $fee - $presale_info['presale_ding_money'];
  4461. }
  4462. }
  4463. }
  4464. //end
  4465. $fee = round($fee , 2);
  4466. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  4467. $body = $pay_goods_name;//'商品购买';
  4468. $body = mb_substr($body,0,32,'utf-8');
  4469. if( empty($body) )
  4470. {
  4471. $body = '商品购买';
  4472. }
  4473. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  4474. $nonce_str = nonce_str();
  4475. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  4476. $notify_url = $shop_domain.'/notify.php';
  4477. $openid = $member_info['we_openid'];
  4478. $out_trade_no = $order_all_id.'-'.time();
  4479. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  4480. $total_fee = $fee*100;
  4481. $trade_type = 'JSAPI';
  4482. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4483. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  4484. //begin
  4485. if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  4486. {
  4487. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4488. $body = '商品购买';
  4489. $post = array();
  4490. $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
  4491. $post['body'] = $body;
  4492. $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
  4493. $post['nonce_str'] = $nonce_str;
  4494. $post['notify_url'] = $notify_url;
  4495. //$post['openid'] = $openid;
  4496. $post['out_trade_no'] = $out_trade_no;
  4497. $post['spbill_create_ip'] = $spbill_create_ip;
  4498. $post['sub_appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  4499. $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  4500. $post['sub_openid'] = $openid;
  4501. $post['total_fee'] = $total_fee;
  4502. $post['trade_type'] = $trade_type;
  4503. $sign = sign($post,$pay_key);
  4504. $post_xml = '<xml>
  4505. <appid>'.$post['appid'].'</appid>
  4506. <body>'.$body.'</body>
  4507. <mch_id>'.$post['mch_id'].'</mch_id>
  4508. <nonce_str>'.$nonce_str.'</nonce_str>
  4509. <notify_url>'.$notify_url.'</notify_url>
  4510. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4511. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4512. <sub_appid>'.$post['sub_appid'].'</sub_appid>
  4513. <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
  4514. <sub_openid>'.$openid.'</sub_openid>
  4515. <total_fee>'.$total_fee.'</total_fee>
  4516. <trade_type>'.$trade_type.'</trade_type>
  4517. <sign>'.$sign.'</sign>
  4518. </xml>';
  4519. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4520. $xml = http_request($url,$post_xml);
  4521. $array = xml($xml);
  4522. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4523. $time = time();
  4524. $tmp= array();
  4525. $tmp['appId'] = $appid;
  4526. $tmp['nonceStr'] = $nonce_str;
  4527. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4528. $tmp['signType'] = 'MD5';
  4529. $tmp['timeStamp'] = "$time";
  4530. $prepay_id = (string)$array['PREPAY_ID'];
  4531. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
  4532. $data['code'] = 0;
  4533. $data['timeStamp'] = "$time";
  4534. $data['nonceStr'] = $nonce_str;
  4535. $data['signType'] = 'MD5';
  4536. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4537. $data['paySign'] = sign($tmp, $pay_key);
  4538. $data['out_trade_no'] = $out_trade_no;
  4539. $data['is_pin'] = $order['is_pin'];
  4540. if($order['is_pin'] == 1)
  4541. {
  4542. $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
  4543. } else {
  4544. $data['redirect_url'] = '../orders/order?id=' + $order_id;
  4545. }
  4546. }else{
  4547. $data['code'] = 1;
  4548. $data['text'] = "错误";
  4549. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4550. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4551. }
  4552. echo json_encode($data);
  4553. die();
  4554. }
  4555. //end
  4556. $post = array();
  4557. $post['appid'] = $appid;
  4558. $post['body'] = $body;
  4559. $post['mch_id'] = $mch_id;
  4560. $post['nonce_str'] = $nonce_str;
  4561. $post['notify_url'] = $notify_url;
  4562. $post['openid'] = $openid;
  4563. $post['out_trade_no'] = $out_trade_no;
  4564. $post['spbill_create_ip'] = $spbill_create_ip;
  4565. $post['total_fee'] = $total_fee;
  4566. $post['trade_type'] = $trade_type;
  4567. $sign = sign($post,$pay_key);
  4568. $post_xml = '<xml>
  4569. <appid>'.$appid.'</appid>
  4570. <body>'.$body.'</body>
  4571. <mch_id>'.$mch_id.'</mch_id>
  4572. <nonce_str>'.$nonce_str.'</nonce_str>
  4573. <notify_url>'.$notify_url.'</notify_url>
  4574. <openid>'.$openid.'</openid>
  4575. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4576. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4577. <total_fee>'.$total_fee.'</total_fee>
  4578. <trade_type>'.$trade_type.'</trade_type>
  4579. <sign>'.$sign.'</sign>
  4580. </xml> ';
  4581. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4582. $xml = http_request($url,$post_xml);
  4583. $array = xml($xml);
  4584. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4585. $time = time();
  4586. $tmp= array();
  4587. $tmp['appId'] = $appid;
  4588. $tmp['nonceStr'] = $nonce_str;
  4589. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4590. $tmp['signType'] = 'MD5';
  4591. $tmp['timeStamp'] = "$time";
  4592. $prepay_id = (string)$array['PREPAY_ID'];
  4593. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
  4594. $data['code'] = 0;
  4595. $data['timeStamp'] = "$time";
  4596. $data['nonceStr'] = $nonce_str;
  4597. $data['signType'] = 'MD5';
  4598. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4599. $data['paySign'] = sign($tmp, $pay_key);
  4600. $data['out_trade_no'] = $out_trade_no;
  4601. $data['is_pin'] = $order['is_pin'];
  4602. //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
  4603. $data['order_info'] = [];
  4604. $data['isRequestOrderPayment'] = $is_need_scene_check;
  4605. if($is_need_scene_check == 1)
  4606. {
  4607. $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $order_id , $time , $fee );
  4608. //如果是微信小程序交易组件,提供订单信息 end
  4609. $data['order_info'] = $orderPamentResult['order_info'];
  4610. }
  4611. if($order['is_pin'] == 1)
  4612. {
  4613. $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
  4614. } else {
  4615. $data['redirect_url'] = '../orders/order?id=' + $order_id;
  4616. }
  4617. }else{
  4618. $data['code'] = 1;
  4619. $data['text'] = "错误";
  4620. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4621. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4622. }
  4623. echo json_encode($data);
  4624. die();
  4625. }
  4626. /**
  4627. * 获取购物车总数
  4628. */
  4629. public function count() {
  4630. $gpc = I('request.');
  4631. $data = array();
  4632. $token = $gpc['token'];
  4633. $community_id = $gpc['community_id'];
  4634. $cart= D('Home/Car');
  4635. $total=$cart->count_goodscar($token, $community_id);
  4636. $data['code'] = 0;
  4637. $data['data'] = $total;
  4638. echo json_encode($data);
  4639. die();
  4640. }
  4641. }