CarController.class.php 220 KB

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