CarController.class.php 188 KB

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