CarController.class.php 137 KB

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