CarController.class.php.new 185 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060
  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. class CarController extends \Home\Controller\CommonController
  15. {
  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. $tmp_goods[] = $tp_val;
  1085. }
  1086. //$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
  1087. //$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
  1088. $store_info = array('s_true_name' => '','s_id' => 1);
  1089. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  1090. if( !empty($s_logo) )
  1091. {
  1092. $s_logo = tomedia($s_logo);
  1093. }
  1094. $val['store_info'] = $store_info;
  1095. $store_data = array();
  1096. $store_data['id'] = $store_info['s_id'];
  1097. if($is_store_ck)
  1098. {
  1099. $store_data['isselect'] = true;
  1100. } else {
  1101. $store_data['isselect'] = false;
  1102. }
  1103. $store_data['shopname'] = $store_info['s_true_name'];
  1104. $store_data['caredit'] = 'inline';
  1105. $store_data['finish'] = 'none';
  1106. $store_data['count'] = '0.00';
  1107. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1108. $full_money = D('Home/Front')->get_config_by_name('full_money');
  1109. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  1110. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  1111. {
  1112. $is_open_fullreduction = 0;
  1113. }
  1114. $store_data['is_open_fullreduction'] = $is_open_fullreduction;
  1115. $store_data['full_money'] = $full_money;
  1116. $store_data['full_reducemoney'] = $full_reducemoney;
  1117. $store_data['goodstype'] = 2;
  1118. $store_data['goodstypeselect'] = 0;
  1119. $store_data['shopcarts'] = $tmp_goods;
  1120. //起送价格
  1121. $localtown_moneytype_fixed_deliverymoney = 0;
  1122. //达到金额免配送费
  1123. $localtown_moneytype_fixed_freemoney = 0;
  1124. $localtown_fixed_list = array();
  1125. if($key == 3){//同城配送商品
  1126. $storename = "";
  1127. if($store_id == 0){
  1128. //配送费类型:0、固定金额,1、按距离收取
  1129. $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
  1130. if($localtown_delivery_moneytype == 0){
  1131. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
  1132. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
  1133. }
  1134. $storename = "平台";
  1135. }else{
  1136. $isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$store_id);
  1137. //配送费类型:0、固定金额,1、按距离收取
  1138. $localtown_delivery_moneytype = D('Home/Front')->get_supply_config_by_name('localtown_delivery_moneytype',$store_id);
  1139. if($isopen_localtown_delivery == 1 && $localtown_delivery_moneytype == 0){
  1140. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_deliverymoney',$store_id);
  1141. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_supply_config_by_name('localtown_moneytype_fixed_freemoney',$store_id);
  1142. }
  1143. $supply_info_data = M('lionfish_comshop_supply')->field('storename')->where( array('id' => $store_id) )->find();
  1144. $storename = $supply_info_data['storename'];
  1145. }
  1146. $localtown_fixed_list['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
  1147. //if($localtown_moneytype_fixed_deliverymoney > $max_can_orderbuy_money){
  1148. //获取起送最大下单金额限制
  1149. //$max_can_orderbuy_money = $localtown_moneytype_fixed_deliverymoney;
  1150. //}
  1151. $localtown_fixed_list['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
  1152. $localtown_fixed_list['store_name'] = $storename;
  1153. }else if($key == 2){
  1154. if($store_id == 0){
  1155. $storename = "平台";
  1156. }else{
  1157. $supply_info_data = M('lionfish_comshop_supply')->field('storename')->where( array('id' => $store_id) )->find();
  1158. $storename = $supply_info_data['storename'];
  1159. }
  1160. $localtown_fixed_list['store_name'] = $storename;
  1161. }
  1162. $store_data['localtown_fixed_list'] = $localtown_fixed_list;
  1163. $seller_goodss_tp[$store_id] = $store_data;
  1164. $i++;
  1165. }
  1166. $seller_goodss_mult[$key] = $seller_goodss_tp;
  1167. }
  1168. foreach($seller_goodss as $store_id => $val)
  1169. {
  1170. //total
  1171. $seller_voucher_list = array();
  1172. $seller_total_fee = 0;
  1173. $total_trans_free = 0;
  1174. $tmp_goods = array();
  1175. $is_store_ck = false;
  1176. foreach($val['goods'] as $kk =>$d_goods)
  1177. {
  1178. $seller_total_fee += $d_goods['total'];
  1179. $total_trans_free += $d_goods[$kk]['trans_free'];
  1180. $val['goods'][$kk] = $d_goods;
  1181. $tp_val = array();
  1182. $tp_val['id'] = $d_goods['goods_id'];
  1183. $tp_val['key'] = $d_goods['key'];
  1184. if($d_goods['singledel'] == 1)
  1185. {
  1186. $tp_val['isselect'] = true;
  1187. $is_store_ck = true;
  1188. $ck_goodstype_count++;
  1189. } else {
  1190. $tp_val['isselect'] = false;
  1191. }
  1192. $tp_val['imgurl'] = $d_goods['image'];
  1193. $tp_val['edit'] = 'inline';
  1194. $tp_val['title'] = $d_goods['name'];
  1195. $tp_val['finish'] = 'none';
  1196. $tp_val['description'] = 'description';
  1197. $option_arr = array();
  1198. $option_str = "";
  1199. foreach($d_goods['option'] as $option_val)
  1200. {
  1201. //$option_arr[] = $option_val['name'].':'.$option_val['value'];
  1202. $option_arr[] = $option_val['value'];
  1203. }
  1204. if(!empty($option_arr))
  1205. {
  1206. $option_str = implode(';', $option_arr);
  1207. }
  1208. $tp_val['can_buy'] = D('Home/Pingoods')->get_goods_time_can_buy($d_goods['goods_id']);
  1209. $tp_val['goodstype'] = $option_str;
  1210. $tp_val['goodstypeedit'] = $option_str;
  1211. $tp_val['goodsnum'] = $d_goods['quantity'];
  1212. $tp_val['can_man_jian'] = $d_goods['can_man_jian'];
  1213. $tp_val['max_quantity'] = $d_goods['max_quantity'];
  1214. $tp_val['cartype'] = 'inline';
  1215. $tp_val['currntprice'] = $d_goods['price'];
  1216. $tp_val['price'] = $d_goods['shop_price'];
  1217. $tp_val['card_price'] = $d_goods['card_price'];
  1218. $tp_val['is_take_vipcard'] = $d_goods['is_take_vipcard'];
  1219. $tp_val['is_new_buy'] = $d_goods['is_new_buy'];
  1220. $tmp_goods[] = $tp_val;
  1221. }
  1222. //$store_info = M('seller')->field('s_id,s_true_name,s_logo')->where( array('s_id' => $store_id) )->find();
  1223. //$store_info['s_logo'] = C('SITE_URL').'Uploads/image/'.$store_info['s_logo'];
  1224. $store_info = array('s_true_name' => '','s_id' => 1);
  1225. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  1226. if( !empty($s_logo) )
  1227. {
  1228. $s_logo = tomedia($s_logo);
  1229. }
  1230. $val['store_info'] = $store_info;
  1231. $store_data = array();
  1232. $store_data['id'] = $store_info['s_id'];
  1233. if($is_store_ck)
  1234. {
  1235. $store_data['isselect'] = true;
  1236. } else {
  1237. $store_data['isselect'] = false;
  1238. }
  1239. $store_data['shopname'] = $store_info['s_true_name'];
  1240. $store_data['caredit'] = 'inline';
  1241. $store_data['finish'] = 'none';
  1242. $store_data['count'] = '0.00';
  1243. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1244. $full_money = D('Home/Front')->get_config_by_name('full_money');
  1245. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  1246. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  1247. {
  1248. $is_open_fullreduction = 0;
  1249. }
  1250. $store_data['is_open_fullreduction'] = $is_open_fullreduction;
  1251. $store_data['full_money'] = $full_money;
  1252. $store_data['full_reducemoney'] = $full_reducemoney;
  1253. $store_data['goodstype'] = 2;
  1254. $store_data['goodstypeselect'] = 0;
  1255. $store_data['shopcarts'] = $tmp_goods;
  1256. $seller_goodss[$store_id] = $store_data;
  1257. $i++;
  1258. }
  1259. // 商家是否休息
  1260. $is_comunity_rest = D('Seller/Communityhead')->is_community_rest($community_id);
  1261. $open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
  1262. $man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
  1263. //if($man_orderbuy_money > $max_can_orderbuy_money){
  1264. //$max_can_orderbuy_money = $man_orderbuy_money;
  1265. //}
  1266. $is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_guess_like');
  1267. // 免配送 man_free_tuanzshipping>0开启
  1268. $delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
  1269. $delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
  1270. $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
  1271. $man_free_tuanzshipping = $delivery_tuanz_money = 0;
  1272. //暂时屏蔽,2020.02.13.14:57
  1273. /**
  1274. if($delivery_type_ziti!=1 && $delivery_type_express!=1 && $delivery_type_tuanz==1) {
  1275. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  1276. if($man_free_tuanzshipping>1 && !empty($man_free_tuanzshipping)) {
  1277. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  1278. }
  1279. }
  1280. **/
  1281. if($delivery_type_tuanz==1) {
  1282. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  1283. }else{
  1284. $man_free_tuanzshipping = 0;
  1285. }
  1286. $open_tuan_ship = $delivery_type_tuanz;
  1287. //团长自定义配送开关
  1288. if($community_id&&$man_free_tuanzshipping>1) {
  1289. $community_modify_shipping = M('lionfish_community_head')->field('is_modify_shipping_method')->where( array('id' => $community_id) )->find();
  1290. $is_modify_shipping_method = $community_modify_shipping['is_modify_shipping_method'];
  1291. if($is_modify_shipping_method==1) {
  1292. $open_tuan_ship = 1;
  1293. } else if($is_modify_shipping_method==2){
  1294. $open_tuan_ship = 0;
  1295. }
  1296. }
  1297. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  1298. $shopcar_tab_all_name = D('Home/Front')->get_config_by_name('shopcar_tab_all_name');
  1299. $shopcar_tab_express_name = D('Home/Front')->get_config_by_name('shopcar_tab_express_name');
  1300. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1301. if($is_open_fullreduction){
  1302. $full_list = D('Home/Front')->get_fullreduction();
  1303. }else{
  1304. $full_list[0]['full_money']= 0 ;
  1305. $full_list[0]['full_reducemoney']= 0 ;
  1306. }
  1307. //同城配送信息
  1308. //配送费类型:0、固定金额,1、按距离收取
  1309. $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
  1310. $localtown_moneytype_fixed_deliverymoney = 0;
  1311. $localtown_moneytype_fixed_freemoney = 0;
  1312. if($localtown_delivery_moneytype == 0){
  1313. //起送价格
  1314. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
  1315. //达到金额免配送费
  1316. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
  1317. }
  1318. $need_data = array();
  1319. $need_data['code'] = 0;
  1320. $need_data['carts'] = $seller_goodss;
  1321. $need_data['mult_carts'] = $seller_goodss_mult;
  1322. $need_data['is_comunity_rest'] = $is_comunity_rest;
  1323. $need_data['open_man_orderbuy'] = $open_man_orderbuy;
  1324. $need_data['man_orderbuy_money'] = $man_orderbuy_money;
  1325. //$need_data['max_can_orderbuy_money'] = $max_can_orderbuy_money;
  1326. $need_data['is_show_guess_like'] = $is_show_guess_like;
  1327. $need_data['man_free_tuanzshipping'] = $man_free_tuanzshipping;
  1328. $need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
  1329. $need_data['is_member_level_buy'] = $is_member_level_buy;//当前会员折扣 购买,1是,0否
  1330. $need_data['level_save_money'] = $level_save_money;//会员折扣省的钱
  1331. $need_data['is_vip_card_member'] = $is_vip_card_member;//当前会员是否是 会员卡会员 0 不是,1是,2已过期
  1332. $need_data['vipcard_save_money'] = $vipcard_save_money;//vip能节约的金额
  1333. $need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy;//vip能节约的金额
  1334. $need_data['modify_vipcard_name'] = $modify_vipcard_name;
  1335. $need_data['shopcar_tab_all_name'] = $shopcar_tab_all_name;
  1336. $need_data['shopcar_tab_express_name'] = $shopcar_tab_express_name;
  1337. $need_data['open_tuan_ship'] = $open_tuan_ship;
  1338. $need_data['is_open_fullreduction'] = $is_open_fullreduction;
  1339. $need_data['full_list'] = $full_list;
  1340. //平台和供应商 起送价格和免配送费价格
  1341. //$need_data['localtown_fixed_list'] = $localtown_fixed_list;
  1342. $need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;//起送价格
  1343. $need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;//达到金额免配送费
  1344. echo json_encode( $need_data );
  1345. die();
  1346. }
  1347. public function checkout_flushall()
  1348. {
  1349. $gpc = I('request.');
  1350. $token = $gpc['token'];
  1351. $community_id = $gpc['community_id'];
  1352. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1353. $member_id = $weprogram_token['member_id'];
  1354. //dan soitaire
  1355. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  1356. //$car_prefix = 'soitairecart.';
  1357. //buy_type和soli_id吗
  1358. $is_community = D('Seller/Communityhead')->is_community($community_id);
  1359. if( !$is_community )
  1360. {
  1361. $json['code'] =6;
  1362. $json['msg']='该小区已经不存在!';
  1363. echo json_encode($json);
  1364. die();
  1365. }
  1366. $data = array();
  1367. $data['car_key'] = $gpc['car_key'];
  1368. $data['all_keys_arr'] = $gpc['all_keys_arr'];
  1369. $data['cur_car_key'] = $gpc['cur_car_key'];
  1370. //car_key:cart.6:MTc0:,cart.13:MjcwXzI3Mw==:
  1371. //all_keys_arr:cart.6:MTc0:_1,cart.13:MjcwXzI3Mw==:_1
  1372. $car_key = explode(',', $data['car_key']);
  1373. $all_keys_arr = explode(',', $data['all_keys_arr']) ;
  1374. if(!empty($data['cur_car_key'])){
  1375. $car_key = array($data['cur_car_key']);
  1376. }
  1377. $save_keys = array();
  1378. if(!empty($all_keys_arr)){
  1379. foreach($all_keys_arr as $val)
  1380. {
  1381. $tmp_val = explode('_', $val);
  1382. $save_keys[ $tmp_val[0] ] = $tmp_val[1];
  1383. }
  1384. }
  1385. if( $buy_type == 'dan')
  1386. {
  1387. $all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'cart.%'")->select();
  1388. }else if( $buy_type == 'soitaire' ){
  1389. $all_cart = M('lionfish_comshop_car')->where("community_id={$community_id} and token='{$token}' and carkey like 'soitairecart.%'")->select();
  1390. }
  1391. if(!empty($all_cart))
  1392. {
  1393. foreach($all_cart as $val)
  1394. {
  1395. $tmp_format_data = unserialize($val['format_data']);
  1396. $tmp_format_data['singledel'] = 0;
  1397. $tmp_format_data['quantity'] = isset( $save_keys[$val['carkey']] ) ? $save_keys[$val['carkey']] : $tmp_format_data['quantity'];
  1398. M('lionfish_comshop_car')->where( array('id' => $val['id'] ,'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
  1399. }
  1400. }
  1401. if(!empty($car_key)){
  1402. foreach( $car_key as $key )
  1403. {
  1404. $car_info = M('lionfish_comshop_car')->where( array('community_id' => $community_id,'carkey' => $key ,'token' => $token) )->find();
  1405. if( !empty($car_info) )
  1406. {
  1407. $tmp_format_data = unserialize($car_info['format_data']);
  1408. $tmp_format_data['singledel'] = 1;
  1409. $quantity = $tmp_format_data['quantity'];
  1410. $sku_quantity_one = $tmp_format_data['quantity'];
  1411. $goods_id = $tmp_format_data['goods_id'];
  1412. $sku_str = $tmp_format_data['sku_str'];
  1413. //同一个商品不同规格 总数量合计
  1414. $sku_quantity = $this->_check_goods_sku_quantity($community_id,$key,$token);
  1415. if($sku_quantity > $quantity) {
  1416. $quantity = $sku_quantity;
  1417. }
  1418. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'goods_start_count');
  1419. //起售数量判断
  1420. if($sku_quantity_one < $goods_description['goods_start_count'])
  1421. {
  1422. $json['code'] = 6;
  1423. $json['msg'] = $goods_description['goods_start_count'].'份起售';
  1424. $json['max_quantity'] = $goods_description['goods_start_count'];
  1425. echo json_encode( $json );
  1426. die();
  1427. }
  1428. $check_json = $this->_check_can_buy($member_id, $goods_id,$quantity);
  1429. if($check_json['code'] != 0)
  1430. {
  1431. $tmp_format_data['quantity'] = $check_json['count'];
  1432. M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
  1433. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  1434. die();
  1435. }
  1436. //check sku is ok
  1437. $check_json = $this->_check_goods_sku_canbuy($goods_id,$sku_str);
  1438. if($check_json['code'] != 0)
  1439. {
  1440. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  1441. die();
  1442. }
  1443. $check_json = $this->_check_goods_quantity($goods_id,$sku_quantity_one,$sku_str);
  1444. if($check_json['code'] != 0)
  1445. {
  1446. echo json_encode( array('code' => 6,'msg' => $check_json['msg']) );
  1447. die();
  1448. }
  1449. M('lionfish_comshop_car')->where( array('id' => $car_info['id'], 'community_id' => $community_id) )->save( array('format_data' => serialize($tmp_format_data) ) );
  1450. }
  1451. }
  1452. }
  1453. $is_limit_distance_buy = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
  1454. echo json_encode( array('code' => 0, 'data' => $is_limit_distance_buy) );
  1455. die();
  1456. }
  1457. public function _check_goods_sku_quantity($community_id,$key,$token){
  1458. $quantity = 0;
  1459. $key_array = explode(":",$key);
  1460. $key_result = "";
  1461. foreach($key_array as $k=>$v){
  1462. if($k < 2){
  1463. if(empty($key_result)){
  1464. $key_result = $v;
  1465. }else{
  1466. $key_result = $key_result.":".$v;
  1467. }
  1468. }
  1469. }
  1470. $sql = "SELECT format_data FROM ".C('DB_PREFIX')."lionfish_comshop_car "
  1471. . " WHERE carkey LIKE '".$key_result."%' and community_id = '".$community_id."' "
  1472. . " and token='".$token."'";
  1473. $cart_goods_list = M()->query($sql);
  1474. if(!empty($cart_goods_list)){
  1475. foreach($cart_goods_list as $val)
  1476. {
  1477. $tmp_format_data = unserialize($val['format_data']);
  1478. $quantity = $quantity + $tmp_format_data['quantity'];
  1479. }
  1480. }
  1481. return $quantity;
  1482. }
  1483. public function _check_goods_sku_canbuy($goods_id,$sku_str)
  1484. {
  1485. $json = array('code' => 0);
  1486. $goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where( array('id' => $goods_id ) )->find();
  1487. if(!empty($sku_str))
  1488. {
  1489. $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();
  1490. if( empty($goods_option_mult_value) )
  1491. {
  1492. $json['code'] =3;
  1493. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').',规格已失效,删除后再结算';
  1494. }
  1495. }
  1496. return $json;
  1497. }
  1498. public function del_car_goods()
  1499. {
  1500. $gpc = I('request.');
  1501. $token = $gpc['token'];
  1502. $community_id = $gpc['community_id'];
  1503. $carkey = $gpc['carkey'];
  1504. M('lionfish_comshop_car')->where( "community_id={$community_id} and token='{$token}' and carkey='{$carkey}'" )->delete();
  1505. echo json_encode( array('code' => 0) );
  1506. die();
  1507. }
  1508. public function _check_goods_quantity($goods_id,$quantity,$sku_str)
  1509. {
  1510. $gpc = I('request.');
  1511. $goods_info = M('lionfish_comshop_goods')->field('goodsname as name')->where( array('id' => $goods_id) )->find();
  1512. $goods_quantity= D('Home/Car')->get_goods_quantity($goods_id);
  1513. $json = array('code' => 0);
  1514. if($goods_quantity<$quantity){
  1515. $json['code'] =3;
  1516. $json['msg']= mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_quantity.'个!!';
  1517. }else if(!empty($sku_str)){
  1518. $mul_opt_arr = array();
  1519. $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();
  1520. if( !empty($goods_option_mult_value) )
  1521. {
  1522. if($goods_option_mult_value['quantity']<$quantity){
  1523. $json['code'] =3;
  1524. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,商品数量不足,剩余'.$goods_option_mult_value['quantity'].'个!!';
  1525. }
  1526. }
  1527. }
  1528. return $json;
  1529. }
  1530. private function _check_can_buy($member_id, $goods_id,$quantity)
  1531. {
  1532. $gpc = I('request.');
  1533. //$can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  1534. $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');
  1535. //单次限购判断
  1536. if($goods_description['one_limit_count'] > 0 && $quantity > $goods_description['one_limit_count'])
  1537. {
  1538. $json['code'] = 6;
  1539. $json['msg'] = '您本次只能购买'.$goods_description['one_limit_count'].'份';
  1540. $json['count'] = $goods_description['one_limit_count'];
  1541. return $json;
  1542. }
  1543. $can_buy_day_count = D('Home/Front')->check_goods_user_canbuy_day_count($member_id, $goods_id);
  1544. if($can_buy_day_count == -1 || ($can_buy_day_count > 0 && $quantity >$can_buy_day_count))
  1545. {
  1546. $json['code'] =6;
  1547. $json['msg'] = '您今天只能购买'.$goods_description['oneday_limit_count'].'份';
  1548. $json['count']=1;
  1549. return $json;
  1550. }else if($can_buy_day_count > 0 && $quantity > $can_buy_day_count){
  1551. $json['code'] =6;
  1552. $json['msg'] = '您今天还能购买'.$can_buy_day_count.'份';
  1553. $json['count']=$can_buy_day_count;
  1554. return $json;
  1555. }
  1556. $can_buy_all_count = D('Home/Front')->check_goods_user_canbuy_all_count($member_id, $goods_id);
  1557. //历史限购判断
  1558. if($can_buy_all_count == -1 && $goods_description['total_limit_count'] >0)
  1559. {
  1560. $json['code'] =6;
  1561. $json['msg']='您最多只能购买'.$goods_description['total_limit_count'].'个';
  1562. $json['count'] = 1;
  1563. return $json;
  1564. }else if($can_buy_all_count > 0 && $quantity > $can_buy_all_count)
  1565. {
  1566. $json['code'] =6;
  1567. $json['msg']='您还能购买'.$can_buy_all_count.'份';
  1568. $json['count'] = $can_buy_all_count;
  1569. return $json;
  1570. }
  1571. $goods_info = M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->find();
  1572. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'per_number');
  1573. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  1574. $json = array();
  1575. if($can_buy_count == -1 || $can_buy_day_count == -1)
  1576. {
  1577. $json['code'] =6;
  1578. $json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您本次只能购买'.$goods_description['per_number'].'个';
  1579. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  1580. {
  1581. $json['code'] =6;
  1582. //$json['msg']=mb_substr($goods_info['name'],0,4,'utf-8').'...,您还能购买'.$can_buy_count.'份';
  1583. $json['msg']='本次最多购买'.$can_buy_count.'份';
  1584. $json['count']=$can_buy_count;
  1585. }else{
  1586. $json['code'] = 0;
  1587. }
  1588. return $json;
  1589. }
  1590. private function _add_address($token,$userName,$telNumber,$provinceName,$cityName, $countyName,$detailInfo,$latitude='',$longitude='',$lou_meng_hao='')
  1591. {
  1592. $_GPC = I('request.');
  1593. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1594. $member_id = $weprogram_token['member_id'];
  1595. // lionfish_comshop_area
  1596. $province_info = M('lionfish_comshop_area')->where("name like '%{$provinceName}%' ")->find();
  1597. if( !empty($province_info))
  1598. {
  1599. $province_id = $province_info['id'];
  1600. }else{
  1601. $area_data = array();
  1602. $area_data['name'] = $provinceName;
  1603. $area_data['pid'] = 0;
  1604. $area_data['code'] = $max_dp['code']+1;
  1605. $province_id = M('lionfish_comshop_area')->add($area_data);
  1606. $up_data = array();
  1607. $up_data['code'] = $province_id;
  1608. M('lionfish_comshop_area')->where( array('id' => $province_id ) )->save($up_data);
  1609. }
  1610. $guding_arr = ['鞍山市'];
  1611. if( in_array($cityName , $guding_arr) )
  1612. {
  1613. $city_info = M('lionfish_comshop_area')->where("name = '{$cityName}'")->find();
  1614. }else{
  1615. $city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
  1616. }
  1617. //$city_info = M('lionfish_comshop_area')->where("name like '%{$cityName}%'")->find();
  1618. if( !empty($city_info))
  1619. {
  1620. $city_id = $city_info['id'];
  1621. }else{
  1622. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  1623. $area_data = array();
  1624. $area_data['name'] = $cityName;
  1625. $area_data['pid'] = $province_id;
  1626. $area_data['code'] = $max_dp['code']+1;
  1627. $city_id = M('lionfish_comshop_area')->add( $area_data);
  1628. $up_data = array();
  1629. $up_data['code'] = $city_id;
  1630. M('lionfish_comshop_area')->where( array('id' => $city_id ) )->save($up_data);
  1631. }
  1632. //city_name: 东莞市
  1633. if( empty($countyName) )
  1634. {
  1635. if( $cityName == '东莞市' )
  1636. {
  1637. $countyName = '东莞';
  1638. }
  1639. if( $cityName == '中山市' )
  1640. {
  1641. $countyName = '中山';
  1642. //453
  1643. }
  1644. }
  1645. $country_info = M('lionfish_comshop_area')->where( "name like '%{$countyName}%' " )->find();
  1646. if( $countyName == '中山' )
  1647. {
  1648. $country_info = M('lionfish_comshop_area')->where( array('id' => 453 ) )->find();
  1649. //
  1650. }
  1651. if( !empty($country_info))
  1652. {
  1653. $country_id = $country_info['id'];
  1654. }else{
  1655. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  1656. $area_data = array();
  1657. $area_data['name'] = $countyName;
  1658. $area_data['pid'] = $city_id;
  1659. $area_data['code'] = $max_dp['code']+1;
  1660. $country_id = M('lionfish_comshop_area')->add( $area_data );
  1661. $up_data = array();
  1662. $up_data['code'] = $country_id;
  1663. M('lionfish_comshop_area')->where( array('id' => $country_id ) )->save( $up_data );
  1664. }
  1665. $address_param = array();
  1666. $address_param['member_id'] = $member_id;
  1667. $address_param['province_id'] = $province_id;
  1668. $address_param['country_id'] = $country_id;
  1669. $address_param['city_id'] = $city_id;
  1670. $address_param['address'] = $detailInfo;
  1671. $address_param['name'] = $userName;
  1672. $address_param['telephone'] = $telNumber;
  1673. $address_param['lon_lat'] = '';
  1674. $address_param['lou_meng_hao'] = $lou_meng_hao;
  1675. if(!empty($latitude))
  1676. {
  1677. $address_param['lon_lat'] = $longitude.','.$latitude;
  1678. }
  1679. $has_addre = M('lionfish_comshop_address')->where($address_param)->find();
  1680. if(empty($has_addre))
  1681. {
  1682. $has_default_address = M('lionfish_comshop_address')->where( array('is_default' => 1,'member_id' => $member_id) )->find();
  1683. $address_data = array();
  1684. $address_data['member_id'] = $member_id;
  1685. $address_data['name'] = $userName;
  1686. $address_data['telephone'] = $telNumber;
  1687. $address_data['lou_meng_hao'] = $lou_meng_hao;
  1688. if(!empty($latitude))
  1689. {
  1690. $address_data['lon_lat'] = $longitude.','.$latitude;
  1691. }else{
  1692. $address_data['lon_lat'] = '';
  1693. }
  1694. $address_data['address'] = $detailInfo;
  1695. $address_data['address_name'] = empty($data['address_name']) ? 'HOME' : $data['address_name'];
  1696. if(!empty($has_default_address) && false)
  1697. {
  1698. $address_data['is_default'] = 0;
  1699. }else{
  1700. $data = array();
  1701. $data['is_default'] = 0;
  1702. M('lionfish_comshop_address')->where( array('member_id' => $member_id ) )->save($data);
  1703. $address_data['is_default'] = 1;
  1704. }
  1705. $address_data['city_id'] = $city_id;
  1706. $address_data['country_id'] = $country_id;
  1707. $address_data['province_id'] = $province_id;
  1708. $res = M('lionfish_comshop_address')->add($address_data);
  1709. }else{
  1710. $res = $has_addre['address_id'];
  1711. }
  1712. return $res;
  1713. }
  1714. public function checkout()
  1715. {
  1716. $gpc = I('request.');
  1717. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  1718. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  1719. if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
  1720. {
  1721. $pintuan_model_buy = 0;
  1722. }
  1723. $mb_city_name = isset($gpc['mb_city_name']) ? $gpc['mb_city_name'] : '';
  1724. if($buy_type == 'undefined')
  1725. {
  1726. $buy_type = 'dan';
  1727. }
  1728. $community_id = $gpc['community_id'];
  1729. $token = $gpc['token'];
  1730. $voucher_id = isset($gpc['voucher_id']) ? $gpc['voucher_id'] : 0;
  1731. $soli_id = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : '';
  1732. $use_quan_str = isset($gpc['use_quan_str']) ? $gpc['use_quan_str'] : '';
  1733. $use_quan_arr = array();
  1734. if($use_quan_str != '')
  1735. {
  1736. $use_quan_arr_tmp = explode('@',$use_quan_str );
  1737. foreach($use_quan_arr_tmp as $val)
  1738. {
  1739. $tmp_arr = explode('_', $val);
  1740. $use_quan_arr[$tmp_arr[0]] = $tmp_arr[1];
  1741. }
  1742. }
  1743. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1744. $member_id = $weprogram_token['member_id'];
  1745. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  1746. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  1747. $is_vip_card_member = 0;
  1748. $is_member_level_buy = 0;
  1749. if( $member_id > 0 )
  1750. {
  1751. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  1752. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  1753. {
  1754. $now_time = time();
  1755. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  1756. {
  1757. $is_vip_card_member = 1;//还是会员
  1758. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  1759. $is_vip_card_member = 2;//已过期
  1760. }
  1761. }
  1762. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  1763. {
  1764. $is_member_level_buy = 1;
  1765. }
  1766. }
  1767. //预售不开启会员卡
  1768. if($buy_type == 'pesale')
  1769. {
  1770. $is_member_level_buy = 0;
  1771. $is_vip_card_member = 0;
  1772. }
  1773. if( empty($member_id) )
  1774. {
  1775. //需要登录
  1776. echo json_encode( array('code' =>5) );
  1777. die();
  1778. }
  1779. $cart = D('Home/Car');
  1780. if ((!$cart->has_goodswecar($buy_type,$token,$community_id) ) ) {
  1781. //购物车中没有商品
  1782. echo json_encode( array('code' =>4) );
  1783. die();
  1784. }
  1785. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1786. //soitaire
  1787. $goods=$cart->get_all_goodswecar($buy_type, $token,1,$community_id,$soli_id);
  1788. $address = M('lionfish_comshop_address')->where( array('member_id' => $member_id) )->order('is_default desc,address_id desc')->find();
  1789. $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();
  1790. if( !empty($add_old_order) && $add_old_order['address_id'] > 0)
  1791. {
  1792. $address = M('lionfish_comshop_address')->where( array('address_id' => $add_old_order['address_id'],'member_id' => $member_id) )->find();
  1793. }
  1794. $mb_city_id = 0;
  1795. if(!empty($mb_city_name))
  1796. {
  1797. $mb_city_info = M('lionfish_comshop_area')->where(" name='{$mb_city_name}' ")->find();
  1798. if( !empty($mb_city_info) )
  1799. {
  1800. $mb_city_id = $mb_city_info['id'];
  1801. }
  1802. }
  1803. if($address){
  1804. //get_area_info($id)
  1805. $province_info = D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
  1806. $city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
  1807. $country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
  1808. $address['province_name'] = $province_info['name'];
  1809. $address['city_name'] = $city_info['name'];
  1810. $address['country_name'] = $country_info['name'];
  1811. }else{
  1812. $address = array();
  1813. }
  1814. $seller_goodss = array();
  1815. $show_voucher = 0;
  1816. //判断是否仅快递的配送方式 is_only_express
  1817. $is_open_only_express = D('Home/Front')->get_config_by_name('is_open_only_express');
  1818. $is_only_express = 0;
  1819. if( !empty($is_open_only_express) && $is_open_only_express == 1)
  1820. {
  1821. $is_only_express = 1;
  1822. }
  1823. /**
  1824. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  1825. {
  1826. $is_member_level_buy = 1;
  1827. }
  1828. **/
  1829. foreach($goods as $key => $val)
  1830. {
  1831. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  1832. if( $is_only_express == 1 && $val['is_only_express'] != 1 )
  1833. {
  1834. $is_only_express = 0;
  1835. }
  1836. if($is_only_express == 0 && $val['is_only_express'] == 3 )
  1837. {
  1838. $is_only_express = 3;
  1839. }
  1840. if($is_only_express == 0 && $val['is_only_express'] == 2 )
  1841. {
  1842. $is_only_express = 2;
  1843. }
  1844. $supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
  1845. if($supply_id > 0)
  1846. {
  1847. $supply_info = D('Home/Front')->get_supply_info($supply_id);
  1848. if($supply_info['type'] ==0)
  1849. {
  1850. $supply_id = 0;
  1851. }
  1852. }
  1853. $val['name'] = htmlspecialchars_decode($val['name']);
  1854. $seller_goodss[ $supply_id ]['goods'][$key] = $val;
  1855. }
  1856. //begin 如果是同城配送 ,查一查有没有新提交的地址,如果有,按照新的来处理
  1857. $localtown_address = array();
  1858. if( $is_only_express == 3 )
  1859. {
  1860. $localtown_old_order = M('lionfish_comshop_order')->field('address_id')->where( array('delivery' => 'localtown_delivery','member_id' => $member_id) )->order('order_id desc')->find();
  1861. $localtown_id = 0;
  1862. if( !empty($localtown_old_order) && $localtown_old_order['address_id'] > 0)
  1863. {
  1864. $localtown_address = M('lionfish_comshop_address')->where( array('address_id' => $localtown_old_order['address_id'],'member_id' => $member_id) )->find();
  1865. if(!empty($localtown_address))
  1866. {
  1867. $province_info = D('Home/Front')->get_area_info($address['province_id']);// M('area')->field('area_name')->where( array('area_id' => $address['province_id']) )->find();
  1868. $city_info = D('Home/Front')->get_area_info($address['city_id']);//M('area')->field('area_name')->where( array('area_id' => $address['city_id']) )->find();
  1869. $country_info = D('Home/Front')->get_area_info($address['country_id']);//M('area')->field('area_name')->where( array('area_id' => $address['country_id']) )->find();
  1870. $localtown_address['province_name'] = $province_info['name'];
  1871. $localtown_address['city_name'] = $city_info['name'];
  1872. $localtown_address['country_name'] = $country_info['name'];
  1873. }else if( isset($gpc['longitude']) && isset($gpc['latitude']) )
  1874. {
  1875. $localtown_address['lon_lat'] = $gpc['longitude'].','.$gpc['latitude'];
  1876. }
  1877. }else{
  1878. $address = array();
  1879. }
  1880. }
  1881. //end同城配送
  1882. $quan_model = D('Home/Voucher');
  1883. $pin_model = D('Home/Pin');
  1884. $voucher_price = 0;
  1885. $reduce_money = 0;
  1886. $cha_reduce_money = 0;
  1887. $is_pin_over = 0;
  1888. $is_moban = false;
  1889. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  1890. $full_money = D('Home/Front')->get_config_by_name('full_money');
  1891. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  1892. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  1893. {
  1894. $is_open_fullreduction = 0;
  1895. }
  1896. $show_voucher = 0;
  1897. $voucher_can_use =1;//目前都是平台券,
  1898. $man_total_free = 0;
  1899. $store_buy_total_money = 0;
  1900. $pin_id = 0;
  1901. $presale_goods_id = 0;//预售商品id
  1902. $presale_goods_total = 0;//预售商品价格
  1903. $is_zero_buy = 0;
  1904. $vipcard_save_money = 0;
  1905. $level_save_money = 0;
  1906. $today_time = time();
  1907. $arr = array('天','一','二','三','四','五','六');
  1908. //计算优惠券
  1909. foreach($seller_goodss as $store_id => $val)
  1910. {
  1911. $seller_voucher_list = array();
  1912. $seller_total_fee = 0;
  1913. $total_trans_free = 0;
  1914. $is_no_quan = false;
  1915. $total_weight = 0;
  1916. $total_quantity = 0;
  1917. $vch_goods_ids = array();
  1918. foreach($val['goods'] as $kk =>$d_goods)
  1919. {
  1920. //预售不参与会员卡
  1921. if($d_goods['is_take_vipcard'] == 1)
  1922. {
  1923. $vipcard_save_money += $d_goods['total'] - $d_goods['card_total'];
  1924. }else if( $d_goods['is_mb_level_buy'] == 1 && $d_goods['is_mb_level_buy'] == 1 && $is_member_level_buy == 1)
  1925. {
  1926. $level_save_money += $d_goods['total'] - $d_goods['level_total'];
  1927. }
  1928. if( $is_vip_card_member == 1 && $d_goods['is_take_vipcard'] == 1 )
  1929. {
  1930. $seller_total_fee += $d_goods['card_total'];
  1931. if( $store_id == 0 )
  1932. {
  1933. $store_buy_total_money += $d_goods['card_total'];
  1934. }
  1935. if( $d_goods['can_man_jian'] == 1)
  1936. {
  1937. $man_total_free += $d_goods['card_total'];
  1938. }
  1939. }
  1940. else if( $d_goods['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  1941. {
  1942. $seller_total_fee += $d_goods['level_total'];
  1943. if( $store_id == 0 )
  1944. {
  1945. $store_buy_total_money += $d_goods['level_total'];
  1946. }
  1947. if( $d_goods['can_man_jian'] == 1)
  1948. {
  1949. $man_total_free += $d_goods['level_total'];
  1950. }
  1951. }
  1952. else
  1953. {
  1954. $seller_total_fee += $d_goods['total'];
  1955. if( $store_id == 0 )
  1956. {
  1957. $store_buy_total_money += $d_goods['total'];
  1958. }
  1959. if( $d_goods['can_man_jian'] == 1)
  1960. {
  1961. $man_total_free += $d_goods['total'];
  1962. }
  1963. }
  1964. if($buy_type == 'pintuan' && $d_goods['pin_id'] > 0)
  1965. {
  1966. $is_pin_over = $pin_model->getNowPinState($d_goods['pin_id']);
  1967. if( $is_pin_over == 2 )
  1968. {
  1969. $is_zero_buy = $pin_model->check_goods_iszero_opentuan( $d_goods['goods_id'] );
  1970. }
  1971. }else if($buy_type == 'pintuan' && $d_goods['pin_id'] == 0)
  1972. {
  1973. $is_zero_buy = $pin_model->check_goods_iszero_opentuan( $d_goods['goods_id'] );
  1974. }
  1975. if( $buy_type == 'presale' )
  1976. {
  1977. $presale_goods_id = $d_goods['goods_id'];
  1978. $presale_goods_total = $seller_total_fee;
  1979. }
  1980. $tp_goods_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $d_goods['goods_id']) )->find();
  1981. $vch_goods_ids[$d_goods['goods_id']] = $vch_goods_ids[$d_goods['goods_id']] + $d_goods['total'];
  1982. //$is_no_quan = true;
  1983. //预售不开启优惠券
  1984. if($tp_goods_info['type'] == 'integral' || $tp_goods_info['type'] == 'presale' )
  1985. {
  1986. $is_no_quan = true;
  1987. }
  1988. if($d_goods['shipping']==0)
  1989. {
  1990. $is_moban = true;
  1991. $val['is_moban'] = true;
  1992. $total_weight += $d_goods['weight']*$d_goods['quantity'];
  1993. $total_quantity += $d_goods['quantity'];
  1994. }
  1995. $d_goods[$kk]['trans_free'] = 0;
  1996. /**
  1997. if($d_goods['shipping']==1)
  1998. {
  1999. //统一运费
  2000. $d_goods[$kk]['trans_free'] = $d_goods['goods_freight'];
  2001. }else {
  2002. //运费模板
  2003. if(!empty($address))
  2004. {
  2005. $trans_free = load_model_class('transport')->calc_transport($d_goods['transport_id'], $d_goods['quantity'],$d_goods['quantity']*$d_goods['weight'], $address['city_id'] );
  2006. }else{
  2007. $trans_free = 0;
  2008. }
  2009. $d_goods[$kk]['trans_free'] = $trans_free;
  2010. }
  2011. **/
  2012. $total_trans_free += $d_goods[$kk]['trans_free'];
  2013. //自提时间
  2014. $goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $d_goods['goods_id']) )->find();
  2015. $pick_up_type = -1;
  2016. if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
  2017. {
  2018. $pick_up_type = $goods_info['pick_up_type'];
  2019. if($pick_up_type == 0)
  2020. {
  2021. $pick_up_time = date('m-d', $today_time);
  2022. $pick_up_weekday = '周'.$arr[date('w',$today_time)];
  2023. }else if( $pick_up_type == 1 ){
  2024. $pick_up_time = date('m-d', $today_time+86400);
  2025. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  2026. }else if( $pick_up_type == 2 )
  2027. {
  2028. $pick_up_time = date('m-d', $today_time+86400*2);
  2029. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  2030. }else if($pick_up_type == 3)
  2031. {
  2032. $pick_up_time = $goods_info['pick_up_modify'];
  2033. }
  2034. }
  2035. $d_goods['pick_up_type'] = $pick_up_type;
  2036. $d_goods['pick_up_time'] = $pick_up_time;
  2037. $d_goods['pick_up_weekday'] = $pick_up_weekday;
  2038. $val['goods'][$kk] = $d_goods;
  2039. }
  2040. $val['reduce_money'] = 0;
  2041. //pindan (拼团商品单独购买) pintuan (拼团)
  2042. //预售关闭满减
  2043. if($buy_type == 'pindan' || $buy_type == 'pintuan' || $buy_type == 'integral' || $buy_type == 'presale')
  2044. {
  2045. $is_open_fullreduction = 0;
  2046. }
  2047. //原来满级计算man_total_free
  2048. /*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
  2049. {
  2050. $val['reduce_money'] = $full_reducemoney;
  2051. $reduce_money = $full_reducemoney;
  2052. }else if($is_open_fullreduction == 1 && $man_total_free < $full_money)
  2053. {
  2054. $cha_reduce_money = $full_money - $man_total_free;
  2055. }*/
  2056. /**
  2057. * 新满减计算
  2058. */
  2059. if($is_open_fullreduction == 1)
  2060. {
  2061. $reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
  2062. $val['reduce_money'] = $reduce_result['reduce_money'];
  2063. $reduce_money = $reduce_result['reduce_money'];
  2064. $cha_reduce_money = $reduce_result['cha_reduce_money'];
  2065. }
  2066. $chose_vouche = array();
  2067. if(!$is_no_quan)
  2068. {
  2069. $vouche_list = $quan_model->get_user_canpay_voucher($member_id,$store_id,$seller_total_fee,'',$vch_goods_ids);
  2070. $vouche_list = $quan_model->get_voucher_amout_bygoods($vouche_list,$val['goods'],$reduce_money);
  2071. //var_dump( $vouche_list );
  2072. //die();
  2073. if(!empty($vouche_list) && empty($use_quan_arr) ) {
  2074. $ling_vouche_list = $vouche_list;
  2075. if($voucher_can_use == 1)
  2076. {
  2077. $voucher_can_use++;
  2078. $show_voucher = 1;
  2079. reset($ling_vouche_list);
  2080. $chose_vouche = current($ling_vouche_list);
  2081. //$voucher_price += $chose_vouche['credit'];
  2082. $voucher_price += $chose_vouche['can_vouche_amount'];
  2083. //$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
  2084. $seller_total_fee = round( $seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
  2085. }
  2086. }else if( !empty($vouche_list) && !empty($use_quan_arr) )
  2087. {
  2088. foreach($vouche_list as $tmp_voucher)
  2089. {
  2090. if($tmp_voucher['id'] == $use_quan_arr[$store_id])
  2091. {
  2092. $show_voucher = 1;
  2093. $chose_vouche = $tmp_voucher;
  2094. //$seller_total_fee = round( $seller_total_fee - $chose_vouche['credit'], 2);
  2095. //$voucher_price += $chose_vouche['credit'];
  2096. $seller_total_fee = round( $seller_total_fee - $chose_vouche['can_vouche_amount'], 2);
  2097. $voucher_price += $chose_vouche['can_vouche_amount'];
  2098. break;
  2099. }
  2100. }
  2101. }
  2102. }
  2103. $val['chose_vouche'] = $chose_vouche;
  2104. $val['show_voucher'] = $show_voucher;
  2105. $val['voucher_list'] = $vouche_list;
  2106. $val['total'] = $seller_total_fee;
  2107. if($val['total'] < 0)
  2108. {
  2109. $val['total'] = 0;
  2110. }
  2111. $val['trans_free'] = $total_trans_free;
  2112. $val['total_weight'] = $total_weight;
  2113. $val['total_quantity'] = $total_quantity;
  2114. $s_logo = D('Home/Front')->get_config_by_name('shoplogo');
  2115. $shoname = D('Home/Front')->get_config_by_name('shoname');
  2116. if( !empty($s_logo) )
  2117. {
  2118. $s_logo = tomedia( $s_logo );
  2119. }
  2120. $store_info = array('s_id' => $store_id,'s_true_name' => $shoname,'s_logo' => $s_logo );
  2121. if( !empty($store_id) && $store_id > 0 )
  2122. {
  2123. $supply_info = D('Home/Front')->get_supply_info($store_id);
  2124. //logo
  2125. if( !empty($supply_info) )
  2126. {
  2127. $store_info['s_true_name'] = $supply_info['shopname'];
  2128. $store_info['s_logo'] = tomedia( $supply_info['logo'] );
  2129. }
  2130. }
  2131. $val['store_info'] = $store_info;
  2132. $seller_goodss[$store_id] = $val;
  2133. }
  2134. $trans_free_toal = 0;//运费
  2135. //delivery_type_ziti delivery_type_express delivery_type_tuanz delivery_tuanz_money
  2136. $delivery_type_ziti = D('Home/Front')->get_config_by_name('delivery_type_ziti');
  2137. $delivery_type_express = D('Home/Front')->get_config_by_name('delivery_type_express');
  2138. $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
  2139. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  2140. //---
  2141. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  2142. $man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
  2143. $delivery_express_name = D('Home/Front')->get_config_by_name('delivery_express_name');
  2144. if( empty($man_free_tuanzshipping) || $buy_type == 'integral')
  2145. {
  2146. $man_free_tuanzshipping = 0;
  2147. }
  2148. //关闭团长配送费 免 预售
  2149. if( empty($man_free_tuanzshipping) || $buy_type == 'presale' )
  2150. {
  2151. $man_free_tuanzshipping = 0;
  2152. }
  2153. if( empty($man_free_shipping) || $buy_type == 'integral' )
  2154. {
  2155. $man_free_shipping = 0;
  2156. }
  2157. //关闭快递配送费 免 预售
  2158. if( empty($man_free_shipping) || $buy_type == 'presale' )
  2159. {
  2160. $man_free_shipping = 0;
  2161. }
  2162. //if( $buy_type == 'dan' )
  2163. if( $buy_type == 'dan' || $buy_type == 'soitaire' || ($pintuan_model_buy == 1 && $buy_type != 'dan' && $buy_type != 'integral' ) )
  2164. {
  2165. //...判断团长是否开启自定义的情况 store_buy_total_money
  2166. $community_info_modify = M('lionfish_community_head')->field('is_modify_shipping_method,is_modify_shipping_fare,shipping_fare')->where( array('id' => $community_id) )->find();
  2167. if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 && $delivery_type_tuanz == 1)
  2168. {
  2169. //开启配送
  2170. $delivery_type_tuanz = 1;
  2171. if( !empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0 )
  2172. {
  2173. $delivery_tuanz_money = $community_info_modify['shipping_fare'];
  2174. }
  2175. }else if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 2 )
  2176. {
  2177. //关闭配送
  2178. $delivery_type_tuanz = 0;
  2179. }
  2180. }else if( $buy_type == 'pindan' || $buy_type == 'pintuan' ){
  2181. if($pintuan_model_buy == 0)
  2182. {
  2183. $delivery_type_tuanz = 0;
  2184. $delivery_type_express = 1;
  2185. $delivery_type_ziti = 2;
  2186. }
  2187. }else if( $buy_type == 'integral' )
  2188. {
  2189. $delivery_type_tuanz = 0;
  2190. $delivery_type_express = 1;
  2191. $delivery_type_ziti = 2;
  2192. }
  2193. foreach($val['goods'] as $kk =>$d_goods)
  2194. {
  2195. if($d_goods['is_only_express'] == 1){
  2196. $delivery_type_express = 1;
  2197. }
  2198. }
  2199. $is_man_delivery_tuanz_fare = 0;//是否达到满xx减团长配送费
  2200. $fare_man_delivery_tuanz_fare_money = 0;//达到满xx减团长配送费, 减了多少钱
  2201. if( ( $buy_type == 'dan' || $buy_type == 'soitaire' ) && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $man_free_tuanzshipping <= $store_buy_total_money )
  2202. {
  2203. //$delivery_tuanz_money = 0;
  2204. $is_man_delivery_tuanz_fare = 1;
  2205. $fare_man_delivery_tuanz_fare_money = $delivery_tuanz_money;
  2206. }
  2207. $is_man_shipping_fare = 0;//是否达到满xx减运费
  2208. $fare_man_shipping_fare_money = 0;//达到满xx减运费,司机减了多少运费
  2209. //----开始计算运费 //dispatchtype
  2210. if($delivery_type_express == 1)
  2211. {
  2212. //ims_
  2213. $store_trans_free_toal = 0;
  2214. if($mb_city_id > 0){
  2215. $shipping_default = M('lionfish_comshop_shipping')->where(array('enabled' => 1))->order('isdefault desc,id desc')->find();
  2216. foreach($seller_goodss as $store_id => $val)
  2217. {
  2218. //$val['is_moban'] = true;
  2219. $store_shipping_fare = 0;
  2220. if( isset($val['is_moban']) && $val['is_moban'] )
  2221. {
  2222. $store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'],$val['total_weight'], $mb_city_id );
  2223. }
  2224. $val['store_shipping_fare'] = $store_shipping_fare;
  2225. $trans_free_toal += $store_shipping_fare;
  2226. if( $store_id == 0 )
  2227. {
  2228. $store_trans_free_toal += $store_shipping_fare;
  2229. }
  2230. foreach($val['goods'] as $kk =>$d_goods)
  2231. {
  2232. if($d_goods['shipping']==1)
  2233. {
  2234. //统一运费
  2235. $trans_free_toal += $d_goods['goods_freight'];
  2236. if( $store_id == 0 )
  2237. {
  2238. $store_trans_free_toal += $d_goods['goods_freight'];
  2239. }
  2240. }
  2241. }
  2242. }
  2243. }else if(!empty($address) && $mb_city_id == 0)
  2244. {
  2245. $shipping_default = M('lionfish_comshop_shipping')->where( array('enabled' => 1) )->order('isdefault desc,id desc')->find();
  2246. foreach($seller_goodss as $store_id => $val)
  2247. {
  2248. $store_shipping_fare = 0;
  2249. if(isset($val['is_moban']) && $val['is_moban'])
  2250. {
  2251. $store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $val['total_quantity'],$val['total_weight'], $address['city_id'] );
  2252. }
  2253. $val['store_shipping_fare'] = $store_shipping_fare;
  2254. $trans_free_toal += $store_shipping_fare;
  2255. if( $store_id == 0 )
  2256. {
  2257. $store_trans_free_toal += $store_shipping_fare;
  2258. }
  2259. foreach($val['goods'] as $kk =>$d_goods)
  2260. {
  2261. if($d_goods['shipping']==1)
  2262. {
  2263. //统一运费
  2264. $trans_free_toal += $d_goods['goods_freight'];
  2265. $val['store_shipping_fare'] += $d_goods['goods_freight'];
  2266. if( $store_id == 0 )
  2267. {
  2268. $store_trans_free_toal += $d_goods['goods_freight'];
  2269. }
  2270. }
  2271. }
  2272. }
  2273. }else{
  2274. $trans_free_toal = 0;
  2275. }
  2276. //
  2277. if( !empty($man_free_shipping) && $man_free_shipping > 0 && $man_free_shipping <= $store_buy_total_money )
  2278. {
  2279. $fare_man_shipping_fare_money = $store_trans_free_toal;
  2280. $is_man_shipping_fare = 1;
  2281. //$trans_free_toal = 0;
  2282. }
  2283. }
  2284. //礼品卡配送费0
  2285. if( $buy_type == 'virtualcard' )
  2286. {
  2287. $trans_free_toal = 0;
  2288. }
  2289. //---结束结算运费
  2290. if( empty($delivery_type_ziti) )
  2291. {
  2292. $delivery_type_ziti = 1;//开启
  2293. }
  2294. if( empty($delivery_type_express) )
  2295. {
  2296. $delivery_type_express = 2;
  2297. }
  2298. if( empty($delivery_type_tuanz) )
  2299. {
  2300. $delivery_type_tuanz = 2;
  2301. }
  2302. //默认关闭同城配送
  2303. $delivery_type_localtown = 0;
  2304. //默认关闭核销商品
  2305. $delvery_type_hexiao = 0;
  2306. //is_only_express
  2307. if( $is_only_express == 1 )
  2308. {
  2309. $delivery_type_ziti = 2;
  2310. $delivery_type_express = 1;
  2311. $delivery_type_tuanz = 2;
  2312. }else if( $is_only_express == 3 )
  2313. {
  2314. //同城配送
  2315. $delivery_type_ziti = 0;
  2316. $delivery_type_express = 0;
  2317. $delivery_type_tuanz = 0;
  2318. $delivery_type_localtown = 1;
  2319. }else if( $is_only_express == 2 )
  2320. {
  2321. //核销商品
  2322. $delivery_type_ziti = 0;
  2323. $delivery_type_express = 0;
  2324. $delivery_type_tuanz = 0;
  2325. $delivery_type_localtown = 0;
  2326. $delvery_type_hexiao = 1;
  2327. }
  2328. $total_free = 0;
  2329. $is_ziti = 2;
  2330. $pick_up_time = "";
  2331. $pick_up_type = -1;
  2332. $pick_up_weekday = '';
  2333. $today_time = time();
  2334. $arr = array('天','一','二','三','四','五','六');
  2335. $pick_up_arr = array();
  2336. foreach($goods as $key => $good)
  2337. {
  2338. //暂时关闭
  2339. //ims_lionfish_comshop_goods
  2340. //ims_ lionfish_comshop_good_common
  2341. $goods_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $good['goods_id']) )->find();
  2342. if($pick_up_type == -1 || $goods_info['pick_up_type'] > $pick_up_type)
  2343. {
  2344. $pick_up_type = $goods_info['pick_up_type'];
  2345. if($pick_up_type == 0)
  2346. {
  2347. $pick_up_time = date('m-d', $today_time);
  2348. $pick_up_weekday = '周'.$arr[date('w',$today_time)];
  2349. }else if( $pick_up_type == 1 ){
  2350. $pick_up_time = date('m-d', $today_time+86400);
  2351. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  2352. }else if( $pick_up_type == 2 )
  2353. {
  2354. $pick_up_time = date('m-d', $today_time+86400*2);
  2355. $pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  2356. }else if($pick_up_type == 3)
  2357. {
  2358. $pick_up_time = $goods_info['pick_up_modify'];
  2359. }
  2360. }
  2361. $goods[$key]['trans_free'] = $good['goods_freight'];
  2362. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  2363. {
  2364. $total_free += $good['card_total'];
  2365. }
  2366. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  2367. {
  2368. $total_free += $good['level_total'];
  2369. }
  2370. else
  2371. {
  2372. $total_free += $good['total'];
  2373. }
  2374. }
  2375. //同城配送费
  2376. $localtown_shipping_fare = 0;
  2377. //包装费
  2378. $picking_fare = 0;
  2379. $picking_fare_arr = array();
  2380. $localtown_shipping_fare_arr = array();
  2381. $localtown_dispatchtime = 0;//预计一共需要配送多少分钟
  2382. $localtown_expected_delivery = array();//预计送达时间段
  2383. $localtown_modifypickingname = "";//包装费标题
  2384. if( $is_only_express == 3 )
  2385. {
  2386. $picking_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money( $seller_goodss );// $seller_goodss;
  2387. $picking_fare = $picking_fare_arr['total_picking_fare'];
  2388. $localtown_dispatchtime = D('Home/LocaltownDelivery')->get_order_dispatchtime($seller_goodss);
  2389. if( isset($gpc['latitude']) && !empty($gpc['latitude']) && isset($gpc['longitude']) && !empty($gpc['longitude']) )
  2390. {
  2391. $lon = $gpc['longitude'];
  2392. $lat = $gpc['latitude'];
  2393. $localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $seller_goodss );
  2394. $localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
  2395. $trans_free_toal = $localtown_shipping_fare;
  2396. }else if( !empty($localtown_address) )
  2397. {
  2398. list($lon,$lat) = explode(',', $localtown_address['lon_lat'] );
  2399. $localtown_shipping_fare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $seller_goodss );
  2400. $localtown_shipping_fare = $localtown_shipping_fare_arr['total_shipping_fare'];
  2401. $trans_free_toal = $localtown_shipping_fare;
  2402. }
  2403. //配送时间段间隔
  2404. $localtown_expected_delivery = D('Home/LocaltownDelivery')->get_expected_delivery($localtown_dispatchtime);
  2405. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  2406. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  2407. }
  2408. //暂时关闭自提代码
  2409. /**
  2410. if(!empty($pick_up))
  2411. {
  2412. $pick_up = unserialize($pick_up);
  2413. $pick_up_ids = implode(',',$pick_up);
  2414. $pick_up_arr = M('pick_up')->where( array('id'=>array('in',$pick_up_ids)) )->select();
  2415. }
  2416. **/
  2417. $pick_up_name = '';
  2418. $pick_up_mobile = '';
  2419. $tuan_send_address = '';
  2420. $order_note_content = '';
  2421. $tuan_send_address_info = array();
  2422. $shop_limit_buy_distance = D('Home/Front')->get_config_by_name('shop_limit_buy_distance');
  2423. if($is_ziti >= 1)
  2424. {
  2425. //寻找上一个订单的自提电话 自提姓名
  2426. $last_order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'delivery' => 'pickup') )->order('order_id desc')->find();
  2427. if(empty($last_order_info)){
  2428. $last_order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'delivery' => 'hexiao') )->order('order_id desc')->find();
  2429. }
  2430. if(!empty($last_order_info))
  2431. {
  2432. $pick_up_name = $last_order_info['shipping_name'];
  2433. $pick_up_mobile = $last_order_info['telephone'];
  2434. $order_note_content = $last_order_info['note_content'];
  2435. }
  2436. //order_note_content
  2437. $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();
  2438. if(!empty($last_tuanz_send_order_info))
  2439. {
  2440. $tuan_send_address = $last_tuanz_send_order_info['tuan_send_address'];
  2441. if( !empty($last_tuanz_send_order_info['note_content']) && $last_tuanz_send_order_info['order_id'] > $last_order_info['order_id'] )
  2442. {
  2443. $order_note_content = $last_tuanz_send_order_info['note_content'];
  2444. }
  2445. if( !empty($last_tuanz_send_order_info['address_id']) )
  2446. {
  2447. if($shop_limit_buy_distance == 1)
  2448. {
  2449. $tuan_send_address_info = M('lionfish_comshop_address')->where( "address_id=".$last_tuanz_send_order_info['address_id']." and lon_lat != '' " )->find();
  2450. }else{
  2451. $tuan_send_address_info = M('lionfish_comshop_address')->where( "address_id=".$last_tuanz_send_order_info['address_id'] )->find();
  2452. }
  2453. if( !empty($tuan_send_address) && !empty($tuan_send_address_info['lon_lat']) )
  2454. {
  2455. $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();
  2456. $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();
  2457. $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();
  2458. $tuan_send_address_info['province_name'] = $province_info['name'];
  2459. $tuan_send_address_info['city_name'] = $city_info['name'];
  2460. $tuan_send_address_info['country_name'] = $country_info['name'];
  2461. $tuan_send_address = $tuan_send_address_info['address'];
  2462. }else{
  2463. //todo...
  2464. $tuan_send_address = '';
  2465. }
  2466. }else{
  2467. $tuan_send_address = '';
  2468. }
  2469. }
  2470. }
  2471. /**
  2472. **/
  2473. /**
  2474. tuan_region
  2475. store_buy_total_money
  2476. **/
  2477. //open_score_buy_score $shop_limit_buy_distance = load_model_class('front')->get_config_by_name('shop_limit_buy_distance');
  2478. /**
  2479. $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
  2480. $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
  2481. $delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
  2482. if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
  2483. if( empty($tuan_send_address_info) )
  2484. {
  2485. $tuan_send_address_info = array();
  2486. }
  2487. //判断是否预售,给出预售的信息 begin todo
  2488. $presale_info = [];
  2489. if( $buy_type == 'presale' )
  2490. {
  2491. // $presale_goods_id
  2492. $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
  2493. if( $presale_result['code'] == 0 )
  2494. {
  2495. $presale_info = $presale_result['data'];
  2496. }
  2497. }
  2498. //end
  2499. **/
  2500. $open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
  2501. if( empty($open_score_buy_score) || $buy_type == 'integral' )
  2502. {
  2503. $open_score_buy_score = 0;
  2504. }
  2505. $score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
  2506. if( empty($score_forbuy_money_maxbi) )
  2507. {
  2508. $score_forbuy_money_maxbi = 100;
  2509. }
  2510. $score_for_money = 0;
  2511. $bue_use_score = 0;
  2512. if( $open_score_buy_score == 1 )
  2513. {
  2514. if( $member_info['score'] > 0 )
  2515. {
  2516. $score_can_max = $store_buy_total_money - $voucher_price - $reduce_money;
  2517. //计算能兑换多少钱
  2518. $score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
  2519. //只有兑换比例大于0才能允许兑换
  2520. if( !empty($score_forbuy_money) && $score_forbuy_money >0 )
  2521. {
  2522. $score_for_money = sprintf("%.2f",$member_info['score'] / $score_forbuy_money);
  2523. if( $score_can_max < $score_for_money )
  2524. {
  2525. $score_for_money = $score_can_max;
  2526. $bue_use_score = floor($score_can_max * $score_forbuy_money);
  2527. $score_for_money = round($bue_use_score/$score_forbuy_money,2);
  2528. }
  2529. $max_store_buy_total_money = sprintf("%.2f",($score_forbuy_money_maxbi * $score_can_max) /100);
  2530. if($score_for_money > $max_store_buy_total_money)
  2531. {
  2532. $score_for_money = $max_store_buy_total_money;
  2533. $bue_use_score = floor($max_store_buy_total_money * $score_forbuy_money);
  2534. $score_for_money = round($bue_use_score/$score_forbuy_money,2);
  2535. }else if($bue_use_score <= $max_store_buy_total_money){
  2536. $bue_use_score = floor($score_for_money * $score_forbuy_money);
  2537. //$bue_use_score = $member_info['score'];
  2538. if($bue_use_score > $member_info['score'] )
  2539. {
  2540. $bue_use_score = floor($member_info['score']);
  2541. }
  2542. $score_for_money = round($bue_use_score/$score_forbuy_money,2);
  2543. }
  2544. }
  2545. //预售
  2546. //if($buy_type == 'presale'){
  2547. // $sum_deduction_money = $goods[0]["quantity"] * $presale_info['deduction_money'] ;
  2548. //}
  2549. }
  2550. }
  2551. //score_forbuy_money score
  2552. $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name');
  2553. $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name');
  2554. $delivery_diy_sort = D('Home/Front')->get_config_by_name('delivery_diy_sort');
  2555. if(empty($delivery_diy_sort) || !isset($delivery_diy_sort)) $delivery_diy_sort = '0,1,2';
  2556. if( empty($tuan_send_address_info) )
  2557. {
  2558. $tuan_send_address_info = array();
  2559. }
  2560. //判断是否预售,给出预售的信息 begin todo
  2561. $presale_info = [];
  2562. if( $buy_type == 'presale' )
  2563. {
  2564. // $presale_goods_id
  2565. $presale_result = D('Home/PresaleGoods')->getCheckOutPresaleGoodsInfo( $presale_goods_id , $presale_goods_total );
  2566. if( $presale_result['code'] == 0 )
  2567. {
  2568. $presale_info = $presale_result['data'];
  2569. }
  2570. }
  2571. //end
  2572. $need_data = array();
  2573. $need_data['code'] = 1;
  2574. $need_data['open_score_buy_score'] = $open_score_buy_score;//1开启积分抵扣
  2575. $need_data['score'] = $member_info['score'];//会员持有的积分
  2576. $need_data['score_for_money'] = $score_for_money;//会员能抵扣的金额
  2577. $need_data['bue_use_score'] = $bue_use_score;//会员能抵扣的积分数
  2578. $need_data['delivery_type_ziti'] = $delivery_type_ziti;
  2579. $need_data['delivery_type_express'] = $delivery_type_express;
  2580. $need_data['delivery_type_tuanz'] = $delivery_type_tuanz;
  2581. $need_data['delivery_type_localtown'] = $delivery_type_localtown;
  2582. $need_data['delvery_type_hexiao'] = $delvery_type_hexiao;
  2583. $need_data['delivery_express_name'] = $delivery_express_name;
  2584. $need_data['delivery_ziti_name'] = $delivery_ziti_name;
  2585. $need_data['delivery_tuanzshipping_name'] = $delivery_tuanzshipping_name;
  2586. $need_data['delivery_diy_sort'] = $delivery_diy_sort;
  2587. $need_data['presale_info'] = $presale_info;//预售信息
  2588. $seller_goodss_keys = array_keys($seller_goodss);
  2589. $need_data['delivery_tuanz_money'] = round($delivery_tuanz_money * count($seller_goodss_keys) , 2);
  2590. //$need_data['delivery_tuanz_money'] = $delivery_tuanz_money;
  2591. $need_data['man_free_tuanzshipping'] = empty($man_free_tuanzshipping) ? 0 : $man_free_tuanzshipping;//团长配送,满多少免配送费,0或者为空表示不减免
  2592. $need_data['man_free_shipping'] = empty($man_free_shipping) ? 0 : $man_free_shipping;//快递配送,满多少免配送费,0或者为空表示不减免
  2593. $need_data['address'] = $address;
  2594. $need_data['pick_up_time'] = $pick_up_time;
  2595. $need_data['pick_up_type'] = $pick_up_type;
  2596. $need_data['pick_up_weekday'] = $pick_up_weekday;
  2597. $need_data['is_pin_over'] = $is_pin_over;
  2598. $need_data['is_integer'] = 0;//$is_no_quan ? 1: 0;
  2599. $need_data['pick_up_arr'] = $pick_up_arr;
  2600. $need_data['is_ziti'] = 2;
  2601. $need_data['ziti_name'] = $pick_up_name;
  2602. $need_data['ziti_mobile'] = $pick_up_mobile;
  2603. $need_data['tuan_send_address'] = $tuan_send_address;
  2604. $need_data['tuan_send_address_info'] = $tuan_send_address_info;
  2605. $need_data['seller_goodss'] = $seller_goodss;
  2606. $need_data['show_voucher'] = $show_voucher;
  2607. $need_data['buy_type'] = $buy_type;
  2608. $need_data['address'] = $address;
  2609. $need_data['trans_free_toal'] = $trans_free_toal;
  2610. $need_data['is_limit_distance_buy'] = 0;
  2611. $need_data['limit_distance'] = 100;//km
  2612. $need_data['is_member_level_buy'] = $is_member_level_buy;//km
  2613. $need_data['level_save_money'] = $level_save_money;//km
  2614. //begin
  2615. $need_data['localtown_shipping_fare'] = $localtown_shipping_fare;//同城配送配送费
  2616. $need_data['pickingup_fare'] = $picking_fare;//包装费
  2617. $need_data['localtown_dispatchtime'] = $localtown_dispatchtime;//预计一共需要配送多少分钟
  2618. $need_data['picking_fare_arr'] = $picking_fare_arr;
  2619. $need_data['localtown_shipping_fare_arr'] = $localtown_shipping_fare_arr;
  2620. $need_data['localtown_expected_delivery'] = $localtown_expected_delivery;
  2621. //end
  2622. $need_data['is_vip_card_member'] = $is_vip_card_member;//km
  2623. $need_data['vipcard_save_money'] = $vipcard_save_money;//km
  2624. $need_data['is_open_vipcard_buy'] = $is_open_vipcard_buy;//km
  2625. if( !empty($shop_limit_buy_distance) && $shop_limit_buy_distance ==1 )
  2626. {
  2627. $latitude = 0;
  2628. $longitude = 0;
  2629. if( !empty($tuan_send_address_info) && !empty($tuan_send_address_info['lon_lat']) )
  2630. {
  2631. //lon_lat
  2632. $lon_lat_arr = explode(',', $tuan_send_address_info['lon_lat']);
  2633. $longitude = $lon_lat_arr[0];
  2634. $latitude = $lon_lat_arr[1];
  2635. }
  2636. if( isset($gpc['latitude']) && !empty($gpc['latitude']) )
  2637. {
  2638. $latitude = $gpc['latitude'];
  2639. }
  2640. if( isset($gpc['longitude']) && !empty($gpc['longitude']) )
  2641. {
  2642. $longitude = $gpc['longitude'];
  2643. }
  2644. if( !empty($latitude) && !empty($longitude) )
  2645. {
  2646. $shop_buy_distance = D('Home/Front')->get_config_by_name('shop_buy_distance');
  2647. $shop_buy_distance = $shop_buy_distance * 1000;
  2648. $community_info = M('lionfish_community_head')->field('lon,lat')->where( array('id' => $community_id ) )->find();
  2649. $distince = D('Seller/Communityhead')->GetDistance($longitude,$latitude,$community_info['lon'],$community_info['lat']);
  2650. $need_data['current_distance'] = $distince;
  2651. $need_data['shop_buy_distance'] = $shop_buy_distance;
  2652. if($distince > $shop_buy_distance )
  2653. {
  2654. $need_data['is_limit_distance_buy'] = 1;
  2655. $need_data['limit_distance'] = $distince/1000;
  2656. }
  2657. }
  2658. }
  2659. $need_data['reduce_money'] = $reduce_money;
  2660. $need_data['is_open_fullreduction'] = $is_open_fullreduction;
  2661. $need_data['cha_reduce_money'] = $cha_reduce_money;
  2662. $need_data['is_man_delivery_tuanz_fare'] = $is_man_delivery_tuanz_fare; //是否达到满xx减团长配送费
  2663. $need_data['fare_man_delivery_tuanz_fare_money'] = $fare_man_delivery_tuanz_fare_money; //达到满xx减团长配送费, 减了多少钱
  2664. $need_data['is_man_shipping_fare'] = $is_man_shipping_fare; //是否达到满xx减运费
  2665. $need_data['fare_man_shipping_fare_money'] = $fare_man_shipping_fare_money; //达到满xx减运费,司机减了多少运费
  2666. $dispatching = isset($gpc['dispatching']) ? $gpc['dispatching']:'pickup';
  2667. //is_ziti == 2
  2668. if($dispatching == 'express')
  2669. {
  2670. $need_data['total_free'] = $total_free + $trans_free_toal - $voucher_price -$reduce_money;
  2671. }
  2672. else if( $dispatching == 'localtown_delivery' )
  2673. {
  2674. $need_data['total_free'] = $total_free + $localtown_shipping_fare + $picking_fare - $voucher_price - $reduce_money;
  2675. }
  2676. else{
  2677. $need_data['total_free'] = $total_free - $voucher_price -$reduce_money;
  2678. }
  2679. if($is_ziti == 2)
  2680. {
  2681. $need_data['total_free'] = $total_free - $voucher_price -$reduce_money;
  2682. }
  2683. //积分兑换 不算总金额,但是算总积分
  2684. if( $buy_type == 'integral' )
  2685. {
  2686. $need_data['total_free'] = $trans_free_toal;
  2687. $need_data['total_integral'] = $total_free;
  2688. }
  2689. if($need_data['total_free'] < 0)
  2690. {
  2691. $need_data['total_free'] = 0;
  2692. }
  2693. //判断是否可以余额支付
  2694. //暂时关闭 会员余额功能
  2695. /**
  2696. $is_yue_open_info = M('config')->where( array('name' => 'is_yue_open') )->find();
  2697. $is_yue_open = $is_yue_open_info['value'];
  2698. **/
  2699. $is_yue_open = 0;
  2700. $is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
  2701. if( empty($is_yue_open) )
  2702. {
  2703. $is_yue_open = 0;
  2704. }
  2705. $need_data['is_yue_open'] = $is_yue_open;
  2706. $need_data['can_yupay'] = 0;
  2707. //暂时关闭 会员余额功能
  2708. if($is_yue_open == 1 && $need_data['total_free'] >=0 && $member_info['account_money'] >= $need_data['total_free'])
  2709. {
  2710. $need_data['can_yupay'] = 1;
  2711. }
  2712. //前端隐藏 团长信息
  2713. $index_hide_headdetail_address = D('Home/Front')->get_config_by_name('index_hide_headdetail_address');
  2714. if( empty($index_hide_headdetail_address) )
  2715. {
  2716. $index_hide_headdetail_address = 0;
  2717. }
  2718. $need_data['index_hide_headdetail_address'] = $index_hide_headdetail_address;
  2719. //订单留言
  2720. $is_open_order_message = D('Home/Front')->get_config_by_name('is_open_order_message');
  2721. $need_data['yu_money'] = $member_info['account_money'];
  2722. $need_data['goods'] = $goods;
  2723. $need_data['is_open_order_message'] = $is_open_order_message;
  2724. $need_data['is_zero_opentuan'] = 0;
  2725. //拼团特殊情况0元开团
  2726. if( $buy_type == 'pintuan' && $is_zero_buy == 1 )
  2727. {
  2728. //$need_data['total_free'] = 0;
  2729. //$need_data['trans_free_toal'] = 0;
  2730. //$need_data['is_zero_opentuan'] = 1;
  2731. }
  2732. //订阅消息begin
  2733. $is_need_subscript = 0;
  2734. $need_subscript_template = array();
  2735. //'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
  2736. //$member_id
  2737. if( $buy_type == 'pintuan' )
  2738. {
  2739. //pin_tuansuccess
  2740. //send_order parameter[weprogram_subtemplate_pin_tuansuccess]
  2741. //hexiao_success
  2742. $pin_tuansuccess_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'pin_tuansuccess' ) )->find();
  2743. //if( empty($pin_tuansuccess_info) )
  2744. //{
  2745. $weprogram_subtemplate_pin_tuansuccess = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
  2746. if( !empty($weprogram_subtemplate_pin_tuansuccess) )
  2747. {
  2748. $need_subscript_template['pin_tuansuccess'] = $weprogram_subtemplate_pin_tuansuccess;
  2749. }
  2750. //}
  2751. }else{
  2752. //pay_order
  2753. $pay_order_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'pay_order') )->find();
  2754. //if( empty($pay_order_info) )
  2755. //{
  2756. $weprogram_subtemplate_pay_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
  2757. if( !empty($weprogram_subtemplate_pay_order) )
  2758. {
  2759. $need_subscript_template['pay_order'] = $weprogram_subtemplate_pay_order;
  2760. }
  2761. //}
  2762. }
  2763. //send_order
  2764. $send_order_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'send_order' ) )->find();
  2765. //if( empty($send_order_info) )
  2766. //{
  2767. $weprogram_subtemplate_send_order = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
  2768. if( !empty($weprogram_subtemplate_send_order) )
  2769. {
  2770. $need_subscript_template['send_order'] = $weprogram_subtemplate_send_order;
  2771. }
  2772. //}
  2773. //hexiao_success
  2774. $hexiao_success_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'hexiao_success' ) )->find();
  2775. //if( empty($hexiao_success_info) )
  2776. //{
  2777. $weprogram_subtemplate_hexiao_success = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
  2778. if( !empty($weprogram_subtemplate_hexiao_success) )
  2779. {
  2780. $need_subscript_template['hexiao_success'] = $weprogram_subtemplate_hexiao_success;
  2781. }
  2782. //}
  2783. if( !empty($need_subscript_template) )
  2784. {
  2785. $is_need_subscript = 1;
  2786. }
  2787. //下单万能表单
  2788. $need_data['allform'] = D('Home/Allform')->getOrderForms();
  2789. //判断是否使用货到付款
  2790. $cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
  2791. $need_data['cashondelivery_data'] = $cashondelivery_data;
  2792. //订阅消息end
  2793. $need_data['is_need_subscript'] = $is_need_subscript;
  2794. $need_data['need_subscript_template'] = $need_subscript_template;
  2795. //订单提交页面备注信息
  2796. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  2797. $order_note_open = isset($order_note_open) && $order_note_open == 1 ? 1: 0;
  2798. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  2799. $order_note_name = !isset($order_note_name) || empty($order_note_name) ? '店名' : $order_note_name;
  2800. $need_data['order_note_open'] = $order_note_open;//开启下单页面备注,仅 自提跟 团长配送时需要
  2801. $need_data['order_note_name'] = $order_note_name;//备注名称,默认是店名
  2802. $need_data['order_note_content'] = $order_note_content;//备注名称,默认是店名
  2803. $need_data['localtown_modifypickingname'] = $localtown_modifypickingname;//备注名称,默认是店名
  2804. //配送费类型:0、固定金额,1、按距离收取
  2805. $localtown_delivery_moneytype = D('Home/Front')->get_config_by_name('localtown_delivery_moneytype');
  2806. //起送价格
  2807. $localtown_moneytype_fixed_deliverymoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_deliverymoney');
  2808. //达到金额免配送费
  2809. $localtown_moneytype_fixed_freemoney = D('Home/Front')->get_config_by_name('localtown_moneytype_fixed_freemoney');
  2810. //加价配送
  2811. $localtown_makeup_delivery_money = D('Home/Front')->get_config_by_name('localtown_makeup_delivery_money');
  2812. //1、固定金额,订单价格超过起送价格 无加价配送费,2、按距离收取 无加价配送费 3、固定金额,起送价格为0 无加价配送费
  2813. if(($localtown_delivery_moneytype == 0 && ($localtown_shipping_fare_arr[0]['is_can_qisong'] == 1 || $localtown_moneytype_fixed_deliverymoney == 0)) || $localtown_delivery_moneytype == 1){
  2814. $localtown_makeup_delivery_money = 0;
  2815. }else{
  2816. $localtown_makeup_delivery_money = 0;
  2817. }
  2818. $need_data['localtown_delivery_moneytype'] = $localtown_delivery_moneytype;
  2819. $need_data['localtown_moneytype_fixed_deliverymoney'] = $localtown_moneytype_fixed_deliverymoney;
  2820. $need_data['localtown_moneytype_fixed_freemoney'] = $localtown_moneytype_fixed_freemoney;
  2821. $need_data['localtown_makeup_delivery_money'] = $localtown_makeup_delivery_money;
  2822. $need_data['order_lou_meng_hao'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao');
  2823. $need_data['order_lou_meng_hao_placeholder'] = D('Home/Front')->get_config_by_name('order_lou_meng_hao_placeholder');
  2824. echo json_encode($need_data);
  2825. die();
  2826. }
  2827. public function sub_order()
  2828. {
  2829. $gpc = I('request.');
  2830. $buy_type = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  2831. $token = $gpc['token'];
  2832. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2833. $member_id = $weprogram_token['member_id'];
  2834. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  2835. $allform_id = $gpc['allform_id'];
  2836. $allform_list = $gpc['allform_list'];
  2837. if( empty($pintuan_model_buy) || $pintuan_model_buy ==0 )
  2838. {
  2839. $pintuan_model_buy = 0;
  2840. }
  2841. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  2842. $is_open_vipcard_buy = !empty($is_open_vipcard_buy) && $is_open_vipcard_buy ==1 ? 1:0;
  2843. $is_vip_card_member = 0;
  2844. $is_member_level_buy = 0;
  2845. if( $member_id > 0 )
  2846. {
  2847. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  2848. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  2849. {
  2850. $now_time = time();
  2851. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  2852. {
  2853. $is_vip_card_member = 1;//还是会员
  2854. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  2855. $is_vip_card_member = 2;//已过期
  2856. }
  2857. }
  2858. if($is_vip_card_member != 1 && $member_info['level_id'] >0 )
  2859. {
  2860. $is_member_level_buy = 1;
  2861. }
  2862. }
  2863. if($buy_type == 'presale')
  2864. {
  2865. $is_vip_card_member = 0;
  2866. $is_member_level_buy = 0;
  2867. }
  2868. //use_score = 1
  2869. $use_score = isset($gpc['use_score']) ? intval($gpc['use_score']) : 0;
  2870. $puis_not_buy = D('Home/Front')->get_config_by_name('puis_not_buy');
  2871. if( !empty($puis_not_buy) && $puis_not_buy ==1 )
  2872. {
  2873. $member_info = M('lionfish_comshop_member')->field('level_id')->where( array('member_id' => $member_id) )->find();
  2874. if($member_info['level_id'] == 0)
  2875. {
  2876. echo json_encode( array('code' => 2, 'msg' => '普通会员不能购买') );
  2877. die();
  2878. }
  2879. }
  2880. //$buy_type == 'presale'
  2881. $data_s = array();
  2882. $data_s['pay_method'] = $gpc['wxpay'];
  2883. $data_s['buy_type'] = isset($gpc['buy_type']) ? $gpc['buy_type'] : 'dan';
  2884. $data_s['pick_up_id'] = $gpc['pick_up_id'];
  2885. $data_s['dispatching'] = $gpc['dispatching'];
  2886. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  2887. if($order_note_open == 1){
  2888. $data_s['note_content'] = $gpc['note_content'];
  2889. }else{
  2890. $data_s['note_content'] = '';
  2891. }
  2892. $data_s['soli_id'] = isset($gpc['soli_id']) ? intval($gpc['soli_id']) : 0 ;
  2893. if($data_s['dispatching'] != 'express' && empty($data_s['pick_up_id']))
  2894. {
  2895. $last_community = M('lionfish_community_history')->where( array('member_id' => $member_id) )->order('id desc')->find();
  2896. if( !empty($last_community) )
  2897. {
  2898. $data_s['pick_up_id'] = $last_community['head_id'];
  2899. }
  2900. //$data_s['pick_up_id']
  2901. }
  2902. //礼品卡不用配送地址begin
  2903. if( $data_s['buy_type'] == 'virtualcard' )
  2904. {
  2905. $data_s['dispatching'] = 'express';
  2906. $data_s['address_id'] = 0;
  2907. }
  2908. //end
  2909. 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' ) )
  2910. {
  2911. D('Seller/Community')->in_community_history($member_id,$data_s['pick_up_id']);
  2912. }
  2913. //'express' 快递, 'pickup' 自提, 'tuanz_send' 团长配送) tuan_send_address
  2914. $data_s['ziti_name'] = $gpc['ziti_name'];
  2915. $data_s['quan_arr'] = $gpc['quan_arr'];
  2916. $data_s['comment'] = $gpc['comment'];
  2917. $data_s['ziti_mobile'] = $gpc['ziti_mobile'];
  2918. $data_s['tuan_send_address'] = $gpc['tuan_send_address'];
  2919. $data_s['ck_yupay'] = $gpc['ck_yupay'];
  2920. //是否货到付款
  2921. $data_s['cashon_delivery'] = $gpc['cashon_delivery'];
  2922. $data_s['province_name'] = isset($gpc['province_name']) ? $gpc['province_name']:'' ;
  2923. $data_s['city_name'] = isset($gpc['city_name']) ? $gpc['city_name']: '';
  2924. $data_s['country_name'] = isset($gpc['country_name']) ? $gpc['country_name']: '';
  2925. $data_s['address_name'] = isset($gpc['address_name']) ? $gpc['address_name']:'' ;
  2926. $data_s['latitude'] = isset($gpc['latitude']) ? $gpc['latitude']:'' ;
  2927. $data_s['longitude'] = isset($gpc['longitude']) ? $gpc['longitude']:'' ;
  2928. $data_s['lou_meng_hao'] = isset($gpc['lou_meng_hao']) ? $gpc['lou_meng_hao']:'' ;
  2929. $data_s['expected_delivery_time'] = isset($gpc['expected_delivery_time']) ? $gpc['expected_delivery_time']:'' ;
  2930. //$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
  2931. //$data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
  2932. //tuan_send_address
  2933. $province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
  2934. $city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
  2935. $country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
  2936. $address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
  2937. //判断配送距离
  2938. /*if($data_s['dispatching'] == 'localtown_delivery'){
  2939. //服务距离
  2940. $localtown_servvice_maxdistance = D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
  2941. //商家经纬度
  2942. $localtown_shop_lon = D('Home/Front')->get_config_by_name('localtown_shop_lon');
  2943. $localtown_shop_lat = D('Home/Front')->get_config_by_name('localtown_shop_lat');
  2944. $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
  2945. $distince = round($distince/1000,2);
  2946. if($distince > $localtown_servvice_maxdistance){
  2947. //echo json_encode( array('code' => 2, 'msg' => '超出服务距离'.$localtown_servvice_maxdistance.'KM') );
  2948. echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
  2949. die();
  2950. }
  2951. }*/
  2952. $json=array();
  2953. $pay_method = $data_s['pay_method'];//支付类型
  2954. $order_msg_str = $data_s['order_msg_str'];//商品订单留言
  2955. $comment = $data_s['comment'];//商品订单留言
  2956. $comment_arr = array();
  2957. if( !empty($data_s['comment']) )
  2958. {
  2959. $comment_arr1 = explode('@EOF@', $data_s['comment']);
  2960. foreach($comment_arr1 as $var){
  2961. $count = substr_count($var, '_');
  2962. $a = explode('_', $var);
  2963. for($i=1 ; $i<$count ; $i++ ){
  2964. $comment_arr[$a[$i]] = $a[$count];
  2965. }
  2966. }
  2967. }
  2968. $pick_up_id = $data_s['pick_up_id'];
  2969. $dispatching = $data_s['dispatching'];
  2970. $ziti_name = $data_s['ziti_name'];
  2971. $ziti_mobile = $data_s['ziti_mobile'];
  2972. //新增快递
  2973. $province_name = isset($data_s['province_name']) ? $data_s['province_name'] : '';
  2974. $city_name = isset($data_s['city_name']) ? $data_s['city_name'] : '';
  2975. $country_name = isset($data_s['country_name']) ? $data_s['country_name'] : '';
  2976. $address_name = isset($data_s['address_name']) ? $data_s['address_name'] : '';
  2977. $ck_yupay = $data_s['ck_yupay'];
  2978. $cashon_delivery = $data_s['cashon_delivery'];
  2979. if($dispatching == 'express')
  2980. {
  2981. $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name);
  2982. }
  2983. else if( $dispatching == 'localtown_delivery' )
  2984. {
  2985. $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'] );
  2986. }
  2987. else if($dispatching == 'tuanz_send'){
  2988. $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'] );
  2989. $data_s['tuan_send_address'] .= $data_s['lou_meng_hao'];
  2990. }
  2991. /**
  2992. pick_up_id: that.data.pick_up_id,
  2993. dispatching: that.data.dispatching, //express pickup
  2994. ziti_name: t_ziti_name,
  2995. ziti_mobile: t_ziti_mobile
  2996. **/
  2997. $order_msg_arr = explode('@,@', $order_msg_str);
  2998. $quan_arr = $data_s['quan_arr'];//商品订单留言
  2999. $order_quan_arr = array();
  3000. if( !empty($quan_arr) )
  3001. {
  3002. if( !is_array($quan_arr) )
  3003. {
  3004. $quan_arr = array($quan_arr);
  3005. }
  3006. foreach($quan_arr as $q_val)
  3007. {
  3008. $tmp_q = array();
  3009. $tmp_q = explode('_',$q_val);
  3010. $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();
  3011. if( !empty($voucher_info) )
  3012. {
  3013. //$order_quan_arr[$tmp_q[0]] = $tmp_q[1];
  3014. $order_quan_arr[1] = $tmp_q[1];
  3015. }
  3016. }
  3017. }
  3018. $msg_arr = array();
  3019. foreach($order_msg_arr as $val)
  3020. {
  3021. $tmp_val = explode('@_@', $val);
  3022. $msg_arr[ $tmp_val[0] ] = $tmp_val[1];
  3023. }
  3024. $cart= D('Home/Car');
  3025. // 验证商品数量
  3026. //buy_type:buy_type
  3027. $buy_type = $data_s['buy_type'];//I('post.buy_type');
  3028. $is_pin = 0;
  3029. if($buy_type == 'pintuan')
  3030. {
  3031. $is_pin = 1;
  3032. }
  3033. $goodss = $cart->get_all_goodswecar($buy_type,$token,1,$data_s['pick_up_id'], $data_s['soli_id']);
  3034. //付款人
  3035. $payment = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  3036. //收货人
  3037. $addr_param = array();
  3038. $addr_param[':uniacid'] = $_W['uniacid'];
  3039. $addr_param[':member_id'] = $member_id;
  3040. //$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";
  3041. //$address = pdo_fetch($addr_sql, $addr_param);
  3042. $seller_goodss = array();
  3043. /** 计算每个订单的优惠券占比begin */
  3044. $zanbi_total_money = 0;
  3045. //是否需要校验ticket 交易组件
  3046. $scene = $gpc['scene'];
  3047. $is_need_scene_check = 0;
  3048. if(!empty($scene))
  3049. {
  3050. $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
  3051. }
  3052. foreach($goodss as $key => $val) {
  3053. //单商户先屏蔽
  3054. //$goods_store_field = M('goods')->field('store_id')->where( array('goods_id' => $val['goods_id']) )->find();
  3055. $supply_id = D('Home/Front')->get_goods_supply_id($val['goods_id']);
  3056. if ($supply_id > 0) {
  3057. $supply_info = D('Home/Front')->get_supply_info($supply_id);
  3058. if ($supply_info['type'] == 0) {
  3059. $supply_id = 0;
  3060. }
  3061. }
  3062. if($data_s['dispatching'] == 'localtown_delivery'){
  3063. if($supply_id > 0){
  3064. $isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$supply_id);
  3065. if($isopen_localtown_delivery == 1){
  3066. //服务距离
  3067. $localtown_servvice_maxdistance = D('Home/Front')->get_supply_config_by_name('localtown_servvice_maxdistance',$supply_id);
  3068. //商家经纬度
  3069. $localtown_shop_lon = D('Home/Front')->get_supply_config_by_name('localtown_shop_lon',$supply_id);
  3070. $localtown_shop_lat = D('Home/Front')->get_supply_config_by_name('localtown_shop_lat',$supply_id);
  3071. $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
  3072. $distince = round($distince/1000,2);
  3073. if($distince > $localtown_servvice_maxdistance){
  3074. echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
  3075. die();
  3076. }
  3077. }
  3078. }else{
  3079. //服务距离
  3080. $localtown_servvice_maxdistance = D('Home/Front')->get_config_by_name('localtown_servvice_maxdistance');
  3081. //商家经纬度
  3082. $localtown_shop_lon = D('Home/Front')->get_config_by_name('localtown_shop_lon');
  3083. $localtown_shop_lat = D('Home/Front')->get_config_by_name('localtown_shop_lat');
  3084. $distince = D('Seller/Communityhead')->GetDistance($data_s['longitude'],$data_s['latitude'], $localtown_shop_lon, $localtown_shop_lat);
  3085. $distince = round($distince/1000,2);
  3086. if($distince > $localtown_servvice_maxdistance){
  3087. echo json_encode( array('code' => 2, 'msg' => '您与商家的距离过远,商家的配送范围是'.$localtown_servvice_maxdistance.'KM内') );
  3088. die();
  3089. }
  3090. }
  3091. }
  3092. $seller_goodss[$supply_id][$key] = $val;
  3093. //$cart->removecar($val['key'],$token);
  3094. if ($is_vip_card_member == 1 && $val['is_take_vipcard'] == 1) {
  3095. $zanbi_total_money += $val['card_total'];
  3096. } else if ($val['is_mb_level_buy'] > 0 && $is_member_level_buy == 1) {
  3097. $zanbi_total_money += $val['level_total'];
  3098. } else if ($val['is_mb_level_buy'] == 1 && $member_info['level_id'] > 0){
  3099. $zanbi_total_money += $val['level_total'];
  3100. }
  3101. else
  3102. {
  3103. $zanbi_total_money += $val['total'];
  3104. }
  3105. //检测是否场景符合begin
  3106. if( $is_need_scene_check == 1 )
  3107. {
  3108. if( $val['isTradeComponts'] == 0 )
  3109. {
  3110. echo json_encode( array('code' => 2,'msg' => $val['name'].':未提交小程序交易组件' ) );
  3111. die();
  3112. }
  3113. }
  3114. //检测是否场景符合end
  3115. }
  3116. //判断是否可以货到付款
  3117. if($cashon_delivery == 1){
  3118. $cashondelivery_data = D('Home/Front')->getCashonDeliveryAction($buy_type, $seller_goodss);
  3119. if($cashondelivery_data['isopen_cashondelivery'] == 1){
  3120. if($dispatching == 'express' && $cashondelivery_data['isopen_cashondelivery_express'] == 0){
  3121. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3122. die();
  3123. }else if($dispatching == 'tuanz_send' && $cashondelivery_data['isopen_cashondelivery_communityhead'] == 0){
  3124. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3125. die();
  3126. }else if($dispatching == 'localtown_delivery' && $cashondelivery_data['isopen_cashondelivery_localtown'] == 0){
  3127. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3128. die();
  3129. }else if($dispatching == 'hexiao' && $cashondelivery_data['isopen_cashondelivery_hexiao'] == 0){
  3130. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3131. die();
  3132. }else if($dispatching == 'pickup' && $cashondelivery_data['isopen_cashondelivery_ziti'] == 0){
  3133. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3134. die();
  3135. }
  3136. }else{
  3137. echo json_encode( array('code' => 3,'msg' => '货到付款未开启' ) );
  3138. die();
  3139. }
  3140. }
  3141. //....看看有没有满多少才能下单begin
  3142. $open_man_orderbuy = D('Home/Front')->get_config_by_name('open_man_orderbuy');
  3143. $man_orderbuy_money = D('Home/Front')->get_config_by_name('man_orderbuy_money');
  3144. //pindan (拼团商品单独购买) pintuan (拼团)
  3145. if($buy_type == 'pintuan' || $buy_type == 'pindan' || $buy_type == 'integral' )
  3146. {
  3147. $open_man_orderbuy = 0;
  3148. }
  3149. if( !empty($open_man_orderbuy) && $open_man_orderbuy == 1 )
  3150. {
  3151. if( !empty($man_orderbuy_money) && $man_orderbuy_money >0 )
  3152. {
  3153. if($man_orderbuy_money > $zanbi_total_money)
  3154. {
  3155. echo json_encode( array('code' => 2,'msg' => '满'.$man_orderbuy_money.'元才可以下单' , 'is_forb' => 1) );
  3156. die();
  3157. }
  3158. }
  3159. }
  3160. //....看看有没有满多少才能下单end
  3161. //清除购物车
  3162. foreach($goodss as $key => $val)
  3163. {
  3164. $cart->removecar($val['key'],$token);
  3165. }
  3166. /** 计算每个订单的优惠券占比end */
  3167. $pay_total = 0;
  3168. //M('order_all')
  3169. $order_all_data = array();
  3170. $order_all_data['member_id'] = $member_id;
  3171. $order_all_data['order_num_alias'] = build_order_no($member_id);
  3172. $order_all_data['transaction_id'] = '';
  3173. $order_all_data['order_status_id'] = 3;
  3174. $order_all_data['is_pin'] = $is_pin;
  3175. $order_all_data['paytime'] = 0;
  3176. $order_all_data['addtime'] = time();
  3177. $order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
  3178. //暂时屏蔽积分商城模块
  3179. $integral_model = D('Home/Integral');
  3180. $order_ids_arr = array();
  3181. $del_integral = 0;
  3182. if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0 )
  3183. {
  3184. $community_info = array();
  3185. $community_detail_info = array();
  3186. }
  3187. else if( $buy_type == 'integral' )
  3188. {
  3189. $community_info = array();
  3190. $community_detail_info = array();
  3191. }
  3192. else if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1 )
  3193. {
  3194. $community_info = M('lionfish_community_head')->where( array('id' => $data_s['pick_up_id'] ) )->find();
  3195. $community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
  3196. }else{
  3197. $community_info = M('lionfish_community_head')->where( array('id' => $data_s['pick_up_id'] ) )->find();
  3198. $community_detail_info = D('Home/Front')->get_community_byid($data_s['pick_up_id']);
  3199. }
  3200. $address_info = M('lionfish_comshop_address')->where( array('address_id' => $data_s['address_id'] ) )->find();
  3201. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  3202. $full_money = D('Home/Front')->get_config_by_name('full_money');
  3203. $full_reducemoney = D('Home/Front')->get_config_by_name('full_reducemoney');
  3204. $man_free_tuanzshipping = D('Home/Front')->get_config_by_name('man_free_tuanzshipping');
  3205. $man_free_shipping = D('Home/Front')->get_config_by_name('man_free_shipping');
  3206. if( empty($man_free_tuanzshipping) )
  3207. {
  3208. $man_free_tuanzshipping = 0;
  3209. }
  3210. if( empty($man_free_shipping) )
  3211. {
  3212. $man_free_shipping = 0;
  3213. }
  3214. if(empty($full_reducemoney) || $full_reducemoney <= 0)
  3215. {
  3216. $is_open_fullreduction = 0;
  3217. }
  3218. if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 0 )
  3219. {
  3220. $man_free_tuanzshipping = 0;
  3221. $man_free_shipping = 0;
  3222. $is_open_fullreduction = 0;
  3223. }
  3224. else if( $buy_type == 'integral' )
  3225. {
  3226. $man_free_tuanzshipping = 0;
  3227. $man_free_shipping = 0;
  3228. $is_open_fullreduction = 0;
  3229. }
  3230. else if( ($buy_type == 'pintuan' || $buy_type == 'pindan') && $pintuan_model_buy == 1 )
  3231. {
  3232. $man_free_shipping = 0;
  3233. $is_open_fullreduction = 0;
  3234. }
  3235. //预售不参与满减
  3236. if($buy_type == 'presale')
  3237. {
  3238. $man_free_tuanzshipping = 0;
  3239. $man_free_shipping = 0;
  3240. $is_open_fullreduction = 0;
  3241. }
  3242. $is_moban = false;
  3243. $cart = D('Home/Car');
  3244. $is_just_1 = 0;
  3245. $index_comment = 0;
  3246. $pay_goods_name = "";
  3247. $store_buy_total_money = 0;
  3248. $open_score_buy_score = D('Home/Front')->get_config_by_name('open_score_buy_score');
  3249. $score_for_money = 0;//use_score
  3250. if( $buy_type == 'integral' )
  3251. {
  3252. $open_score_buy_score = 0;
  3253. }
  3254. //预售不参与积分抵扣
  3255. if($open_score_buy_score == 1 && $use_score == 1 && $payment['score'] > 0 && $buy_type != 'presale')
  3256. {
  3257. //计算能兑换多少钱
  3258. $score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
  3259. //只有兑换比例大于0才能允许兑换
  3260. if( !empty($score_forbuy_money) && $score_forbuy_money >0 )
  3261. {
  3262. $score_for_money = sprintf('%.2f', $payment['score'] / $score_forbuy_money);
  3263. }
  3264. }
  3265. foreach($seller_goodss as $kk => $vv)
  3266. {
  3267. $is_just_1++;
  3268. $data = array();
  3269. $data['member_id']=$member_id;
  3270. $data['name']= $payment['username'];
  3271. $data['use_score']= $use_score;//是否使用积分抵扣
  3272. $data['telephone']= $data_s['ziti_mobile'];
  3273. $data['note_content']= $data_s['note_content'];
  3274. $data['shipping_name']= $data_s['ziti_name'];
  3275. $data['shipping_tel']= $data_s['ziti_mobile'];
  3276. if($dispatching == 'express' || $dispatching == 'tuanz_send' || $dispatching == 'localtown_delivery')
  3277. {
  3278. $data['shipping_address'] = $address_info['address'];
  3279. $data['shipping_province_id']=$address_info['province_id'];
  3280. $data['shipping_city_id']=$address_info['city_id'];
  3281. $data['shipping_stree_id']= 0;
  3282. $data['shipping_country_id']=$address_info['country_id'];
  3283. }else{
  3284. $data['shipping_address'] = $community_detail_info['fullAddress'];
  3285. $data['shipping_province_id']=$community_info['province_id'];
  3286. $data['shipping_city_id']=$community_info['city_id'];
  3287. $data['shipping_stree_id']=$community_info['country_id'];
  3288. $data['shipping_country_id']=$community_info['area_id'];
  3289. }
  3290. $data['shipping_method'] = 0;
  3291. $data['delivery']=$dispatching;
  3292. $data['pick_up_id']=$pick_up_id;
  3293. $data['ziti_name']=$community_info['head_name'];
  3294. $data['ziti_mobile']=$community_info['head_mobile'];
  3295. $data['payment_method']=$pay_method;
  3296. $data['address_id']= $data_s['address_id'];
  3297. $data['voucher_id'] = isset($order_quan_arr[1]) ? $order_quan_arr[1]:0;//目前都是平台券
  3298. $data['user_agent']=$_SERVER['HTTP_USER_AGENT'];
  3299. $data['date_added']=time();
  3300. $subject='';
  3301. $fare = 0;
  3302. $order_total = 0;
  3303. $trans_free_toal = 0;//运费
  3304. $is_localtown_free_shipping_fare = 0;
  3305. $localtown_shipping_fare_total = 0;//同城配送费
  3306. $localtown_free_shipping_fare = 0;//满减的同城配送费用
  3307. $reduce_money = 0;
  3308. $man_total_free = 0;
  3309. $score_buy_money = 0;
  3310. $is_lottery = 0;
  3311. $is_integral = 0;
  3312. $is_spike = 0;
  3313. $is_hexiao = 0;
  3314. $total_weight = 0;
  3315. $total_quantity = 0;
  3316. $redis_has_add_list = array();
  3317. $is_free_shipping_fare = 0;//是否免除运费
  3318. $order_goods_total_money = 0;
  3319. $goods_data = array();
  3320. $is_moban = false;
  3321. //comment_arr comment_arr
  3322. $packing_fare = 0;
  3323. $iscan_fu_packing = 1;
  3324. if('localtown_delivery' == $dispatching)
  3325. {
  3326. $tmp_sellergd = array($kk => array('goods'=>$vv) );
  3327. $town_address = M('lionfish_comshop_address')->where( array('address_id' => $data_s['address_id'] ) )->find();
  3328. list($lon, $lat ) = explode(",",$town_address['lon_lat'] );
  3329. $localtown_shippingfare_arr = D('Home/LocaltownDelivery')->calc_shipping_fare( $lon, $lat , $tmp_sellergd );
  3330. $trans_free_toal = $localtown_shippingfare_arr['total_shipping_fare'];
  3331. $localtown_shipping_fare_total = $trans_free_toal;
  3332. $packing_fare_arr = D('Home/LocaltownDelivery')->calc_packing_money( array( $kk => array('goods' => $vv ) ) );
  3333. $packing_fare = $packing_fare_arr['total_picking_fare'];
  3334. $localtown_shipping_fare = $localtown_shippingfare_arr['total_shipping_fare'];
  3335. $localtown_yl_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
  3336. if($localtown_shipping_fare != $localtown_yl_shipping_fare && $localtown_shipping_fare == 0){
  3337. $is_localtown_free_shipping_fare = 1;
  3338. $localtown_free_shipping_fare = $localtown_shippingfare_arr['total_yl_shipping_fare'];
  3339. }
  3340. $data['localtown_add_shipping_fare'] = $localtown_shippingfare_arr[$kk]['localtown_add_shipping_fare'];
  3341. }
  3342. $data['expected_delivery_time'] = $data_s['expected_delivery_time'];
  3343. $data['packing_fare'] = floatval($packing_fare);
  3344. foreach($vv as $key => $good)
  3345. {
  3346. if( $kk == 0 )
  3347. {
  3348. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3349. {
  3350. $store_buy_total_money += $good['card_total'];
  3351. }
  3352. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3353. {
  3354. $store_buy_total_money += $good['level_total'];
  3355. }
  3356. else
  3357. {
  3358. $store_buy_total_money += $good['total'];
  3359. }
  3360. }
  3361. /**
  3362. if($good['shipping']==1)
  3363. {
  3364. //统一运费
  3365. $trans_free_toal += $good['goods_freight'];
  3366. $trans_free = $good['goods_freight'];
  3367. }else {
  3368. //运费模板
  3369. $trans_free = load_model_class('transport')->calc_transport($good['transport_id'], $good['quantity'], $good['quantity']*$good['weight'], $address['city_id'] );
  3370. //$trans_free = D('Home/Transport')->calc_transport($good['transport_id'], $good['quantity']*$good['weight'], $address['city_id'] );
  3371. $trans_free_toal +=$trans_free;
  3372. }
  3373. **/
  3374. $trans_free = 0;
  3375. //$trans_free_toal +=$trans_free;
  3376. //sku_str
  3377. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3378. {
  3379. $order_goods_total_money += $good['card_total'];
  3380. $order_total += $good['card_total'];
  3381. }
  3382. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3383. {
  3384. $order_goods_total_money += $good['level_total'];
  3385. $order_total += $good['level_total'];
  3386. }
  3387. else
  3388. {
  3389. $order_goods_total_money += $good['total'];
  3390. $order_total += $good['total'];
  3391. }
  3392. $tp_goods_info = M('lionfish_comshop_goods')->field('type')->where( array('id' => $good['goods_id']) )->find();
  3393. $tp_goods_info['store_id'] = 1;
  3394. if($tp_goods_info['type'] == 'lottery')
  3395. {
  3396. $is_lottery = 1;
  3397. }
  3398. if($tp_goods_info['type'] == 'spike')
  3399. {
  3400. $is_spike = 1;
  3401. $is_pin = 0;
  3402. }
  3403. //暂时屏蔽积分商城模块
  3404. if($tp_goods_info['type'] == 'integral')
  3405. {
  3406. $is_integral = 1;
  3407. $is_pin = 0;
  3408. $check_result = $integral_model->check_user_score_can_pay($member_id, $good['sku_str'], $good['goods_id'] );
  3409. if($check_result['code'] == 1)
  3410. {
  3411. echo json_encode( array('code' => 2, 'msg' => '剩余'.$check_result['cur_score'].'积分,积分不足!' , 'is_forb' => 1 ) );
  3412. die();
  3413. }
  3414. }
  3415. //is_hexiao is_only_express
  3416. if($good['is_only_express']==2)
  3417. {
  3418. $is_hexiao = 2;
  3419. $is_pin = 0;
  3420. }
  3421. if($good['shipping']==0)
  3422. {
  3423. $is_moban = true;
  3424. //统一运费
  3425. $total_weight += $good['weight']*$good['quantity'];
  3426. $total_quantity += $good['quantity'];
  3427. }
  3428. $fenbi_li = 1;
  3429. if( $zanbi_total_money > 0 )
  3430. {
  3431. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3432. {
  3433. $fenbi_li = round($good['card_total'] / $zanbi_total_money, 2);
  3434. }
  3435. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3436. {
  3437. $fenbi_li = round($good['level_total'] / $zanbi_total_money, 2);
  3438. }
  3439. else
  3440. {
  3441. $fenbi_li = round($good['total'] / $zanbi_total_money, 2);
  3442. }
  3443. }
  3444. //if( isset($comment_arr[$index_comment]) )
  3445. //{
  3446. // $comment = $comment_arr[$index_comment];
  3447. //}
  3448. //$good['goods_id']
  3449. if( isset($comment_arr) )
  3450. {
  3451. foreach($comment_arr as $key => $var){
  3452. if($good['goods_id'] == $key ){
  3453. $comment = $var;
  3454. }
  3455. }
  3456. }
  3457. //监测库存数量
  3458. $quantity_flag = D('Seller/Redisorder')->check_goods_can_buy($good['goods_id'], $good['sku_str'],$good['quantity']);
  3459. if( $quantity_flag <=0 )
  3460. {
  3461. if( !empty($redis_has_add_list) )
  3462. {
  3463. D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
  3464. }
  3465. echo json_encode( array('code' => 2, 'msg' => '已抢光' , 'is_forb' => 1) );
  3466. die();
  3467. }
  3468. //如果是下单减库存,那么用占坑法来避免超库存---begin
  3469. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
  3470. if( empty($kucun_method) )
  3471. {
  3472. $kucun_method = 0;
  3473. }
  3474. if($kucun_method == 0)
  3475. {
  3476. //$ret = $redis->rPush('city', 'guangzhou');
  3477. $check_redis_quantity = D('Seller/Redisorder')->add_goods_buy_user($good['goods_id'], $good['sku_str'],$good['quantity'],$member_id);
  3478. //注意要回滚
  3479. //$key = "user_goods_{$member_id}_{$goods_id}_{$sku_str}";
  3480. if($check_redis_quantity == 0)
  3481. {
  3482. //cancle_redis_user_list
  3483. if( !empty($redis_has_add_list) )
  3484. {
  3485. D('Seller/Redisorder')->bu_car_has_delquantity($redis_has_add_list);
  3486. }
  3487. echo json_encode( array('code' => 2, 'msg' => '已抢光' , 'is_forb' => 1) );
  3488. die();
  3489. }
  3490. $redis_has_add_list[] = array('member_id' => $member_id, 'goods_id' => $good['goods_id'], 'sku_str' => $good['sku_str'],'quantity' => $good['quantity'] );
  3491. }
  3492. //----------------redis end
  3493. if( $good['can_man_jian'] == 1)
  3494. {
  3495. //$man_total_free += $good['total'];
  3496. //begggg
  3497. if( $is_vip_card_member == 1 && $good['is_take_vipcard'] == 1 )
  3498. {
  3499. if( $good['can_man_jian'] == 1)
  3500. {
  3501. $man_total_free += $good['card_total'];
  3502. }
  3503. }
  3504. else if( $good['is_mb_level_buy'] == 1 && $member_info['level_id'] >0 )
  3505. {
  3506. if( $good['can_man_jian'] == 1)
  3507. {
  3508. $man_total_free += $good['level_total'];
  3509. }
  3510. }
  3511. else
  3512. {
  3513. if( $good['can_man_jian'] == 1)
  3514. {
  3515. $man_total_free += $good['total'];
  3516. }
  3517. }
  3518. //eddddd
  3519. }
  3520. $pay_goods_name .= $good['name'];
  3521. if( $good['is_mb_level_buy'] == 1 && $is_vip_card_member ==0 && $member_info['level_id'] >0 )
  3522. {
  3523. $good['is_mb_level_buy'] == 1;
  3524. }else{
  3525. $good['is_mb_level_buy'] == 0;
  3526. }
  3527. $localtown_superposition_pickingmoney = 0;
  3528. $localtown_superposition_pickingmoney = isset($localtown_superposition_pickingmoney) ? $localtown_superposition_pickingmoney : 0;
  3529. $gd_packing_fare = 0;
  3530. if( $localtown_superposition_pickingmoney == 0 )
  3531. {
  3532. $gd_packing_fare = $good['packing_free'];
  3533. } else
  3534. {
  3535. if( $packing_fare == $good['packing_free'] && $iscan_fu_packing == 1)
  3536. {
  3537. $iscan_fu_packing = 0;
  3538. $gd_packing_fare = $good['packing_free'];
  3539. }
  3540. }
  3541. $goods_data[] = array(
  3542. 'goods_id' => $good['goods_id'],
  3543. 'store_id' => $tp_goods_info['store_id'],
  3544. 'name' => $good['name'],
  3545. 'model' => $good['model'],
  3546. 'is_pin' => $is_pin,
  3547. 'pin_id' => $good['pin_id'],
  3548. 'header_disc' => $good['header_disc'],
  3549. 'member_disc' => $good['member_disc'],
  3550. 'level_name' => $good['level_name'],
  3551. 'option' => $good['sku_str']== 'undefined' ? '':$good['sku_str'],
  3552. 'quantity' => $good['quantity'],
  3553. 'shipping_fare' => $trans_free,
  3554. 'price' => $good['price'],
  3555. 'costprice' => $good['costprice'],
  3556. 'card_price' => $good['card_price'],
  3557. 'levelprice' => $good['levelprice'],
  3558. 'total' => $good['total'],
  3559. 'packing_fare' => $gd_packing_fare,
  3560. 'card_total' => $good['card_total'] ,
  3561. 'level_total' => $good['level_total'] ,
  3562. 'is_mb_level_buy' => $good['is_mb_level_buy'] ,
  3563. 'is_take_vipcard' => $good['is_take_vipcard'],
  3564. 'fenbi_li' => $fenbi_li,
  3565. 'can_man_jian' => $good['can_man_jian'],
  3566. 'soli_id' => $good['soli_id'],
  3567. 'comment' => htmlspecialchars($comment)
  3568. );
  3569. }
  3570. $index_comment++;
  3571. //$total_weight = 0;
  3572. //$total_quantity = 0;
  3573. if($dispatching == 'express')
  3574. {
  3575. //结算运费新模式
  3576. $trans_free_toal = 0;//运费
  3577. //----开始计算运费
  3578. //ims_
  3579. $shipping_default = M('lionfish_comshop_shipping')->where("enabled=1")->order('isdefault desc,id desc')->find();
  3580. $seller_goodss_re = $seller_goodss;
  3581. $store_shipping_fare = 0;
  3582. if($is_moban)
  3583. {
  3584. $store_shipping_fare = D('Home/Transport')->calc_transport($shipping_default['id'], $total_quantity,$total_weight, $address_info['city_id'] );
  3585. }
  3586. $trans_free_toal += $store_shipping_fare;
  3587. foreach($vv as $kkc =>$d_goods)
  3588. {
  3589. if($d_goods['shipping']==1)
  3590. {
  3591. //统一运费
  3592. $trans_free_toal += $d_goods['goods_freight'];
  3593. }
  3594. }
  3595. if( $kk == 0 && !empty($man_free_shipping) && $man_free_shipping > 0 && $order_goods_total_money >= $man_free_shipping )
  3596. {
  3597. //$trans_free_toal = 0;
  3598. $is_free_shipping_fare = 1;
  3599. }
  3600. //---结束结算运费 address_id
  3601. $data_s['address_id'] = $this->_add_address($token,$ziti_name,$ziti_mobile,$province_name,$city_name, $country_name,$address_name);
  3602. }
  3603. else if('tuanz_send' == $dispatching)
  3604. {
  3605. $trans_free_toal = 0;
  3606. $delivery_tuanz_money = D('Home/Front')->get_config_by_name('delivery_tuanz_money');
  3607. $community_info_modify = $community_info;
  3608. if( !empty($community_info_modify['is_modify_shipping_method']) && $community_info_modify['is_modify_shipping_method'] == 1 )
  3609. {
  3610. if( !empty($community_info_modify['is_modify_shipping_fare']) && $community_info_modify['is_modify_shipping_fare'] == 1 && $community_info_modify['shipping_fare'] > 0 )
  3611. {
  3612. $delivery_tuanz_money = $community_info_modify['shipping_fare'];
  3613. }
  3614. }
  3615. $trans_free_toal = $delivery_tuanz_money;
  3616. $data['tuan_send_address'] = $data_s['tuan_send_address'];
  3617. if( $kk == 0 && !empty($man_free_tuanzshipping) && $man_free_tuanzshipping > 0 && $order_goods_total_money >= $man_free_tuanzshipping )
  3618. {
  3619. $is_free_shipping_fare = 1;
  3620. //$trans_free_toal = 0;
  3621. }
  3622. }
  3623. //$is_pin; is_lottery
  3624. //'pintuan', 'normal', 'lottery'
  3625. $data['type'] = 'normal';
  3626. if($is_pin == 1)
  3627. {
  3628. $data['type'] = 'pintuan';
  3629. if($is_lottery == 1)
  3630. {
  3631. $data['type'] = 'lottery';
  3632. }
  3633. }
  3634. if($is_integral == 1)
  3635. {
  3636. $data['type'] = 'integral';
  3637. $is_pin = 0;
  3638. }
  3639. if($is_hexiao == 1)
  3640. {
  3641. $data['type'] = 'virtual';
  3642. $is_pin = 0;
  3643. }
  3644. if($is_spike == 1)
  3645. {
  3646. $data['type'] = 'spike';
  3647. $is_pin = 0;
  3648. }
  3649. //礼品卡配送费0
  3650. if( $buy_type == 'virtualcard' )
  3651. {
  3652. $trans_free_toal = 0;
  3653. }
  3654. $data['shipping_fare'] = floatval($trans_free_toal);
  3655. if($is_free_shipping_fare == 1)
  3656. {
  3657. $trans_free_toal = 0;
  3658. }
  3659. //原先计算满减金额
  3660. /*if($is_open_fullreduction == 1 && $man_total_free >= $full_money )
  3661. {
  3662. $reduce_money = $full_reducemoney ;
  3663. }*/
  3664. //多组满减金额计算
  3665. if($is_open_fullreduction == 1)
  3666. {
  3667. $reduce_result = D('Home/Front')->get_reduce_money($man_total_free);
  3668. $reduce_money = $reduce_result['reduce_money'];
  3669. }
  3670. $data['is_free_shipping_fare']= $is_free_shipping_fare;
  3671. $data['store_id']= $kk;
  3672. $data['order_goods_total_money']= $order_goods_total_money;
  3673. $data['is_localtown_free_shipping_fare']= $is_localtown_free_shipping_fare;
  3674. $data['localtown_free_shipping_fare']= $localtown_free_shipping_fare;
  3675. $data['goodss'] = $goods_data;
  3676. $data['order_num_alias']=build_order_no($member_id);
  3677. $data['totals'][0]=array(
  3678. 'code'=>'sub_total',
  3679. 'title'=>'商品价格',
  3680. 'text'=>'¥'.$order_total,
  3681. 'value'=>$order_total
  3682. );
  3683. $data['totals'][1]=array(
  3684. 'code'=>'shipping',
  3685. 'title'=>'运费',
  3686. 'text'=>'¥'.$trans_free_toal,
  3687. 'value'=>$trans_free_toal
  3688. );
  3689. $data['totals'][2]=array(
  3690. 'code'=>'total',
  3691. 'title'=>'总价',
  3692. 'text'=>'¥'.($order_total+$trans_free_toal-$reduce_money),
  3693. 'value'=>($order_total+$trans_free_toal-$reduce_money)
  3694. );
  3695. $data['from_type'] = 'wepro';
  3696. //目前都是平台券
  3697. if($data['voucher_id'] > 0) {
  3698. //暂时屏蔽优惠券,等待开启
  3699. /**
  3700. $voucher_info = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ",
  3701. array(':uniacid' => $_W['uniacid'],':id' => $data['voucher_id']));
  3702. $data['voucher_credit'] = $voucher_info['credit'];
  3703. pdo_update('lionfish_comshop_coupon_list', array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time()), array('id' => $data['voucher_id'] ));
  3704. **/
  3705. $voucher_info = M('lionfish_comshop_coupon_list')->where( array('id' => $data['voucher_id']) )->find();
  3706. //检查优惠券指定商品或指定商品分类 优惠金额 begin
  3707. $voucher_list[0] = $voucher_info;
  3708. $voucher_list = D('Home/Voucher')->get_voucher_amout_bygoods($voucher_list,$goods_data, 0);
  3709. $voucher_info = $voucher_list[0];
  3710. //检查优惠券指定商品或指定商品分类 优惠金额 end
  3711. $data['voucher_credit'] = $voucher_info['can_vouche_amount'];
  3712. $bili = 1;
  3713. if( $zanbi_total_money > 0 )
  3714. {
  3715. $bili = round( ($order_goods_total_money / $zanbi_total_money), 2);
  3716. }
  3717. $data['voucher_credit'] = $data['voucher_credit'] * $bili;
  3718. //判断是否超出订单商品金额,不算运费
  3719. //if($data['voucher_credit'] > $order_total+$trans_free_toal - $reduce_money )
  3720. if($data['voucher_credit'] > $order_total - $reduce_money )
  3721. {
  3722. $data['voucher_credit'] = $order_total - $reduce_money;
  3723. }
  3724. M('lionfish_comshop_coupon_list')->where( array('id' => $data['voucher_id'] ) )->save( array('ordersn' => $data['order_num_alias'],'consume' => 'Y','usetime' => time() ) );
  3725. } else {
  3726. $data['voucher_credit'] = 0;
  3727. }
  3728. $use_score_total = 0;//用掉用户多少积分了.
  3729. $data['score_for_money'] = 0;
  3730. if( $kk == 0 && $score_for_money > 0)
  3731. {
  3732. if( $order_total+$trans_free_toal - $reduce_money - $data['voucher_credit'] <= 0)
  3733. {
  3734. //没必要扣积分了,单价已经是0
  3735. }else{
  3736. //只能抵扣扣除优惠券部分的金额
  3737. $del_money = $order_total - $data['voucher_credit'] - $reduce_money;
  3738. //var_dump($del_money, $score_for_money);die();
  3739. //score_for_money 会员能抵扣的最大金额
  3740. //计算多少积分了。
  3741. $score_forbuy_money_maxbi = D('Home/Front')->get_config_by_name('score_forbuy_money_maxbi');
  3742. $score_forbuy_money = D('Home/Front')->get_config_by_name('score_forbuy_money');
  3743. if( empty($score_forbuy_money_maxbi) )
  3744. {
  3745. $score_forbuy_money_maxbi = 100;
  3746. }
  3747. //$max_dikou_money = sprintf('%.2f', ($del_money * $score_forbuy_money_maxbi) /100);
  3748. $max_dikou_score = floor($del_money * $score_forbuy_money_maxbi * $score_forbuy_money / 100 );
  3749. $max_dikou_money = sprintf('%.2f', ($max_dikou_score / $score_forbuy_money));
  3750. if($max_dikou_money < $score_for_money)
  3751. {
  3752. $score_for_money = $max_dikou_money;
  3753. }
  3754. //$score_buy_money = 0;
  3755. $data['score_for_money'] = $score_for_money;
  3756. //TODO...扣除会员积分,将积分分拆入每个商品订单,写入日志
  3757. //var_dump($data['score_for_money'], $max_dikou_money);die();
  3758. }
  3759. }
  3760. $data['comment'] = htmlspecialchars($comment);
  3761. $data['reduce_money'] = $reduce_money;
  3762. $data['man_total_free'] = $man_total_free;
  3763. //判断自提 dispatching:"pickup"
  3764. //dispatching, //express pickup
  3765. if($dispatching == 'express')
  3766. {
  3767. $data['total']=($order_total);//+$fare - $data['voucher_credit']
  3768. }else if('tuanz_send' == $dispatching){
  3769. $data['total']=($order_total);// - $data['voucher_credit']);
  3770. }
  3771. else{
  3772. $data['total'] = ($order_total );// - $data['voucher_credit']
  3773. }
  3774. //积分商城
  3775. //暂时屏蔽积分商城模块
  3776. if($data['type'] == 'integral')
  3777. {
  3778. $del_integral += $order_total;//扣除积分
  3779. $data['total'] = $order_total;
  3780. }
  3781. $data['buy_type'] = $buy_type;//判断预售使用
  3782. //万能表单数据
  3783. $data['allform_id'] = $allform_id;
  3784. $data['allform_list'] = $allform_list;
  3785. $oid= D('Home/Frontorder')->addOrder($data);// D('Order')->addOrder($data);
  3786. //暂时屏蔽自提模块
  3787. /**
  3788. if($data['delivery'] == 'pickup')
  3789. {
  3790. $verify_bool = true;
  3791. $verifycode = 0;
  3792. while($verify_bool)
  3793. {
  3794. $code = (ceil(time()/100)+rand(10000000,40000000)).rand(1000,9999);
  3795. $verifycode = $code ? $code : rand(100000,999999);
  3796. $verifycode = str_replace('1989','9819',$verifycode);
  3797. $verifycode = str_replace('1259','9521',$verifycode);
  3798. $verifycode = str_replace('12590','95210',$verifycode);
  3799. $verifycode = str_replace('10086','68001',$verifycode);
  3800. $pick_order = M('pick_order')->where( array('pick_sn' => $verifycode) )->find();
  3801. if(empty($pick_order))
  3802. {
  3803. $verify_bool = false;
  3804. }
  3805. }
  3806. $pick_data = array();
  3807. $pick_data['pick_sn'] = $verifycode;
  3808. $pick_data['pick_id'] = $pick_up_id;
  3809. $pick_data['order_id'] = $oid;
  3810. $pick_data['state'] = 0;
  3811. $pick_data['ziti_name'] = $ziti_name;
  3812. $pick_data['ziti_mobile'] = $ziti_mobile;
  3813. $pick_data['addtime'] = time();
  3814. M('pick_order')->add($pick_data);
  3815. }
  3816. **/
  3817. $order_ids_arr[] = $oid;
  3818. //$pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'];
  3819. if($dispatching == 'express' && $data['type'] != 'integral')
  3820. {
  3821. $pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit']- $reduce_money - $data['score_for_money'];
  3822. }
  3823. else if( $dispatching == 'express' && $data['type'] == 'integral' )
  3824. {
  3825. $pay_total = $trans_free_toal;
  3826. }
  3827. else if('localtown_delivery' == $dispatching)
  3828. {
  3829. $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'];
  3830. }
  3831. else if('tuanz_send' == $dispatching){
  3832. $pay_total = $pay_total + $order_total+$trans_free_toal - $data['voucher_credit'] -$reduce_money - $data['score_for_money'];
  3833. }
  3834. else{
  3835. $pay_total = $pay_total + $order_total - $data['voucher_credit'] -$reduce_money - $data['score_for_money'];
  3836. }
  3837. if( $buy_type == 'presale' )
  3838. {
  3839. //如果是预售,此处支付的就是定金
  3840. $presale_order_info = M('lionfish_comshop_order_presale')->where(['order_id' => $oid ])->find();
  3841. if( $presale_order_info['presale_type'] == 1 )
  3842. {
  3843. M('lionfish_comshop_order_presale')->where( ['id' => $presale_order_info['id'] ] )->save( ['presale_ding_money' => $pay_total ] );
  3844. }else{
  3845. $pay_total = $presale_order_info['presale_ding_money'];
  3846. }
  3847. }
  3848. $pay_total = round($pay_total, 2);
  3849. $order_relate_data = array();
  3850. $order_relate_data['order_all_id'] = $order_all_id;
  3851. $order_relate_data['order_id'] = $oid;
  3852. $order_relate_data['addtime'] = time();
  3853. M('lionfish_comshop_order_relate')->add($order_relate_data);
  3854. }
  3855. $order_all_data = array();
  3856. $order_all_data['total_money'] = $pay_total;
  3857. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id) )->save($order_all_data);
  3858. if($order_all_id){
  3859. $order = M('lionfish_comshop_order')->where( array('order_id' => $oid) )->find();
  3860. $member_info = M('lionfish_comshop_member')->field('we_openid,account_money')->where( array('member_id' => $member_id ) )->find();
  3861. $is_yue_open = 0;
  3862. $is_yue_open = D('Home/Front')->get_config_by_name('is_open_yue_pay');
  3863. if( empty($is_yue_open) )
  3864. {
  3865. $is_yue_open = 0;
  3866. }
  3867. //检测是否需要扣除积分
  3868. if($data['type'] == 'integral' && $del_integral> 0 && $is_integral == 1)
  3869. {
  3870. $order_goods_tp = M('lionfish_comshop_order_goods')->field('order_goods_id')->where( array('order_id' => $oid ) )->find();
  3871. D('Admin/Member')->sendMemberPointChange($member_id,$del_integral, 1 ,'积分兑换商品', 'integral_exchange', $oid ,$order_goods_tp['order_goods_id']);
  3872. }
  3873. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  3874. if( $order['type'] == 'ignore' || $pay_total<=0 || ($is_yue_open == 1 && $ck_yupay == 1 && $member_info['account_money'] >= $pay_total) )
  3875. {
  3876. //余额支付独立方法
  3877. D('Home/OrderV2')->carOrderYuerPay( $order_all_id, $order ,$pay_total , $ck_yupay ,$buy_type, $is_integral, $is_spike , $is_just_1 );
  3878. }else if($buy_type == 'dan' && $cashon_delivery == 1){//货到付款订单
  3879. //货到付款支付独立方法
  3880. D('Home/OrderV2')->carOrderCashonPay( $order_all_id, $order ,$pay_total , $cashon_delivery , $buy_type , $is_spike , $is_just_1);
  3881. }
  3882. else if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  3883. {
  3884. //begin
  3885. $fee = $pay_total;
  3886. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  3887. $body = $pay_goods_name;//'商品购买';
  3888. $body = mb_substr($body,0,32,'utf-8');
  3889. if( empty($body) )
  3890. {
  3891. $body = '商品购买';
  3892. }
  3893. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  3894. $nonce_str = nonce_str();
  3895. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  3896. $notify_url = $shop_domain.'/notify.php';
  3897. $openid = $payment['we_openid'];
  3898. $out_trade_no = $order_all_id.'-'.time();
  3899. //out_trade_no
  3900. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id ) )->save( array('out_trade_no' => $out_trade_no ) );
  3901. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  3902. $total_fee = $fee*100;
  3903. //float(0.99999999999998)
  3904. $trade_type = 'JSAPI';
  3905. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  3906. $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');// 'wx7c38e2f177e0af59';
  3907. $post['body'] = $body;
  3908. $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');//'1562705521';
  3909. $post['nonce_str'] = $nonce_str;
  3910. $post['notify_url'] = $notify_url;
  3911. //$post['openid'] = $openid;
  3912. $post['out_trade_no'] = $out_trade_no;
  3913. $post['spbill_create_ip'] = $spbill_create_ip;
  3914. $post['sub_appid'] = $appid;
  3915. $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  3916. $post['sub_openid'] = $openid;
  3917. $post['total_fee'] = $total_fee;
  3918. $post['trade_type'] = $trade_type;
  3919. $sign = sign($post,$pay_key);
  3920. //var_dump( $notify_url );die();
  3921. $post_xml = '<xml>
  3922. <appid>'.$post['appid'].'</appid>
  3923. <body>'.$body.'</body>
  3924. <mch_id>'.$post['mch_id'].'</mch_id>
  3925. <nonce_str>'.$nonce_str.'</nonce_str>
  3926. <notify_url>'.$notify_url.'</notify_url>
  3927. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  3928. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  3929. <sub_appid>'.$post['sub_appid'].'</sub_appid>
  3930. <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
  3931. <sub_openid>'.$openid.'</sub_openid>
  3932. <total_fee>'.$total_fee.'</total_fee>
  3933. <trade_type>'.$trade_type.'</trade_type>
  3934. <sign>'.$sign.'</sign>
  3935. </xml> ';
  3936. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  3937. $xml = http_request($url,$post_xml);
  3938. $array = xml($xml);
  3939. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  3940. D('Home/Pin')->insertNotifyOrder($order['order_id']);
  3941. $time = time();
  3942. $tmp=array();
  3943. $tmp['appId'] = $appid;
  3944. $tmp['nonceStr'] = $nonce_str;
  3945. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  3946. $tmp['signType'] = 'MD5';
  3947. $tmp['timeStamp'] = "$time";
  3948. $prepay_id = (string)$array['PREPAY_ID'];
  3949. M('lionfish_comshop_order')->where( array('order_id' => array('in', $order_ids_arr)) )->save( array('perpay_id' => $prepay_id) );
  3950. //M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
  3951. $data = array();
  3952. $data['code'] = 0;
  3953. $data['appid'] = $appid;
  3954. $data['timeStamp'] = "$time";
  3955. $data['nonceStr'] = $nonce_str;
  3956. $data['signType'] = 'MD5';
  3957. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  3958. $data['paySign'] = sign($tmp,$pay_key);
  3959. $data['out_trade_no'] = $out_trade_no;
  3960. $data['is_go_orderlist'] = $is_just_1;
  3961. if($is_pin == 1)
  3962. {
  3963. $data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
  3964. } else {
  3965. $data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
  3966. }
  3967. }else{
  3968. $data = array();
  3969. $data['code'] = 1;
  3970. $data['text'] = "错误";
  3971. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  3972. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  3973. }
  3974. $data['has_yupay'] = 0;
  3975. //end
  3976. }
  3977. else{
  3978. $fee = $pay_total;
  3979. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  3980. $body = $pay_goods_name;//'商品购买';
  3981. $body = mb_substr($body,0,32,'utf-8');
  3982. if( empty($body) )
  3983. {
  3984. $body = '商品购买';
  3985. }
  3986. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  3987. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  3988. $nonce_str = nonce_str();
  3989. $notify_url = $shop_domain.'/notify.php';
  3990. $openid = $payment['we_openid'];
  3991. $out_trade_no = $order_all_id.'-'.time();
  3992. //out_trade_no
  3993. M('lionfish_comshop_order_all')->where( array('id' => $order_all_id ) )->save( array('out_trade_no' => $out_trade_no ) );
  3994. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  3995. $total_fee = $fee*100;
  3996. $trade_type = 'JSAPI';
  3997. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  3998. $post['appid'] = $appid;
  3999. $post['body'] = $body;
  4000. $post['mch_id'] = $mch_id;
  4001. $post['nonce_str'] = $nonce_str;
  4002. $post['notify_url'] = $notify_url;
  4003. $post['openid'] = $openid;
  4004. $post['out_trade_no'] = $out_trade_no;
  4005. $post['spbill_create_ip'] = $spbill_create_ip;
  4006. $post['total_fee'] = $total_fee;
  4007. $post['trade_type'] = $trade_type;
  4008. $sign = sign($post,$pay_key);
  4009. $post_xml = '<xml>
  4010. <appid>'.$appid.'</appid>
  4011. <body>'.$body.'</body>
  4012. <mch_id>'.$mch_id.'</mch_id>
  4013. <nonce_str>'.$nonce_str.'</nonce_str>
  4014. <notify_url>'.$notify_url.'</notify_url>
  4015. <openid>'.$openid.'</openid>
  4016. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4017. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4018. <total_fee>'.$total_fee.'</total_fee>
  4019. <trade_type>'.$trade_type.'</trade_type>
  4020. <sign>'.$sign.'</sign>
  4021. </xml> ';
  4022. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4023. $xml = http_request($url,$post_xml);
  4024. $array = xml($xml);
  4025. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4026. D('Home/Pin')->insertNotifyOrder($order['order_id']);
  4027. $time = time();
  4028. $tmp=array();
  4029. $tmp['appId'] = $appid;
  4030. $tmp['nonceStr'] = $nonce_str;
  4031. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4032. $tmp['signType'] = 'MD5';
  4033. $tmp['timeStamp'] = "$time";
  4034. $prepay_id = (string)$array['PREPAY_ID'];
  4035. M('lionfish_comshop_order')->where( array('order_id' => array('in', $order_ids_arr)) )->save( array('perpay_id' => $prepay_id) );
  4036. //M('order')->where( array('order_id' => array('in',$order_ids_arr) ) )->save( array('perpay_id' => (string)$array['PREPAY_ID']) );
  4037. $data = array();
  4038. $data['code'] = 0;
  4039. $data['appid'] = $appid;
  4040. $data['timeStamp'] = "$time";
  4041. $data['nonceStr'] = $nonce_str;
  4042. $data['signType'] = 'MD5';
  4043. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4044. $data['paySign'] = sign($tmp,$pay_key);
  4045. $data['out_trade_no'] = $out_trade_no;
  4046. $data['is_go_orderlist'] = $is_just_1;
  4047. //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
  4048. $data['order_info'] = [];
  4049. $data['isRequestOrderPayment'] = $is_need_scene_check;
  4050. if($is_need_scene_check == 1)
  4051. {
  4052. $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $oid , $time , $pay_total );
  4053. //如果是微信小程序交易组件,提供订单信息 end
  4054. $data['order_info'] = $orderPamentResult['order_info'];
  4055. }
  4056. if($is_pin == 1)
  4057. {
  4058. $data['redirect_url'] = '../groups/group?id='.$oid.'&is_show=1';
  4059. } else {
  4060. $data['redirect_url'] = '../orders/order_show_all?order_all_id=' + $order_all_id;
  4061. }
  4062. }else{
  4063. $data = array();
  4064. $data['code'] = 1;
  4065. $data['text'] = "错误";
  4066. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4067. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4068. }
  4069. $data['has_yupay'] = 0;
  4070. }
  4071. if($is_pin == 1)
  4072. {
  4073. $data['order_id'] = $oid;
  4074. $data['order_all_id'] = $order_all_id;
  4075. }else{
  4076. $data['order_id'] = $oid;
  4077. $data['order_all_id'] = $order_all_id;
  4078. }
  4079. $data['is_go_orderlist'] = $is_just_1;
  4080. $data['is_spike'] = $is_spike;
  4081. echo json_encode($data);
  4082. die();
  4083. }else{
  4084. echo json_encode( array('code' =>1,'order_all_id' =>$order_all_id) );
  4085. die();
  4086. }
  4087. }
  4088. function requestAsHttpPOST($data, $service_url){
  4089. $HTTP_TIME_OUT= "20";
  4090. ksort(array_filter($data)); //删除数组中的空值并排序
  4091. $post_data = http_build_query($data);
  4092. $options = array(
  4093. 'http' => array(
  4094. 'method' => 'POST',
  4095. 'header' => 'Content-type:application/x-www-form-urlencoded;charset=MD5',
  4096. 'content' => $post_data,
  4097. 'timeout' => $HTTP_TIME_OUT * 1000 //超时时间,*1000将毫秒变为秒(单位:s)
  4098. )
  4099. );
  4100. $context = stream_context_create($options);
  4101. $result = file_get_contents($service_url, false, $context);
  4102. return $result;
  4103. }
  4104. /**
  4105. 微信充值
  4106. **/
  4107. public function wxcharge()
  4108. {
  4109. $_GPC = I('request.');
  4110. $token = $_GPC['token'];
  4111. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  4112. $member_id = $weprogram_token['member_id'];
  4113. if( empty($member_id) )
  4114. {
  4115. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  4116. die();
  4117. }
  4118. $money = $_GPC['money'];
  4119. $rech_id = isset($_GPC['rech_id']) && $_GPC['rech_id'] > 0 ? $_GPC['rech_id'] : 0;
  4120. $member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
  4121. $give_money = 0;
  4122. if( $rech_id > 0 )
  4123. {
  4124. $rech_info = M('lionfish_comshop_chargetype')->where( array('id' => $rech_id ) )->find();
  4125. if( !empty($rech_info) )
  4126. {
  4127. $give_money = $rech_info['send_money'];
  4128. }
  4129. $money = $rech_info['money'];
  4130. }else{
  4131. $recharge_get_money = D('Home/Front')->get_config_by_name('recharge_get_money');
  4132. if(isset($recharge_get_money) && $recharge_get_money == 1){
  4133. $rech_info = M('lionfish_comshop_chargetype')->where( "money <= ".$money )->order('money desc')->limit(1)->find();
  4134. if( !empty($rech_info) )
  4135. {
  4136. $give_money = $rech_info['send_money'];
  4137. }
  4138. }
  4139. }
  4140. $member_charge_flow_data = array();
  4141. $member_charge_flow_data['member_id'] = $member_id;
  4142. $member_charge_flow_data['money'] = $money;
  4143. $member_charge_flow_data['state'] = 0;
  4144. $member_charge_flow_data['give_money'] = $give_money;
  4145. $member_charge_flow_data['charge_time'] = 0;
  4146. $member_charge_flow_data['remark'] = '会员前台微信充值';
  4147. $member_charge_flow_data['add_time'] = time();
  4148. $order_id = M('lionfish_comshop_member_charge_flow')->add( $member_charge_flow_data );
  4149. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  4150. $fee = $money;
  4151. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  4152. $body = '会员充值';
  4153. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  4154. $nonce_str = nonce_str();
  4155. $notify_url = $shop_domain.'/notify.php';
  4156. $openid = $member_info['we_openid'];
  4157. $out_trade_no = $order_id.'-'.time().'-charge-'.$id;
  4158. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  4159. $total_fee = $fee*100;
  4160. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  4161. if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  4162. {
  4163. $trade_type = 'JSAPI';
  4164. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4165. $post = array();
  4166. $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');// 'wx7c38e2f177e0af59';
  4167. $post['body'] = $body;
  4168. $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');//'1562705521';
  4169. $post['nonce_str'] = $nonce_str;
  4170. $post['notify_url'] = $notify_url;
  4171. //$post['openid'] = $openid;
  4172. $post['out_trade_no'] = $out_trade_no;
  4173. $post['spbill_create_ip'] = $spbill_create_ip;
  4174. $post['sub_appid'] = $appid;
  4175. $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  4176. $post['sub_openid'] = $openid;
  4177. $post['total_fee'] = $total_fee;
  4178. $post['trade_type'] = $trade_type;
  4179. $sign = sign($post,$pay_key);
  4180. $post_xml = '<xml>
  4181. <appid>'.$post['appid'].'</appid>
  4182. <body>'.$body.'</body>
  4183. <mch_id>'.$post['mch_id'].'</mch_id>
  4184. <nonce_str>'.$nonce_str.'</nonce_str>
  4185. <notify_url>'.$notify_url.'</notify_url>
  4186. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4187. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4188. <sub_appid>'.$post['sub_appid'].'</sub_appid>
  4189. <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
  4190. <sub_openid>'.$openid.'</sub_openid>
  4191. <total_fee>'.$total_fee.'</total_fee>
  4192. <trade_type>'.$trade_type.'</trade_type>
  4193. <sign>'.$sign.'</sign>
  4194. </xml> ';
  4195. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4196. $xml = http_request($url,$post_xml);
  4197. $array = xml($xml);
  4198. //end
  4199. }else{
  4200. $trade_type = 'JSAPI';
  4201. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4202. $post = array();
  4203. $post['appid'] = $appid;
  4204. $post['body'] = $body;
  4205. $post['mch_id'] = $mch_id;
  4206. $post['nonce_str'] = $nonce_str;
  4207. $post['notify_url'] = $notify_url;
  4208. $post['openid'] = $openid;
  4209. $post['out_trade_no'] = $out_trade_no;
  4210. $post['spbill_create_ip'] = $spbill_create_ip;
  4211. $post['total_fee'] = $total_fee;
  4212. $post['trade_type'] = $trade_type;
  4213. $sign = sign($post,$pay_key);
  4214. //sign()
  4215. $post_xml = '<xml>
  4216. <appid>'.$appid.'</appid>
  4217. <body>'.$body.'</body>
  4218. <mch_id>'.$mch_id.'</mch_id>
  4219. <nonce_str>'.$nonce_str.'</nonce_str>
  4220. <notify_url>'.$notify_url.'</notify_url>
  4221. <openid>'.$openid.'</openid>
  4222. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4223. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  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. }
  4232. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4233. $time = time();
  4234. $tmp= array();
  4235. $tmp['appId'] = $appid;
  4236. $tmp['nonceStr'] = $nonce_str;
  4237. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4238. $tmp['signType'] = 'MD5';
  4239. $tmp['timeStamp'] = "$time";
  4240. M('lionfish_comshop_member_charge_flow')->where( array('id' => $order_id) )->save( array('formid' => $array['PREPAY_ID'] ) );
  4241. $data['code'] = 0;
  4242. $data['timeStamp'] = "$time";
  4243. $data['nonceStr'] = $nonce_str;
  4244. $data['signType'] = 'MD5';
  4245. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4246. $data['paySign'] = sign($tmp, $pay_key);
  4247. $data['out_trade_no'] = $out_trade_no;
  4248. $data['redirect_url'] = '../dan/me';
  4249. }else{
  4250. $data['code'] = 1;
  4251. $data['text'] = "错误";
  4252. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4253. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4254. }
  4255. echo json_encode($data);
  4256. die();
  4257. }
  4258. public function wxpay()
  4259. {
  4260. $gpc = I('request.');
  4261. $token = $gpc['token'];
  4262. $order_id = $gpc['order_id'];
  4263. $scene = $gpc['scene'];
  4264. $is_need_scene_check = 0;
  4265. if(!empty($scene))
  4266. {
  4267. $is_need_scene_check = D('Seller/MpModifyTradeComponts')->sceneCheck( $scene );
  4268. }
  4269. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  4270. $member_id = $weprogram_token['member_id'];
  4271. if( empty($member_id) )
  4272. {
  4273. echo json_encode( array('code' =>1,'msg' =>'未登录') );
  4274. die();
  4275. }
  4276. $member_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $member_id) )->find();
  4277. $order = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  4278. //order_status_id
  4279. if( $order['order_status_id'] != 3 && $order['order_status_id'] != 15 )
  4280. {
  4281. $json = array();
  4282. $json['msg']='商品已下架!';
  4283. $json['code'] = 2;
  4284. if($order['order_status_id'] == 1)
  4285. {
  4286. $json['msg']='订单已付款,请勿重新付款!';
  4287. }
  4288. else if( $order['order_status_id'] == 5){
  4289. $json['msg']='订单已取消,请重新选择商品下单!';
  4290. }
  4291. echo json_encode($json);
  4292. die();
  4293. }
  4294. //检测商品是否下架 begin
  4295. $sql = "select name,quantity,rela_goodsoption_valueid,goods_id from ".C('DB_PREFIX')."lionfish_comshop_order_goods
  4296. where order_id={$order_id} ";
  4297. $order_goods_list = M()->query($sql);
  4298. foreach($order_goods_list as $tp_val)
  4299. {
  4300. $tp_gd_info = M('lionfish_comshop_goods')->field('grounding')->where( array('id' => $tp_val['goods_id'] ) )->find();
  4301. if( empty($tp_gd_info) || $tp_gd_info['grounding'] != 1 )
  4302. {
  4303. $json['code'] = 2;
  4304. $json['msg']='商品已下架!';
  4305. echo json_encode($json);
  4306. die();
  4307. }
  4308. }
  4309. //检测商品是否下架end
  4310. //检测是否预售商品。预售商品不需要检测二次支付问题
  4311. $presale_info = [];
  4312. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
  4313. if( $presale_result['code'] == 0 )
  4314. {
  4315. $presale_info = $presale_result['data'];
  4316. }
  4317. //检测是否已经支付过了begin
  4318. $order_relate_info = M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id ) )->order('id desc')->find();
  4319. if( !empty($order_relate_info) && $order_relate_info['order_all_id'] > 0 && empty($presale_info) )
  4320. {
  4321. $order_all_info = M('lionfish_comshop_order_all')->where( array('id' => $order_relate_info['order_all_id'] ) )->find();
  4322. if( !empty($order_all_info) && !empty($order_all_info['out_trade_no']) )
  4323. {
  4324. $out_trade_no = $order_all_info['out_trade_no'];
  4325. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  4326. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  4327. $nonce_str = nonce_str();
  4328. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4329. $post = array();
  4330. $post['appid'] = $appid;
  4331. $post['mch_id'] = $mch_id;
  4332. $post['nonce_str'] = $nonce_str;
  4333. $post['out_trade_no'] = $out_trade_no;
  4334. $sign = sign($post,$pay_key);
  4335. $post_xml = '<xml>
  4336. <appid>'.$appid.'</appid>
  4337. <mch_id>'.$mch_id.'</mch_id>
  4338. <nonce_str>'.$nonce_str.'</nonce_str>
  4339. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4340. <sign>'.$sign.'</sign>
  4341. </xml>';
  4342. $url = "https://api.mch.weixin.qq.com/pay/orderquery";
  4343. $result = http_request($url,$post_xml);
  4344. $array = xml($result);
  4345. if( $array['RETURN_CODE'] == 'SUCCESS' && $array['RETURN_MSG'] == 'OK' )
  4346. {
  4347. if( $array['TRADE_STATE'] == 'SUCCESS' )
  4348. {
  4349. $json = array();
  4350. $json['msg']='商品已下架!';
  4351. $json['code'] = 2;
  4352. $json['msg']='订单已付款,请勿重新付款,请刷新页面!';
  4353. echo json_encode($json);
  4354. die();
  4355. }
  4356. }
  4357. }
  4358. }
  4359. //检测是否已经支付过了end
  4360. //支付才减库存,才需要判断
  4361. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
  4362. if( empty($kucun_method) )
  4363. {
  4364. $kucun_method = 0;
  4365. }
  4366. if($kucun_method == 1 && ( empty($presale_info) || $presale_info['state'] != 1 ) )
  4367. {
  4368. /*** 检测商品库存begin **/
  4369. //goods_id
  4370. foreach($order_goods_list as $val)
  4371. {
  4372. $quantity = $val['quantity'];
  4373. $goods_id = $val['goods_id'];
  4374. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  4375. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
  4376. if($can_buy_count == -1)
  4377. {
  4378. $json['code'] = 2;
  4379. $json['msg']='您还能购买'.$goods_description['total_limit_count'].'个';
  4380. echo json_encode($json);
  4381. die();
  4382. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  4383. {
  4384. $json['code'] = 2;
  4385. $json['msg']='您还能购买'.$can_buy_count.'份';
  4386. echo json_encode($json);
  4387. die();
  4388. }
  4389. //rela_goodsoption_valueid
  4390. if(!empty($val['rela_goodsoption_valueid']))
  4391. {
  4392. $mul_opt_arr = array();
  4393. //ims_
  4394. $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();
  4395. if( !empty($goods_option_mult_value) )
  4396. {
  4397. if($goods_option_mult_value['stock']<$quantity){
  4398. $json['code'] =2;
  4399. $json['msg']='商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
  4400. echo json_encode($json);
  4401. die();
  4402. }
  4403. }
  4404. }
  4405. }
  4406. /*** 检测商品库存end **/
  4407. }
  4408. $pin_order = array();
  4409. if( !empty($pin_order) )
  4410. {
  4411. /**
  4412. $pin_model = load_model_class('pin');
  4413. $is_pin_over = $pin_model->getNowPinState($pin_order['pin_id']);
  4414. if($is_pin_over != 0)
  4415. {
  4416. pdo_query("delete from ".tablename('lionfish_comshop_pin_order')." where order_id = {$order_id} ");
  4417. pdo_query("delete from ".tablename('lionfish_comshop_pin')." where pin_id = ".$pin_order['pin_id']." and order_id = ".$order_id);
  4418. $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']));
  4419. //新开团
  4420. $pin_id = $pin_model->openNewTuan($order_id,$order_goods_info['goods_id'],$member_id);
  4421. //插入拼团订单
  4422. $pin_model->insertTuanOrder($pin_id,$order_id);
  4423. }
  4424. **/
  4425. }
  4426. //单独支付一个店铺的订单
  4427. //M('lionfish_comshop_order_relate')->where( array('order_id' => $order_id) )->delete();
  4428. $order_all_data = array();
  4429. $order_all_data['member_id'] = $member_id;
  4430. $order_all_data['order_num_alias'] = build_order_no($member_id);
  4431. $order_all_data['transaction_id'] = '';
  4432. $order_all_data['order_status_id'] = 3;
  4433. $order_all_data['is_pin'] = $order['is_pin'];
  4434. $order_all_data['paytime'] = 0;
  4435. $order_all_data['total_money'] = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'];
  4436. $order_all_data['addtime'] = time();
  4437. $order_all_id = M('lionfish_comshop_order_all')->add($order_all_data);
  4438. $order_relate_data = array();
  4439. $order_relate_data['order_all_id'] = $order_all_id;
  4440. $order_relate_data['order_id'] = $order_id;
  4441. $order_relate_data['addtime'] = time();
  4442. M('lionfish_comshop_order_relate')->add($order_relate_data);
  4443. if( $order['delivery'] == 'pickup' )
  4444. {
  4445. $fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
  4446. }else if($order['delivery'] == 'localtown_delivery'){
  4447. $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'];
  4448. }else {
  4449. $fee = $order['total']+ $order['shipping_fare']-$order['voucher_credit']-$order['fullreduction_money'] - $order['score_for_money'] - $order['fare_shipping_free'];
  4450. }
  4451. //如果是预售 begin
  4452. if( !empty($presale_info) )
  4453. {
  4454. if( $presale_info['state'] == 0 )
  4455. {
  4456. //首次支付,
  4457. $fee = $presale_info['presale_ding_money'];
  4458. }else if( $presale_info['state'] == 1 )
  4459. {
  4460. //第二次支付
  4461. if( !empty($presale_info['presale_deduction_money']) && false )
  4462. {
  4463. $fee = $fee - $presale_info['presale_deduction_money'];
  4464. }else{
  4465. $fee = $fee - $presale_info['presale_ding_money'];
  4466. }
  4467. }
  4468. }
  4469. //end
  4470. $fee = round($fee , 2);
  4471. $appid = D('Home/Front')->get_config_by_name('wepro_appid');
  4472. $body = $pay_goods_name;//'商品购买';
  4473. $body = mb_substr($body,0,32,'utf-8');
  4474. if( empty($body) )
  4475. {
  4476. $body = '商品购买';
  4477. }
  4478. $mch_id = D('Home/Front')->get_config_by_name('wepro_partnerid');
  4479. $nonce_str = nonce_str();
  4480. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  4481. $notify_url = $shop_domain.'/notify.php';
  4482. $openid = $member_info['we_openid'];
  4483. $out_trade_no = $order_all_id.'-'.time();
  4484. $spbill_create_ip = $_SERVER['REMOTE_ADDR'];
  4485. $total_fee = $fee*100;
  4486. $trade_type = 'JSAPI';
  4487. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4488. $is_open_yinpay = D('Home/Front')->get_config_by_name('is_open_yinpay');
  4489. //begin
  4490. if( isset($is_open_yinpay) && $is_open_yinpay == 3 )
  4491. {
  4492. $pay_key = D('Home/Front')->get_config_by_name('wepro_key');
  4493. $body = '商品购买';
  4494. $post = array();
  4495. $post['appid'] = D('Home/Front')->get_config_by_name('wepro_fuwu_appid');
  4496. $post['body'] = $body;
  4497. $post['mch_id'] = D('Home/Front')->get_config_by_name('wepro_fuwu_partnerid');
  4498. $post['nonce_str'] = $nonce_str;
  4499. $post['notify_url'] = $notify_url;
  4500. //$post['openid'] = $openid;
  4501. $post['out_trade_no'] = $out_trade_no;
  4502. $post['spbill_create_ip'] = $spbill_create_ip;
  4503. $post['sub_appid'] = D('Home/Front')->get_config_by_name('wepro_appid');
  4504. $post['sub_mch_id'] = D('Home/Front')->get_config_by_name('wepro_sub_mch_id');
  4505. $post['sub_openid'] = $openid;
  4506. $post['total_fee'] = $total_fee;
  4507. $post['trade_type'] = $trade_type;
  4508. $sign = sign($post,$pay_key);
  4509. $post_xml = '<xml>
  4510. <appid>'.$post['appid'].'</appid>
  4511. <body>'.$body.'</body>
  4512. <mch_id>'.$post['mch_id'].'</mch_id>
  4513. <nonce_str>'.$nonce_str.'</nonce_str>
  4514. <notify_url>'.$notify_url.'</notify_url>
  4515. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4516. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4517. <sub_appid>'.$post['sub_appid'].'</sub_appid>
  4518. <sub_mch_id>'.$post['sub_mch_id'].'</sub_mch_id>
  4519. <sub_openid>'.$openid.'</sub_openid>
  4520. <total_fee>'.$total_fee.'</total_fee>
  4521. <trade_type>'.$trade_type.'</trade_type>
  4522. <sign>'.$sign.'</sign>
  4523. </xml>';
  4524. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4525. $xml = http_request($url,$post_xml);
  4526. $array = xml($xml);
  4527. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4528. $time = time();
  4529. $tmp= array();
  4530. $tmp['appId'] = $appid;
  4531. $tmp['nonceStr'] = $nonce_str;
  4532. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4533. $tmp['signType'] = 'MD5';
  4534. $tmp['timeStamp'] = "$time";
  4535. $prepay_id = (string)$array['PREPAY_ID'];
  4536. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
  4537. $data['code'] = 0;
  4538. $data['timeStamp'] = "$time";
  4539. $data['nonceStr'] = $nonce_str;
  4540. $data['signType'] = 'MD5';
  4541. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4542. $data['paySign'] = sign($tmp, $pay_key);
  4543. $data['out_trade_no'] = $out_trade_no;
  4544. $data['is_pin'] = $order['is_pin'];
  4545. if($order['is_pin'] == 1)
  4546. {
  4547. $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
  4548. } else {
  4549. $data['redirect_url'] = '../orders/order?id=' + $order_id;
  4550. }
  4551. }else{
  4552. $data['code'] = 1;
  4553. $data['text'] = "错误";
  4554. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4555. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4556. }
  4557. echo json_encode($data);
  4558. die();
  4559. }
  4560. //end
  4561. $post = array();
  4562. $post['appid'] = $appid;
  4563. $post['body'] = $body;
  4564. $post['mch_id'] = $mch_id;
  4565. $post['nonce_str'] = $nonce_str;
  4566. $post['notify_url'] = $notify_url;
  4567. $post['openid'] = $openid;
  4568. $post['out_trade_no'] = $out_trade_no;
  4569. $post['spbill_create_ip'] = $spbill_create_ip;
  4570. $post['total_fee'] = $total_fee;
  4571. $post['trade_type'] = $trade_type;
  4572. $sign = sign($post,$pay_key);
  4573. $post_xml = '<xml>
  4574. <appid>'.$appid.'</appid>
  4575. <body>'.$body.'</body>
  4576. <mch_id>'.$mch_id.'</mch_id>
  4577. <nonce_str>'.$nonce_str.'</nonce_str>
  4578. <notify_url>'.$notify_url.'</notify_url>
  4579. <openid>'.$openid.'</openid>
  4580. <out_trade_no>'.$out_trade_no.'</out_trade_no>
  4581. <spbill_create_ip>'.$spbill_create_ip.'</spbill_create_ip>
  4582. <total_fee>'.$total_fee.'</total_fee>
  4583. <trade_type>'.$trade_type.'</trade_type>
  4584. <sign>'.$sign.'</sign>
  4585. </xml> ';
  4586. $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
  4587. $xml = http_request($url,$post_xml);
  4588. $array = xml($xml);
  4589. if($array['RETURN_CODE'] == 'SUCCESS' && $array['RESULT_CODE'] == 'SUCCESS'){
  4590. $time = time();
  4591. $tmp= array();
  4592. $tmp['appId'] = $appid;
  4593. $tmp['nonceStr'] = $nonce_str;
  4594. $tmp['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4595. $tmp['signType'] = 'MD5';
  4596. $tmp['timeStamp'] = "$time";
  4597. $prepay_id = (string)$array['PREPAY_ID'];
  4598. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('perpay_id' => $prepay_id) );
  4599. $data['code'] = 0;
  4600. $data['timeStamp'] = "$time";
  4601. $data['nonceStr'] = $nonce_str;
  4602. $data['signType'] = 'MD5';
  4603. $data['package'] = 'prepay_id='.$array['PREPAY_ID'];
  4604. $data['paySign'] = sign($tmp, $pay_key);
  4605. $data['out_trade_no'] = $out_trade_no;
  4606. $data['is_pin'] = $order['is_pin'];
  4607. //如果是微信小程序交易组件begin---新支付方法 wx.requestOrderPayment
  4608. $data['order_info'] = [];
  4609. $data['isRequestOrderPayment'] = $is_need_scene_check;
  4610. if($is_need_scene_check == 1)
  4611. {
  4612. $orderPamentResult = D('Seller/MpModifyTradeComponts')->getTradeOrderInfo( $order_id , $time , $fee );
  4613. //如果是微信小程序交易组件,提供订单信息 end
  4614. $data['order_info'] = $orderPamentResult['order_info'];
  4615. }
  4616. if($order['is_pin'] == 1)
  4617. {
  4618. $data['redirect_url'] = '../groups/group?id='.$order_id.'&is_show=1';
  4619. } else {
  4620. $data['redirect_url'] = '../orders/order?id=' + $order_id;
  4621. }
  4622. }else{
  4623. $data['code'] = 1;
  4624. $data['text'] = "错误";
  4625. $data['RETURN_CODE'] = $array['RETURN_CODE'];
  4626. $data['RETURN_MSG'] = $array['RETURN_MSG'];
  4627. }
  4628. echo json_encode($data);
  4629. die();
  4630. }
  4631. /**
  4632. * 获取购物车总数
  4633. */
  4634. public function count() {
  4635. $gpc = I('request.');
  4636. $data = array();
  4637. $token = $gpc['token'];
  4638. $community_id = $gpc['community_id'];
  4639. $cart= D('Home/Car');
  4640. $total=$cart->count_goodscar($token, $community_id);
  4641. $data['code'] = 0;
  4642. $data['data'] = $total;
  4643. echo json_encode($data);
  4644. die();
  4645. }
  4646. }