wxapp.php 249 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076
  1. <?php
  2. /**
  3. * 志汇-同城微圈小程序模块小程序接口定义
  4. *
  5. * @author 武汉志汇科技
  6. * @url
  7. //tid3
  8. */
  9. defined('IN_IA') or exit('Access Denied');
  10. class Zh_tcwqModuleWxapp extends WeModuleWxapp {
  11. public function __construct() {
  12. global $_W, $_GPC;
  13. if ($_GPC['details']) {
  14. function getaccess_token($_W) {
  15. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  16. $appid = $res['appid'];
  17. $secret = $res['appsecret'];
  18. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  19. $ch = curl_init();
  20. curl_setopt($ch, CURLOPT_URL, $url);
  21. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  23. $data = curl_exec($ch);
  24. curl_close($ch);
  25. $data = json_decode($data, true);
  26. return $data['access_token'];
  27. }
  28. $url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" . getaccess_token($_W);
  29. $data['content'] = $_GPC['details'];
  30. $ch = curl_init();
  31. curl_setopt($ch, CURLOPT_URL, $url);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  33. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  34. curl_setopt($ch, CURLOPT_POST, 1);
  35. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  36. $data = curl_exec($ch);
  37. curl_close($ch);
  38. $res = json_decode($data, true);
  39. if ($res['errcode'] == 87014) {
  40. return '文字内容违规,请重新输入!';
  41. }
  42. }
  43. }
  44. //获取openid
  45. public function doPageOpenid() {
  46. global $_W, $_GPC;
  47. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  48. $code = $_GPC['code'];
  49. $appid = $res['appid'];
  50. $secret = $res['appsecret'];
  51. $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
  52. function httpRequest($url, $data = null) {
  53. $curl = curl_init();
  54. curl_setopt($curl, CURLOPT_URL, $url);
  55. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  56. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  57. if (!empty($data)) {
  58. curl_setopt($curl, CURLOPT_POST, 1);
  59. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  60. }
  61. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  62. //执行
  63. $output = curl_exec($curl);
  64. curl_close($curl);
  65. return $output;
  66. }
  67. $res = httpRequest($url);
  68. print_r($res);
  69. }
  70. //登录用户信息
  71. public function doPageLogin() {
  72. global $_GPC, $_W;
  73. $openid = $_GPC['openid'];
  74. $res = pdo_get('zhtc_user', array('openid' => $openid, 'uniacid' => $_W['uniacid']));
  75. if ($openid and $openid != 'undefined') {
  76. if ($res) {
  77. $user_id = $res['id'];
  78. if ($_GPC['openid']) {
  79. $data['openid'] = $_GPC['openid'];
  80. }
  81. if ($_GPC['img']) {
  82. $data['img'] = $_GPC['img'];
  83. }
  84. if ($_GPC['name']) {
  85. $data['name'] = $_GPC['name'];
  86. }
  87. $res = pdo_update('zhtc_user', $data, array('id' => $user_id));
  88. $user = pdo_get('zhtc_user', array('openid' => $openid, 'uniacid' => $_W['uniacid']));
  89. echo json_encode($user);
  90. } else {
  91. $data['openid'] = $_GPC['openid'];
  92. $data['img'] = $_GPC['img'];
  93. $data['name'] = $_GPC['name'];
  94. $data['uniacid'] = $_W['uniacid'];
  95. $data['time'] = time();
  96. $res2 = pdo_insert('zhtc_user', $data);
  97. $user = pdo_get('zhtc_user', array('openid' => $openid, 'uniacid' => $_W['uniacid']));
  98. echo json_encode($user);
  99. }
  100. }
  101. }
  102. //轮播图
  103. public function doPageAd() {
  104. global $_GPC, $_W;
  105. $where = " where uniacid=:uniacid and status=1";
  106. if ($_GPC['cityname']) {
  107. $where .= " and (cityname LIKE concat('%', :name,'%') or cityname='全国版')";
  108. $data[':name'] = $_GPC['cityname'];
  109. }
  110. $data[':uniacid'] = $_W['uniacid'];
  111. $sql = "select * from " . tablename('zhtc_ad') . $where . " order by orderby asc";
  112. $res = pdo_fetchall($sql, $data);
  113. echo json_encode($res);
  114. }
  115. public function doPageUrl() {
  116. global $_GPC, $_W;
  117. echo $_W['attachurl'];
  118. }
  119. //url
  120. public function doPageUrl2() {
  121. global $_W, $_GPC;
  122. echo $_W['siteroot'];
  123. }
  124. //主分类
  125. public function doPageType() {
  126. global $_GPC, $_W;
  127. $res = pdo_getall('zhtc_type', array('uniacid' => $_W['uniacid'], 'state' => 1), array(), '', 'num asc');
  128. echo json_encode($res);
  129. }
  130. //子分类
  131. public function doPageType2() {
  132. global $_GPC, $_W;
  133. $res = pdo_getall('zhtc_type2', array('type_id' => $_GPC['id']), array(), '', 'num asc');
  134. echo json_encode($res);
  135. }
  136. //发帖
  137. public function doPagePosting() {
  138. global $_GPC, $_W;
  139. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  140. // $data['details']=base64_encode($_GPC['details']);//帖子内容
  141. $data['details'] = $_GPC['details']; //帖子内容
  142. $data['img'] = $_GPC['img']; //帖子图片
  143. $data['user_id'] = $_GPC['user_id']; //用户id
  144. $data['user_name'] = $_GPC['user_name']; //姓名
  145. $data['user_tel'] = $_GPC['user_tel']; //电话
  146. $data['type2_id'] = $_GPC['type2_id']; //子分类id
  147. $data['type_id'] = $_GPC['type_id']; //主分类id
  148. $data['money'] = $_GPC['money']; //价格
  149. $data['top_type'] = $_GPC['type']; //置顶类型
  150. $data['address'] = $_GPC['address']; //帖子地址
  151. $data['store_id'] = $_GPC['store_id'];
  152. $data['cityname'] = $_GPC['cityname'];
  153. $data['code'] = time() . $_GPC['user_id'];
  154. $data['lat'] = $_GPC['lat'];
  155. $data['lng'] = $_GPC['lng'];
  156. if ($_GPC['type']) {
  157. $data['top'] = 1;
  158. } else {
  159. $data['top'] = 2;
  160. }
  161. $data['time'] = time();
  162. $data['uniacid'] = $_W['uniacid'];
  163. if ($_GPC['money'] <= 0) {
  164. if ($system['tz_audit'] == 2) {
  165. $data['sh_time'] = time();
  166. if ($_GPC['type'] == 1) {
  167. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60;
  168. } elseif ($_GPC['type'] == 2) {
  169. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 7;
  170. } elseif ($_GPC['type'] == 3) {
  171. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 30;
  172. }
  173. $data['state'] = 2;
  174. } else {
  175. $data['state'] = 1;
  176. }
  177. } else {
  178. if ($system['tz_audit'] == 2) {
  179. $data['sh_time'] = time();
  180. if ($_GPC['type'] == 1) {
  181. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60;
  182. } elseif ($_GPC['type'] == 2) {
  183. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 7;
  184. } elseif ($_GPC['type'] == 3) {
  185. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 30;
  186. }
  187. $data['state'] = 2;
  188. } else {
  189. $data['state'] = 1;
  190. }
  191. }
  192. $data['hb_money'] = $_GPC['hb_money']; //红包金额
  193. $data['hb_num'] = $_GPC['hb_num']; //红包个数
  194. $data['hb_type'] = $_GPC['hb_type']; //红包类型1.普通 2.口令
  195. $data['hb_keyword'] = $_GPC['hb_keyword']; //红包口令
  196. $data['hb_random'] = $_GPC['hb_random']; //随机1.是 2否
  197. if ($_GPC['hb_random'] == 1) {
  198. function sendRandBonus($total = 0, $count = 3) {
  199. $input = range(0.01, $total, 0.01);
  200. if ($count > 1) {
  201. $rand_keys = (array) array_rand($input, $count - 1);
  202. $last = 0;
  203. foreach ($rand_keys as $i => $key) {
  204. $current = $input[$key] - $last;
  205. $items[] = $current;
  206. $last = $input[$key];
  207. }
  208. }
  209. $items[] = $total - array_sum($items);
  210. return $items;
  211. }
  212. $hong = json_encode(sendRandBonus($_GPC['hb_money'], $_GPC['hb_num']));
  213. $data['hong'] = $hong;
  214. }
  215. $res = pdo_insert('zhtc_information', $data);
  216. $tz_id = pdo_insertid();
  217. $post_id = pdo_insertid();
  218. $a = json_decode(html_entity_decode($_GPC['sz']));
  219. $sz = json_decode(json_encode($a), true);
  220. // print_r($sz);die;
  221. if ($res) {
  222. for ($i = 0; $i < count($sz); $i++) {
  223. $data2['label_id'] = $sz[$i]['label_id'];
  224. $data2['information_id'] = $post_id;
  225. $res2 = pdo_insert('zhtc_mylabel', $data2);
  226. }
  227. if ($system['tz_audit'] == 2) {
  228. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=AddScore&m=zh_tcwq&user_id=" . $_GPC['user_id']); //加积分
  229. }
  230. //echo '1';
  231. echo $tz_id;
  232. } else {
  233. echo '发帖失败';
  234. }
  235. }
  236. //发帖加积分
  237. public function doPageAddScore() {
  238. global $_GPC, $_W;
  239. $user_id = $_GPC['user_id'];
  240. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  241. if ($system['is_jf'] == 1 and $system['integral'] > 0) {
  242. $res = pdo_update('zhtc_user', array('total_score +=' => $system['integral']), array('id' => $user_id));
  243. if ($res) {
  244. $data3['score'] = $system['integral'];
  245. $data3['user_id'] = $user_id;
  246. $data3['note'] = '发帖';
  247. $data3['type'] = 1;
  248. $data3['cerated_time'] = date('Y-m-d H:i:s');
  249. $data3['uniacid'] = $_W['uniacid']; //小程序id
  250. pdo_insert('zhtc_integral', $data3); //添加积分明细
  251. }
  252. }
  253. }
  254. //修改帖子
  255. public function doPageUpdPost() {
  256. global $_GPC, $_W;
  257. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  258. $tz = pdo_get('zhtc_information', array('id' => $_GPC['id']));
  259. if ($tz['details'] != $_GPC['details']) {
  260. $data['details'] = $_GPC['details']; //帖子内容
  261. }
  262. if ($tz['img'] != $_GPC['img']) {
  263. $data['img'] = $_GPC['img']; //帖子图片
  264. }
  265. if ($tz['user_name'] != $_GPC['user_name']) {
  266. $data['user_name'] = $_GPC['user_name']; //姓名
  267. }
  268. if ($tz['user_tel'] != $_GPC['user_tel']) {
  269. $data['user_tel'] = $_GPC['user_tel']; //电话
  270. }
  271. if ($tz['address'] != $_GPC['address']) {
  272. $data['address'] = $_GPC['address']; //帖子地址
  273. }
  274. if ($tz['cityname'] != $_GPC['cityname']) {
  275. $data['cityname'] = $_GPC['cityname']; //帖子地址
  276. }
  277. $data['uniacid'] = $_W['uniacid'];
  278. if ($system['tz_audit'] == 2) {
  279. $data['state'] = 2;
  280. } else {
  281. $data['state'] = 1;
  282. }
  283. $res = pdo_update('zhtc_information', $data, array('id' => $_GPC['id']));
  284. pdo_delete('zhtc_mylabel', array('information_id' => $_GPC['id']));
  285. // $a=json_decode(html_entity_decode($_GPC['sz']));
  286. // $sz=json_decode(json_encode($a),true);
  287. // // print_r($sz);die;
  288. if ($res) {
  289. // for($i=0;$i<count($sz);$i++){
  290. // $data2['label_id']=$sz[$i]['label_id'];
  291. // $data2['information_id']=$_GPC['id'] ;
  292. // $res2=pdo_insert('zhtc_mylabel',$data2);
  293. // }
  294. echo '1';
  295. } else {
  296. echo '2';
  297. }
  298. }
  299. //删除帖子
  300. public function doPageDelPost() {
  301. global $_GPC, $_W;
  302. $res = pdo_update('zhtc_information', array('del' => 1), array('id' => $_GPC['id']));
  303. if ($res) {
  304. echo '1';
  305. } else {
  306. echo '2';
  307. }
  308. }
  309. //帖子点赞
  310. public function doPageLike() {
  311. global $_GPC, $_W;
  312. $data['information_id'] = $_GPC['information_id'];
  313. $data['user_id'] = $_GPC['user_id'];
  314. $res = pdo_get('zhtc_like', $data);
  315. if ($res) {
  316. echo '不能重复点赞!';
  317. } else {
  318. pdo_insert('zhtc_like', $data);
  319. pdo_update('zhtc_information', array('givelike +=' => 1), array('id' => $_GPC['information_id']));
  320. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=dzMessage&m=zh_tcwq&user_id=" . $_GPC['user_id'] . "&information_id=" . $_GPC['information_id']); //模板消息
  321. echo '1';
  322. }
  323. }
  324. //资讯点赞
  325. public function doPageZxLike() {
  326. global $_GPC, $_W;
  327. $data['zx_id'] = $_GPC['zx_id'];
  328. $data['user_id'] = $_GPC['user_id'];
  329. $res = pdo_get('zhtc_like', $data);
  330. if ($res) {
  331. echo '不能重复点赞!';
  332. } else {
  333. $res2 = pdo_insert('zhtc_like', $data);
  334. if ($res2) {
  335. echo '1';
  336. } else {
  337. echo '2';
  338. }
  339. }
  340. }
  341. //资讯点赞列表
  342. public function doPageZxLikeList() {
  343. global $_GPC, $_W;
  344. $sql = "select a.*,b.img as user_img ,b.name as user_name from " . tablename("zhtc_like") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.zx_id=:zx_id ORDER BY a.id DESC";
  345. $res = pdo_fetchall($sql, array(':zx_id' => $_GPC['zx_id']));
  346. echo json_encode($res);
  347. }
  348. //查看我的帖子
  349. public function doPageMyPost() {
  350. global $_GPC, $_W;
  351. $pageindex = max(1, intval($_GPC['page']));
  352. $pagesize = $_GPC['pagesize'];
  353. $sql = "select a.*,b.type_name,c.name as type2_name from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_type") . " b on b.id=a.type_id " . " left join " . tablename("zhtc_type2") . " c on a.type2_id=c.id WHERE a.user_id=:user_id and a.del=2 ORDER BY a.id DESC";
  354. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  355. $res = pdo_fetchall($select_sql, array(':user_id' => $_GPC['user_id']));
  356. echo json_encode($res);
  357. }
  358. //查看商家的帖子
  359. public function doPageStorePost() {
  360. global $_GPC, $_W;
  361. $res = pdo_getall('zhtc_information', array('store_id' => $_GPC['store_id'], 'del' => 2));
  362. echo json_encode($res);
  363. }
  364. //查看商家帖子列表
  365. public function doPageStorePostList() {
  366. global $_GPC, $_W;
  367. $sql = "select a.*,b.logo from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id WHERE a.uniacid=:uniacid and a.store_id!='' and a.del=2 ORDER BY a.sh_time DESC";
  368. $res = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));
  369. // $res=pdo_getall('zhtc_information',array('uniacid'=>$_W['uniacid'],'store_id !='=>''));
  370. echo json_encode($res);
  371. }
  372. //查看帖子详情
  373. public function doPagePostInfo() {
  374. global $_GPC, $_W;
  375. pdo_update('zhtc_information', array('views +=' => 1), array('id' => $_GPC['id']));
  376. $sql = "select a.*,b.type_name,c.name as type2_name,d.img as user_img,e.logo,e.coordinates,b.tel_money from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_type") . " b on b.id=a.type_id " . " left join " . tablename("zhtc_type2") . " c on a.type2_id=c.id " . " left join " . tablename("zhtc_user") . " d on a.user_id=d.id" . " left join " . tablename("zhtc_store") . " e on a.store_id=e.id WHERE a.id=:id ORDER BY a.id DESC";
  377. $res = pdo_fetch($sql, array(':id' => $_GPC['id']));
  378. //$res['details']=base64_decode($res['details']);
  379. $sql2 = "select a.*,b.img as user_img from " . tablename("zhtc_like") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.information_id=:id ORDER BY a.id DESC";
  380. $res2 = pdo_fetchall($sql2, array(':id' => $_GPC['id']));
  381. $pl = "select a.id,a.details,a.time,b.name as user_name,b.img as user_img from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id where a.information_id={$_GPC['id']} and a.bid=0 and a.hf_id=0 and a.state=2 order by a.time ASC";
  382. $pl = pdo_fetchall($pl);
  383. //$res=pdo_getall('zhtc_testpl',array('tid'=>$_GPC['tid'],'bid'=>0,'hf_id'=>0),array(),'','time ASC');
  384. for ($i = 0; $i < count($pl); $i++) {
  385. $pl2 = "select a.details,FROM_UNIXTIME(a.time) as time,a.user_id,b.name as user_name,b.img as user_img,c.name as hf_name from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id left join " . tablename("zhtc_user") . " c on c.id=a.hf_id where a.bid={$pl[$i]['id']} and a.state=2 order by a.time ASC";
  386. $pl2 = pdo_fetchall($pl2);
  387. $pl[$i]['hf'] = $pl2;
  388. }
  389. // $sql3="select a.*,b.img as user_img,b.name from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.information_id=:id ORDER BY a.id DESC";
  390. // $res3=pdo_fetchall($sql3,array(':id'=>$_GPC['id']));
  391. $call = pdo_get('zhtc_call', array('post_id' => $_GPC['id'], 'state' => 2, 'user_id' => $_GPC['user_id']));
  392. $sql4 = "select a.*,b.label_name from " . tablename("zhtc_mylabel") . " a" . " left join " . tablename("zhtc_label") . " b on b.id=a.label_id WHERE a.information_id=:id ORDER BY a.id DESC";
  393. $res4 = pdo_fetchall($sql4, array(':id' => $_GPC['id']));
  394. $data['tz'] = $res;
  395. $data['dz'] = $res2;
  396. $data['pl'] = $pl;
  397. $data['label'] = $res4;
  398. $data['call'] = $call ? true : false;
  399. echo json_encode($data);
  400. }
  401. //查看二级分类下的帖子
  402. public function doPagePostList() {
  403. global $_GPC, $_W;
  404. $time = time();
  405. // pdo_update('zhtc_information',array('top'=>2),array('dq_time <'=>time(),'state'=>2,'uniacid'=>$_W['uniacid']));
  406. $list = pdo_getall('zhtc_information', array('uniacid' => $_W['uniacid'], 'state' => 2));
  407. $where = " WHERE a.type2_id=:type2_id and a.state=:state and a.del=2";
  408. $order = " ORDER BY a.top asc,a.sh_time DESC";
  409. $data[':type2_id'] = $_GPC['type2_id'];
  410. $data[':state'] = 2;
  411. $pageindex = max(1, intval($_GPC['page']));
  412. $pagesize = 10;
  413. $lat = $_GPC['lat'];
  414. $lng = $_GPC['lng'];
  415. if ($_GPC['cityname']) {
  416. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='')";
  417. $data[':name'] = $_GPC['cityname'];
  418. }
  419. if ($lat && $lng) {
  420. $sql = "select a.*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-lat*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(lat*3.1415926/180)*POW(SIN(($lng*3.1415926/180-lng*3.1415926/180)/2),2)))*1000) AS juli,b.img as user_img,c.type_name,d.name as type2_name from" . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_type") . " c on a.type_id=c.id " . " left join " . tablename("zhtc_type2") . " d on a.type2_id=d.id " . $where . $order;
  421. } else {
  422. $sql = "select a.*,b.img as user_img,c.logo from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id" . " left join " . tablename("zhtc_store") . " c on c.id=a.store_id" . $where . " ORDER BY a.top asc,a.sh_time DESC";
  423. }
  424. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  425. $res = pdo_fetchall($select_sql, $data);
  426. $sql2 = "select a.*,b.label_name from " . tablename("zhtc_mylabel") . " a" . " left join " . tablename("zhtc_label") . " b on b.id=a.label_id";
  427. $res2 = pdo_fetchall($sql2);
  428. // $res2=pdo_getall('zhtc_label',array('uniacid'=>$_W['uniacid']));
  429. $data2 = array();
  430. for ($i = 0; $i < count($res); $i++) {
  431. $data = array();
  432. for ($k = 0; $k < count($res2); $k++) {
  433. if ($res[$i]['id'] == $res2[$k]['information_id']) {
  434. $data[] = array(
  435. 'label_name' => $res2[$k]['label_name'],
  436. );
  437. }
  438. }
  439. $data2[] = array(
  440. 'tz' => $res[$i],
  441. 'label' => $data,
  442. );
  443. }
  444. echo json_encode($data2);
  445. }
  446. //大分类帖子列表
  447. public function doPageList() {
  448. global $_GPC, $_W;
  449. $pageindex = max(1, intval($_GPC['page']));
  450. $pagesize = 10;
  451. $time = time();
  452. $where = " where a.type_id=:type_id and a.state=:state and a.del=2 ";
  453. $order = " ORDER BY a.top asc,a.sh_time DESC";
  454. $data[':type_id'] = $_GPC['type_id'];
  455. $data[':state'] = 2;
  456. $lat = $_GPC['lat'];
  457. $lng = $_GPC['lng'];
  458. if ($_GPC['cityname']) {
  459. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='')";
  460. $data[':name'] = $_GPC['cityname'];
  461. }
  462. if ($lat && $lng) {
  463. $sql = "select a.*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-lat*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(lat*3.1415926/180)*POW(SIN(($lng*3.1415926/180-lng*3.1415926/180)/2),2)))*1000) AS juli,b.img as user_img,c.type_name,d.name as type2_name from" . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_type") . " c on a.type_id=c.id " . " left join " . tablename("zhtc_type2") . " d on a.type2_id=d.id " . $where . $order;
  464. } else {
  465. $sql = "select a.*,b.img as user_img,c.logo from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id" . " left join " . tablename("zhtc_store") . " c on c.id=a.store_id" . $where . " ORDER BY a.top asc,a.sh_time DESC";
  466. }
  467. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  468. $res = pdo_fetchall($select_sql, $data);
  469. $sql2 = "select a.*,b.label_name from " . tablename("zhtc_mylabel") . " a" . " left join " . tablename("zhtc_label") . " b on b.id=a.label_id";
  470. $res2 = pdo_fetchall($sql2);
  471. $data2 = array();
  472. for ($i = 0; $i < count($res); $i++) {
  473. $data = array();
  474. for ($k = 0; $k < count($res2); $k++) {
  475. if ($res[$i]['id'] == $res2[$k]['information_id']) {
  476. $data[] = array(
  477. 'label_name' => $res2[$k]['label_name'],
  478. );
  479. }
  480. }
  481. $data2[] = array(
  482. 'tz' => $res[$i],
  483. 'label' => $data,
  484. );
  485. }
  486. echo json_encode($data2);
  487. }
  488. //所有帖子列表
  489. public function doPageList2() {
  490. global $_GPC, $_W;
  491. $time = time();
  492. $gx = " update " . tablename("zhtc_information") . " a inner join (select id from " . tablename("zhtc_information") . " where dq_time<{$time} and state=2 and top=1 and uniacid={$_W['uniacid']} order by dq_time ASC limit 0,100 ) b on a.id =b.id set a.top =2";
  493. pdo_query($gx);
  494. $pageindex = max(1, intval($_GPC['page']));
  495. $pagesize = 10;
  496. $where = " WHERE a.state=:state and a.del=2 and a.user_id != 0 and a.uniacid=:uniacid";
  497. $data[':state'] = 2;
  498. $data[':uniacid'] = $_W['uniacid'];
  499. $order = " ORDER BY a.top asc,a.sh_time DESC ";
  500. $lat = $_GPC['lat'] ?: '30.537967242806708';
  501. $lng = $_GPC['lng'] ?: '114.38415518961847';
  502. if ($_GPC['fj_tz'] == 1) {
  503. $order = "ORDER BY juli asc ";
  504. }
  505. if ($_GPC['keywords']) {
  506. $where .= " and (a.details LIKE concat('%', :name,'%') || a.user_name LIKE concat('%', :name,'%')) ";
  507. $data[':name'] = $_GPC['keywords'];
  508. }
  509. if ($_GPC['type_id']) {
  510. $where .= " and a.type_id=:type_id ";
  511. $data[':type_id'] = $_GPC['type_id'];
  512. }
  513. if ($_GPC['cityname']) {
  514. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='')";
  515. $data[':name'] = $_GPC['cityname'];
  516. }
  517. $sql = "select a.*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-lat*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(lat*3.1415926/180)*POW(SIN(($lng*3.1415926/180-lng*3.1415926/180)/2),2)))*1000) AS juli,b.img as user_img,c.type_name,d.name as type2_name from" . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_type") . " c on a.type_id=c.id " . " left join " . tablename("zhtc_type2") . " d on a.type2_id=d.id " . $where . $order;
  518. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  519. $res = pdo_fetchall($select_sql, $data);
  520. $sql2 = "select a.*,b.label_name from " . tablename("zhtc_mylabel") . " a" . " left join " . tablename("zhtc_label") . " b on b.id=a.label_id";
  521. $res2 = pdo_fetchall($sql2);
  522. //$res2=pdo_getall('zhtc_label',array('uniacid'=>$_W['uniacid']));
  523. $data2 = array();
  524. for ($i = 0; $i < count($res); $i++) {
  525. $data = array();
  526. for ($k = 0; $k < count($res2); $k++) {
  527. if ($res[$i]['id'] == $res2[$k]['information_id']) {
  528. $data[] = array(
  529. 'label_name' => $res2[$k]['label_name'],
  530. );
  531. }
  532. }
  533. $data2[] = array(
  534. 'tz' => $res[$i],
  535. 'label' => $data,
  536. );
  537. }
  538. $name_list = '';
  539. $name_list = array_map('array_shift', $res);
  540. //更新所有帖子阅读数量
  541. $sys = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), 'sj_max');
  542. $rand = empty($sys['sj_max']) ? 1 : $sys['sj_max'];
  543. pdo_update('zhtc_information', array('views +=' => rand(1, $rand)), array('id' => $name_list));
  544. echo json_encode($data2);
  545. }
  546. //查看二级分类下的标签
  547. public function doPageLabel() {
  548. global $_GPC, $_W;
  549. $res = pdo_getall('zhtc_label', array('type2_id' => $_GPC['type2_id']));
  550. echo json_encode($res);
  551. }
  552. //帖子评论
  553. public function doPageComments() {
  554. global $_GPC, $_W;
  555. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  556. $data['information_id'] = $_GPC['information_id'];
  557. $data['user_id'] = $_GPC['user_id'];
  558. $data['details'] = $_GPC['details'];
  559. if ($_GPC['bid']) {
  560. $data['bid'] = $_GPC['bid'];
  561. }
  562. if ($_GPC['hf_id']) {
  563. $data['hf_id'] = $_GPC['hf_id'];
  564. }
  565. if ($system['is_plsh'] == 1) {
  566. $data['state'] = 1;
  567. } else {
  568. $data['state'] = 2;
  569. }
  570. $data['time'] = time();
  571. $res = pdo_insert('zhtc_comments', $data);
  572. $assess_id = pdo_insertid();
  573. if ($res) {
  574. if ($data['state'] == 2) {
  575. if ($_GPC['bid'] || $_GPC['hf_id']) {
  576. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=hpMessage2&m=zh_tcwq&id=" . $assess_id); //模板消息
  577. }
  578. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=TzhfMessage&m=zh_tcwq&pl_id=" . $assess_id); //模板消息
  579. }
  580. echo $assess_id;
  581. } else {
  582. echo 'error';
  583. }
  584. }
  585. //帖子评论成功模板消息
  586. public function doPageTzhfMessage() {
  587. global $_W, $_GPC;
  588. function getaccess_token($_W) {
  589. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  590. $appid = $res['appid'];
  591. $secret = $res['appsecret'];
  592. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  593. $ch = curl_init();
  594. curl_setopt($ch, CURLOPT_URL, $url);
  595. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  596. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  597. $data = curl_exec($ch);
  598. curl_close($ch);
  599. $data = json_decode($data, true);
  600. return $data['access_token'];
  601. }
  602. //设置与发送模板信息
  603. function set_msg($_W, $_GPC) {
  604. $access_token = getaccess_token($_W);
  605. $res2 = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  606. $sql = "select a.user_id,a.details,a.information_id,a.time,b.name as user_name,b.openid from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.id=:id ";
  607. $res = pdo_fetch($sql, array(':id' => $_GPC['pl_id']));
  608. $tz = pdo_get('zhtc_information', array('id' => $res['information_id']));
  609. if ($tz['user_id']) {
  610. $user = pdo_get('zhtc_user', array('id' => $tz['user_id']));
  611. $userid = $tz['user_id'];
  612. } else {
  613. $store = pdo_get('zhtc_store', array('id' => $tz['store_id']));
  614. $userid = $store['user_id'];
  615. $user = pdo_get('zhtc_user', array('id' => $store['user_id']));
  616. }
  617. $time = date("Y-m-d H:i:s", $res['time']);
  618. $time2 = time() - 60 * 60 * 24 * 7;
  619. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$userid} and UNIX_TIMESTAMP(time)>={$time2} order by id asc");
  620. $formwork = '{
  621. "touser": "' . $user["openid"] . '",
  622. "template_id": "' . $res2["tid3"] . '",
  623. "page":"zh_tcwq/pages/infodetial/infodetial?id=' . $res['information_id'] . '",
  624. "form_id":"' . $form['form_id'] . '",
  625. "data": {
  626. "keyword1": {
  627. "value": "' . $res['details'] . '",
  628. "color": "#173177"
  629. },
  630. "keyword2": {
  631. "value":"' . $res['user_name'] . '",
  632. "color": "#173177"
  633. },
  634. "keyword3": {
  635. "value": "' . $time . '",
  636. "color": "#173177"
  637. }
  638. }
  639. }';
  640. // $formwork=$data;
  641. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  642. $ch = curl_init();
  643. curl_setopt($ch, CURLOPT_URL, $url);
  644. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  645. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  646. curl_setopt($ch, CURLOPT_POST, 1);
  647. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  648. $data = curl_exec($ch);
  649. curl_close($ch);
  650. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  651. }
  652. echo set_msg($_W, $_GPC);
  653. }
  654. //测试评论
  655. public function doPageTestPl() {
  656. global $_W, $_GPC;
  657. $sql = "select a.id,a.details,a.time,b.name as user_name,b.img as user_img from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id where a.information_id={$_GPC['tid']} and a.bid=0 and a.hf_id=0 order by a.time ASC";
  658. $res = pdo_fetchall($sql);
  659. //$res=pdo_getall('zhtc_testpl',array('tid'=>$_GPC['tid'],'bid'=>0,'hf_id'=>0),array(),'','time ASC');
  660. for ($i = 0; $i < count($res); $i++) {
  661. $sql2 = "select a.details,a.time,b.name as user_name,b.img as user_img,c.name as hf_name from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id left join " . tablename("zhtc_user") . " c on c.id=a.hf_id where a.bid={$res[$i]['id']} order by a.time ASC";
  662. $res2 = pdo_fetchall($sql2);
  663. $res[$i]['hf'] = $res2;
  664. }
  665. echo json_encode($res);
  666. }
  667. //测试评论
  668. public function doPageTestPl2() {
  669. global $_W, $_GPC;
  670. $sql = "select a.id,a.content,a.time,b.name as user_name,b.img as user_img from " . tablename("zhtc_testpl") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id where a.tid={$_GPC['tid']} and a.bid=0 and a.hf_id=0 order by a.time ASC";
  671. $res = pdo_fetchall($sql);
  672. //$res=pdo_getall('zhtc_testpl',array('tid'=>$_GPC['tid'],'bid'=>0,'hf_id'=>0),array(),'','time ASC');
  673. for ($i = 0; $i < count($res); $i++) {
  674. $sql2 = "select a.content,a.time,b.name as user_name,b.img as user_img,c.name as hf_name from " . tablename("zhtc_testpl") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id left join " . tablename("zhtc_user") . " c on c.id=a.hf_id where a.bid={$res[$i]['id']} order by a.time ASC";
  675. $res2 = pdo_fetchall($sql2);
  676. $res[$i]['hf'] = $res2;
  677. }
  678. print_r($res);
  679. echo json_encode($res);
  680. }
  681. //商家评分
  682. public function doPageStoreComments() {
  683. global $_GPC, $_W;
  684. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  685. $data['store_id'] = $_GPC['store_id'];
  686. $data['user_id'] = $_GPC['user_id'];
  687. $data['details'] = $_GPC['details'];
  688. $data['score'] = $_GPC['score'];
  689. $data['time'] = time();
  690. if ($system['is_plsh'] == 1) {
  691. $data['state'] = 1;
  692. } else {
  693. $data['state'] = 2;
  694. }
  695. $res = pdo_insert('zhtc_comments', $data);
  696. $assess_id = pdo_insertid();
  697. if ($res) {
  698. $total = pdo_get('zhtc_comments', array('store_id' => $_GPC['store_id']), array('sum(score) as total'));
  699. $count = pdo_get('zhtc_comments', array('store_id' => $_GPC['store_id']), array('count(id) as count'));
  700. if ($total['total'] > 0 and $count['count'] > 0) {
  701. $pf = ($total['total'] / $count['count']);
  702. } else {
  703. $pf = 0;
  704. }
  705. pdo_update('zhtc_store', array('score' => $pf), array('id' => $_GPC['store_id']));
  706. echo $assess_id;
  707. } else {
  708. echo '评论失败';
  709. }
  710. }
  711. //回复
  712. public function doPageReply() {
  713. global $_GPC, $_W;
  714. $data['reply'] = $_GPC['reply'];
  715. $data['hf_time'] = time();
  716. $res = pdo_update('zhtc_comments', $data, array('id' => $_GPC['id']));
  717. if ($res) {
  718. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=hpMessage&m=zh_tcwq&id=" . $_GPC['id']); //模板消息
  719. echo '1';
  720. } else {
  721. echo '2';
  722. }
  723. }
  724. //总浏览量
  725. public function doPageViews() {
  726. global $_W, $_GPC;
  727. $sys = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  728. if ($sys['zfwl_max']) {
  729. $rand = $sys['zfwl_max'];
  730. } else {
  731. $rand = 1;
  732. }
  733. pdo_update('zhtc_system', array('total_num +=' => rand(1, $rand)), array('uniacid' => $_W['uniacid']));
  734. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  735. }
  736. //帖子总量
  737. public function doPageNum() {
  738. global $_W, $_GPC;
  739. $sql = "select count(*) as count from " . tablename("zhtc_information") . " where uniacid={$_W['uniacid']}";
  740. $res = pdo_fetch($sql);
  741. //echo $res['count'];
  742. // $res=pdo_getall('zhtc_information',array('uniacid'=>$_W['uniacid']));
  743. // $total=count($res);
  744. $res2 = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), array('tz_num'));
  745. echo $res['count'] + $res2['tz_num'];
  746. }
  747. //置顶
  748. public function doPageTop() {
  749. global $_W, $_GPC;
  750. $res = pdo_getall('zhtc_top', array('uniacid' => $_W['uniacid']), array(), '', 'num asc');
  751. echo json_encode($res);
  752. }
  753. //支付
  754. public function doPagePay() {
  755. global $_W, $_GPC;
  756. include IA_ROOT . '/addons/zh_tcwq/wxpay2.php';
  757. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  758. if ($res['pt_name']) {
  759. $res['pt_name'] = $res['pt_name'];
  760. } else {
  761. $res['pt_name'] = '同城小程序';
  762. }
  763. $order = pdo_get('zhtc_order', array('id' => $_GPC['order_id']));
  764. $appid = $res['appid'];
  765. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  766. $mch_id = $res['mchid'];
  767. $key = $res['wxkey'];
  768. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  769. $out_trade_no = time() . $user['id'];
  770. $total_fee = $_GPC['money'];
  771. if (empty($total_fee)) //押金
  772. {
  773. $body = $res['pt_name'];
  774. $total_fee = floatval(99 * 100);
  775. } else {
  776. $body = $res['pt_name'];
  777. $total_fee = floatval($total_fee * 100);
  778. }
  779. if ($_GPC['order_id']) {
  780. pdo_update('zhtc_order', array('out_trade_no' => $out_trade_no), array('id' => $_GPC['order_id']));
  781. }
  782. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee);
  783. $return = $weixinpay->pay();
  784. echo json_encode($return);
  785. }
  786. //商家入驻
  787. public function doPageStore() {
  788. global $_W, $_GPC;
  789. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  790. $data['user_id'] = $_GPC['user_id']; //用户id
  791. $data['store_name'] = $_GPC['store_name']; //商家名称
  792. $data['address'] = $_GPC['address']; //地址
  793. $data['announcement'] = $_GPC['announcement']; //公告
  794. $data['storetype_id'] = $_GPC['storetype_id']; //行业分类id
  795. $data['storetype2_id'] = $_GPC['storetype2_id']; //之行业分类id
  796. $data['area_id'] = $_GPC['area_id']; //区域id
  797. $data['start_time'] = $_GPC['start_time']; //营业时间
  798. $data['end_time'] = $_GPC['end_time']; //营业时间
  799. $data['keyword'] = $_GPC['keyword']; //关键字
  800. $data['skzf'] = $_GPC['skzf']; //刷卡支付
  801. $data['wifi'] = $_GPC['wifi']; //wifi
  802. $data['mftc'] = $_GPC['mftc']; //免费停车
  803. $data['jzxy'] = $_GPC['jzxy']; //禁止吸烟
  804. $data['tgbj'] = $_GPC['tgbj']; //提供包间
  805. $data['sfxx'] = $_GPC['sfxx']; //沙发休闲
  806. $data['tel'] = $_GPC['tel']; //电话
  807. $data['logo'] = $_GPC['logo']; //商家logo
  808. $data['vr_link'] = $_GPC['vr_link']; //vr
  809. $data['weixin_logo'] = $_GPC['weixin_logo']; //老板微信
  810. $data['ad'] = $_GPC['ad']; //轮播图
  811. $data['img'] = $_GPC['img']; //商家图片
  812. $data['yyzz_img'] = $_GPC['yyzz_img'];
  813. $data['sfz_img'] = $_GPC['sfz_img'];
  814. $data['start_time'] = $_GPC['start_time'];
  815. $data['end_time'] = $_GPC['end_time'];
  816. $data['cityname'] = $_GPC['cityname'];
  817. if ($system['sj_audit'] == 2) {
  818. $data['sh_time'] = time();
  819. if ($_GPC['type'] == 1) {
  820. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 7;
  821. } elseif ($_GPC['type'] == 2) {
  822. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 182;
  823. } elseif ($_GPC['type'] == 3) {
  824. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * 365;
  825. }
  826. $data['state'] = 2;
  827. } else {
  828. $data['state'] = 1;
  829. }
  830. if ($_GPC['type']) {
  831. $data['type'] = $_GPC['type']; //入驻类型
  832. $data['time_over'] = 2;
  833. }
  834. $data['time'] = date('Y-m-d H:i:s', time());
  835. $data['money'] = $_GPC['money']; //付款价格
  836. $data['details'] = $_GPC['details']; //商家简介
  837. $data['coordinates'] = $_GPC['coordinates']; //坐标
  838. $data['uniacid'] = $_W['uniacid'];
  839. $res = pdo_insert('zhtc_store', $data);
  840. $store_id = pdo_insertid();
  841. if ($res) {
  842. //echo '1';
  843. echo $store_id;
  844. } else {
  845. echo '入驻失败';
  846. }
  847. }
  848. //修改入驻
  849. public function doPageUpdStore() {
  850. global $_W, $_GPC;
  851. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  852. //$data['user_id']=$_GPC['user_id'];//用户id
  853. $data['store_name'] = $_GPC['store_name']; //商家名称
  854. $data['address'] = $_GPC['address']; //地址
  855. $data['announcement'] = $_GPC['announcement']; //公告
  856. $data['storetype_id'] = $_GPC['storetype_id']; //行业分类id
  857. $data['storetype2_id'] = $_GPC['storetype2_id']; //之行业分类id
  858. $data['area_id'] = $_GPC['area_id']; //区域id
  859. $data['start_time'] = $_GPC['start_time']; //营业时间
  860. $data['end_time'] = $_GPC['end_time']; //营业时间
  861. $data['keyword'] = $_GPC['keyword']; //关键字
  862. $data['skzf'] = $_GPC['skzf']; //刷卡支付
  863. $data['wifi'] = $_GPC['wifi']; //wifi
  864. $data['mftc'] = $_GPC['mftc']; //免费停车
  865. $data['jzxy'] = $_GPC['jzxy']; //禁止吸烟
  866. $data['tgbj'] = $_GPC['tgbj']; //提供包间
  867. $data['sfxx'] = $_GPC['sfxx']; //沙发休闲
  868. $data['tel'] = $_GPC['tel']; //电话
  869. $data['logo'] = $_GPC['logo']; //商家logo
  870. $data['vr_link'] = $_GPC['vr_link']; //vr
  871. $data['weixin_logo'] = $_GPC['weixin_logo']; //老板微信
  872. $data['ad'] = $_GPC['ad']; //轮播图
  873. $data['img'] = $_GPC['img']; //商家图片
  874. if ($system['sj_audit'] == 2) {
  875. $data['state'] = 2;
  876. } else {
  877. $data['state'] = 1;
  878. }
  879. $data['money'] = $_GPC['money']; //付款价格
  880. $data['details'] = $_GPC['details']; //商家简介
  881. $data['coordinates'] = $_GPC['coordinates']; //坐标
  882. $data['uniacid'] = $_W['uniacid'];
  883. $res = pdo_update('zhtc_store', $data, array('id' => $_GPC['id']));
  884. if ($res) {
  885. echo '1';
  886. } else {
  887. echo '2';
  888. }
  889. }
  890. //商家列表
  891. public function doPageStoreList() {
  892. global $_W, $_GPC;
  893. $time = time();
  894. $gx = " update " . tablename("zhtc_store") . " a inner join (select id from " . tablename("zhtc_store") . " where dq_time<={$time} and time_over =2 and state=2 and uniacid={$_W['uniacid']} order by dq_time ASC limit 0,100 ) b on a.id =b.id set a.time_over =1";
  895. pdo_query($gx);
  896. $where = " where uniacid=:uniacid and time_over !=1 and state=2";
  897. $data[':uniacid'] = $_W['uniacid'];
  898. if ($_GPC['lat']) {
  899. $lat = $_GPC['lat'];
  900. } else {
  901. $lat = '30.592760';
  902. }
  903. if ($_GPC['lng']) {
  904. $lng = $_GPC['lng'];
  905. } else {
  906. $lng = '114.305250';
  907. }
  908. if ($_GPC['storetype_id']) {
  909. $where .= " and storetype_id=" . $_GPC['storetype_id'];
  910. }
  911. if ($_GPC['storetype2_id']) {
  912. $where .= " and storetype2_id=" . $_GPC['storetype2_id'];
  913. }
  914. if ($_GPC['keywords']) {
  915. $where .= " and (store_name LIKE concat('%', :name,'%') or keyword LIKE concat('%', :name,'%'))";
  916. $data[':name'] = $_GPC['keywords'];
  917. }
  918. if ($_GPC['cityname']) {
  919. $where .= " and (cityname LIKE concat('%', :name,'%') || cityname='')";
  920. $data[':name'] = $_GPC['cityname'];
  921. }
  922. $pageindex = max(1, intval($_GPC['page']));
  923. if ($_GPC['pagesize']) {
  924. $pagesize = $_GPC['pagesize'];
  925. } else {
  926. $pagesize = 10;
  927. }
  928. if ($_GPC['type'] == 1) {
  929. $sql = "select *,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli from" . tablename('zhtc_store') . $where . " order by is_top asc,juli asc";
  930. } elseif ($_GPC['type'] == 2) {
  931. $sql = "select *,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli from" . tablename('zhtc_store') . $where . " order by is_top asc,sh_time DESC";
  932. } elseif ($_GPC['type'] == 3) {
  933. $sql = "select *,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli from" . tablename('zhtc_store') . $where . " order by is_top asc,views DESC";
  934. } else {
  935. $sql = "select *,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli from" . tablename('zhtc_store') . $where . " order by is_top asc";
  936. }
  937. // echo $sql;die;
  938. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  939. $res = pdo_fetchall($select_sql, $data);
  940. $name_list = '';
  941. $name_list = array_map('array_shift', $res);
  942. $sys = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), 'sj_max2');
  943. $rand = empty($sys['sj_max2']) ? 1 : $sys['sj_max2'];
  944. pdo_update('zhtc_store', array('views +=' => rand(1, $rand)), array('id' => $name_list));
  945. // $res=pdo_getall('zhtc_store',array('uniacid'=>$_W['uniacid'],'time_over !='=>1),array(),'','num asc');
  946. echo json_encode($res);
  947. }
  948. //热门商家
  949. public function doPageRmStore() {
  950. global $_W, $_GPC;
  951. $where = " where uniacid=:uniacid and time_over !=1 and state=2 and is_rm=1";
  952. $data[':uniacid'] = $_W['uniacid'];
  953. if ($_GPC['cityname']) {
  954. $where .= " and (cityname LIKE concat('%', :name,'%') || cityname='')";
  955. $data[':name'] = $_GPC['cityname'];
  956. }
  957. $sql = "select * from" . tablename('zhtc_store') . $where . " order by is_top,sh_time DESC,num asc";
  958. $res = pdo_fetchall($sql, $data);
  959. echo json_encode($res);
  960. }
  961. //分类下商家列表
  962. public function doPageTypeStoreList() {
  963. global $_W, $_GPC;
  964. $pageindex = max(1, intval($_GPC['page']));
  965. $pagesize = $_GPC['pagesize'];
  966. $time = time();
  967. //pdo_update('zhtc_store',array('time_over'=>1),array('dq_time <='=>time(),'state'=>2,'uniacid'=>$_W['uniacid']));
  968. if ($_GPC['storetype2_id']) {
  969. $sql = "select * from" . tablename('zhtc_store') . " where uniacid=:uniacid and time_over !=1 and storetype2_id=:storetype_id and state=2 order by id DESC";
  970. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  971. $res = pdo_fetchall($select_sql, array(':uniacid' => $_W['uniacid'], ':storetype_id' => $_GPC['storetype2_id']));
  972. } else {
  973. $sql = "select * from" . tablename('zhtc_store') . " where uniacid=:uniacid and time_over !=1 and storetype_id=:storetype_id and state=2 order by id DESC";
  974. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  975. $res = pdo_fetchall($select_sql, array(':uniacid' => $_W['uniacid'], ':storetype_id' => $_GPC['storetype_id']));
  976. }
  977. echo json_encode($res);
  978. }
  979. //查看我的商家信息
  980. public function doPageMyStore() {
  981. global $_W, $_GPC;
  982. $sql = "select a.*,b.type_name,c.name as type2_name from " . tablename("zhtc_store") . " a" . " left join " . tablename("zhtc_storetype") . " b on b.id=a.storetype_id " . " left join " . tablename("zhtc_storetype2") . " c on a.storetype2_id=c.id WHERE a.id=:store_id ORDER BY a.id DESC";
  983. $res = pdo_fetch($sql, array(':store_id' => $_GPC['user_id']));
  984. echo json_encode($res);
  985. }
  986. //商家微信登录
  987. public function doPageSjdLogin() {
  988. global $_W, $_GPC;
  989. $sql = "select a.*,b.type_name,c.name as type2_name from " . tablename("zhtc_store") . " a" . " left join " . tablename("zhtc_storetype") . " b on b.id=a.storetype_id " . " left join " . tablename("zhtc_storetype2") . " c on a.storetype2_id=c.id WHERE a.user_id=:user_id and a.uniacid=:uniacid ORDER BY a.id DESC";
  990. $res = pdo_fetch($sql, array(':user_id' => $_GPC['user_id'], ':uniacid' => $_W['uniacid']));
  991. echo json_encode($res);
  992. }
  993. //商家详情
  994. public function doPageStoreInfo() {
  995. global $_W, $_GPC;
  996. pdo_update('zhtc_store', array('views +=' => 1), array('id' => $_GPC['id']));
  997. $res = pdo_getall('zhtc_store', array('id' => $_GPC['id']));
  998. function video($video) {
  999. $vid = trim(strrchr($video, '/'), '/');
  1000. $vid = substr($vid, 0, -5);
  1001. $json = file_get_contents("http://vv.video.qq.com/getinfo?vids=" . $vid . "&platform=101001&charge=0&otype=json");
  1002. // echo $json;die;
  1003. $json = substr($json, 13);
  1004. $json = substr($json, 0, -1);
  1005. $a = json_decode(html_entity_decode($json));
  1006. $sz = json_decode(json_encode($a), true);
  1007. // print_R($sz);die;
  1008. $url = $sz['vl']['vi']['0']['ul']['ui']['0']['url'];
  1009. $fn = $sz['vl']['vi']['0']['fn'];
  1010. $fvkey = $sz['vl']['vi']['0']['fvkey'];
  1011. $url = $url . $fn . '?vkey=' . $fvkey;
  1012. return $url;
  1013. }
  1014. $res[0]['video'] = video($res[0]['video']);
  1015. $sql2 = "select a.*,b.img as user_img,b.name from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.store_id=:id and a.state=2 ORDER BY a.id DESC";
  1016. $res2 = pdo_fetchall($sql2, array(':id' => $_GPC['id']));
  1017. $data['store'] = $res;
  1018. $data['pl'] = $res2;
  1019. echo json_encode($data);
  1020. }
  1021. //区域信息
  1022. public function doPageArea() {
  1023. global $_W, $_GPC;
  1024. $res = pdo_getall('zhtc_area', array('uniacid' => $_W['uniacid']), array(), '', 'num asc');
  1025. echo json_encode($res);
  1026. }
  1027. //行业分类
  1028. public function doPageStoreType() {
  1029. global $_W, $_GPC;
  1030. $res = pdo_getall('zhtc_storetype', array('uniacid' => $_W['uniacid'], 'state' => 1), array(), '', 'num asc');
  1031. echo json_encode($res);
  1032. }
  1033. //二级行业分类
  1034. public function doPageStoreType2() {
  1035. global $_W, $_GPC;
  1036. $res = pdo_getall('zhtc_storetype2', array('type_id' => $_GPC['type_id'], 'state' => 1), array(), '', 'num asc');
  1037. echo json_encode($res);
  1038. }
  1039. //黄页分类
  1040. public function doPageYellowType() {
  1041. global $_W, $_GPC;
  1042. $res = pdo_getall('zhtc_yellowtype', array('uniacid' => $_W['uniacid'], 'state' => 1), array(), '', 'num asc');
  1043. echo json_encode($res);
  1044. }
  1045. //二级黄页分类
  1046. public function doPageYellowType2() {
  1047. global $_W, $_GPC;
  1048. $res = pdo_getall('zhtc_yellowtype2', array('type_id' => $_GPC['type_id'], 'state' => 1), array(), '', 'num asc');
  1049. echo json_encode($res);
  1050. }
  1051. //地图
  1052. public function doPageMap() {
  1053. global $_GPC, $_W;
  1054. $op = $_GPC['op'];
  1055. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1056. // $url="https://apis.map.qq.com/ws/geocoder/v1/?location=".$op."&key=".$res['mapkey']."&get_poi=0&coord_type=1";
  1057. // $html = file_get_contents($url);
  1058. $url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" . $op . "&key=" . $res['mapkey'] . "&get_poi=0&coord_type=1";
  1059. $ch = curl_init();
  1060. curl_setopt($ch, CURLOPT_URL, $url);
  1061. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1062. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1063. $data = curl_exec($ch);
  1064. curl_close($ch);
  1065. echo $data;
  1066. }
  1067. //系统设置
  1068. public function doPageSystem() {
  1069. global $_W, $_GPC;
  1070. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1071. echo json_encode($res);
  1072. }
  1073. //公告列表
  1074. public function doPageNews() {
  1075. global $_GPC, $_W;
  1076. $where = " where uniacid=:uniacid and state=1";
  1077. if ($_GPC['cityname']) {
  1078. $where .= " and (cityname LIKE concat('%', :name,'%') || cityname='全国版')";
  1079. $data[':name'] = $_GPC['cityname'];
  1080. }
  1081. $data[':uniacid'] = $_W['uniacid'];
  1082. $sql = "select * from " . tablename('zhtc_news') . $where . " order by num asc";
  1083. $res = pdo_fetchall($sql, $data);
  1084. echo json_encode($res);
  1085. }
  1086. //公告详情
  1087. public function doPageNewsInfo() {
  1088. global $_W, $_GPC;
  1089. $res = pdo_get('zhtc_news', array('id' => $_GPC['id']));
  1090. echo json_encode($res);
  1091. }
  1092. //收藏
  1093. public function doPageCollection() {
  1094. global $_W, $_GPC;
  1095. if ($_GPC['information_id']) {
  1096. $data['information_id'] = $_GPC['information_id'];
  1097. }
  1098. if ($_GPC['store_id']) {
  1099. $data['store_id'] = $_GPC['store_id'];
  1100. }
  1101. $data['user_id'] = $_GPC['user_id'];
  1102. $list = pdo_get('zhtc_share', $data);
  1103. if ($list) {
  1104. pdo_delete('zhtc_share', $data);
  1105. } else {
  1106. $res = pdo_insert('zhtc_share', $data);
  1107. if ($res) {
  1108. echo '1';
  1109. } else {
  1110. echo '2';
  1111. }
  1112. }
  1113. }
  1114. //查看是否收藏
  1115. public function doPageIsCollection() {
  1116. global $_W, $_GPC;
  1117. if ($_GPC['information_id']) {
  1118. $data['information_id'] = $_GPC['information_id'];
  1119. }
  1120. if ($_GPC['store_id']) {
  1121. $data['store_id'] = $_GPC['store_id'];
  1122. }
  1123. $data['user_id'] = $_GPC['user_id'];
  1124. $list = pdo_get('zhtc_share', $data);
  1125. if ($list) {
  1126. echo '1';
  1127. } else {
  1128. echo '2';
  1129. }
  1130. }
  1131. //我的收藏
  1132. public function doPageMyCollection() {
  1133. global $_W, $_GPC;
  1134. $sql = "select a.*,b.img,b.details,b.time,b.top,b.user_img2,c.type_name,d.name as type2_name,e.img as user_img,b.user_tel from" . tablename("zhtc_share") . " a" . " left join " . tablename("zhtc_information") . " b on b.id=a.information_id " . " left join " . tablename("zhtc_type") . " c on b.type_id=c.id " . " left join " . tablename("zhtc_type2") . " d on b.type2_id=d.id " . " left join " . tablename("zhtc_user") . " e on b.user_id=e.id WHERE a.user_id=:user_id ORDER BY b.top DESC,b.id DESC";
  1135. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  1136. echo json_encode($res);
  1137. }
  1138. //我的商家收藏
  1139. public function doPageMyStoreCollection() {
  1140. global $_W, $_GPC;
  1141. $sql = "select a.*,b.store_name,b.address,b.tel,b.logo,b.score,b.views,b.coordinates from" . tablename("zhtc_share") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id WHERE a.user_id=:user_id ORDER BY a.id DESC";
  1142. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  1143. echo json_encode($res);
  1144. }
  1145. //入驻费用
  1146. public function doPageInMoney() {
  1147. global $_W, $_GPC;
  1148. $res = pdo_getall('zhtc_in', array('uniacid' => $_W['uniacid']), array(), '', 'num asc');
  1149. echo json_encode($res);
  1150. }
  1151. //帮助中心
  1152. public function doPageGetHelp() {
  1153. global $_W, $_GPC;
  1154. $res = pdo_getall('zhtc_help', array('uniacid' => $_W['uniacid']), array(), '', 'sort ASC');
  1155. echo json_encode($res);
  1156. }
  1157. public function doPageSms() {
  1158. global $_W, $_GPC;
  1159. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  1160. $tpl_id = $res['tpl_id'];
  1161. $tel = $_GPC['tel'];
  1162. $code = $_GPC['code'];
  1163. $key = $res['appkey'];
  1164. if ($res['item'] == 1) {
  1165. $url = "http://v.juhe.cn/sms/send?mobile=" . $tel . "&tpl_id=" . $tpl_id . "&tpl_value=%23code%23%3D" . $code . "&key=" . $key;
  1166. $data = file_get_contents($url);
  1167. }
  1168. if ($res['item'] == 2) {
  1169. $this->doPageAliyun($_GPC['tel'], $_GPC['code']);
  1170. }
  1171. }
  1172. public function doPageSms2() {
  1173. global $_W, $_GPC;
  1174. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  1175. $store = pdo_get('zhtc_store', array('id' => $_GPC['store_id']));
  1176. $tpl_id = $res['tpl2_id'];
  1177. $tel = $store['tel'];
  1178. $key = $res['appkey'];
  1179. if ($res['item'] == 1) {
  1180. $url = "http://v.juhe.cn/sms/send?mobile=" . $tel . "&tpl_id=" . $tpl_id . "&tpl_value=%23code%23%3D654654&key=" . $key;
  1181. $data = file_get_contents($url);
  1182. }
  1183. if ($res['item'] == 2) {
  1184. $this->doPageAliyun2($tel, $res['aliyun_appkey'], $res['aliyun_appsecret'], $res['aliyun_sign'], $res['tpl2_id']);
  1185. }
  1186. }
  1187. //我的分享码
  1188. public function doPageHxCode() {
  1189. global $_W, $_GPC;
  1190. function getCoade($user_id) {
  1191. function getaccess_token() {
  1192. global $_W, $_GPC;
  1193. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1194. $appid = $res['appid'];
  1195. $secret = $res['appsecret'];
  1196. /*$appid='wx80fa1d36c435231a';
  1197. $secret='41d8f6e7fad1a13cfa2e6de8acf14280';*/
  1198. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  1199. $ch = curl_init();
  1200. curl_setopt($ch, CURLOPT_URL, $url);
  1201. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1202. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1203. $data = curl_exec($ch);
  1204. curl_close($ch);
  1205. $data = json_decode($data, true);
  1206. return $data['access_token'];
  1207. }
  1208. function set_msg($user_id) {
  1209. $access_token = getaccess_token();
  1210. $data2 = array(
  1211. "scene" => $user_id,
  1212. "width" => 100,
  1213. );
  1214. $data2 = json_encode($data2);
  1215. //$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
  1216. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  1217. $ch = curl_init();
  1218. curl_setopt($ch, CURLOPT_URL, $url);
  1219. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1220. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1221. curl_setopt($ch, CURLOPT_POST, 1);
  1222. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  1223. $data = curl_exec($ch);
  1224. curl_close($ch);
  1225. return $data;
  1226. }
  1227. $img = set_msg($user_id);
  1228. $img = base64_encode($img);
  1229. return $img;
  1230. }
  1231. echo getCoade($_GPC['user_id']);
  1232. }
  1233. //扫码进来
  1234. public function doPageCodeIn() {
  1235. global $_W, $_GPC;
  1236. $user = pdo_get('zhtc_user', array('opneid' => $_GPC['openid']));
  1237. if (!$user) {
  1238. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1239. $date['user_id'] = $_GPC['user_id'];
  1240. $date['zf_user_id'] = $_GPC['zf_user_id'];
  1241. $date['money'] = $res['fx_money'];
  1242. $date['uniacid'] = $_W['uniacid'];
  1243. $list = pdo_get('zhtc_fx', $data);
  1244. if (!$list) {
  1245. $date['time'] = time();
  1246. $res2 = pdo_insert('zhtc_fx', $data);
  1247. pdo_update('zhtc_user', array('money +=' => $date['money']), array('id' => $_GPC['user_id']));
  1248. }
  1249. }
  1250. }
  1251. //领取红包
  1252. public function doPageGetHong() {
  1253. global $_W, $_GPC;
  1254. $res = pdo_get('zhtc_information', array('id' => $_GPC['id'])); //查找帖子
  1255. //判断红包个数
  1256. $list = pdo_getall('zhtc_hblq', array('tz_id' => $_GPC['id'], 'user_id' => $_GPC['user_id']));
  1257. $user = pdo_getall('zhtc_hblq', array('tz_id' => $_GPC['id']));
  1258. if (!$list and count($user) < $res['hb_num']) {
  1259. if ($res['hb_random'] == 1) {
  1260. $hong = json_decode($res['hong']);
  1261. $num = count($user);
  1262. $money = $hong[$num];
  1263. $data['user_id'] = $_GPC['user_id'];
  1264. $data['tz_id'] = $_GPC['id'];
  1265. $data['money'] = $money;
  1266. $data['time'] = time();
  1267. $data['uniacid'] = $_W['uniacid'];
  1268. $get = pdo_insert('zhtc_hblq', $data);
  1269. if ($get) {
  1270. pdo_update('zhtc_user', array('money +=' => $hong[$num]), array('id' => $_GPC['user_id']));
  1271. echo $hong[$num];
  1272. }
  1273. } else if ($res['hb_random'] == 2) {
  1274. $data['user_id'] = $_GPC['user_id'];
  1275. $data['tz_id'] = $_GPC['id'];
  1276. $data['money'] = $res['hb_money'];
  1277. $data['time'] = time();
  1278. $data['uniacid'] = $_W['uniacid'];
  1279. $get = pdo_insert('zhtc_hblq', $data);
  1280. if ($get) {
  1281. pdo_update('zhtc_user', array('money +=' => $data['money']), array('id' => $_GPC['user_id']));
  1282. echo $data['money'];
  1283. }
  1284. }
  1285. } else {
  1286. echo 'error';
  1287. }
  1288. }
  1289. //领取列表
  1290. public function doPageHongList() {
  1291. global $_W, $_GPC;
  1292. $sql = "select a.*,b.img,b.name from" . tablename("zhtc_hblq") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.tz_id=:tz_id ORDER BY a.id DESC";
  1293. $list = pdo_fetchall($sql, array(':tz_id' => $_GPC['id']));
  1294. echo json_encode($list);
  1295. }
  1296. //红包
  1297. public function doPageHong() {
  1298. global $_W, $_GPC;
  1299. function hongbao($money, $number, $ratio = 1) {
  1300. $res = array(); //结果数组
  1301. $min = 0.01; //最小值
  1302. $max = ($money / $number) * (1 + $ratio); //最大值
  1303. /*--- 第一步:分配低保 ---*/
  1304. for ($i = 0; $i < $number; $i++) {
  1305. $res[$i] = $min;
  1306. }
  1307. $money = $money - $min * $number;
  1308. /*--- 第二步:随机分配 ---*/
  1309. $randRatio = 100;
  1310. $randMax = ($max - $min) * $randRatio;
  1311. for ($i = 0; $i < $number; $i++) {
  1312. //随机分钱
  1313. $randRes = mt_rand(0, $randMax);
  1314. $randRes = $randRes / $randRatio;
  1315. if ($money >= $randRes) {
  1316. //余额充足
  1317. $res[$i] += $randRes;
  1318. $money -= $randRes;
  1319. } elseif ($money > 0) {
  1320. //余额不足
  1321. $res[$i] += $money;
  1322. $money -= $money;
  1323. } else {
  1324. //没有余额
  1325. break;
  1326. }
  1327. }
  1328. /*--- 第三步:平均分配上一步剩余 ---*/
  1329. if ($money > 0) {
  1330. $avg = $money / $number;
  1331. for ($i = 0; $i < $number; $i++) {
  1332. $res[$i] += $avg;
  1333. }
  1334. $money = 0;
  1335. }
  1336. /*--- 第四步:打乱顺序 ---*/
  1337. shuffle($res);
  1338. /*--- 第五步:格式化金额(可选) ---*/
  1339. foreach ($res as $k => $v) {
  1340. //两位小数,不四舍五入
  1341. preg_match('/^\d+(\.\d{1,2})?/', $v, $match);
  1342. $match[0] = number_format($match[0], 2);
  1343. $res[$k] = $match[0];
  1344. }
  1345. return $res;
  1346. }
  1347. print_r(hongbao(1, 5));
  1348. }
  1349. //提现
  1350. public function doPageTiXian() {
  1351. global $_W, $_GPC;
  1352. if ($_GPC['method'] == 1) {
  1353. $user = pdo_get('zhtc_user', array('id' => $_GPC['user_id']), 'money');
  1354. if ($user['money'] >= $_GPC['tx_cost']) {
  1355. $data['name'] = $_GPC['name']; //真实姓名
  1356. $data['username'] = $_GPC['username']; //账号
  1357. $data['type'] = $_GPC['type']; //type(1支付宝 2.微信 3.银行)
  1358. $data['tx_cost'] = $_GPC['tx_cost']; //提现金额
  1359. $data['sj_cost'] = $_GPC['sj_cost']; //实际到账金额
  1360. $data['user_id'] = $_GPC['user_id']; //用户id
  1361. $data['store_id'] = $_GPC['store_id']; //商家id
  1362. $data['bank'] = $_GPC['bank']; //银行
  1363. $data['method'] = $_GPC['method']; //1.红包 2.商家
  1364. $data['time'] = time();
  1365. $data['state'] = 1;
  1366. $data['uniacid'] = $_W['uniacid'];
  1367. $res = pdo_insert('zhtc_withdrawal', $data);
  1368. $txsh_id = pdo_insertid();
  1369. if ($res) {
  1370. pdo_update('zhtc_user', array('money -=' => $_GPC['tx_cost']), array('id' => $_GPC['user_id']));
  1371. }
  1372. }
  1373. }
  1374. if ($_GPC['method'] == 2) {
  1375. $store = pdo_get('zhtc_store', array('id' => $_GPC['store_id']), 'wallet');
  1376. if ($store['wallet'] >= $_GPC['tx_cost']) {
  1377. $data['name'] = $_GPC['name']; //真实姓名
  1378. $data['username'] = $_GPC['username']; //账号
  1379. $data['type'] = $_GPC['type']; //type(1支付宝 2.微信 3.银行)
  1380. $data['tx_cost'] = $_GPC['tx_cost']; //提现金额
  1381. $data['sj_cost'] = $_GPC['sj_cost']; //实际到账金额
  1382. $data['user_id'] = $_GPC['user_id']; //用户id
  1383. $data['store_id'] = $_GPC['store_id']; //商家id
  1384. $data['bank'] = $_GPC['bank']; //银行
  1385. $data['method'] = $_GPC['method']; //1.红包 2.商家
  1386. $data['time'] = time();
  1387. $data['state'] = 1;
  1388. $data['uniacid'] = $_W['uniacid'];
  1389. $res = pdo_insert('zhtc_withdrawal', $data);
  1390. $txsh_id = pdo_insertid();
  1391. if ($res) {
  1392. pdo_update('zhtc_store', array('wallet -=' => $_GPC['tx_cost']), array('id' => $_GPC['store_id']));
  1393. pdo_insert('zhtc_store_wallet', array('store_id' => $_GPC['store_id'], 'money' => $_GPC['tx_cost'], 'note' => '提现申请', 'type' => 2, 'time' => date("Y-m-d H:i:s"), 'tx_id' => $txsh_id));
  1394. }
  1395. }
  1396. }
  1397. echo $txsh_id;
  1398. }
  1399. //我的提现
  1400. public function doPageMyTiXian() {
  1401. global $_W, $_GPC;
  1402. $res = pdo_getall('zhtc_withdrawal', array('user_id' => $_GPC['user_id']));
  1403. echo json_encode($res);
  1404. }
  1405. //商家的提现
  1406. public function doPageStoreTiXian() {
  1407. global $_W, $_GPC;
  1408. $res = pdo_getall('zhtc_withdrawal', array('store_id' => $_GPC['store_id']));
  1409. echo json_encode($res);
  1410. }
  1411. //红包明细
  1412. public function doPageHbmx() {
  1413. global $_W, $_GPC;
  1414. $res = pdo_getall('zhtc_hblq', array('user_id' => $_GPC['user_id']), array(), '', 'time DESC');
  1415. echo json_encode($res);
  1416. }
  1417. //短信信息
  1418. public function doPageIsSms() {
  1419. global $_W, $_GPC;
  1420. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  1421. echo $res['is_open'];
  1422. }
  1423. //解密
  1424. public function doPageJiemi() {
  1425. global $_W, $_GPC;
  1426. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1427. include_once IA_ROOT . '/addons/zh_tcwq/wxBizDataCrypt.php';
  1428. $appid = $res['appid'];
  1429. $sessionKey = $_GPC['sessionKey'];
  1430. $encryptedData = $_GPC['data'];
  1431. $iv = $_GPC['iv'];
  1432. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1433. $errCode = $pc->decryptData($encryptedData, $iv, $data);
  1434. if ($errCode == 0) {
  1435. //echo json_encode($data);
  1436. print($data . "\n");
  1437. } else {
  1438. print($errCode . "\n");
  1439. }
  1440. }
  1441. //资讯分类
  1442. public function doPageZxType() {
  1443. global $_W, $_GPC;
  1444. $res = pdo_getall('zhtc_zx_type', array('uniacid' => $_W['uniacid']), array(), '', 'sort asc');
  1445. echo json_encode($res);
  1446. }
  1447. //资讯
  1448. public function doPageZx() {
  1449. global $_W, $_GPC;
  1450. $res = pdo_get('zhtc_sensitive', array('uniacid' => $_W['uniacid']));
  1451. if ($res) {
  1452. $res['content'] = "/" . str_replace(",", "|", $res['content']) . "/";
  1453. $content = preg_replace($res['content'], "***", $_GPC['content']); //内容
  1454. } else {
  1455. $content = $_GPC['content'];
  1456. }
  1457. $data['type_id'] = $_GPC['type_id']; //分类id
  1458. $data['type'] = 1; //1前台发布
  1459. $data['user_id'] = $_GPC['user_id']; //发布人id
  1460. $data['title'] = $_GPC['title']; //标题
  1461. $data['content'] = $content; //内容
  1462. $data['imgs'] = $_GPC['imgs']; //图片
  1463. $data['time'] = date('Y-m-d H:i:s'); //发布时间
  1464. $data['cityname'] = $_GPC['cityname'];
  1465. $data['video'] = $_GPC['video'];
  1466. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1467. if ($system['is_zx'] == 1) {
  1468. $data['state'] = 1;
  1469. } else {
  1470. $data['state'] = 2;
  1471. }
  1472. $data['uniacid'] = $_W['uniacid'];
  1473. $res = pdo_insert('zhtc_zx', $data);
  1474. if ($res) {
  1475. echo '1';
  1476. } else {
  1477. echo '2';
  1478. }
  1479. }
  1480. //资讯列表
  1481. public function doPageZxList() {
  1482. global $_W, $_GPC;
  1483. //查看资讯设置
  1484. $zxset = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), 'zx_type');
  1485. $pageindex = max(1, intval($_GPC['page']));
  1486. $pagesize = 10;
  1487. $where = " where a.uniacid=:uniacid and a.state=2";
  1488. $data[':uniacid'] = $_W['uniacid'];
  1489. if ($_GPC['type_id']) {
  1490. $where .= " and a.type_id=:type_id";
  1491. $data[':type_id'] = $_GPC['type_id'];
  1492. }
  1493. if ($zxset['zx_type'] == 2) {
  1494. if ($_GPC['cityname']) {
  1495. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='' ) ";
  1496. $data[':name'] = $_GPC['cityname'];
  1497. }
  1498. }
  1499. $sql = "select a.*,b.img,b.name,c.type_name from" . tablename("zhtc_zx") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_zx_type") . " c on a.type_id=c.id" . $where . " ORDER BY a.id DESC";
  1500. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  1501. $res = pdo_fetchall($select_sql, $data);
  1502. $name_list = '';
  1503. $name_list = array_map('array_shift', $res);
  1504. $sys = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), 'sj_max');
  1505. $rand = empty($sys['sj_max']) ? 1 : $sys['sj_max'];
  1506. pdo_update('zhtc_zx', array('yd_num +=' => rand(1, $rand)), array('id' => $name_list));
  1507. echo json_encode($res);
  1508. }
  1509. //资讯详情
  1510. public function doPageZxInfo() {
  1511. global $_W, $_GPC;
  1512. pdo_update('zhtc_zx', array('yd_num +=' => 1), array('id' => $_GPC['id']));
  1513. $sql = "select a.*,b.img,b.name,c.type_name from" . tablename("zhtc_zx") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . " left join " . tablename("zhtc_zx_type") . " c on a.type_id=c.id WHERE a.id=:id ORDER BY a.id DESC";
  1514. $res = pdo_fetch($sql, array(':id' => $_GPC['id']));
  1515. //查看是否点赞
  1516. $dz = pdo_get('zhtc_like', array('zx_id' => $_GPC['id'], 'user_id' => $_GPC['user_id']));
  1517. if ($dz) {
  1518. $res['dz'] = 1;
  1519. } else {
  1520. $res['dz'] = 2;
  1521. }
  1522. function video($video) {
  1523. $vid = trim(strrchr($video, '/'), '/');
  1524. $vid = substr($vid, 0, -5);
  1525. $json = file_get_contents("http://vv.video.qq.com/getinfo?vids=" . $vid . "&platform=101001&charge=0&otype=json");
  1526. // echo $json;die;
  1527. $json = substr($json, 13);
  1528. $json = substr($json, 0, -1);
  1529. $a = json_decode(html_entity_decode($json));
  1530. $sz = json_decode(json_encode($a), true);
  1531. // print_R($sz);die;
  1532. $url = $sz['vl']['vi']['0']['ul']['ui']['0']['url'];
  1533. $fn = $sz['vl']['vi']['0']['fn'];
  1534. $fvkey = $sz['vl']['vi']['0']['fvkey'];
  1535. $url = $url . $fn . '?vkey=' . $fvkey;
  1536. return $url;
  1537. }
  1538. $res['video'] = video($res['video']);
  1539. echo json_encode($res);
  1540. }
  1541. //资讯评论
  1542. public function doPageZxPl() {
  1543. global $_W, $_GPC;
  1544. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), array('is_zxplsh'));
  1545. if ($system['is_zxplsh'] == 1) {
  1546. $data['state'] = 1;
  1547. } else {
  1548. $data['state'] = 2;
  1549. }
  1550. $data['zx_id'] = $_GPC['zx_id']; //资讯id
  1551. $data['content'] = $_GPC['content']; //回复内容
  1552. $data['cerated_time'] = date("Y-m-d H:i:s");
  1553. $data['user_id'] = $_GPC['user_id']; //用户id
  1554. $data['status'] = 1;
  1555. $data['uniacid'] = $_W['uniacid'];
  1556. $res = pdo_insert('zhtc_zx_assess', $data);
  1557. if ($res) {
  1558. echo '1';
  1559. } else {
  1560. echo '2';
  1561. }
  1562. }
  1563. //回复
  1564. public function doPageZxHf() {
  1565. global $_W, $_GPC;
  1566. $data['reply'] = $_GPC['reply']; //回复内容
  1567. $data['status'] = 2;
  1568. $data['reply_time'] = date("Y-m-d H:i:s");
  1569. $res = pdo_update('zhtc_zx_assess', $data, array('id' => $_GPC['id']));
  1570. if ($res) {
  1571. echo '1';
  1572. } else {
  1573. echo '2';
  1574. }
  1575. }
  1576. //评论列表
  1577. public function doPageZxPlList() {
  1578. global $_W, $_GPC;
  1579. $sql = "select a.*,b.img as user_img,b.name from " . tablename("zhtc_zx_assess") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.zx_id=:zx_id and a.state=2 ORDER BY a.id DESC";
  1580. $res = pdo_fetchall($sql, array(':zx_id' => $_GPC['zx_id']));
  1581. echo json_encode($res);
  1582. }
  1583. //足迹
  1584. public function doPageFootprint() {
  1585. global $_W, $_GPC;
  1586. $data['user_id'] = $_GPC['user_id'];
  1587. $data['zx_id'] = $_GPC['zx_id'];
  1588. $data['uniacid'] = $_W['uniacid'];
  1589. $data['time'] = time();
  1590. $list = pdo_get('zhtc_zx_zj', array('user_id' => $_GPC['user_id'], 'zx_id' => $_GPC['zx_id']));
  1591. if ($list) {
  1592. $res = pdo_update('zhtc_zx_zj', array('time' => time()), array('id' => $list['id']));
  1593. if ($res) {
  1594. echo '1';
  1595. } else {
  1596. echo '2';
  1597. }
  1598. } else {
  1599. $res = pdo_insert('zhtc_zx_zj', $data);
  1600. if ($res) {
  1601. echo '1';
  1602. } else {
  1603. echo '2';
  1604. }
  1605. }
  1606. }
  1607. //我的足迹
  1608. public function doPageMyFootprint() {
  1609. global $_W, $_GPC;
  1610. $sql = "select a.*,b.title,b.imgs,b.time as zx_time,c.type_name,d.name as user_name,d.img as user_img from " . tablename("zhtc_zx_zj") . " a" . " left join " . tablename("zhtc_zx") . " b on b.id=a.zx_id " . " left join " . tablename("zhtc_zx_type") . " c on b.type_id=c.id " . " left join " . tablename("zhtc_user") . " d on b.user_id=d.id WHERE a.user_id=:user_id ORDER BY a.time DESC";
  1611. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  1612. echo json_encode($res);
  1613. }
  1614. //商家二维码
  1615. public function doPageStoreCode() {
  1616. global $_W, $_GPC;
  1617. function getCoade($storeid) {
  1618. function getaccess_token() {
  1619. global $_W, $_GPC;
  1620. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1621. $appid = $res['appid'];
  1622. $secret = $res['appsecret'];
  1623. // print_r($res);die;
  1624. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  1625. $ch = curl_init();
  1626. curl_setopt($ch, CURLOPT_URL, $url);
  1627. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1628. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1629. $data = curl_exec($ch);
  1630. curl_close($ch);
  1631. $data = json_decode($data, true);
  1632. return $data['access_token'];
  1633. }
  1634. function set_msg($storeid) {
  1635. $access_token = getaccess_token();
  1636. $data2 = array(
  1637. "scene" => $storeid,
  1638. "page" => "zh_tcwq/pages/sellerinfo/sellerinfo",
  1639. "width" => 400,
  1640. );
  1641. $data2 = json_encode($data2);
  1642. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  1643. $ch = curl_init();
  1644. curl_setopt($ch, CURLOPT_URL, $url);
  1645. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1646. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1647. curl_setopt($ch, CURLOPT_POST, 1);
  1648. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  1649. $data = curl_exec($ch);
  1650. curl_close($ch);
  1651. return $data;
  1652. }
  1653. $img = set_msg($storeid);
  1654. $img = base64_encode($img);
  1655. return $img;
  1656. }
  1657. $base64 = getCoade($_GPC['store_id']);
  1658. $base64_image_content = "data:image/jpeg;base64," . $base64;
  1659. $ename = 'tcsj' . $_GPC['store_id'];
  1660. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  1661. $type = $result[2];
  1662. $new_file = IA_ROOT . "/addons/zh_tcwq/inc/upload/";
  1663. if (!file_exists($new_file)) {
  1664. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1665. mkdir($new_file, 0777);
  1666. }
  1667. $wname = $ename . ".{$type}";
  1668. //$wname="1511.jpeg";
  1669. $new_file = $new_file . $wname;
  1670. //$new_file = $new_file.$ename;
  1671. if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))) {
  1672. //echo $new_file;
  1673. } else {
  1674. echo '新文件保存失败';
  1675. }
  1676. }
  1677. echo $_W['siteroot'] . "addons/zh_tcwq/inc/upload/tcsj{$_GPC['store_id']}.jpeg";
  1678. }
  1679. //商家商品二维码
  1680. public function doPageStoreGoodCode() {
  1681. global $_W, $_GPC;
  1682. function getCoade($storeid) {
  1683. function getaccess_token() {
  1684. global $_W, $_GPC;
  1685. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1686. $appid = $res['appid'];
  1687. $secret = $res['appsecret'];
  1688. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  1689. $ch = curl_init();
  1690. curl_setopt($ch, CURLOPT_URL, $url);
  1691. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1692. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1693. $data = curl_exec($ch);
  1694. curl_close($ch);
  1695. $data = json_decode($data, true);
  1696. return $data['access_token'];
  1697. }
  1698. function set_msg($storeid) {
  1699. $access_token = getaccess_token();
  1700. $data2 = array(
  1701. "scene" => $storeid,
  1702. "page" => "zh_tcwq/pages/sellerinfo/good_info",
  1703. "width" => 400,
  1704. );
  1705. $data2 = json_encode($data2);
  1706. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  1707. $ch = curl_init();
  1708. curl_setopt($ch, CURLOPT_URL, $url);
  1709. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1710. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1711. curl_setopt($ch, CURLOPT_POST, 1);
  1712. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  1713. $data = curl_exec($ch);
  1714. curl_close($ch);
  1715. return $data;
  1716. }
  1717. $img = set_msg($storeid);
  1718. $img = base64_encode($img);
  1719. return $img;
  1720. }
  1721. $base64 = getCoade($_GPC['store_id']);
  1722. $base64_image_content = "data:image/jpeg;base64," . $base64;
  1723. $ename = 'tcsp' . $_GPC['store_id'];
  1724. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  1725. $type = $result[2];
  1726. $new_file = IA_ROOT . "/addons/zh_tcwq/inc/upload/";
  1727. if (!file_exists($new_file)) {
  1728. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  1729. mkdir($new_file, 0777);
  1730. }
  1731. $wname = $ename . ".{$type}";
  1732. //$wname="1511.jpeg";
  1733. $new_file = $new_file . $wname;
  1734. //$new_file = $new_file.$ename;
  1735. if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))) {
  1736. //echo $new_file;
  1737. } else {
  1738. echo '新文件保存失败';
  1739. }
  1740. }
  1741. echo $_W['siteroot'] . "addons/zh_tcwq/inc/upload/tcsp{$_GPC['store_id']}.jpeg";
  1742. }
  1743. //查看标签
  1744. public function doPageCarTag() {
  1745. global $_W, $_GPC;
  1746. $res = pdo_getall('zhtc_car_tag', array('typename' => $_GPC['typename'], 'uniacid' => $_W['uniacid']));
  1747. echo json_encode($res);
  1748. }
  1749. //发布拼车
  1750. public function doPageCar() {
  1751. global $_W, $_GPC;
  1752. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1753. $data['user_id'] = $_GPC['user_id'];
  1754. $data['start_place'] = $_GPC['start_place'];
  1755. $data['end_place'] = $_GPC['end_place'];
  1756. $data['start_time'] = $_GPC['start_time'];
  1757. $data['start_time2'] = strtotime($_GPC['start_time']);
  1758. $data['num'] = $_GPC['num'];
  1759. $data['link_name'] = $_GPC['link_name'];
  1760. $data['link_tel'] = $_GPC['link_tel'];
  1761. $data['typename'] = $_GPC['typename'];
  1762. $data['other'] = $_GPC['other'];
  1763. $data['tj_place'] = $_GPC['tj_place'];
  1764. $data['hw_wet'] = $_GPC['hw_wet'];
  1765. $data['star_lat'] = $_GPC['star_lat'];
  1766. $data['star_lng'] = $_GPC['star_lng'];
  1767. $data['end_lat'] = $_GPC['end_lat'];
  1768. $data['end_lng'] = $_GPC['end_lng'];
  1769. $data['cityname'] = $_GPC['cityname'];
  1770. $data['is_open'] = 1;
  1771. $data['time'] = time();
  1772. $data['uniacid'] = $_W['uniacid'];
  1773. if ($system['is_car'] == 1) {
  1774. $data['state'] = 1;
  1775. } else {
  1776. $data['state'] = 2;
  1777. $data['sh_time'] = time();
  1778. }
  1779. $res = pdo_insert('zhtc_car', $data);
  1780. $post_id = pdo_insertid();
  1781. $a = json_decode(html_entity_decode($_GPC['sz']));
  1782. $sz = json_decode(json_encode($a), true);
  1783. // print_r($sz);die;
  1784. if ($res) {
  1785. for ($i = 0; $i < count($sz); $i++) {
  1786. $data2['tag_id'] = $sz[$i]['tag_id'];
  1787. $data2['car_id'] = $post_id;
  1788. $res2 = pdo_insert('zhtc_car_my_tag', $data2);
  1789. }
  1790. echo $post_id;
  1791. } else {
  1792. echo '2';
  1793. }
  1794. }
  1795. //我的拼车
  1796. public function doPageMyCar() {
  1797. global $_W, $_GPC;
  1798. $res = pdo_getall('zhtc_car', array('user_id' => $_GPC['user_id'], 'is_delete' => 2));
  1799. echo json_encode($res);
  1800. }
  1801. //拼车列表
  1802. public function doPageCarList() {
  1803. global $_W, $_GPC;
  1804. //UNIX_TIMESTAMP
  1805. $time = time();
  1806. pdo_update('zhtc_car', array('is_open' => 2), array('start_time2 <=' => $time));
  1807. $pageindex = max(1, intval($_GPC['page']));
  1808. $pagesize = 10;
  1809. $where = " where uniacid=:uniacid and state=2 and is_delete=2";
  1810. $data[':uniacid'] = $_W['uniacid'];
  1811. if ($_GPC['cityname']) {
  1812. $where .= " and cityname LIKE concat('%', :name,'%') ";
  1813. $data[':name'] = $_GPC['cityname'];
  1814. }
  1815. $sql = " select * from " . tablename('zhtc_car') . $where . " order by id DESC";
  1816. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  1817. $res = pdo_fetchall($select_sql, $data);
  1818. //$res=pdo_getall('zhtc_car',array('uniacid'=>$_W['uniacid'],'state'=>2),array(),'','id DESC');
  1819. $sql2 = "select a.*,b.tagname from " . tablename("zhtc_car_my_tag") . " a" . " left join " . tablename("zhtc_car_tag") . " b on b.id=a.car_id";
  1820. $res2 = pdo_fetchall($sql2);
  1821. // $res2=pdo_getall('zhtc_label',array('uniacid'=>$_W['uniacid']));
  1822. $data2 = array();
  1823. for ($i = 0; $i < count($res); $i++) {
  1824. $data = array();
  1825. for ($k = 0; $k < count($res2); $k++) {
  1826. if ($res[$i]['id'] == $res2[$k]['car_id']) {
  1827. $data[] = array(
  1828. 'tagname' => $res2[$k]['tagname'],
  1829. );
  1830. }
  1831. }
  1832. $data2[] = array(
  1833. 'tz' => $res[$i],
  1834. 'label' => $data,
  1835. );
  1836. }
  1837. echo json_encode($data2);
  1838. }
  1839. //分类拼车列表
  1840. public function doPageTypeCarList() {
  1841. global $_W, $_GPC;
  1842. $res = pdo_getall('zhtc_car', array('uniacid' => $_W['uniacid'], 'typename' => $_GPC['typename'], 'state' => 2), array(), '', 'id DESC');
  1843. $sql2 = "select a.*,b.tagname from " . tablename("zhtc_car_my_tag") . " a" . " left join " . tablename("zhtc_car_tag") . " b on b.id=a.tag_id";
  1844. $res2 = pdo_fetchall($sql2);
  1845. // $res2=pdo_getall('zhtc_label',array('uniacid'=>$_W['uniacid']));
  1846. $data2 = array();
  1847. for ($i = 0; $i < count($res); $i++) {
  1848. $data = array();
  1849. for ($k = 0; $k < count($res2); $k++) {
  1850. if ($res[$i]['id'] == $res2[$k]['car_id']) {
  1851. $data[] = array(
  1852. 'tagname' => $res2[$k]['tagname'],
  1853. );
  1854. }
  1855. }
  1856. $data2[] = array(
  1857. 'tz' => $res[$i],
  1858. 'label' => $data,
  1859. );
  1860. }
  1861. echo json_encode($data2);
  1862. }
  1863. //拼车详情
  1864. public function doPageCarInfo() {
  1865. global $_W, $_GPC;
  1866. $sql = "select a.*,b.name as user_name,b.img as user_img from " . tablename("zhtc_car") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id where a.id =:id";
  1867. $res = pdo_fetch($sql, array(':id' => $_GPC['id']));
  1868. $sql2 = "select a.*,b.tagname from " . tablename("zhtc_car_my_tag") . " a" . " left join " . tablename("zhtc_car_tag") . " b on b.id=a.tag_id where a.
  1869. car_id=:car_id";
  1870. $res2 = pdo_fetchall($sql2, array(':car_id' => $_GPC['id']));
  1871. // $res=pdo_getall('zhtc_car',array('id'=>$_GPC['id']));
  1872. $data['pc'] = $res;
  1873. $data['tag'] = $res2;
  1874. echo json_encode($data);
  1875. }
  1876. //关闭
  1877. public function doPageCarShut() {
  1878. global $_W, $_GPC;
  1879. $res = pdo_update('zhtc_car', array('is_open' => 2), array('id' => $_GPC['id']));
  1880. if ($res) {
  1881. echo '1';
  1882. } else {
  1883. echo '2';
  1884. }
  1885. }
  1886. //规格分类
  1887. public function doPageSpec() {
  1888. global $_W, $_GPC;
  1889. $res = pdo_getall('zhtc_goods_spec', array('uniacid' => $_W['uniacid']));
  1890. echo json_encode($res);
  1891. }
  1892. //发布商品
  1893. public function doPageAddGoods() {
  1894. global $_W, $_GPC;
  1895. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1896. $data['store_id'] = $_GPC['store_id']; //商家id
  1897. $data['goods_name'] = $_GPC['goods_name']; //商品名称
  1898. $data['goods_num'] = $_GPC['goods_num']; //商品数量
  1899. $data['goods_cost'] = $_GPC['goods_cost']; //商品价格
  1900. $data['freight'] = $_GPC['freight']; //运费
  1901. $data['delivery'] = $_GPC['delivery']; //关于发货
  1902. $data['quality'] = $_GPC['quality']; //正品1是,2否
  1903. $data['free'] = $_GPC['free']; //包邮1是,2否
  1904. $data['all_day'] = $_GPC['all_day']; //24小时发货1是,2否
  1905. $data['service'] = $_GPC['service']; //售后服务1是,2否
  1906. $data['refund'] = $_GPC['refund']; //极速退款1是,2否
  1907. $data['weeks'] = $_GPC['weeks']; //7天包邮1是,2否
  1908. $data['lb_imgs'] = $_GPC['lb_imgs']; //轮播图
  1909. $data['imgs'] = $_GPC['imgs']; //商品介绍图
  1910. $data['goods_details'] = $_GPC['goods_details']; //商品详细
  1911. $data['vr'] = $_GPC['vr']; //vr
  1912. $data['is_xs'] = $_GPC['is_xs']; //抢购
  1913. $data['end_time'] = $_GPC['end_time']; //结束时间
  1914. if ($system['is_goods'] == 1) {
  1915. $data['state'] = 1;
  1916. } else {
  1917. $data['state'] = 2;
  1918. }
  1919. $data['time'] = time();
  1920. $data['uniacid'] = $_W['uniacid'];
  1921. $res = pdo_insert('zhtc_goods', $data); //
  1922. $post_id = pdo_insertid();
  1923. if ($_GPC['sz']) {
  1924. $a = json_decode(html_entity_decode($_GPC['sz']));
  1925. $sz = json_decode(json_encode($a), true);
  1926. }
  1927. // print_r($sz);die;
  1928. if ($res) {
  1929. if ($_GPC['sz']) {
  1930. for ($i = 0; $i < count($sz); $i++) {
  1931. $data2['spec_id'] = $sz[$i]['spec_id'];
  1932. $data2['money'] = $sz[$i]['money'];
  1933. $data2['name'] = $sz[$i]['name'];
  1934. $data2['num'] = $sz[$i]['num'];
  1935. $data2['goods_id'] = $post_id;
  1936. $res2 = pdo_insert('zhtc_spec_value', $data2);
  1937. }
  1938. }
  1939. echo '1';
  1940. } else {
  1941. echo '2';
  1942. }
  1943. }
  1944. //修改商品
  1945. public function doPageUpdGoods() {
  1946. global $_W, $_GPC;
  1947. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  1948. $data['store_id'] = $_GPC['store_id']; //商家id
  1949. $data['goods_name'] = $_GPC['goods_name']; //商品名称
  1950. $data['goods_num'] = $_GPC['goods_num']; //商品数量
  1951. $data['goods_cost'] = $_GPC['goods_cost']; //商品价格
  1952. $data['freight'] = $_GPC['freight']; //运费
  1953. $data['delivery'] = $_GPC['delivery']; //关于发货
  1954. $data['quality'] = $_GPC['quality']; //正品1是,2否
  1955. $data['free'] = $_GPC['free']; //包邮1是,2否
  1956. $data['all_day'] = $_GPC['all_day']; //24小时发货1是,2否
  1957. $data['service'] = $_GPC['service']; //售后服务1是,2否
  1958. $data['refund'] = $_GPC['refund']; //极速退款1是,2否
  1959. $data['weeks'] = $_GPC['weeks']; //7天包邮1是,2否
  1960. $data['lb_imgs'] = $_GPC['lb_imgs']; //轮播图
  1961. $data['imgs'] = $_GPC['imgs']; //商品介绍图
  1962. $data['goods_details'] = $_GPC['goods_details']; //商品详细
  1963. $data['vr'] = $_GPC['vr']; //商品详细
  1964. if ($system['is_goods'] == 1) {
  1965. $data['state'] = 1;
  1966. } else {
  1967. $data['state'] = 2;
  1968. }
  1969. $data['time'] = time();
  1970. $data['uniacid'] = $_W['uniacid'];
  1971. $res = pdo_update('zhtc_goods', $data, array('id' => $_GPC['good_id'])); //
  1972. $post_id = pdo_insertid();
  1973. // if($_GPC['sz']){
  1974. // $a=json_decode(html_entity_decode($_GPC['sz']));
  1975. // $sz=json_decode(json_encode($a),true);
  1976. // }
  1977. // print_r($sz);die;
  1978. if ($res) {
  1979. // if($_GPC['sz']){
  1980. // for($i=0;$i<count($sz);$i++){
  1981. // $data2['spec_id']=$sz[$i]['spec_id'];
  1982. // $data2['money']=$sz[$i]['money'];
  1983. // $data2['name']=$sz[$i]['name'];
  1984. // $data2['num']=$sz[$i]['num'];
  1985. // $data2['goods_id']=$post_id ;
  1986. // $res2=pdo_insert('zhtc_spec_value',$data2);
  1987. // }
  1988. // }
  1989. echo '1';
  1990. } else {
  1991. echo '2';
  1992. }
  1993. }
  1994. //删除商品
  1995. public function doPageDelGood() {
  1996. global $_W, $_GPC;
  1997. $res = pdo_delete('zhtc_goods', array('id' => $_GPC['good_id']));
  1998. if ($res) {
  1999. $res = pdo_delete('zhtc_spec_value', array('goods_id' => $_GPC['good_id']));
  2000. echo '1';
  2001. } else {
  2002. echo '2';
  2003. }
  2004. }
  2005. //下架
  2006. public function doPageDownGood() {
  2007. global $_W, $_GPC;
  2008. $res = pdo_update('zhtc_goods', array('is_show' => 2), array('id' => $_GPC['good_id']));
  2009. if ($res) {
  2010. echo '1';
  2011. } else {
  2012. echo '2';
  2013. }
  2014. }
  2015. //上架
  2016. public function doPageUpGood() {
  2017. global $_W, $_GPC;
  2018. $res = pdo_update('zhtc_goods', array('is_show' => 1), array('id' => $_GPC['good_id']));
  2019. if ($res) {
  2020. echo '1';
  2021. } else {
  2022. echo '2';
  2023. }
  2024. }
  2025. //商品列表
  2026. public function doPageGoodList() {
  2027. global $_W, $_GPC;
  2028. $where = " WHERE uniacid={$_W['uniacid']} and state=2 and is_show=1 and store_id={$_GPC['store_id']}";
  2029. if ($_GPC['keywords']) {
  2030. $op = $_GPC['keywords'];
  2031. $where .= " and goods_name LIKE concat('%', :name,'%') ";
  2032. $data[':name'] = $op;
  2033. }
  2034. $sql = "select * from " . tablename("zhtc_goods") . " " . $where . " order by id desc ";
  2035. $res = pdo_fetchall($sql, $data);
  2036. echo json_encode($res);
  2037. }
  2038. //商家商品列表
  2039. public function doPageStoreGoodList() {
  2040. global $_W, $_GPC;
  2041. $res = pdo_getall('zhtc_goods', array('store_id' => $_GPC['store_id'], 'state' => 2), array(), '', 'id DESC');
  2042. echo json_encode($res);
  2043. }
  2044. //商家商品列表
  2045. public function doPageStoreGoodList2() {
  2046. global $_W, $_GPC;
  2047. $res = pdo_getall('zhtc_goods', array('store_id' => $_GPC['store_id'], 'state' => 2, 'is_show' => 1), array(), '', 'id DESC');
  2048. echo json_encode($res);
  2049. }
  2050. //商品详情
  2051. public function doPageGoodInfo() {
  2052. global $_W, $_GPC;
  2053. $res = pdo_get('zhtc_goods', array('id' => $_GPC['id']));
  2054. $sql = "select a.*,b.spec_name from " . tablename("zhtc_spec_value") . " a" . " left join " . tablename("zhtc_goods_spec") . " b on b.id=a.spec_id WHERE a.goods_id=:goods_id";
  2055. $res2 = pdo_fetchall($sql, array(':goods_id' => $_GPC['id']));
  2056. $data['good'] = $res;
  2057. $data['spec'] = $res2;
  2058. echo json_encode($data);
  2059. }
  2060. //下订单
  2061. public function doPageAddOrder() {
  2062. global $_W, $_GPC;
  2063. $data['user_id'] = $_GPC['user_id']; //用户id
  2064. $data['store_id'] = $_GPC['store_id']; //商家id
  2065. $data['money'] = $_GPC['money']; //订单金额
  2066. $data['user_name'] = $_GPC['user_name']; //用户名称
  2067. $data['address'] = $_GPC['address']; //地址
  2068. $data['tel'] = $_GPC['tel']; //电话
  2069. $data['good_id'] = $_GPC['good_id']; //商品id
  2070. $data['good_name'] = $_GPC['good_name']; //商品名称
  2071. $data['good_img'] = $_GPC['good_img']; //商品图片
  2072. $data['good_money'] = $_GPC['good_money']; //商品金额
  2073. $data['good_spec'] = $_GPC['good_spec']; //商品规格
  2074. $data['freight'] = $_GPC['freight']; //运费
  2075. $data['note'] = $_GPC['note']; //备注
  2076. $data['good_num'] = $_GPC['good_num']; //商品数量
  2077. $data['uniacid'] = $_W['uniacid'];
  2078. $data['time'] = time(); //下单时间
  2079. $data['order_num'] = date("YmdHis") . rand(1111, 9999); //订单号
  2080. $data['state'] = 1; //状态待付款
  2081. $data['del'] = 2;
  2082. $data['del2'] = 2;
  2083. $data['is_zt'] = $_GPC['is_zt'];
  2084. $data['zt_time'] = $_GPC['zt_time'];
  2085. $res = pdo_insert('zhtc_order', $data);
  2086. $post_id = pdo_insertid();
  2087. if ($res) {
  2088. echo $post_id;
  2089. } else {
  2090. echo '下单失败';
  2091. }
  2092. }
  2093. //付款改变订单状态
  2094. public function doPagePayOrder() {
  2095. global $_W, $_GPC;
  2096. //获取订单信息
  2097. $orderinfo = pdo_get('zhtc_order', array('id' => $_GPC['order_id']));
  2098. pdo_update('zhtc_goods', array('goods_num -=' => $orderinfo['good_num'], 'sales +=' => $orderinfo['good_num']), array('id' => $orderinfo['good_id']));
  2099. $res = pdo_update('zhtc_order', array('state' => 2, 'pay_time' => time()), array('id' => $_GPC['order_id']));
  2100. if ($res) {
  2101. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=xdMessage&m=zh_tcwq&order_id=" . $_GPC['order_id']); //模板消息
  2102. echo '1';
  2103. } else {
  2104. echo '2';
  2105. }
  2106. }
  2107. //发货
  2108. public function doPageDeliveryOrder() {
  2109. global $_W, $_GPC;
  2110. $res = pdo_update('zhtc_order', array('state' => 3, 'fh_time' => time(), 'kd_num' => $_GPC['kd_num'], 'kd_name' => $_GPC['kd_name']), array('id' => $_GPC['order_id']));
  2111. if ($res) {
  2112. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=fhMessage&m=zh_tcwq&order_id=" . $_GPC['order_id']); //模板消息
  2113. echo '1';
  2114. } else {
  2115. echo '2';
  2116. }
  2117. }
  2118. //退款审核
  2119. public function doPageRefundOrder() {
  2120. global $_W, $_GPC;
  2121. $id = $_GPC['order_id'];
  2122. $order = pdo_get('zhtc_order', array('id' => $id));
  2123. if ($order['state'] != 5) {
  2124. echo '订单状态异常';
  2125. }
  2126. if ($_GPC['type'] == 1) {
  2127. include_once IA_ROOT . '/addons/zh_tcwq/cert/WxPay.Api.php';
  2128. load()->model('account');
  2129. load()->func('communication');
  2130. $WxPayApi = new WxPayApi();
  2131. $input = new WxPayRefund();
  2132. $path_cert = IA_ROOT . "/addons/zh_tcwq/cert/" . 'apiclient_cert_' . $_W['uniacid'] . '.pem';
  2133. $path_key = IA_ROOT . "/addons/zh_tcwq/cert/" . 'apiclient_key_' . $_W['uniacid'] . '.pem';
  2134. $account_info = $_W['account'];
  2135. $refund_order = pdo_get('zhtc_order', array('id' => $id));
  2136. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2137. $appid = $res['appid'];
  2138. $key = $res['wxkey'];
  2139. $mchid = $res['mchid'];
  2140. $out_trade_no = $refund_order['out_trade_no'];
  2141. $fee = $refund_order['money'] * 100;
  2142. $input->SetAppid($appid);
  2143. $input->SetMch_id($mchid);
  2144. $input->SetOp_user_id($mchid);
  2145. $input->SetRefund_fee($fee);
  2146. $input->SetTotal_fee($fee);
  2147. $input->SetOut_refund_no($id);
  2148. $input->SetOut_trade_no($out_trade_no);
  2149. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  2150. if ($result['result_code'] == 'SUCCESS') {
  2151. pdo_update('zhtc_order', array('state' => 6), array('id' => $id));
  2152. echo '1';
  2153. } else {
  2154. echo $result['return_msg'];
  2155. }
  2156. } else {
  2157. $res = pdo_update('zhtc_order', array('state' => 7), array('id' => $id));
  2158. if ($res) {
  2159. echo '1';
  2160. } else {
  2161. echo '2';
  2162. }
  2163. }
  2164. }
  2165. //确认收货
  2166. public function doPageCompleteOrder() {
  2167. global $_W, $_GPC;
  2168. $order = pdo_get('zhtc_order', array('id' => $_GPC['order_id']));
  2169. $res = pdo_update('zhtc_order', array('state' => 4, 'complete_time' => time()), array('id' => $_GPC['order_id']));
  2170. if ($res) {
  2171. pdo_update('zhtc_store', array('wallet +=' => $order['money']), array('id' => $order['store_id']));
  2172. $data['store_id'] = $order['store_id'];
  2173. $data['money'] = $order['money'];
  2174. $data['note'] = '商品订单';
  2175. $data['type'] = 1;
  2176. $data['time'] = date("Y-m-d H:i:s");
  2177. pdo_insert('zhtc_store_wallet', $data);
  2178. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2179. if ($system['good_jf'] > 0) {
  2180. pdo_update('zhtc_user', array('total_score +=' => $system['good_jf']), array('id' => $order['user_id']));
  2181. $data2['score'] = $system['good_jf'];
  2182. $data2['user_id'] = $order['user_id'];
  2183. $data2['tid'] = $order['id'];
  2184. $data2['note'] = '商品订单';
  2185. $data2['type'] = 1;
  2186. $data2['cerated_time'] = date('Y-m-d H:i:s');
  2187. $data2['uniacid'] = $_W['uniacid']; //小程序id
  2188. pdo_insert('zhtc_integral', $data2); //添加积分明细
  2189. }
  2190. echo '1';
  2191. } else {
  2192. echo '2';
  2193. }
  2194. }
  2195. //查看商家余额明细
  2196. public function doPageStoreWallet() {
  2197. global $_W, $_GPC;
  2198. $res = pdo_getall('zhtc_store_wallet', array('store_id' => $_GPC['store_id']), array(), '', 'id DESC');
  2199. echo json_encode($res);
  2200. }
  2201. //查看我的订单
  2202. public function doPageMyOrder() {
  2203. global $_W, $_GPC;
  2204. // $pageindex = max(1, intval($_GPC['page']));
  2205. // $pagesize=10;
  2206. $sql = "select a.*,b.store_name from " . tablename("zhtc_order") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id WHERE a.user_id=:user_id and a.del=2 order by id DESC";
  2207. // $select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
  2208. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  2209. // $res=pdo_getall('zhtc_order',array('user_id'=>$_GPC['user_id'],'del'=>2));
  2210. echo json_encode($res);
  2211. }
  2212. //查看订单详情
  2213. public function doPageOrderInfo() {
  2214. global $_W, $_GPC;
  2215. $sql = "select a.*,b.store_name from " . tablename("zhtc_order") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id WHERE a.id=:id ";
  2216. $res = pdo_fetch($sql, array(':id' => $_GPC['order_id']));
  2217. function getCoade($storeid) {
  2218. function getaccess_token() {
  2219. global $_W, $_GPC;
  2220. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2221. $appid = $res['appid'];
  2222. $secret = $res['appsecret'];
  2223. // print_r($res);die;
  2224. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  2225. $ch = curl_init();
  2226. curl_setopt($ch, CURLOPT_URL, $url);
  2227. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2228. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2229. $data = curl_exec($ch);
  2230. curl_close($ch);
  2231. $data = json_decode($data, true);
  2232. return $data['access_token'];
  2233. }
  2234. function set_msg($storeid) {
  2235. $access_token = getaccess_token();
  2236. $data2 = array(
  2237. "scene" => $storeid,
  2238. "page" => "zh_tcwq/pages/logs/hxorder",
  2239. "width" => 400,
  2240. );
  2241. $data2 = json_encode($data2);
  2242. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  2243. $ch = curl_init();
  2244. curl_setopt($ch, CURLOPT_URL, $url);
  2245. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2246. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2247. curl_setopt($ch, CURLOPT_POST, 1);
  2248. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  2249. $data = curl_exec($ch);
  2250. curl_close($ch);
  2251. return $data;
  2252. }
  2253. $img = set_msg($storeid);
  2254. $img = base64_encode($img);
  2255. return $img;
  2256. }
  2257. $res['code_url'] = getCoade($_GPC['order_id']);
  2258. echo json_encode($res);
  2259. }
  2260. //核销订单
  2261. public function doPageHxOrder() {
  2262. global $_W, $_GPC;
  2263. $order = pdo_get('zhtc_order', array('id' => $_GPC['order_id']));
  2264. if ($order['store_id'] == $_GPC['store_id']) {
  2265. $res = pdo_update('zhtc_order', array('state' => 4), array('id' => $_GPC['order_id']));
  2266. if ($res) {
  2267. pdo_update('zhtc_store', array('wallet +=' => $order['money']), array('id' => $order['store_id']));
  2268. $data['store_id'] = $order['store_id'];
  2269. $data['money'] = $order['money'];
  2270. $data['note'] = '商品订单';
  2271. $data['type'] = 1;
  2272. $data['time'] = date("Y-m-d H:i:s");
  2273. pdo_insert('zhtc_store_wallet', $data);
  2274. echo '核销成功!';
  2275. } else {
  2276. echo '核销失败!';
  2277. }
  2278. } else {
  2279. echo '无核销权限!';
  2280. }
  2281. }
  2282. //更新用户地址信息
  2283. public function doPageUpdAdd() {
  2284. global $_W, $_GPC;
  2285. $data['user_name'] = $_GPC['user_name'];
  2286. $data['user_tel'] = $_GPC['user_tel'];
  2287. $data['user_address'] = $_GPC['user_address'];
  2288. $res = pdo_update('zhtc_user', $data, array('id' => $_GPC['user_id']));
  2289. if ($res) {
  2290. echo '1';
  2291. } else {
  2292. echo '2';
  2293. }
  2294. }
  2295. //用户删除订单
  2296. public function doPageDelOrder() {
  2297. global $_W, $_GPC;
  2298. $res = pdo_update('zhtc_order', array('del' => 1), array('id' => $_GPC['order_id']));
  2299. if ($res) {
  2300. echo '1';
  2301. } else {
  2302. echo '2';
  2303. }
  2304. }
  2305. //商家删除订单
  2306. public function doPageDelOrder2() {
  2307. global $_W, $_GPC;
  2308. $res = pdo_update('zhtc_order', array('del2' => 1), array('id' => $_GPC['order_id']));
  2309. if ($res) {
  2310. echo '1';
  2311. } else {
  2312. echo '2';
  2313. }
  2314. }
  2315. //商家订单列表
  2316. public function doPageStoreOrder() {
  2317. global $_W, $_GPC;
  2318. $sql = "select a.*,b.name,b.img from " . tablename("zhtc_order") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.store_id=:store_id and a.del2=2";
  2319. $res = pdo_fetchall($sql, array(':store_id' => $_GPC['store_id']));
  2320. echo json_encode($res);
  2321. }
  2322. //商家订单详情
  2323. public function doPageStoreOrderInfo() {
  2324. global $_W, $_GPC;
  2325. $sql = "select a.*,b.name,b.img from " . tablename("zhtc_order") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.id=:order_id and a.del2=2";
  2326. $res = pdo_fetch($sql, array(':order_id' => $_GPC['order_id']));
  2327. echo json_encode($res);
  2328. }
  2329. //申请退款
  2330. public function doPageTuOrder() {
  2331. global $_W, $_GPC;
  2332. $res = pdo_update('zhtc_order', array('state' => 5), array('id' => $_GPC['order_id']));
  2333. if ($res) {
  2334. echo '1';
  2335. } else {
  2336. echo '2';
  2337. }
  2338. }
  2339. //申请分销商
  2340. public function doPageDistribution() {
  2341. global $_W, $_GPC;
  2342. pdo_delete('zhtc_distribution', array('user_id' => $_GPC['user_id']));
  2343. $set = pdo_get('zhtc_fxset', array('uniacid' => $_W['uniacid']));
  2344. $data['user_id'] = $_GPC['user_id'];
  2345. $data['user_name'] = $_GPC['user_name'];
  2346. $data['user_tel'] = $_GPC['user_tel'];
  2347. $data['level'] = $_GPC['level'];
  2348. $fxlevel = pdo_get('zhtc_fxlevel', array('id' => $_GPC['level'], 'uniacid' => $_W['uniacid']));
  2349. $data['cityname'] = $_GPC['cityname'];
  2350. $data['money'] = $fxlevel['money'];
  2351. $data['is_log'] = 2;
  2352. $data['time'] = time();
  2353. if ($set['is_fx'] == 1) {
  2354. $data['state'] = 2;
  2355. } else {
  2356. $data['state'] = 1;
  2357. }
  2358. if ($_GPC['money']) {
  2359. $data['pay_state'] = 1;
  2360. } else {
  2361. $data2['user_id'] = $_GPC['user_id'];
  2362. $data2['money'] = $_GPC['money'];
  2363. $data2['time'] = date("Y-m-d H:i:s");
  2364. $data2['level'] = $_GPC['level'];
  2365. $data2['uniacid'] = $_W['uniacid'];
  2366. $data2['state'] = 2;
  2367. $data2['note'] = '申请分销商';
  2368. pdo_insert('zhtc_fxlog', $data2);
  2369. $data['pay_state'] = 2;
  2370. }
  2371. $data['uniacid'] = $_W['uniacid'];
  2372. $res = pdo_insert('zhtc_distribution', $data);
  2373. $order = pdo_insertid();
  2374. if ($res) {
  2375. $fx = pdo_get('zhtc_fxuser', array('fx_user' => $_GPC['user_id']));
  2376. if ($set['is_fx'] == 1 and !$fx) {
  2377. pdo_insert("zhtc_fxuser", array('user_id' => 0, 'fx_user' => $_GPC['user_id'], 'time' => time()));
  2378. }
  2379. echo $order;
  2380. } else {
  2381. echo '下单失败!';
  2382. }
  2383. }
  2384. //分销商支付
  2385. public function doPagePay2() {
  2386. global $_W, $_GPC;
  2387. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  2388. // include 'wxpay.php';
  2389. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2390. if ($res['pt_name']) {
  2391. $res['pt_name'] = $res['pt_name'];
  2392. } else {
  2393. $res['pt_name'] = '同城小程序';
  2394. }
  2395. $appid = $res['appid'];
  2396. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  2397. $mch_id = $res['mchid'];
  2398. $key = $res['wxkey'];
  2399. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  2400. $out_trade_no = time() . $user['id'];
  2401. $root = $_W['siteroot'];
  2402. pdo_update('zhtc_distribution', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  2403. $rst = pdo_get('zhtc_distribution', array('id' => $_GPC['order_id']), 'money');
  2404. //$total_fee =$_GPC['money'];
  2405. $total_fee = $rst['money'];
  2406. if (empty($total_fee)) //押金
  2407. {
  2408. $body = $res['pt_name'];
  2409. $total_fee = floatval(99 * 100);
  2410. } else {
  2411. $body = $res['pt_name'];
  2412. $total_fee = floatval($total_fee * 100);
  2413. }
  2414. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  2415. $return = $weixinpay->pay();
  2416. echo json_encode($return);
  2417. }
  2418. //查看我的申请
  2419. public function doPageMyDistribution() {
  2420. global $_W, $_GPC;
  2421. $sql = "select a.* ,b.name,d.name as sj_name from " . tablename("zhtc_distribution") . " a" . " left join " . tablename("zhtc_fxlevel") . " b on b.id=a.level left join " . tablename("zhtc_fxuser") . " c on c.fx_user=a.user_id left join " . tablename("zhtc_user") . " d on d.id=c.user_id WHERE a.user_id=:user_id and a.pay_state=2";
  2422. $res = pdo_fetch($sql, array(':user_id' => $_GPC['user_id']));
  2423. echo json_encode($res);
  2424. }
  2425. //分销设置
  2426. public function doPageFxSet() {
  2427. global $_W, $_GPC;
  2428. $res = pdo_get('zhtc_fxset', array('uniacid' => $_W['uniacid']));
  2429. echo json_encode($res);
  2430. }
  2431. //分销等级
  2432. public function doPageFxLevel() {
  2433. global $_W, $_GPC;
  2434. $res = pdo_getall('zhtc_fxlevel', array('uniacid' => $_W['uniacid']), array(), '', 'num asc');
  2435. echo json_encode($res);
  2436. }
  2437. //查看我的上线
  2438. public function doPageMySx() {
  2439. global $_W, $_GPC;
  2440. $sql = "select a.* ,b.name from " . tablename("zhtc_fxuser") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.fx_user=:fx_user ";
  2441. $res = pdo_fetch($sql, array(':fx_user' => $_GPC['user_id']));
  2442. echo json_encode($res);
  2443. }
  2444. //查看我的佣金收益
  2445. public function doPageEarnings() {
  2446. global $_W, $_GPC;
  2447. $sql = "select a.* ,b.name,b.img from " . tablename("zhtc_earnings") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.son_id WHERE a.user_id=:user_id order by id DESC";
  2448. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  2449. echo json_encode($res);
  2450. }
  2451. //我的二维码
  2452. public function doPageMyCode() {
  2453. global $_W, $_GPC;
  2454. function getCoade($storeid) {
  2455. function getaccess_token() {
  2456. global $_W, $_GPC;
  2457. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2458. $appid = $res['appid'];
  2459. $secret = $res['appsecret'];
  2460. // print_r($res);die;
  2461. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  2462. $ch = curl_init();
  2463. curl_setopt($ch, CURLOPT_URL, $url);
  2464. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2465. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2466. $data = curl_exec($ch);
  2467. curl_close($ch);
  2468. $data = json_decode($data, true);
  2469. return $data['access_token'];
  2470. }
  2471. function set_msg($storeid) {
  2472. $access_token = getaccess_token();
  2473. $data2 = array(
  2474. "scene" => $storeid,
  2475. "page" => "zh_tcwq/pages/index/index",
  2476. "width" => 400,
  2477. );
  2478. $data2 = json_encode($data2);
  2479. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  2480. $ch = curl_init();
  2481. curl_setopt($ch, CURLOPT_URL, $url);
  2482. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2483. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2484. curl_setopt($ch, CURLOPT_POST, 1);
  2485. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  2486. $data = curl_exec($ch);
  2487. curl_close($ch);
  2488. return $data;
  2489. }
  2490. $img = set_msg($storeid);
  2491. $img = base64_encode($img);
  2492. return $img;
  2493. }
  2494. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['user_id']);
  2495. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  2496. $type = $result[2];
  2497. $new_file = IA_ROOT . "/addons/zh_tcwq/img/";
  2498. if (!file_exists($new_file)) {
  2499. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  2500. mkdir($new_file, 0777);
  2501. }
  2502. $wname = "{$_GPC['user_id']}" . ".{$type}";
  2503. //$wname="1511.jpeg";
  2504. $new_file = $new_file . $wname;
  2505. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  2506. }
  2507. echo $_W['siteroot'] . "/addons/zh_tcwq/img/" . $wname;
  2508. }
  2509. //佣金提现
  2510. public function doPageYjtx() {
  2511. global $_W, $_GPC;
  2512. $user = pdo_get('zhtc_user', array('id' => $_GPC['user_id']));
  2513. if ($user['commission'] < $_GPC['tx_cost']) {
  2514. echo '2';
  2515. } else {
  2516. $data['user_id'] = $_GPC['user_id'];
  2517. $data['type'] = $_GPC['type']; //类型
  2518. $data['user_name'] = $_GPC['user_name']; //姓名
  2519. $data['account'] = $_GPC['account']; //账号
  2520. $data['tx_cost'] = $_GPC['tx_cost']; //提现金额
  2521. $data['sj_cost'] = $_GPC['sj_cost']; //实际到账金额
  2522. $data['bank'] = $_GPC['bank']; //银行
  2523. $data['state'] = 1;
  2524. $data['time'] = time();
  2525. $data['uniacid'] = $_W['uniacid'];
  2526. $res = pdo_insert('zhtc_commission_withdrawal', $data);
  2527. if ($res) {
  2528. pdo_update('zhtc_user', array('commission -=' => $_GPC['tx_cost']), array('id' => $_GPC['user_id']));
  2529. echo '1';
  2530. } else {
  2531. echo '2';
  2532. }
  2533. }
  2534. }
  2535. //提现明细
  2536. public function doPageYjtxList() {
  2537. global $_W, $_GPC;
  2538. $res = pdo_getall('zhtc_commission_withdrawal', array('user_id' => $_GPC['user_id']), array(), '', 'id DESC');
  2539. echo json_encode($res);
  2540. }
  2541. //绑定分销商
  2542. public function doPageBinding() {
  2543. global $_W, $_GPC;
  2544. $set = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2545. $res = pdo_get('zhtc_fxuser', array('fx_user' => $_GPC['fx_user']));
  2546. $res2 = pdo_get('zhtc_fxuser', array('user_id' => $_GPC['fx_user'], 'fx_user' => $_GPC['user_id']));
  2547. $distribution = pdo_get('zhtc_distribution', array('user_id' => $_GPC['user_id'], 'state' => 2));
  2548. if ($distribution) {
  2549. if ($set['is_hhr'] == 1) {
  2550. if ($_GPC['user_id'] == $_GPC['fx_user']) {
  2551. echo '自己不能绑定自己';
  2552. } elseif ($res || $res2) {
  2553. echo '不能重复绑定';
  2554. } else {
  2555. $res3 = pdo_insert('zhtc_fxuser', array('user_id' => $_GPC['user_id'], 'fx_user' => $_GPC['fx_user'], 'time' => time()));
  2556. if ($res3) {
  2557. echo '1';
  2558. } else {
  2559. echo '2';
  2560. }
  2561. }
  2562. }
  2563. } else {
  2564. echo '该用户不是分销商';
  2565. }
  2566. }
  2567. //查看我的团队
  2568. public function doPageMyTeam() {
  2569. global $_W, $_GPC;
  2570. $sql = "select a.* ,b.name,b.img from " . tablename("zhtc_fxuser") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.fx_user WHERE a.user_id=:user_id order by id DESC";
  2571. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  2572. $res2 = array();
  2573. for ($i = 0; $i < count($res); $i++) {
  2574. $sql2 = "select a.* ,b.name,b.img from " . tablename("zhtc_fxuser") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.fx_user WHERE a.user_id=:user_id order by id DESC";
  2575. $res3 = pdo_fetchall($sql2, array(':user_id' => $res[$i]['fx_user']));
  2576. $res2[] = $res3;
  2577. }
  2578. $res4 = array();
  2579. for ($k = 0; $k < count($res2); $k++) {
  2580. for ($j = 0; $j < count($res2[$k]); $j++) {
  2581. $res4[] = $res2[$k][$j];
  2582. }
  2583. }
  2584. $data['one'] = $res;
  2585. $data['two'] = $res4;
  2586. // print_r($data);die;
  2587. echo json_encode($data);
  2588. }
  2589. //查看佣金
  2590. public function doPageMyCommission() {
  2591. global $_W, $_GPC;
  2592. $system = pdo_get('zhtc_fxset', array('uniacid' => $_W['uniacid'])); //tx_money
  2593. $user = pdo_get('zhtc_user', array('id' => $_GPC['user_id']));
  2594. if ($user['commission'] < $system['tx_money']) {
  2595. $ke = 0.00;
  2596. } else {
  2597. $ke = $user['commission'];
  2598. }
  2599. $sq = "select sum(tx_cost) as tx_cost from " . tablename("zhtc_commission_withdrawal") . " WHERE user_id=" . $_GPC['user_id'];
  2600. $sq = pdo_fetch($sq);
  2601. $sq = $sq['tx_cost'];
  2602. $cg = "select sum(tx_cost) as tx_cost from " . tablename("zhtc_commission_withdrawal") . " WHERE state=2 and user_id=" . $_GPC['user_id'];
  2603. $cg = pdo_fetch($cg);
  2604. $cg = $cg['tx_cost'];
  2605. $lei = "select sum(money) as tx_cost from " . tablename("zhtc_earnings") . " WHERE user_id=" . $_GPC['user_id'];
  2606. $lei = pdo_fetch($lei);
  2607. $lei = $lei['tx_cost'];
  2608. $data['ke'] = $ke;
  2609. $data['sq'] = $sq;
  2610. $data['cg'] = $cg;
  2611. $data['lei'] = $lei;
  2612. echo json_encode($data);
  2613. }
  2614. //添加佣金
  2615. public function doPageFx() {
  2616. global $_W, $_GPC;
  2617. // echo $_GPC['money'];die;
  2618. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2619. $set = pdo_get('zhtc_fxset', array('uniacid' => $_W['uniacid']));
  2620. if ($system['is_hhr'] == 1) {
  2621. if ($set['is_ej'] == 2) {
  2622. //不开启二级分销
  2623. $user = pdo_get('zhtc_fxuser', array('fx_user' => $_GPC['user_id']));
  2624. if ($user) {
  2625. $sx = pdo_get('zhtc_distribution', array('user_id' => $user['user_id']));
  2626. $level = pdo_get('zhtc_fxlevel', array('id' => $sx['level']));
  2627. $userid = $user['user_id']; //上线id
  2628. $money = $_GPC['money'] * ($level['commission'] / 100); //一级佣金
  2629. pdo_update('zhtc_user', array('commission +=' => $money), array('id' => $userid));
  2630. $data6['user_id'] = $userid; //上线id
  2631. $data6['son_id'] = $_GPC['user_id']; //下线id
  2632. $data6['money'] = $money; //金额
  2633. $data6['time'] = time(); //时间
  2634. $data6['uniacid'] = $_W['uniacid'];
  2635. pdo_insert('zhtc_earnings', $data6);
  2636. }
  2637. } else {
  2638. //开启二级
  2639. $user = pdo_get('zhtc_fxuser', array('fx_user' => $_GPC['user_id']));
  2640. $user2 = pdo_get('zhtc_fxuser', array('fx_user' => $user['user_id'])); //上线
  2641. if ($user) {
  2642. $sx = pdo_get('zhtc_distribution', array('user_id' => $user['user_id']));
  2643. $level = pdo_get('zhtc_fxlevel', array('id' => $sx['level']));
  2644. //echo $level['commission'];die;
  2645. $userid = $user['user_id']; //上线id
  2646. $money = $_GPC['money'] * ($level['commission'] / 100); //一级佣金
  2647. pdo_update('zhtc_user', array('commission +=' => $money), array('id' => $userid));
  2648. $data6['user_id'] = $userid; //上线id
  2649. $data6['son_id'] = $_GPC['user_id']; //下线id
  2650. $data6['money'] = $money; //金额
  2651. $data6['time'] = time(); //时间
  2652. $data6['uniacid'] = $_W['uniacid'];
  2653. pdo_insert('zhtc_earnings', $data6);
  2654. }
  2655. if ($user2) {
  2656. $sx2 = pdo_get('zhtc_distribution', array('user_id' => $user2['user_id']));
  2657. $level2 = pdo_get('zhtc_fxlevel', array('id' => $sx2['level']));
  2658. $userid2 = $user2['user_id']; //上线的上线id
  2659. $money = $_GPC['money'] * ($level2['commission2'] / 100); //二级佣金
  2660. pdo_update('zhtc_user', array('commission +=' => $money), array('id' => $userid2));
  2661. $data7['user_id'] = $userid2; //上线id
  2662. $data7['son_id'] = $_GPC['user_id']; //下线id
  2663. $data7['money'] = $money; //金额
  2664. $data7['time'] = time(); //时间
  2665. $data7['uniacid'] = $_W['uniacid'];
  2666. pdo_insert('zhtc_earnings', $data7);
  2667. }
  2668. }
  2669. }
  2670. }
  2671. //入驻黄页
  2672. public function doPageYellowPage() {
  2673. global $_W, $_GPC;
  2674. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2675. $data['user_id'] = $_GPC['user_id'];
  2676. $data['logo'] = $_GPC['logo'];
  2677. $data['company_name'] = $_GPC['company_name'];
  2678. $data['company_address'] = $_GPC['company_address'];
  2679. $data['type_id'] = $_GPC['type_id'];
  2680. $data['type2_id'] = $_GPC['type2_id'];
  2681. $data['link_tel'] = $_GPC['link_tel'];
  2682. $data['rz_type'] = $_GPC['rz_type'];
  2683. $data['coordinates'] = $_GPC['coordinates'];
  2684. $data['content'] = $_GPC['content'];
  2685. $data['imgs'] = $_GPC['imgs'];
  2686. $data['tel2'] = $_GPC['tel2'];
  2687. $data['cityname'] = $_GPC['cityname'];
  2688. $data['uniacid'] = $_W['uniacid'];
  2689. $data['time_over'] = 2;
  2690. if ($system['is_hyset'] == 1) {
  2691. $data['state'] = 1;
  2692. } else {
  2693. $data['state'] = 2;
  2694. $data['sh_time'] = time();
  2695. $rz = pdo_get('zhtc_yellowset', array('id' => $_GPC['rz_type']));
  2696. $data['dq_time'] = $data['sh_time'] + 24 * 60 * 60 * $rz['days'];
  2697. }
  2698. $res = pdo_insert('zhtc_yellowstore', $data);
  2699. $hy_id = pdo_insertid();
  2700. if ($res) {
  2701. echo $hy_id;
  2702. } else {
  2703. echo '2';
  2704. }
  2705. }
  2706. //查看我入驻的黄页
  2707. public function doPageMyYellowPage() {
  2708. global $_W, $_GPC;
  2709. $sql = "select a.* ,b.type_name,c.name as type2_name from " . tablename("zhtc_yellowstore") . " a" . " left join " . tablename("zhtc_yellowtype") . " b on b.id=a.type_id left join " . tablename("zhtc_yellowtype2") . " c on c.id=a.type2_id WHERE a.user_id=:user_id and a.is_delete=2 order by a.id desc ";
  2710. $res = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  2711. echo json_encode($res);
  2712. }
  2713. //查看黄页列表
  2714. public function doPageYellowPageList() {
  2715. global $_W, $_GPC;
  2716. //修改以前的数据
  2717. $time = time();
  2718. $gx = " update " . tablename("zhtc_yellowstore") . " a inner join (select id from " . tablename("zhtc_yellowstore") . " where dq_time<={$time} and state=2 and time_over =2 and uniacid={$_W['uniacid']} order by dq_time ASC limit 0,100 ) b on a.id =b.id set a.time_over =1";
  2719. pdo_query($gx);
  2720. // $rst=pdo_update('zhtc_yellowstore',array('time_over'=>1),array('dq_time <='=>time(),'state'=>2,'uniacid'=>$_W['uniacid']));
  2721. $pageindex = max(1, intval($_GPC['page']));
  2722. $pagesize = 10;
  2723. $where = " WHERE a.uniacid=:uniacid and a.state=2 and a.time_over=2 and a.is_delete=2 ";
  2724. if ($_GPC['cityname']) {
  2725. $where .= " and a.cityname LIKE concat('%', :name,'%') ";
  2726. $data[':name'] = $_GPC['cityname'];
  2727. }
  2728. if ($_GPC['keywords']) {
  2729. $where .= " and a.company_name LIKE concat('%', :name,'%') ";
  2730. $data[':name'] = $_GPC['keywords'];
  2731. }
  2732. if ($_GPC['type_id']) {
  2733. $where .= " and a.type_id=:type_id";
  2734. $data[':type_id'] = $_GPC['type_id'];
  2735. }
  2736. if ($_GPC['type2_id']) {
  2737. $where .= " and a.type2_id=:type2_id";
  2738. $data[':type2_id'] = $_GPC['type2_id'];
  2739. }
  2740. $data[':uniacid'] = $_W['uniacid'];
  2741. if ($_GPC['lat']) {
  2742. $lat = $_GPC['lat'];
  2743. } else {
  2744. $lat = '30.592760';
  2745. }
  2746. if ($_GPC['lng']) {
  2747. $lng = $_GPC['lng'];
  2748. } else {
  2749. $lng = '114.305250';
  2750. }
  2751. if (!$_GPC['type']) {
  2752. $_GPC['type'] = 1;
  2753. }
  2754. if ($_GPC['type'] == 1) {
  2755. $sql = "select a.*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(a.coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(a.coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(a.coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli,b.type_name,c.name as type2_name from " . tablename("zhtc_yellowstore") . " a" . " left join " . tablename("zhtc_yellowtype") . " b on b.id=a.type_id left join " . tablename("zhtc_yellowtype2") . " c on c.id=a.type2_id " . $where . " order by juli asc";
  2756. } elseif ($_GPC['type'] == 2) {
  2757. $sql = "select a.*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(a.coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(a.coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(a.coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli,b.type_name,c.name as type2_name from " . tablename("zhtc_yellowstore") . " a" . " left join " . tablename("zhtc_yellowtype") . " b on b.id=a.type_id left join " . tablename("zhtc_yellowtype2") . " c on c.id=a.type2_id " . $where . " order by a.sh_time desc";
  2758. } elseif ($_GPC['type'] == 3) {
  2759. $sql = "select a.*,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(a.coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(a.coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(a.coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli,b.type_name,c.name as type2_name from " . tablename("zhtc_yellowstore") . " a" . " left join " . tablename("zhtc_yellowtype") . " b on b.id=a.type_id left join " . tablename("zhtc_yellowtype2") . " c on c.id=a.type2_id " . $where . " order by a.views desc";
  2760. }
  2761. // $sql="select a.* ,b.type_name,c.name as type2_name from " . tablename("zhtc_yellowstore") . " a" . " left join " . tablename("zhtc_yellowtype") . " b on b.id=a.type_id left join " . tablename("zhtc_yellowtype2") . " c on c.id=a.type2_id ".$where." order by id DESC";
  2762. // $res=pdo_fetch($sql,array(':uniacid'=>$_W['uniacid']));
  2763. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  2764. $res = pdo_fetchall($select_sql, $data);
  2765. echo json_encode($res);
  2766. }
  2767. //查看黄页详情
  2768. public function doPageYellowPageInfo() {
  2769. global $_W, $_GPC;
  2770. pdo_update('zhtc_yellowstore', array('views +=' => 1), array('id' => $_GPC['id']));
  2771. $sql = "select a.* ,b.type_name,c.name as type2_name from " . tablename("zhtc_yellowstore") . " a" . " left join " . tablename("zhtc_yellowtype") . " b on b.id=a.type_id left join " . tablename("zhtc_yellowtype2") . " c on c.id=a.type2_id WHERE a.id=:id";
  2772. $res = pdo_fetch($sql, array(':id' => $_GPC['id']));
  2773. echo json_encode($res);
  2774. }
  2775. //查看黄页入驻设置
  2776. public function doPageYellowSet() {
  2777. global $_W, $_GPC;
  2778. $res = pdo_getall('zhtc_yellowset', array('uniacid' => $_W['uniacid']), array(), '', 'num asc');
  2779. echo json_encode($res);
  2780. }
  2781. //登录
  2782. public function doPageStoreLogin() {
  2783. global $_W, $_GPC;
  2784. $res = pdo_get('zhtc_store', array('user_name' => $_GPC['user_name']));
  2785. $res2 = pdo_get('zhtc_store', array('user_name' => $_GPC['user_name'], 'pwd' => md5($_GPC['pwd'])));
  2786. if (!$res) {
  2787. echo '账号不存在!';
  2788. } elseif (!$res2) {
  2789. echo '密码不正确!';
  2790. } elseif ($res2) {
  2791. echo json_encode($res2);
  2792. }
  2793. }
  2794. //上传图片
  2795. public function doPageUpload() {
  2796. global $_W, $_GPC;
  2797. function getaccess_token($_W) {
  2798. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2799. $appid = $res['appid'];
  2800. $secret = $res['appsecret'];
  2801. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  2802. $ch = curl_init();
  2803. curl_setopt($ch, CURLOPT_URL, $url);
  2804. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2805. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2806. $data = curl_exec($ch);
  2807. curl_close($ch);
  2808. $data = json_decode($data, true);
  2809. return $data['access_token'];
  2810. }
  2811. $url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=" . getaccess_token($_W);
  2812. //echo $_FILES['file']['tmp_name'];die;
  2813. $data['media'] = new \CURLFile($_FILES['upfile']['tmp_name']);
  2814. $ch = curl_init();
  2815. curl_setopt($ch, CURLOPT_URL, $url);
  2816. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2817. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2818. curl_setopt($ch, CURLOPT_POST, 1);
  2819. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  2820. $data = curl_exec($ch);
  2821. curl_close($ch);
  2822. $res = json_decode($data, true);
  2823. if ($res['errcode'] == 87014) {
  2824. return '图片内容违规,请重新上传!';
  2825. }
  2826. $uptypes = array(
  2827. 'image/jpg',
  2828. 'image/jpeg',
  2829. 'image/png',
  2830. 'image/pjpeg',
  2831. 'image/gif',
  2832. 'image/bmp',
  2833. 'image/x-png',
  2834. );
  2835. $max_file_size = 2000000; //上传文件大小限制, 单位BYTE
  2836. $destination_folder = "../attachment/zh_tcwq/" . date(Y) . "/" . date(m) . "/" . date(d) . "/"; //上传文件路径
  2837. //$destination_folder="../attachment/"; //上传文件路径
  2838. $watermark = 2; //是否附加水印(1为加水印,其他为不加水印);
  2839. $watertype = 1; //水印类型(1为文字,2为图片)
  2840. $waterposition = 1; //水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);
  2841. $waterstring = "666666"; //水印字符串
  2842. // $waterimg="xplore.gif"; //水印图片
  2843. $imgpreview = 1; //是否生成预览图(1为生成,其他为不生成);
  2844. $imgpreviewsize = 1 / 2; //缩略图比例
  2845. if (!is_uploaded_file($_FILES["upfile"]['tmp_name']))
  2846. //是否存在文件
  2847. {
  2848. echo "图片不存在!";
  2849. exit;
  2850. }
  2851. $file = $_FILES["upfile"];
  2852. if ($max_file_size < $file["size"])
  2853. //检查文件大小
  2854. {
  2855. echo "文件太大!";
  2856. exit;
  2857. }
  2858. // if(!in_array($file["type"], $uptypes))
  2859. // //检查文件类型
  2860. // {
  2861. // echo "文件类型不符!".$file["type"];
  2862. // exit;
  2863. // }
  2864. if (!file_exists($destination_folder)) {
  2865. mkdir($destination_folder, 0777, true);
  2866. }
  2867. $filename = $file["tmp_name"];
  2868. $image_size = getimagesize($filename);
  2869. $pinfo = pathinfo($file["name"]);
  2870. $ftype = $pinfo['extension'];
  2871. $destination = $destination_folder . str_shuffle(time() . rand(111111, 999999)) . "." . $ftype;
  2872. if (file_exists($destination) && $overwrite != true) {
  2873. echo "同名文件已经存在了";
  2874. exit;
  2875. }
  2876. if (!move_uploaded_file($filename, $destination)) {
  2877. echo "移动文件出错";
  2878. exit;
  2879. }
  2880. $pinfo = pathinfo($destination);
  2881. $fname = "zh_tcwq/" . date(Y) . "/" . date(m) . "/" . date(d) . "/" . $pinfo['basename'];
  2882. echo $fname;
  2883. @require_once IA_ROOT . '/framework/function/file.func.php';
  2884. @$filename = $fname;
  2885. @file_remote_upload($filename);
  2886. }
  2887. /////////////////////////////////////////
  2888. //提现金额模板消息
  2889. public function doPageTxMessage() {
  2890. global $_W, $_GPC;
  2891. function getaccess_token($_W) {
  2892. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2893. $appid = $res['appid'];
  2894. $secret = $res['appsecret'];
  2895. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  2896. $ch = curl_init();
  2897. curl_setopt($ch, CURLOPT_URL, $url);
  2898. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2899. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2900. $data = curl_exec($ch);
  2901. curl_close($ch);
  2902. $data = json_decode($data, true);
  2903. return $data['access_token'];
  2904. }
  2905. //设置与发送模板信息
  2906. function set_msg($_W, $_GPC) {
  2907. $access_token = getaccess_token($_W);
  2908. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  2909. $tx = pdo_get('zhtc_withdrawal', array('id' => $_GPC['txsh_id']));
  2910. if ($tx['type'] == 1) {
  2911. $typename = "支付宝";
  2912. }
  2913. if ($tx['type'] == 2) {
  2914. $typename = "微信";
  2915. }
  2916. if ($tx['type'] == 3) {
  2917. $typename = "银行卡";
  2918. }
  2919. $time = date('Y-m-d H:i:s', $tx['time']);
  2920. $formwork = '{
  2921. "touser": "' . $_GET["openid"] . '",
  2922. "template_id": "' . $res["tid2"] . '",
  2923. "page":"zh_tcwq/pages/index/index",
  2924. "form_id":"' . $_GET['form_id'] . '",
  2925. "data": {
  2926. "keyword1": {
  2927. "value": "' . $tx['name'] . '",
  2928. "color": "#173177"
  2929. },
  2930. "keyword2": {
  2931. "value":"' . $tx['username'] . '",
  2932. "color": "#173177"
  2933. },
  2934. "keyword3": {
  2935. "value": "' . $tx['tx_cost'] . '",
  2936. "color": "#173177"
  2937. },
  2938. "keyword4": {
  2939. "value": "' . $tx['sj_cost'] . '",
  2940. "color": "#173177"
  2941. },
  2942. "keyword5": {
  2943. "value": "' . $typename . '",
  2944. "color": "#173177"
  2945. },
  2946. "keyword6": {
  2947. "value": "' . $time . '",
  2948. "color": "#173177"
  2949. }
  2950. }
  2951. }';
  2952. // $formwork=$data;
  2953. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  2954. $ch = curl_init();
  2955. curl_setopt($ch, CURLOPT_URL, $url);
  2956. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2957. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2958. curl_setopt($ch, CURLOPT_POST, 1);
  2959. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  2960. $data = curl_exec($ch);
  2961. curl_close($ch);
  2962. return $data;
  2963. }
  2964. echo set_msg($_W, $_GPC);
  2965. }
  2966. //商家入驻模板消息
  2967. public function doPageRzMessage() {
  2968. global $_W, $_GPC;
  2969. function getaccess_token($_W) {
  2970. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  2971. $appid = $res['appid'];
  2972. $secret = $res['appsecret'];
  2973. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  2974. $ch = curl_init();
  2975. curl_setopt($ch, CURLOPT_URL, $url);
  2976. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2977. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2978. $data = curl_exec($ch);
  2979. curl_close($ch);
  2980. $data = json_decode($data, true);
  2981. return $data['access_token'];
  2982. }
  2983. //设置与发送模板信息
  2984. function set_msg($_W, $_GPC) {
  2985. $access_token = getaccess_token($_W);
  2986. $res2 = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  2987. $sql = "select a.store_name,a.time,a.state,b.name as user_name from " . tablename("zhtc_store") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.id=:store_id";
  2988. $res = pdo_fetch($sql, array(':store_id' => $_GPC['store_id']));
  2989. $type = "待审核";
  2990. $note = "1-3日完成审核";
  2991. $formwork = '{
  2992. "touser": "' . $_GET["openid"] . '",
  2993. "template_id": "' . $res2["tid1"] . '",
  2994. "page":"zh_tcwq/pages/index/index",
  2995. "form_id":"' . $_GET['form_id'] . '",
  2996. "data": {
  2997. "keyword1": {
  2998. "value": "' . $res['store_name'] . '",
  2999. "color": "#173177"
  3000. },
  3001. "keyword2": {
  3002. "value":"' . $res['user_name'] . '",
  3003. "color": "#173177"
  3004. },
  3005. "keyword3": {
  3006. "value": "' . $res['time'] . '",
  3007. "color": "#173177"
  3008. },
  3009. "keyword4": {
  3010. "value": "' . $type . '",
  3011. "color": "#173177"
  3012. },
  3013. "keyword5": {
  3014. "value": "' . $note . '",
  3015. "color": "#173177"
  3016. }
  3017. }
  3018. }';
  3019. // $formwork=$data;
  3020. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  3021. $ch = curl_init();
  3022. curl_setopt($ch, CURLOPT_URL, $url);
  3023. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  3024. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  3025. curl_setopt($ch, CURLOPT_POST, 1);
  3026. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  3027. $data = curl_exec($ch);
  3028. curl_close($ch);
  3029. return $data;
  3030. }
  3031. echo set_msg($_W, $_GPC);
  3032. }
  3033. //保存商家支付记录
  3034. public function doPageSaveStorePayLog() {
  3035. global $_W, $_GPC;
  3036. include IA_ROOT . '/addons/zh_tcwq/yj.php';
  3037. $data['store_id'] = $_GPC['store_id'];
  3038. $data['money'] = $_GPC['money'];
  3039. $data['note'] = $_GPC['note'];
  3040. $data['time'] = date('Y-m-d H:i:s');
  3041. $data['uniacid'] = $_W['uniacid'];
  3042. $res = pdo_insert('zhtc_storepaylog', $data);
  3043. if ($res) {
  3044. //代理商佣金
  3045. $cityname = Yj::getStoreCity($_GPC['store_id']);
  3046. $yjset = Yj::getYjSet($_W['uniacid']);
  3047. if ($yjset['type'] == 1) {
  3048. $money = $_GPC['money'] * $yjset['typer'] / 100;
  3049. } else {
  3050. $money = $_GPC['money'] * $yjset['sjper'] / 100;
  3051. }
  3052. pdo_update('zhtc_account', array('money +=' => $money), array('cityname' => $cityname));
  3053. echo '1';
  3054. } else {
  3055. echo '2';
  3056. }
  3057. }
  3058. //保存帖子支付记录
  3059. public function doPageSaveTzPayLog() {
  3060. global $_W, $_GPC;
  3061. include IA_ROOT . '/addons/zh_tcwq/yj.php';
  3062. if ($_GPC['money1']) {
  3063. //发帖价格
  3064. $data['tz_id'] = $_GPC['tz_id'];
  3065. $data['note'] = '发帖费用';
  3066. $data['money'] = $_GPC['money1'];
  3067. $data['time'] = date('Y-m-d H:i:s');
  3068. $data['uniacid'] = $_W['uniacid'];
  3069. $res = pdo_insert('zhtc_tzpaylog', $data);
  3070. }
  3071. if ($_GPC['money2']) {
  3072. //置顶价格
  3073. $data['tz_id'] = $_GPC['tz_id'];
  3074. $data['note'] = '发帖置顶';
  3075. $data['money'] = $_GPC['money2'];
  3076. $data['time'] = date('Y-m-d H:i:s');
  3077. $data['uniacid'] = $_W['uniacid'];
  3078. $res = pdo_insert('zhtc_tzpaylog', $data);
  3079. }
  3080. if ($_GPC['money3']) {
  3081. //红包
  3082. $data['tz_id'] = $_GPC['tz_id'];
  3083. $data['note'] = '红包福利';
  3084. $data['money'] = $_GPC['money3'];
  3085. $data['time'] = date('Y-m-d H:i:s');
  3086. $data['uniacid'] = $_W['uniacid'];
  3087. $res = pdo_insert('zhtc_tzpaylog', $data);
  3088. }
  3089. if ($_GPC['money4']) {
  3090. //置顶续费
  3091. $data['tz_id'] = $_GPC['tz_id'];
  3092. $data['note'] = '置顶续费';
  3093. $data['money'] = $_GPC['money4'];
  3094. $data['time'] = date('Y-m-d H:i:s');
  3095. $data['uniacid'] = $_W['uniacid'];
  3096. $res = pdo_insert('zhtc_tzpaylog', $data);
  3097. }
  3098. if ($_GPC['money5']) {
  3099. //帖子刷新
  3100. $data['tz_id'] = $_GPC['tz_id'];
  3101. $data['note'] = '帖子刷新';
  3102. $data['money'] = $_GPC['money5'];
  3103. $data['time'] = date('Y-m-d H:i:s');
  3104. $data['uniacid'] = $_W['uniacid'];
  3105. $res = pdo_insert('zhtc_tzpaylog', $data);
  3106. }
  3107. if ($res) {
  3108. //代理商佣金
  3109. $cityname = Yj::getTzCity($_GPC['tz_id']);
  3110. //var_dump($cityname);die;
  3111. $yjset = Yj::getYjSet($_W['uniacid']);
  3112. if ($yjset['type'] == 1) {
  3113. $money = $_GPC['money'] * $yjset['typer'] / 100;
  3114. } else {
  3115. $money = $_GPC['money'] * $yjset['tzper'] / 100;
  3116. }
  3117. pdo_update('zhtc_account', array('money +=' => $money), array('cityname' => $cityname));
  3118. echo '1';
  3119. } else {
  3120. echo '2';
  3121. }
  3122. }
  3123. //保存拼车支付记录
  3124. public function doPageSaveCarPayLog() {
  3125. global $_W, $_GPC;
  3126. include IA_ROOT . '/addons/zh_tcwq/yj.php';
  3127. $data['car_id'] = $_GPC['car_id'];
  3128. $data['money'] = $_GPC['money'];
  3129. $data['time'] = date('Y-m-d H:i:s');
  3130. $data['uniacid'] = $_W['uniacid'];
  3131. $res = pdo_insert('zhtc_carpaylog', $data);
  3132. if ($res) {
  3133. //代理商佣金
  3134. $cityname = Yj::getCarCity($_GPC['car_id']);
  3135. //var_dump($cityname);die;
  3136. $yjset = Yj::getYjSet($_W['uniacid']);
  3137. if ($yjset['type'] == 1) {
  3138. $money = $_GPC['money'] * $yjset['typer'] / 100;
  3139. } else {
  3140. $money = $_GPC['money'] * $yjset['pcper'] / 100;
  3141. }
  3142. pdo_update('zhtc_account', array('money +=' => $money), array('cityname' => $cityname));
  3143. echo '1';
  3144. } else {
  3145. echo '2';
  3146. }
  3147. }
  3148. //保存黄页支付记录
  3149. public function doPageSaveHyPayLog() {
  3150. global $_W, $_GPC;
  3151. include IA_ROOT . '/addons/zh_tcwq/yj.php';
  3152. $data['hy_id'] = $_GPC['hy_id'];
  3153. $data['money'] = $_GPC['money'];
  3154. $data['time'] = date('Y-m-d H:i:s');
  3155. $data['uniacid'] = $_W['uniacid'];
  3156. $res = pdo_insert('zhtc_yellowpaylog', $data);
  3157. if ($res) {
  3158. //代理商佣金
  3159. $cityname = Yj::getYellowCity($_GPC['hy_id']);
  3160. $yjset = Yj::getYjSet($_W['uniacid']);
  3161. if ($yjset['type'] == 1) {
  3162. $money = $_GPC['money'] * $yjset['typer'] / 100;
  3163. } else {
  3164. $money = $_GPC['money'] * $yjset['hyper'] / 100;
  3165. }
  3166. pdo_update('zhtc_account', array('money +=' => $money), array('cityname' => $cityname));
  3167. echo '1';
  3168. } else {
  3169. echo '2';
  3170. }
  3171. }
  3172. //保存定位城市
  3173. public function doPageSaveHotCity() {
  3174. global $_W, $_GPC;
  3175. $rst = pdo_get('zhtc_hotcity', array('cityname' => $_GPC['cityname'], 'uniacid' => $_W['uniacid'], 'user_id' => $_GPC['user_id']));
  3176. if (empty($rst)) {
  3177. $data['user_id'] = $_GPC['user_id'];
  3178. $data['cityname'] = $_GPC['cityname'];
  3179. $data['time'] = time();
  3180. $data['uniacid'] = $_W['uniacid'];
  3181. $res = pdo_insert('zhtc_hotcity', $data);
  3182. if ($res) {
  3183. echo '1';
  3184. } else {
  3185. echo '2';
  3186. }
  3187. }
  3188. }
  3189. //查看是否拉黑
  3190. public function doPageGetUserInfo() {
  3191. global $_W, $_GPC;
  3192. $res = pdo_get('zhtc_user', array('id' => $_GPC['user_id']));
  3193. echo json_encode($res);
  3194. }
  3195. //商家分享数量加一
  3196. public function doPageStoreFxNum() {
  3197. global $_W, $_GPC;
  3198. $res = pdo_update('zhtc_store', array('fx_num +=' => 1), array('id' => $_GPC['store_id']));
  3199. if ($res) {
  3200. echo '1';
  3201. } else {
  3202. echo '2';
  3203. }
  3204. }
  3205. //红包
  3206. public function doPageRedPaperList() {
  3207. global $_GPC, $_W;
  3208. $pageindex = max(1, intval($_GPC['page']));
  3209. $pagesize = $_GPC['pagesize'];
  3210. $sql = "select a.*,b.logo,c.img as user_img from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id" . " left join " . tablename("zhtc_user") . " c on c.id=a.user_id WHERE a.uniacid=:uniacid and a.hb_num>0 and a.del=2 and a.state=2 ORDER BY a.id DESC";
  3211. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  3212. $res = pdo_fetchall($select_sql, array(':uniacid' => $_W['uniacid']));
  3213. echo json_encode($res);
  3214. }
  3215. //获取城市
  3216. public function doPageGetCity() {
  3217. global $_W, $_GPC;
  3218. $res = pdo_getall('zhtc_hotcity', array('uniacid' => $_W['uniacid'], 'user_id' => $_GPC['user_id']));
  3219. echo json_encode($res);
  3220. }
  3221. //保存formid
  3222. public function doPageSaveFormid() {
  3223. global $_W, $_GPC;
  3224. $time = time() - 60 * 60 * 24 * 7;
  3225. pdo_query("delete from " . tablename('zhtc_userformid') . " where UNIX_TIMESTAMP(time)<={$time}");
  3226. $data['user_id'] = $_GPC['user_id'];
  3227. $data['form_id'] = $_GPC['form_id'];
  3228. $data['openid'] = $_GPC['openid'];
  3229. $data['time'] = date('Y-m-d H:i:s');
  3230. $data['uniacid'] = $_W['uniacid'];
  3231. if ($_GPC['form_id'] != 'the formId is a mock one' and $_GPC['form_id']) {
  3232. $res = pdo_insert('zhtc_userformid', $data);
  3233. }
  3234. if ($res) {
  3235. echo '1';
  3236. } else {
  3237. echo '2';
  3238. }
  3239. }
  3240. //删除formid
  3241. public function doPageDelFormid() {
  3242. global $_W, $_GPC;
  3243. $res = pdo_delete('zhtc_userformid', array('user_id' => $_GPC['user_id'], 'form_id' => $_GPC['form_id']));
  3244. if ($res) {
  3245. echo '1';
  3246. } else {
  3247. echo '2';
  3248. }
  3249. }
  3250. //获取用户的formid
  3251. public function doPageGetFormid() {
  3252. global $_W, $_GPC;
  3253. $time = time() - 60 * 60 * 24 * 7;
  3254. $sql = "delete from " . tablename("zhtc_userformid") . " where UNIX_TIMESTAMP(time) <=" . $time;
  3255. pdo_query($sql);
  3256. $res = pdo_getall('zhtc_userformid', array('user_id' => $_GPC['user_id'], 'uniacid' => $_W['uniacid']));
  3257. echo json_encode($res);
  3258. }
  3259. //帖子评论成功模板消息
  3260. public function doPageStorehfMessage() {
  3261. global $_W, $_GPC;
  3262. function getaccess_token($_W) {
  3263. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  3264. $appid = $res['appid'];
  3265. $secret = $res['appsecret'];
  3266. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  3267. $ch = curl_init();
  3268. curl_setopt($ch, CURLOPT_URL, $url);
  3269. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  3270. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  3271. $data = curl_exec($ch);
  3272. curl_close($ch);
  3273. $data = json_decode($data, true);
  3274. return $data['access_token'];
  3275. }
  3276. //设置与发送模板信息
  3277. function set_msg($_W, $_GPC) {
  3278. $access_token = getaccess_token($_W);
  3279. $res2 = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  3280. $sql = "select a.details,a.store_id,a.time,b.name as user_name from " . tablename("zhtc_comments") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.id=:id ";
  3281. $res = pdo_fetch($sql, array(':id' => $_GPC['pl_id']));
  3282. $time = date("Y-m-d H:i:s", $res['time']);
  3283. $formwork = '{
  3284. "touser": "' . $_GET["openid"] . '",
  3285. "template_id": "' . $res2["tid3"] . '",
  3286. "page":"zh_tcwq/pages/sellerinfo/sellerinfo?id=' . $res['store_id'] . '",
  3287. "form_id":"' . $_GET['form_id'] . '",
  3288. "data": {
  3289. "keyword1": {
  3290. "value": "' . $res['details'] . '",
  3291. "color": "#173177"
  3292. },
  3293. "keyword2": {
  3294. "value":"' . $res['user_name'] . '",
  3295. "color": "#173177"
  3296. },
  3297. "keyword3": {
  3298. "value": "' . $time . '",
  3299. "color": "#173177"
  3300. }
  3301. }
  3302. }';
  3303. // $formwork=$data;
  3304. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  3305. $ch = curl_init();
  3306. curl_setopt($ch, CURLOPT_URL, $url);
  3307. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  3308. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  3309. curl_setopt($ch, CURLOPT_POST, 1);
  3310. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  3311. $data = curl_exec($ch);
  3312. curl_close($ch);
  3313. return $data;
  3314. }
  3315. echo set_msg($_W, $_GPC);
  3316. }
  3317. //商家福利
  3318. public function doPageMyPost2() {
  3319. global $_GPC, $_W;
  3320. $pageindex = max(1, intval($_GPC['page']));
  3321. $pagesize = 10;
  3322. $sql = "select a.*,b.type_name,c.name as type2_name from " . tablename("zhtc_information") . " a" . " left join " . tablename("zhtc_type") . " b on b.id=a.type_id " . " left join " . tablename("zhtc_type2") . " c on a.type2_id=c.id WHERE a.store_id=:store_id and a.del=2 ORDER BY a.id DESC";
  3323. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  3324. $res = pdo_fetchall($select_sql, array(':store_id' => $_GPC['user_id']));
  3325. echo json_encode($res);
  3326. }
  3327. //红包分享
  3328. public function doPageHbFx() {
  3329. global $_GPC, $_W;
  3330. $res = pdo_update('zhtc_information', array('hbfx_num +=' => 1), array('id' => $_GPC['information_id']));
  3331. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  3332. $jf = pdo_get('zhtc_integral', array('user_id' => $_GPC['user_id'], 'note' => '分享帖子', 'tid' => $_GPC['information_id']));
  3333. if (!$jf and $system['fx_jf'] > 0) {
  3334. pdo_update('zhtc_user', array('total_score +=' => $system['fx_jf']), array('id' => $_GPC['user_id']));
  3335. $data['score'] = $system['fx_jf'];
  3336. $data['user_id'] = $_GPC['user_id'];
  3337. $data['tid'] = $_GPC['information_id'];
  3338. $data['note'] = '分享帖子';
  3339. $data['type'] = 1;
  3340. $data['cerated_time'] = date('Y-m-d H:i:s');
  3341. $data['uniacid'] = $_W['uniacid']; //小程序id
  3342. pdo_insert('zhtc_integral', $data); //添加积分明细
  3343. }
  3344. if ($res) {
  3345. echo 1;
  3346. } else {
  3347. echo 2;
  3348. }
  3349. }
  3350. //获取广告详情
  3351. public function doPageGetAdInfo() {
  3352. global $_GPC, $_W;
  3353. $res = pdo_get('zhtc_ad', array('id' => $_GPC['ad_id']));
  3354. echo json_encode($res);
  3355. }
  3356. //获取导航信息
  3357. public function doPageGetNav() {
  3358. global $_GPC, $_W;
  3359. $res = pdo_getall('zhtc_nav', array('uniacid' => $_W['uniacid'], 'status' => 1), array(), '', 'orderby asc');
  3360. echo json_encode($res);
  3361. }
  3362. //获取导航详情
  3363. public function doPageGetNavInfo() {
  3364. global $_GPC, $_W;
  3365. $res = pdo_get('zhtc_nav', array('id' => $_GPC['nav_id']));
  3366. echo json_encode($res);
  3367. }
  3368. //视频分类
  3369. public function doPageVideoType() {
  3370. global $_GPC, $_W;
  3371. $res = pdo_getall('zhtc_videotype', array('uniacid' => $_W['uniacid'], 'state' => 1), array(), '', 'num asc');
  3372. echo json_encode($res);
  3373. }
  3374. //视频列表
  3375. public function doPageVideoList() {
  3376. global $_GPC, $_W;
  3377. $pageindex = max(1, intval($_GPC['page']));
  3378. $pagesize = $_GPC['pagesize'];
  3379. $where = " where a.uniacid=:uniacid";
  3380. $data[':uniacid'] = $_W['uniacid'];
  3381. if ($_GPC['type_id']) {
  3382. $where .= " and a.type_id=:type_id";
  3383. $data[':type_id'] = $_GPC['type_id'];
  3384. }
  3385. if ($_GPC['cityname']) {
  3386. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='')";
  3387. $data[':name'] = $_GPC['cityname'];
  3388. }
  3389. $sql = "select a.* from" . tablename("zhtc_video") . " a" . " left join " . tablename("zhtc_videotype") . " b on b.id=a.type_id " . $where . " ORDER BY a.num asc,a.time DESC";
  3390. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  3391. $res = pdo_fetchall($select_sql, $data);
  3392. function video($video) {
  3393. $vid = trim(strrchr($video, '/'), '/');
  3394. $vid = substr($vid, 0, -5);
  3395. $json = file_get_contents("http://vv.video.qq.com/getinfo?vids=" . $vid . "&platform=101001&charge=0&otype=json");
  3396. // echo $json;die;
  3397. $json = substr($json, 13);
  3398. $json = substr($json, 0, -1);
  3399. $a = json_decode(html_entity_decode($json));
  3400. $sz = json_decode(json_encode($a), true);
  3401. // print_R($sz);die;
  3402. $url = $sz['vl']['vi']['0']['ul']['ui']['0']['url'];
  3403. $fn = $sz['vl']['vi']['0']['fn'];
  3404. $fvkey = $sz['vl']['vi']['0']['fvkey'];
  3405. $url = $url . $fn . '?vkey=' . $fvkey;
  3406. return $url;
  3407. }
  3408. for ($i = 0; $i < count($res); $i++) {
  3409. $video = $res[$i]['url'];
  3410. $res[$i]['url'] = video($video);
  3411. }
  3412. echo json_encode($res);
  3413. }
  3414. //视频详情
  3415. public function doPageVideoInfo() {
  3416. global $_GPC, $_W;
  3417. $info = pdo_get('zhtc_video', array('id' => $_GPC['video_id']));
  3418. pdo_update('zhtc_video', array('yd_num +=' => 1), array('id' => $_GPC['video_id']));
  3419. $sql = "select a.*,b.name as user_name ,b.img as user_img from " . tablename("zhtc_videodz") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.video_id=:video_id ORDER BY a.id DESC";
  3420. $dz = pdo_fetchall($sql, array(':video_id' => $_GPC['video_id']));
  3421. $sql2 = "select a.*,b.name as user_name ,b.img as user_img from " . tablename("zhtc_videopl") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.video_id=:video_id ORDER BY a.id DESC";
  3422. $pl = pdo_fetchall($sql2, array(':video_id' => $_GPC['video_id']));
  3423. function video($video) {
  3424. $vid = trim(strrchr($video, '/'), '/');
  3425. $vid = substr($vid, 0, -5);
  3426. $json = file_get_contents("http://vv.video.qq.com/getinfo?vids=" . $vid . "&platform=101001&charge=0&otype=json");
  3427. // echo $json;die;
  3428. $json = substr($json, 13);
  3429. $json = substr($json, 0, -1);
  3430. $a = json_decode(html_entity_decode($json));
  3431. $sz = json_decode(json_encode($a), true);
  3432. // print_R($sz);die;
  3433. $url = $sz['vl']['vi']['0']['ul']['ui']['0']['url'];
  3434. $fn = $sz['vl']['vi']['0']['fn'];
  3435. $fvkey = $sz['vl']['vi']['0']['fvkey'];
  3436. $url = $url . $fn . '?vkey=' . $fvkey;
  3437. return $url;
  3438. }
  3439. $data['info'] = $info;
  3440. $data['info']['url'] = video($data['info']['url']);
  3441. $data['dz'] = $dz;
  3442. $data['pl'] = $pl;
  3443. echo json_encode($data);
  3444. }
  3445. //视频点赞
  3446. public function doPageVideoDz() {
  3447. global $_GPC, $_W;
  3448. $data['user_id'] = $_GPC['user_id'];
  3449. $data['video_id'] = $_GPC['video_id'];
  3450. $dz = pdo_get('zhtc_videodz', $data);
  3451. if ($dz) {
  3452. $res = pdo_delete('zhtc_videodz', $data);
  3453. if ($res) {
  3454. pdo_update('zhtc_video', array('dz_num -=' => 1), array('id' => $_GPC['video_id']));
  3455. echo '取消成功!';
  3456. } else {
  3457. echo '取消失败!';
  3458. }
  3459. } else {
  3460. $res = pdo_insert('zhtc_videodz', $data);
  3461. if ($res) {
  3462. pdo_update('zhtc_video', array('dz_num +=' => 1), array('id' => $_GPC['video_id']));
  3463. echo '点赞成功!';
  3464. } else {
  3465. echo '点赞失败!';
  3466. }
  3467. }
  3468. }
  3469. //视频评论
  3470. public function doPageVideoPl() {
  3471. global $_GPC, $_W;
  3472. $data['user_id'] = $_GPC['user_id'];
  3473. $data['video_id'] = $_GPC['video_id'];
  3474. $data['content'] = $_GPC['content'];
  3475. $data['time'] = date("Y-m-d H:i:s");
  3476. $res = pdo_insert('zhtc_videopl', $data);
  3477. if ($res) {
  3478. pdo_update('zhtc_video', array('pl_num +=' => 1), array('id' => $_GPC['video_id']));
  3479. echo '评论成功!';
  3480. } else {
  3481. echo '评论失败!';
  3482. }
  3483. }
  3484. //帖子续费
  3485. public function doPageTzXf() {
  3486. global $_GPC, $_W;
  3487. $list = pdo_get('zhtc_information', array('id' => $_GPC['id']));
  3488. if ($_GPC['type'] == 1) {
  3489. $time = 24 * 60 * 60;
  3490. } elseif ($_GPC['type'] == 2) {
  3491. $time = 24 * 60 * 60 * 7;
  3492. } elseif ($_GPC['type'] == 3) {
  3493. $time = 24 * 60 * 60 * 30;
  3494. }
  3495. if ($list['dq_time'] == 0 || $list['dq_time'] < time()) {
  3496. $bq_time = time() + $time;
  3497. } else {
  3498. $bq_time = $list['dq_time'] + $time;
  3499. }
  3500. if ($_GPC['cityname'] == '本地') {
  3501. $res = pdo_update('zhtc_information', array('top' => 1, 'dq_time' => $bq_time, 'cityname' => $_GPC['cityname2']), array('id' => $_GPC['id']));
  3502. } elseif ($_GPC['cityname'] == '全国版') {
  3503. $res = pdo_update('zhtc_information', array('top' => 1, 'dq_time' => $bq_time, 'cityname' => ''), array('id' => $_GPC['id']));
  3504. }
  3505. if ($res) {
  3506. echo '1';
  3507. } else {
  3508. echo '2';
  3509. }
  3510. }
  3511. //商家续费
  3512. public function doPageSjXf() {
  3513. global $_GPC, $_W;
  3514. $list = pdo_get('zhtc_store', array('id' => $_GPC['id']));
  3515. if ($_GPC['type'] == 1) {
  3516. $time = 24 * 60 * 60 * 7;
  3517. } elseif ($_GPC['type'] == 2) {
  3518. $time = 24 * 60 * 60 * 182;
  3519. } elseif ($_GPC['type'] == 3) {
  3520. $time = 24 * 60 * 60 * 365;
  3521. }
  3522. if ($list['dq_time'] == 0 || $list['dq_time'] < time()) {
  3523. $bq_time = time() + $time;
  3524. } else {
  3525. $bq_time = $list['dq_time'] + $time;
  3526. }
  3527. if ($_GPC['cityname'] == '本地') {
  3528. $res = pdo_update('zhtc_store', array('time_over' => 2, 'dq_time' => $bq_time, 'cityname' => $_GPC['cityname2']), array('id' => $_GPC['id']));
  3529. } elseif ($_GPC['cityname'] == '全国版') {
  3530. $res = pdo_update('zhtc_store', array('time_over' => 2, 'dq_time' => $bq_time, 'cityname' => ''), array('id' => $_GPC['id']));
  3531. }
  3532. if ($res) {
  3533. echo '1';
  3534. } else {
  3535. echo '2';
  3536. }
  3537. }
  3538. //黄页续费
  3539. public function doPageHyXf() {
  3540. global $_GPC, $_W;
  3541. $list = pdo_get('zhtc_yellowstore', array('id' => $_GPC['id']));
  3542. $time = 24 * 60 * 60 * $_GPC['day'];
  3543. if ($list['dq_time'] == 0 || $list['dq_time'] < time()) {
  3544. $bq_time = time() + $time;
  3545. } else {
  3546. $bq_time = $list['dq_time'] + $time;
  3547. }
  3548. $res = pdo_update('zhtc_yellowstore', array('time_over' => 2, 'dq_time' => $bq_time), array('id' => $_GPC['id']));
  3549. if ($res) {
  3550. echo '1';
  3551. } else {
  3552. echo '2';
  3553. }
  3554. }
  3555. //刷新帖子
  3556. public function doPageSxTz() {
  3557. global $_GPC, $_W;
  3558. $res = pdo_update('zhtc_information', array('sh_time' => time()), array('id' => $_GPC['id']));
  3559. if ($res) {
  3560. echo '1';
  3561. } else {
  3562. echo '2';
  3563. }
  3564. }
  3565. //查看帖子刷新价格
  3566. public function doPageSxMoney() {
  3567. global $_GPC, $_W;
  3568. $res = pdo_get('zhtc_type', array('id' => $_GPC['type_id']));
  3569. echo json_encode($res);
  3570. }
  3571. //查看发帖次数是否超限
  3572. public function doPageFtXz() {
  3573. global $_GPC, $_W;
  3574. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  3575. if ($system['ft_num'] != 0) {
  3576. $time1 = strtotime(date('Y-m-d'));
  3577. $time2 = $time1 + 24 * 60 * 60;
  3578. $res = count(pdo_getall('zhtc_information', array('time >=' => $time1, 'time <' => $time2, 'user_id' => $_GPC['user_id'])));
  3579. if ($res >= $system['ft_num']) {
  3580. echo '今天发帖次数已经超限!';
  3581. }
  3582. }
  3583. }
  3584. //签到
  3585. public function doPageSign() {
  3586. global $_W, $_GPC;
  3587. $sign = pdo_get('zhtc_signlist', array('user_id' => $_GPC['user_id'], 'time' => $_GPC['time']));
  3588. if (!$sign) {
  3589. $time2 = explode(',', $_GPC['time']);
  3590. $time2 = $time2[0] . "-" . $time2[1] . "-" . $time2[2];
  3591. $time2 = strtotime($time2);
  3592. $data['time2'] = $time2;
  3593. $data['time3'] = time();
  3594. $data['user_id'] = $_GPC['user_id'];
  3595. $data['time'] = $_GPC['time'];
  3596. $data['integral'] = $_GPC['integral'];
  3597. $data['uniacid'] = $_W['uniacid'];
  3598. $res = pdo_insert('zhtc_signlist', $data);
  3599. if ($res) {
  3600. if ($_GPC['one']) {
  3601. pdo_update('zhtc_user', array('total_score +=' => $_GPC['one'], 'day +=' => 1), array('id' => $_GPC['user_id'])); //签到增加积分/签到天数
  3602. $data2['score'] = $_GPC['one'];
  3603. $data2['user_id'] = $_GPC['user_id'];
  3604. $data2['note'] = '首次签到';
  3605. $data2['type'] = 1;
  3606. $data2['cerated_time'] = date('Y-m-d H:i:s');
  3607. $data2['uniacid'] = $_W['uniacid']; //小程序id
  3608. pdo_insert('zhtc_integral', $data2); //添加积分明细
  3609. } else {
  3610. pdo_update('zhtc_user', array('total_score +=' => $_GPC['integral'], 'day +=' => 1), array('id' => $_GPC['user_id'])); //签到增加积分/签到天数
  3611. $data2['score'] = $_GPC['integral'];
  3612. $data2['user_id'] = $_GPC['user_id'];
  3613. $data2['note'] = '每日签到';
  3614. $data2['type'] = 1;
  3615. $data2['cerated_time'] = date('Y-m-d H:i:s');
  3616. $data2['uniacid'] = $_W['uniacid']; //小程序id
  3617. pdo_insert('zhtc_integral', $data2); //添加积分明细
  3618. }
  3619. $list = pdo_getall('zhtc_continuous', array('uniacid' => $_W['uniacid'])); //连续签到列表
  3620. $my = pdo_getall('zhtc_signlist', array('user_id' => $_GPC['user_id']), array(), '', 'time2 DESC');
  3621. // print_r($list);die;
  3622. $time = date('Y,n,j', time()); //今天
  3623. $jt = pdo_get('zhtc_signlist', array('user_id' => $_GPC['user_id'], 'time' => $time)); //查看今天有没有签到
  3624. if ($jt) {
  3625. //签到了
  3626. $num = 0;
  3627. for ($i = 0; $i < count($my); $i++) {
  3628. if (date('Y,n,j', time() - $i * 60 * 60 * 24) == $my[$i]['time']) {
  3629. //从今天开始匹对
  3630. $num = $num + 1;
  3631. } else {
  3632. break;
  3633. }
  3634. }
  3635. } else {
  3636. $num = 0;
  3637. for ($i = 0; $i < count($my); $i++) {
  3638. if (date('Y,n,j', time() - ($i + 1) * 60 * 60 * 24) == $my[$i]['time']) {
  3639. //从昨天开始匹对
  3640. $num = $num + 1;
  3641. } else {
  3642. break;
  3643. }
  3644. }
  3645. }
  3646. for ($k = 0; $k < count($list); $k++) {
  3647. if ($num == $list[$k]['day']) {
  3648. $data3['score'] = $list[$k]['integral'];
  3649. $data3['user_id'] = $_GPC['user_id'];
  3650. $data3['note'] = "连续签到" . $list[$k]['day'] . "天";
  3651. $data3['type'] = 1;
  3652. $data3['cerated_time'] = date('Y-m-d H:i:s');
  3653. $data3['uniacid'] = $_W['uniacid']; //小程序id
  3654. $qd = pdo_get('zhtc_integral', array('uniacid' => $_W['uniacid'], 'note' => $data3['note'], 'user_id' => $_GPC['user_id']));
  3655. if (!$qd) {
  3656. pdo_insert('zhtc_integral', $data3); //添加积分明细
  3657. pdo_update('zhtc_user', array('total_score +=' => $list[$k]['integral']), array('id' => $_GPC['user_id'])); //连续签到增加积分
  3658. }
  3659. break;
  3660. }
  3661. }
  3662. echo '1';
  3663. } else {
  3664. echo '2';
  3665. }
  3666. }
  3667. }
  3668. //补签
  3669. public function doPageSign2() {
  3670. global $_W, $_GPC;
  3671. $time2 = explode(',', $_GPC['time']);
  3672. $time2 = $time2[0] . "-" . $time2[1] . "-" . $time2[2];
  3673. $time2 = strtotime($time2);
  3674. $data['time2'] = $time2;
  3675. $data['time3'] = time();
  3676. $data['user_id'] = $_GPC['user_id'];
  3677. $data['time'] = $_GPC['time'];
  3678. $data['integral'] = $_GPC['integral'];
  3679. $data['uniacid'] = $_W['uniacid'];
  3680. $res = pdo_insert('zhtc_signlist', $data);
  3681. $res2 = pdo_get('zhtc_signset', array('uniacid' => $_W['uniacid']));
  3682. if ($res) {
  3683. pdo_update('zhtc_user', array('total_score -=' => $res2['bq_integral']), array('id' => $_GPC['user_id'])); //签到增加积分/签到天数
  3684. $data4['score'] = $res2['bq_integral'];
  3685. $data4['user_id'] = $_GPC['user_id'];
  3686. $data4['note'] = '补签';
  3687. $data4['type'] = 2;
  3688. $data4['cerated_time'] = date('Y-m-d H:i:s');
  3689. $data4['uniacid'] = $_W['uniacid']; //小程序id
  3690. pdo_insert('zhtc_integral', $data4); //添加积分明细
  3691. if ($_GPC['one']) {
  3692. pdo_update('zhtc_user', array('total_score +=' => $_GPC['one'], 'day +=' => 1), array('id' => $_GPC['user_id'])); //签到增加积分/签到天数
  3693. $data2['score'] = $_GPC['one'];
  3694. $data2['user_id'] = $_GPC['user_id'];
  3695. $data2['note'] = '首次签到';
  3696. $data2['type'] = 1;
  3697. $data2['cerated_time'] = date('Y-m-d H:i:s');
  3698. $data2['uniacid'] = $_W['uniacid']; //小程序id
  3699. pdo_insert('zhtc_integral', $data2); //添加积分明细
  3700. } else {
  3701. pdo_update('zhtc_user', array('total_score +=' => $_GPC['integral'], 'day +=' => 1), array('id' => $_GPC['user_id'])); //签到增加积分/签到天数
  3702. $data2['score'] = $_GPC['integral'];
  3703. $data2['user_id'] = $_GPC['user_id'];
  3704. $data2['note'] = '每日签到';
  3705. $data2['type'] = 1;
  3706. $data2['cerated_time'] = date('Y-m-d H:i:s');
  3707. $data2['uniacid'] = $_W['uniacid']; //小程序id
  3708. pdo_insert('zhtc_integral', $data2); //添加积分明细
  3709. }
  3710. $list = pdo_getall('zhtc_continuous', array('uniacid' => $_W['uniacid'])); //连续签到列表
  3711. $my = pdo_getall('zhtc_signlist', array('user_id' => $_GPC['user_id']), array(), '', 'time2 DESC');
  3712. $time = date('Y,n,j', time()); //今天
  3713. $jt = pdo_get('zhtc_signlist', array('user_id' => $_GPC['user_id'], 'time' => $time)); //查看今天有没有签到
  3714. if ($jt) {
  3715. //签到了
  3716. $num = 0;
  3717. for ($i = 0; $i < count($my); $i++) {
  3718. if (date('Y,n,j', time() - $i * 60 * 60 * 24) == $my[$i]['time']) {
  3719. //从今天开始匹对
  3720. $num = $num + 1;
  3721. } else {
  3722. break;
  3723. }
  3724. }
  3725. } else {
  3726. $num = 0;
  3727. for ($i = 0; $i < count($my); $i++) {
  3728. if (date('Y,n,j', time() - ($i + 1) * 60 * 60 * 24) == $my[$i]['time']) {
  3729. //从昨天开始匹对
  3730. $num = $num + 1;
  3731. } else {
  3732. break;
  3733. }
  3734. }
  3735. }
  3736. for ($k = 0; $k < count($list); $k++) {
  3737. if ($num == $list[$k]['day']) {
  3738. $data3['score'] = $list[$k]['integral'];
  3739. $data3['user_id'] = $_GPC['user_id'];
  3740. $data3['note'] = "连续签到" . $list[$k]['day'] . "天";
  3741. $data3['type'] = 1;
  3742. $data3['cerated_time'] = date('Y-m-d H:i:s');
  3743. $data3['uniacid'] = $_W['uniacid']; //小程序id
  3744. $qd = pdo_get('zhtc_integral', array('uniacid' => $_W['uniacid'], 'note' => $data3['note'], 'user_id' => $_GPC['user_id']));
  3745. if (!$qd) {
  3746. pdo_insert('zhtc_integral', $data3); //添加积分明细
  3747. pdo_update('zhtc_user', array('total_score +=' => $list[$k]['integral']), array('id' => $_GPC['user_id'])); //连续签到增加积分
  3748. }
  3749. break;
  3750. }
  3751. }
  3752. echo '1';
  3753. } else {
  3754. echo '2';
  3755. }
  3756. }
  3757. //查看是否补签
  3758. public function doPageIsbq() {
  3759. global $_W, $_GPC;
  3760. $time = date('Y-m-d');
  3761. $time = "'%$time%'";
  3762. // echo $time;die;
  3763. $sql = "select * from " . tablename("zhtc_integral") . " WHERE cerated_time LIKE " . $time . " and user_id=" . $_GPC['user_id'] . " and note='补签'";
  3764. // echo $sql;die;
  3765. $res = pdo_fetch($sql);
  3766. if ($res) {
  3767. echo '1';
  3768. } else {
  3769. echo '2';
  3770. }
  3771. }
  3772. //查看我的签到
  3773. public function doPageMySign() {
  3774. global $_W, $_GPC;
  3775. $res = pdo_getall('zhtc_signlist', array('user_id' => $_GPC['user_id']));
  3776. echo json_encode($res);
  3777. }
  3778. //签到排行
  3779. public function doPageRank() {
  3780. global $_W, $_GPC;
  3781. $pageindex = max(1, intval($_GPC['page']));
  3782. $pagesize = $_GPC['pagesize'];
  3783. $where = "where uniacid=:uniacid and day!=''";
  3784. $sql = "select * from" . tablename('zhtc_user') . $where . " order by day DESC";
  3785. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  3786. $res = pdo_fetchall($select_sql, array(':uniacid' => $_W['uniacid']));
  3787. echo json_encode($res);
  3788. }
  3789. //今日排行
  3790. public function doPageJrRank() {
  3791. global $_W, $_GPC;
  3792. $pageindex = max(1, intval($_GPC['page']));
  3793. $pagesize = $_GPC['pagesize'];
  3794. $sql = "select a.*,b.name,b.img from " . tablename("zhtc_signlist") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.uniacid=:uniacid and a.time=:time order by time3 asc";
  3795. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  3796. $res = pdo_fetchall($select_sql, array(':uniacid' => $_W['uniacid'], ':time' => date('Y,n,j')));
  3797. echo json_encode($res);
  3798. }
  3799. //我的今日排行
  3800. public function doPageMyJrRank() {
  3801. global $_W, $_GPC;
  3802. $sql = "select a.*,b.name,b.img from " . tablename("zhtc_signlist") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.uniacid=:uniacid and a.time=:time order by time3 asc";
  3803. $res = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid'], ':time' => date('Y,n,j')));
  3804. for ($i = 0; $i < count($res); $i++) {
  3805. if ($_GPC['user_id'] == $res[$i]['user_id']) {
  3806. $res[$i]['num'] = $i + 1;
  3807. $list = $res[$i];
  3808. }
  3809. }
  3810. echo json_encode($list);
  3811. }
  3812. //查看今天是否签到
  3813. public function doPageMyJrSign() {
  3814. global $_W, $_GPC;
  3815. $res = pdo_get('zhtc_signlist', array('user_id' => $_GPC['user_id'], 'time' => date('Y,n,j')));
  3816. if ($res) {
  3817. echo '1';
  3818. } else {
  3819. echo '2';
  3820. }
  3821. }
  3822. //查看今日签到所得积分
  3823. public function doPageMyJrJf() {
  3824. global $_W, $_GPC;
  3825. $time = date('Y-m-d');
  3826. $time = "'%$time%'";
  3827. $sql = "select sum(score) as total from " . tablename("zhtc_integral") . " WHERE cerated_time LIKE " . $time . " and user_id=" . $_GPC['user_id'] . " and (note='每日签到' || note='首次签到' || note LIKE '%连续签到%')";
  3828. $res = pdo_fetch($sql);
  3829. echo $res['total'];
  3830. }
  3831. //查看连签奖励
  3832. public function doPageContinuousList() {
  3833. global $_W, $_GPC;
  3834. $res = pdo_getall('zhtc_continuous', array('uniacid' => $_W['uniacid']), array(), '', 'day asc');
  3835. echo json_encode($res);
  3836. }
  3837. //查看特殊日期奖励
  3838. public function doPageSpecial() {
  3839. global $_W, $_GPC;
  3840. $res = pdo_getall('zhtc_special', array('uniacid' => $_W['uniacid']));
  3841. echo json_encode($res);
  3842. }
  3843. //查看签到规则
  3844. public function doPageSignset() {
  3845. global $_W, $_GPC;
  3846. $res = pdo_getall('zhtc_signset', array('uniacid' => $_W['uniacid']));
  3847. $res[0]['time'] = time();
  3848. echo json_encode($res);
  3849. }
  3850. //查看连续签到天数
  3851. public function doPageContinuous() {
  3852. global $_W, $_GPC;
  3853. $my = pdo_getall('zhtc_signlist', array('user_id' => $_GPC['user_id']), array(), '', 'time2 desc');
  3854. $time = date('Y,n,j', time()); //今天
  3855. $jt = pdo_get('zhtc_signlist', array('user_id' => $_GPC['user_id'], 'time' => $time)); //查看今天有没有签到
  3856. if ($jt) {
  3857. //签到了
  3858. $num = 0;
  3859. for ($i = 0; $i < count($my); $i++) {
  3860. if (date('Y,n,j', time() - $i * 60 * 60 * 24) == $my[$i]['time']) {
  3861. //从今天开始匹对
  3862. $num = $num + 1;
  3863. } else {
  3864. break;
  3865. }
  3866. }
  3867. } else {
  3868. $num = 0;
  3869. for ($i = 0; $i < count($my); $i++) {
  3870. if (date('Y,n,j', time() - ($i + 1) * 60 * 60 * 24) == $my[$i]['time']) {
  3871. //从昨天开始匹对
  3872. $num = $num + 1;
  3873. } else {
  3874. break;
  3875. }
  3876. }
  3877. }
  3878. echo $num;
  3879. }
  3880. //用户信息
  3881. public function doPageUserInfo() {
  3882. global $_W, $_GPC;
  3883. $user = pdo_get('zhtc_user', array('id' => $_GPC['user_id']));
  3884. echo json_encode($user);
  3885. }
  3886. //商品分类
  3887. public function doPageJftype() {
  3888. global $_W, $_GPC;
  3889. $res = pdo_getall('zhtc_jftype', array('uniacid' => $_W['uniacid']), array(), '', 'num asc');
  3890. echo json_encode($res);
  3891. }
  3892. //商品列表
  3893. public function doPageJfGoods() {
  3894. global $_W, $_GPC;
  3895. $res = pdo_getall('zhtc_jfgoods', array('uniacid' => $_W['uniacid'], 'is_open' => 1), array(), '', 'num asc');
  3896. echo json_encode($res);
  3897. }
  3898. //商品详情
  3899. public function doPageJfGoodsInfo() {
  3900. global $_W, $_GPC;
  3901. $res = pdo_getall('zhtc_jfgoods', array('id' => $_GPC['id']));
  3902. echo json_encode($res);
  3903. }
  3904. //分类下的商品
  3905. public function doPageJftypeGoods() {
  3906. global $_W, $_GPC;
  3907. $res = pdo_getall('zhtc_jfgoods', array('type_id' => $_GPC['type_id'], 'is_open' => 1), array(), '', 'num asc');
  3908. echo json_encode($res);
  3909. }
  3910. //积分商城广告
  3911. public function doPageAd3() {
  3912. global $_GPC, $_W;
  3913. $where = " where uniacid=:uniacid and status=1 and type=9";
  3914. if ($_GPC['cityname']) {
  3915. $where .= " and (cityname LIKE concat('%', :name,'%') or cityname='全国版')";
  3916. $data[':name'] = $_GPC['cityname'];
  3917. }
  3918. $data[':uniacid'] = $_W['uniacid'];
  3919. $sql = "select * from " . tablename('zhtc_ad') . $where . " order by orderby asc";
  3920. $res = pdo_fetchall($sql, $data);
  3921. echo json_encode($res);
  3922. }
  3923. //兑换商品
  3924. public function doPageExchange() {
  3925. global $_W, $_GPC;
  3926. $data['user_id'] = $_GPC['user_id']; //用户id
  3927. $data['good_id'] = $_GPC['good_id']; //商品id
  3928. $data['user_name'] = $_GPC['user_name']; //用户名称
  3929. $data['user_tel'] = $_GPC['user_tel']; //用户电话
  3930. $data['address'] = $_GPC['address']; //地址
  3931. $data['integral'] = $_GPC['integral']; //积分
  3932. $data['good_name'] = $_GPC['good_name']; //商品名称
  3933. $data['good_img'] = $_GPC['good_img']; //商品图片
  3934. $data['time'] = date("Y-m-d H:i:s");
  3935. $res = pdo_insert('zhtc_jfrecord', $data);
  3936. if ($res) {
  3937. pdo_update('zhtc_jfgoods', array('number -=' => 1), array('id' => $_GPC['good_id']));
  3938. if ($_GPC['type'] == 1) {
  3939. //虚拟红包
  3940. pdo_update('zhtc_user', array('money +=' => $_GPC['hb_money']), array('id' => $_GPC['user_id']));
  3941. $data2['money'] = $_GPC['hb_money'];
  3942. $data2['user_id'] = $_GPC['user_id'];
  3943. $data2['type'] = 1;
  3944. $data2['note'] = '积分兑换';
  3945. $data2['time'] = date('Y-m-d H:i:s');
  3946. pdo_insert('zhtc_qbmx', $data2);
  3947. }
  3948. $data3['score'] = $_GPC['integral'];
  3949. $data3['user_id'] = $_GPC['user_id'];
  3950. $data3['note'] = '兑换商品';
  3951. $data3['type'] = 2;
  3952. $data3['cerated_time'] = date('Y-m-d H:i:s');
  3953. $data3['uniacid'] = $_W['uniacid']; //小程序id
  3954. pdo_insert('zhtc_integral', $data3);
  3955. pdo_update('zhtc_user', array('total_score -=' => $_GPC['integral']), array('id' => $_GPC['user_id']));
  3956. echo '1';
  3957. } else {
  3958. echo '2';
  3959. }
  3960. }
  3961. //兑换明细
  3962. public function doPageDhmx() {
  3963. global $_W, $_GPC;
  3964. $res = pdo_getall('zhtc_jfrecord', array('user_id' => $_GPC['user_id']), array(), '', 'id DESC');
  3965. echo json_encode($res);
  3966. }
  3967. //积分明细
  3968. public function doPageJfmx() {
  3969. global $_W, $_GPC;
  3970. $res = pdo_getall('zhtc_integral', array('user_id' => $_GPC['user_id']), array(), '', 'id DESC');
  3971. echo json_encode($res);
  3972. }
  3973. //分类轮播图
  3974. public function doPageStoreTypeAd() {
  3975. global $_W, $_GPC;
  3976. if ($_GPC['type'] == 1) {
  3977. $sql = "select * from " . tablename("zhtc_storetypead") . " WHERE status=1 and type_id={$_GPC['type_id']} and (cityname='{$_GPC['cityname']}' || cityname='全国版') order by orderby asc";
  3978. $res = pdo_fetchall($sql);
  3979. } elseif ($_GPC['type'] == 2) {
  3980. $sql = "select * from " . tablename("zhtc_storetypead") . " WHERE status=1 and type_id2={$_GPC['type_id']} and (cityname='{$_GPC['cityname']}' || cityname='全国版') order by orderby asc";
  3981. $res = pdo_fetchall($sql);
  3982. }
  3983. echo json_encode($res);
  3984. }
  3985. //活动分类
  3986. public function doPageActType() {
  3987. global $_W, $_GPC;
  3988. $res = pdo_getall('zhtc_acttype', array('uniacid' => $_W['uniacid'], 'state' => 1), array(), '', 'num asc');
  3989. echo json_encode($res);
  3990. }
  3991. //活动列表
  3992. public function doPageActivity() {
  3993. global $_W, $_GPC;
  3994. $where = " where a.uniacid=" . $_W['uniacid'];
  3995. if ($_GPC['type_id']) {
  3996. $where .= " and a.type_id=" . $_GPC['type_id'];
  3997. }
  3998. if ($_GPC['cityname']) {
  3999. $where .= " and (a.cityname='{$_GPC['cityname']}' || a.cityname='')";
  4000. }
  4001. $pageindex = max(1, intval($_GPC['page']));
  4002. $pagesize = $_GPC['pagesize'];
  4003. $sql = " select a.* ,b.type_name from " . tablename('zhtc_activity') . " a" . " left join " . tablename("zhtc_acttype") . " b on b.id=a.type_id " . $where . " order by a.num asc";
  4004. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  4005. $res = pdo_fetchall($select_sql, $data);
  4006. echo json_encode($res);
  4007. }
  4008. //活动详情
  4009. public function doPageActivityInfo() {
  4010. global $_W, $_GPC;
  4011. $res = pdo_get('zhtc_activity', array('id' => $_GPC['id']));
  4012. if ($res['img']) {
  4013. if (strpos($res['img'], ',')) {
  4014. $res['img'] = explode(',', $res['img']);
  4015. } else {
  4016. $res['img'] = array(
  4017. 0 => $res['img'],
  4018. );
  4019. }
  4020. }
  4021. echo json_encode($res);
  4022. }
  4023. //报名
  4024. public function doPageSignUp() {
  4025. global $_W, $_GPC;
  4026. $act = pdo_get('zhtc_activity', array('id' => $_GPC['act_id']));
  4027. if (($act['number'] - $act['sign_num']) > 0 and $act['number'] != 0) {
  4028. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4029. $data['user_id'] = $_GPC['user_id'];
  4030. $data['act_id'] = $_GPC['act_id'];
  4031. $data['time'] = date("Y-m-d H:i:s");
  4032. $data['money'] = $_GPC['money'];
  4033. $data['user_name'] = $_GPC['user_name'];
  4034. $data['user_tel'] = $_GPC['user_tel'];
  4035. $data['form_id'] = $_GPC['form_id'];
  4036. if ($_GPC['money'] == 0) {
  4037. if ($system['is_bm'] == 1) {
  4038. $data['state'] = 3;
  4039. } else {
  4040. $data['state'] = 2;
  4041. }
  4042. } else {
  4043. $data['state'] = 1;
  4044. }
  4045. $data['uniacid'] = $_W['uniacid'];
  4046. $res = pdo_insert('zhtc_joinlist', $data);
  4047. $id = pdo_insertid();
  4048. if ($res) {
  4049. if ($_GPC['money'] == 0) {
  4050. file_get_contents("" . $_W['siteroot'] . "/app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=HdMessage&m=zh_tcwq&id=" . $id); //模板消息
  4051. pdo_update('zhtc_activity', array('sign_num +=' => 1), array('id' => $_GPC['act_id']));
  4052. }
  4053. echo $id;
  4054. } else {
  4055. echo '报名失败';
  4056. }
  4057. } else {
  4058. echo '人数已满';
  4059. }
  4060. }
  4061. //查看是否能报名
  4062. public function doPageIsSignUp() {
  4063. global $_W, $_GPC;
  4064. $res = pdo_get('zhtc_joinlist', array('user_id' => $_GPC['user_id'], 'act_id' => $_GPC['act_id'], 'state' => array('2', '3')));
  4065. if ($res) {
  4066. echo '2';
  4067. } else {
  4068. echo '1';
  4069. }
  4070. }
  4071. //活动支付
  4072. public function doPagePay3() {
  4073. global $_W, $_GPC;
  4074. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  4075. // include 'wxpay.php';
  4076. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4077. if ($res['pt_name']) {
  4078. $res['pt_name'] = $res['pt_name'];
  4079. } else {
  4080. $res['pt_name'] = '同城小程序';
  4081. }
  4082. $appid = $res['appid'];
  4083. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  4084. $mch_id = $res['mchid'];
  4085. $key = $res['wxkey'];
  4086. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  4087. $out_trade_no = time() . $user['id'];
  4088. $root = $_W['siteroot'];
  4089. $order = pdo_get('zhtc_joinlist', array('id' => $_GPC['order_id']));
  4090. pdo_update('zhtc_joinlist', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  4091. $total_fee = $order['money'];
  4092. if (empty($total_fee)) //押金
  4093. {
  4094. $body = $res['pt_name'];
  4095. $total_fee = floatval(99 * 100);
  4096. } else {
  4097. $body = $res['pt_name'];
  4098. $total_fee = floatval($total_fee * 100);
  4099. }
  4100. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  4101. $return = $weixinpay->pay();
  4102. echo json_encode($return);
  4103. }
  4104. //我的报名
  4105. public function doPageMyActivity() {
  4106. global $_W, $_GPC;
  4107. $where = " where a.user_id=" . $_GPC['user_id'] . " and a.state!=1 and b.title!=''";
  4108. $pageindex = max(1, intval($_GPC['page']));
  4109. $pagesize = $_GPC['pagesize'];
  4110. $sql = " select a.* ,b.title,b.start_time,b.end_time,b.address,b.coordinate,b.logo from " . tablename('zhtc_joinlist') . " a" . " left join " . tablename("zhtc_activity") . " b on b.id=a.act_id " . $where . " order by a.id desc";
  4111. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  4112. $res = pdo_fetchall($select_sql, $data);
  4113. echo json_encode($res);
  4114. }
  4115. //核销码
  4116. public function doPageActCode() {
  4117. global $_W, $_GPC;
  4118. function getCoade($storeid) {
  4119. function getaccess_token() {
  4120. global $_W, $_GPC;
  4121. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4122. $appid = $res['appid'];
  4123. $secret = $res['appsecret'];
  4124. // print_r($res);die;
  4125. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4126. $ch = curl_init();
  4127. curl_setopt($ch, CURLOPT_URL, $url);
  4128. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4129. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4130. $data = curl_exec($ch);
  4131. curl_close($ch);
  4132. $data = json_decode($data, true);
  4133. return $data['access_token'];
  4134. }
  4135. function set_msg($storeid) {
  4136. $access_token = getaccess_token();
  4137. $data2 = array(
  4138. "scene" => $storeid,
  4139. "page" => "zh_tcwq/pages/wdbm/hx",
  4140. "width" => 400,
  4141. );
  4142. $data2 = json_encode($data2);
  4143. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  4144. $ch = curl_init();
  4145. curl_setopt($ch, CURLOPT_URL, $url);
  4146. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4147. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4148. curl_setopt($ch, CURLOPT_POST, 1);
  4149. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  4150. $data = curl_exec($ch);
  4151. curl_close($ch);
  4152. return $data;
  4153. }
  4154. $img = set_msg($storeid);
  4155. $img = base64_encode($img);
  4156. return $img;
  4157. }
  4158. echo getCoade($_GPC['id']);
  4159. }
  4160. //核销
  4161. public function doPageActHx() {
  4162. global $_W, $_GPC;
  4163. $join = pdo_get('zhtc_joinlist', array('id' => $_GPC['id']));
  4164. $hx = pdo_get('zhtc_acthxlist', array('user_id' => $_GPC['user_id'], 'act_id' => $join['act_id']));
  4165. if ($join['state'] == 4) {
  4166. echo '2';
  4167. } else {
  4168. if ($hx) {
  4169. $res = pdo_update('zhtc_joinlist', array('state' => 4, 'hx_time' => date("Y-m-d H:i:s")), array('id' => $_GPC['id']));
  4170. if ($res) {
  4171. echo '1';
  4172. } else {
  4173. echo '2';
  4174. }
  4175. } else {
  4176. echo '暂无核销权限';
  4177. }
  4178. }
  4179. }
  4180. //活动城市佣金
  4181. public function doPageActYj() {
  4182. global $_W, $_GPC;
  4183. $cityname = Yj::getActCity($_GPC['act_id']);
  4184. $yjset = Yj::getYjSet($_W['uniacid']);
  4185. include IA_ROOT . '/addons/zh_tcwq/yj.php';
  4186. if ($yjset['type'] == 1) {
  4187. $money = $_GPC['money'] * $yjset['typer'] / 100;
  4188. } else {
  4189. $money = $_GPC['money'] * $yjset['sjper'] / 100;
  4190. }
  4191. pdo_update('zhtc_account', array('money +=' => $money), array('cityname' => $cityname));
  4192. }
  4193. //查看电话城市佣金
  4194. public function doPageCallYj() {
  4195. global $_W, $_GPC;
  4196. $cityname = Yj::getTzCity($_GPC['post_id']);
  4197. $yjset = Yj::getYjSet($_W['uniacid']);
  4198. include IA_ROOT . '/addons/zh_tcwq/yj.php';
  4199. if ($yjset['type'] == 1) {
  4200. $money = $_GPC['money'] * $yjset['typer'] / 100;
  4201. } else {
  4202. $money = $_GPC['money'] * $yjset['sjper'] / 100;
  4203. }
  4204. pdo_update('zhtc_account', array('money +=' => $money), array('cityname' => $cityname));
  4205. }
  4206. //分销二维码
  4207. public function doPageHdPoster() {
  4208. global $_W, $_GPC;
  4209. function getCoade($id) {
  4210. function getaccess_token() {
  4211. global $_W, $_GPC;
  4212. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4213. $appid = $res['appid'];
  4214. $secret = $res['appsecret'];
  4215. // $appid='wx80fa1d36c435231a';
  4216. // $secret='9bb4735bd092f092477049bfd7e183f8';
  4217. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4218. $ch = curl_init();
  4219. curl_setopt($ch, CURLOPT_URL, $url);
  4220. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4221. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4222. $data = curl_exec($ch);
  4223. curl_close($ch);
  4224. $data = json_decode($data, true);
  4225. return $data['access_token'];
  4226. }
  4227. function set_msg($id) {
  4228. $access_token = getaccess_token();
  4229. $data2 = array(
  4230. "scene" => $id,
  4231. "page" => "zh_tcwq/pages/infodetial/infodetial",
  4232. "width" => 100,
  4233. );
  4234. $data2 = json_encode($data2);
  4235. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  4236. $ch = curl_init();
  4237. curl_setopt($ch, CURLOPT_URL, $url);
  4238. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4239. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4240. curl_setopt($ch, CURLOPT_POST, 1);
  4241. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  4242. $data = curl_exec($ch);
  4243. curl_close($ch);
  4244. return $data;
  4245. }
  4246. $img = set_msg($id);
  4247. $img = base64_encode($img);
  4248. return $img;
  4249. }
  4250. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['id']);
  4251. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  4252. $type = $result[2];
  4253. $new_file = IA_ROOT . "/addons/zh_tcwq/img/";
  4254. if (!file_exists($new_file)) {
  4255. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  4256. mkdir($new_file, 0777);
  4257. }
  4258. $wname = "{$_GPC['id']}" . ".{$type}";
  4259. //$wname="1511.jpeg";
  4260. $new_file = $new_file . $wname;
  4261. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  4262. }
  4263. echo "/addons/zh_tcwq/img/" . $wname;
  4264. }
  4265. //商家收银
  4266. public function doPageAddDmOrder() {
  4267. global $_W, $_GPC;
  4268. $data['user_id'] = $_GPC['user_id'];
  4269. $data['store_id'] = $_GPC['store_id'];
  4270. $data['money'] = $_GPC['money'];
  4271. $data['uniacid'] = $_W['uniacid'];
  4272. $data['time'] = date("Y-m-d H:i:s");
  4273. $data['state'] = 1;
  4274. $res = pdo_insert('zhtc_dmorder', $data);
  4275. $order_id = pdo_insertid();
  4276. if ($res) {
  4277. echo $order_id;
  4278. } else {
  4279. echo '下单失败';
  4280. }
  4281. }
  4282. //收银支付
  4283. public function doPagePay4() {
  4284. global $_W, $_GPC;
  4285. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  4286. // include 'wxpay.php';
  4287. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4288. if ($res['pt_name']) {
  4289. $res['pt_name'] = $res['pt_name'];
  4290. } else {
  4291. $res['pt_name'] = '同城小程序';
  4292. }
  4293. $appid = $res['appid'];
  4294. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  4295. $mch_id = $res['mchid'];
  4296. $key = $res['wxkey'];
  4297. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  4298. $out_trade_no = time() . $user['id'];
  4299. $root = $_W['siteroot'];
  4300. $order = pdo_get('zhtc_dmorder', array('id' => $_GPC['order_id']));
  4301. pdo_update('zhtc_dmorder', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  4302. $total_fee = $order['money'];
  4303. if (empty($total_fee)) //押金
  4304. {
  4305. $body = $res['pt_name'];
  4306. $total_fee = floatval(99 * 100);
  4307. } else {
  4308. $body = $res['pt_name'];
  4309. $total_fee = floatval($total_fee * 100);
  4310. }
  4311. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  4312. $return = $weixinpay->pay();
  4313. echo json_encode($return);
  4314. }
  4315. //发布优惠券
  4316. public function doPageAddCoupon() {
  4317. global $_W, $_GPC;
  4318. $store = pdo_get('zhtc_store', array('id' => $_GPC['store_id']));
  4319. $data['name'] = $_GPC['name'];
  4320. $data['number'] = $_GPC['number'];
  4321. $data['surplus'] = $_GPC['number'];
  4322. $data['full'] = $_GPC['full'];
  4323. $data['reduce'] = $_GPC['reduce'];
  4324. $data['money'] = $_GPC['money'];
  4325. $data['end_time'] = $_GPC['end_time'];
  4326. $data['details'] = $_GPC['details'];
  4327. $data['store_id'] = $_GPC['store_id'];
  4328. $data['cityname'] = $store['cityname'];
  4329. $data['img'] = $_GPC['img'];
  4330. $data['type_id'] = $_GPC['type_id'];
  4331. $data['time'] = date("Y-m-d H:i:s");
  4332. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4333. if ($system['is_yhqsh'] == 1) {
  4334. $data['state'] = 1;
  4335. } else {
  4336. $data['state'] = 2;
  4337. }
  4338. $res = pdo_insert('zhtc_coupons', $data);
  4339. if ($res) {
  4340. echo '1';
  4341. } else {
  4342. echo '2';
  4343. }
  4344. }
  4345. //查看店铺优惠券
  4346. public function doPageStoreCoupon() {
  4347. global $_W, $_GPC;
  4348. $res = pdo_getall('zhtc_coupons', array('store_id' => $_GPC['store_id'], 'is_show' => 1, 'state' => 2, 'del' => 2));
  4349. echo json_encode($res);
  4350. }
  4351. //查看店铺优惠券
  4352. public function doPageStoreCoupon2() {
  4353. global $_W, $_GPC;
  4354. $res = pdo_getall('zhtc_coupons', array('store_id' => $_GPC['store_id'], 'del' => 2));
  4355. echo json_encode($res);
  4356. }
  4357. //上下架
  4358. public function doPageUpdCoupon() {
  4359. global $_W, $_GPC;
  4360. $res = pdo_update('zhtc_coupons', array('is_show' => $_GPC['is_show']), array('id' => $_GPC['coupon_id']));
  4361. if ($res) {
  4362. echo '1';
  4363. } else {
  4364. echo '2';
  4365. }
  4366. }
  4367. //优惠券详情
  4368. public function doPageCouponInfo() {
  4369. global $_W, $_GPC;
  4370. $res = pdo_get('zhtc_coupons', array('id' => $_GPC['coupon_id']));
  4371. if ($res['img']) {
  4372. if (strpos($res['img'], ',')) {
  4373. $res['img'] = explode(',', $res['img']);
  4374. } else {
  4375. $res['img'] = array(
  4376. 0 => $res['img'],
  4377. );
  4378. }
  4379. }
  4380. $user = pdo_get('zhtc_usercoupons', array('coupons_id' => $_GPC['coupon_id'], 'user_id' => $_GPC['user_id'], 'pay_type' => 2, 'state' => 2));
  4381. if ($user) {
  4382. $user_state = 1;
  4383. } else {
  4384. $user_state = 2;
  4385. }
  4386. $res['user_state'] = $user_state;
  4387. echo json_encode($res);
  4388. }
  4389. //优惠券详情
  4390. public function doPageCouponInfo2() {
  4391. global $_W, $_GPC;
  4392. $res = pdo_get('zhtc_coupons', array('id' => $_GPC['coupon_id']));
  4393. if ($res['img']) {
  4394. if (strpos($res['img'], ',')) {
  4395. $res['img'] = explode(',', $res['img']);
  4396. } else {
  4397. $res['img'] = array(
  4398. 0 => $res['img'],
  4399. );
  4400. }
  4401. }
  4402. $res2 = pdo_getall('zhtc_usercoupons', array('coupons_id' => $_GPC['coupon_id'], 'pay_type' => 2));
  4403. $res3 = pdo_getall('zhtc_usercoupons', array('coupons_id' => $_GPC['coupon_id'], 'state' => 1, 'pay_type' => 2));
  4404. $res['lq_num'] = count($res2);
  4405. $res['hx_num'] = count($res3);
  4406. echo json_encode($res);
  4407. }
  4408. //领取优惠券
  4409. public function doPageLqCoupon() {
  4410. global $_W, $_GPC;
  4411. $data['user_id'] = $_GPC['user_id'];
  4412. $data['coupons_id'] = $_GPC['coupons_id'];
  4413. $data['lq_money'] = $_GPC['lq_money'];
  4414. if ($_GPC['lq_money'] == 0) {
  4415. $_GPC['pay_type'] = 2;
  4416. } else {
  4417. $_GPC['pay_type'] = 1;
  4418. }
  4419. $data['pay_type'] = $_GPC['pay_type'];
  4420. $data['state'] = 2;
  4421. $data['time'] = date("Y-m-d H:i:s");
  4422. $res = pdo_insert('zhtc_usercoupons', $data);
  4423. $order = pdo_insertid();
  4424. if ($res) {
  4425. if ($_GPC['lq_money'] == 0) {
  4426. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=KqMessage&m=zh_tcwq&id=" . $order); //模板
  4427. pdo_update('zhtc_coupons', array('surplus -=' => 1), array('id' => $_GPC['coupons_id']));
  4428. }
  4429. echo $order;
  4430. } else {
  4431. echo '下单失败';
  4432. }
  4433. }
  4434. //我的优惠券
  4435. public function doPageMyCoupons() {
  4436. global $_W, $_GPC;
  4437. $sql = "select a.* ,b.name as coupons_name,b.end_time,b.full,b.reduce,b.details,c.store_name,c.logo as store_logo,c.id as store_id from " . tablename("zhtc_usercoupons") . " a" . " left join " . tablename("zhtc_coupons") . " b on b.id=a.coupons_id left join " . tablename("zhtc_store") . " c on b.store_id=c.id WHERE a.user_id=:user_id and a.pay_type=2 and a.del=2";
  4438. $list = pdo_fetchall($sql, array(':user_id' => $_GPC['user_id']));
  4439. echo json_encode($list);
  4440. }
  4441. //优惠券支付
  4442. public function doPagePay5() {
  4443. global $_W, $_GPC;
  4444. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  4445. // include 'wxpay.php';
  4446. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4447. if ($res['pt_name']) {
  4448. $res['pt_name'] = $res['pt_name'];
  4449. } else {
  4450. $res['pt_name'] = '同城小程序';
  4451. }
  4452. $appid = $res['appid'];
  4453. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  4454. $mch_id = $res['mchid'];
  4455. $key = $res['wxkey'];
  4456. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  4457. $out_trade_no = time() . $user['id'];
  4458. $root = $_W['siteroot'];
  4459. pdo_update('zhtc_usercoupons', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  4460. $order = pdo_get('zhtc_usercoupons', array('id' => $_GPC['order_id']));
  4461. $total_fee = $order['lq_money'];
  4462. if (empty($total_fee)) //押金
  4463. {
  4464. $body = $res['pt_name'];
  4465. $total_fee = floatval(99 * 100);
  4466. } else {
  4467. $body = $res['pt_name'];
  4468. $total_fee = floatval($total_fee * 100);
  4469. }
  4470. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  4471. $return = $weixinpay->pay();
  4472. echo json_encode($return);
  4473. }
  4474. //升级合伙人
  4475. public function doPagePay6() {
  4476. global $_W, $_GPC;
  4477. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  4478. // include 'wxpay.php';
  4479. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4480. if ($res['pt_name']) {
  4481. $res['pt_name'] = $res['pt_name'];
  4482. } else {
  4483. $res['pt_name'] = '同城小程序';
  4484. }
  4485. $appid = $res['appid'];
  4486. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  4487. $mch_id = $res['mchid'];
  4488. $key = $res['wxkey'];
  4489. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  4490. $out_trade_no = time() . $user['id'];
  4491. $root = $_W['siteroot'];
  4492. pdo_update('zhtc_fxlog', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  4493. $order = pdo_get('zhtc_fxlog', array('id' => $_GPC['order_id']));
  4494. $total_fee = $order['money'];
  4495. if (empty($total_fee)) //押金
  4496. {
  4497. $body = $res['pt_name'];
  4498. $total_fee = floatval(99 * 100);
  4499. } else {
  4500. $body = $res['pt_name'];
  4501. $total_fee = floatval($total_fee * 100);
  4502. }
  4503. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  4504. $return = $weixinpay->pay();
  4505. echo json_encode($return);
  4506. }
  4507. //核销码
  4508. public function doPageCouponCode() {
  4509. global $_W, $_GPC;
  4510. global $_W, $_GPC;
  4511. function getCoade($user_id) {
  4512. function getaccess_token() {
  4513. global $_W, $_GPC;
  4514. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4515. $appid = $res['appid'];
  4516. $secret = $res['appsecret'];
  4517. /*$appid='wx80fa1d36c435231a';
  4518. $secret='41d8f6e7fad1a13cfa2e6de8acf14280';*/
  4519. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4520. $ch = curl_init();
  4521. curl_setopt($ch, CURLOPT_URL, $url);
  4522. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4523. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4524. $data = curl_exec($ch);
  4525. curl_close($ch);
  4526. $data = json_decode($data, true);
  4527. return $data['access_token'];
  4528. }
  4529. function set_msg($user_id) {
  4530. $access_token = getaccess_token();
  4531. $data2 = array(
  4532. "scene" => $user_id,
  4533. "width" => 100,
  4534. 'page' => 'zh_tcwq/pages/wdq/hxyhq',
  4535. );
  4536. $data2 = json_encode($data2);
  4537. //$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token."";
  4538. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  4539. $ch = curl_init();
  4540. curl_setopt($ch, CURLOPT_URL, $url);
  4541. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4542. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4543. curl_setopt($ch, CURLOPT_POST, 1);
  4544. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  4545. $data = curl_exec($ch);
  4546. curl_close($ch);
  4547. return $data;
  4548. }
  4549. $img = set_msg($user_id);
  4550. $img = base64_encode($img);
  4551. return $img;
  4552. }
  4553. echo getCoade($_GPC['id']);
  4554. }
  4555. //核销优惠券
  4556. public function doPageHxCoupon() {
  4557. global $_W, $_GPC;
  4558. $usercoupons = pdo_get('zhtc_usercoupons', array('id' => $_GPC['id']));
  4559. $coupons = pdo_get('zhtc_coupons', array('id' => $usercoupons['coupons_id']));
  4560. if ($usercoupons['state'] == 1) {
  4561. echo '不能重复核销';
  4562. } else {
  4563. if ($coupons['store_id'] == $_GPC['store_id']) {
  4564. $res = pdo_update('zhtc_usercoupons', array('state' => 1, 'hx_time' => date("Y-m-d H:i:s")), array('id' => $_GPC['id']));
  4565. if ($res) {
  4566. echo '核销成功';
  4567. } else {
  4568. echo '核销失败';
  4569. }
  4570. } else {
  4571. echo '无核销权限';
  4572. }
  4573. }
  4574. }
  4575. //领取列表
  4576. public function doPageLqCouponList() {
  4577. global $_W, $_GPC;
  4578. $pageindex = max(1, intval($_GPC['page']));
  4579. $pagesize = $_GPC['pagesize'];
  4580. if ($_GPC['state']) {
  4581. $where = " and a.state=" . $_GPC['state'];
  4582. }
  4583. $sql = "select a.* ,b.name as user_name,b.img as user_img from " . tablename("zhtc_usercoupons") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id WHERE a.coupons_id=:coupons_id and a.pay_type=2 " . $where . " order by " . $_GPC['orderby'];
  4584. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  4585. $list = pdo_fetchall($select_sql, array(':coupons_id' => $_GPC['coupons_id']));
  4586. echo json_encode($list);
  4587. }
  4588. //商家删除优惠券
  4589. public function doPageDelCoupon2() {
  4590. global $_W, $_GPC;
  4591. $res = pdo_update('zhtc_coupons', array('del' => 1), array('id' => $_GPC['coupon_id']));
  4592. if ($res) {
  4593. echo '1';
  4594. } else {
  4595. echo '2';
  4596. }
  4597. }
  4598. //删除优惠券
  4599. public function doPageDelCoupon() {
  4600. global $_W, $_GPC;
  4601. $res = pdo_update('zhtc_usercoupons', array('del' => 1), array('id' => $_GPC['coupon_id']));
  4602. if ($res) {
  4603. echo '1';
  4604. } else {
  4605. echo '2';
  4606. }
  4607. }
  4608. //我的优惠券详情
  4609. public function doPageMyCouponsInfo() {
  4610. global $_W, $_GPC;
  4611. $res = pdo_get('zhtc_usercoupons', array('id' => $_GPC['id']));
  4612. echo json_encode($res);
  4613. }
  4614. //收益统计
  4615. public function doPageProfit() {
  4616. global $_W, $_GPC;
  4617. $time = date("Y-m-d");
  4618. $time = "'%$time%'";
  4619. $zttime = date("Y-m-d", strtotime("-1 day"));
  4620. $zttime = "'%$zttime%'";
  4621. $storeid = $_GPC['store_id'];
  4622. function Profit($storeid, $time) {
  4623. if ($time) {
  4624. $where = " FROM_UNIXTIME(complete_time) LIKE " . $time . " and ";
  4625. $where2 = " time LIKE " . $time . " and";
  4626. $where3 = " a.time LIKE " . $time . " and";
  4627. $where4 = " pay_time LIKE " . $time . " and";
  4628. }
  4629. $dd = "select sum(money) as total from " . tablename("zhtc_order") . " WHERE " . $where . " store_id=" . $storeid . " and state in (4,7)";
  4630. $dd = pdo_fetch($dd); //今天的订单销售额
  4631. $dd = empty($dd['total']) ? '0.00' : $dd['total'];
  4632. $dmf = "select sum(money) as total from " . tablename("zhtc_dmorder") . " WHERE " . $where2 . " store_id=" . $storeid . " and state=2";
  4633. $dmf = pdo_fetch($dmf); //今天的当面付销售额
  4634. $dmf = empty($dmf['total']) ? '0.00' : $dmf['total'];
  4635. $yhq = "select sum(a.lq_money) as total from " . tablename("zhtc_usercoupons") . " a" . " left join " . tablename("zhtc_coupons") . " b on b.id=a.coupons_id WHERE " . $where3 . " b.store_id=" . $storeid . " and a.pay_type=2";
  4636. $yhq = pdo_fetch($yhq); //今天的优惠券销售额
  4637. $yhq = empty($yhq['total']) ? '0.00' : $yhq['total'];
  4638. $qg = "select sum(money) as total from " . tablename("zhtc_qgorder") . " WHERE " . $where4 . " store_id=" . $storeid . " and state in (2,3)";
  4639. $qg = pdo_fetch($qg); //今天的抢购销售额
  4640. $qg = empty($qg['total']) ? '0.00' : $qg['total'];
  4641. $pt = "select sum(money) as total from " . tablename("zhtc_store_wallet") . " WHERE " . $where2 . " note='拼团订单' and store_id=" . $storeid;
  4642. $pt = pdo_fetch($pt);
  4643. $pt = empty($pt['total']) ? '0.00' : $pt['total'];
  4644. $total = $dd + $dmf + $yhq + $qg + $pt; //今天的销售额
  4645. return $total;
  4646. }
  4647. $data['jt'] = Profit($storeid, $time);
  4648. $data['zt'] = Profit($storeid, $zttime);
  4649. $data['all'] = Profit($storeid, '');
  4650. echo json_encode($data);
  4651. }
  4652. //升级
  4653. public function doPageSjFx() {
  4654. global $_W, $_GPC;
  4655. $distribution = pdo_get('zhtc_distribution', array('user_id' => $_GPC['user_id'])); //当前等级
  4656. $oldlevel = pdo_get('zhtc_fxlevel', array('id' => $distribution['level'])); //老等级
  4657. $newlevel = pdo_get('zhtc_fxlevel', array('id' => $_GPC['level'])); //新等级
  4658. $data['user_id'] = $_GPC['user_id'];
  4659. $data['money'] = $newlevel['money'] - $oldlevel['money'];
  4660. $data['time'] = date("Y-m-d H:i:s");
  4661. $data['level'] = $_GPC['level'];
  4662. $data['uniacid'] = $_W['uniacid'];
  4663. $data['note'] = '升级合伙人';
  4664. if ($_GPC['money'] == 0) {
  4665. $data['state'] = 2;
  4666. } else {
  4667. $data['state'] = 1;
  4668. }
  4669. $res = pdo_insert('zhtc_fxlog', $data);
  4670. $id = pdo_insertid();
  4671. if ($res) {
  4672. if ($_GPC['money'] == 0) {
  4673. pdo_update('zhtc_distribution', array('level' => $_GPC['level']), array('user_id' => $_GPC['user_id'], 'pay_state' => 2, 'state' => 2));
  4674. }
  4675. echo $id;
  4676. } else {
  4677. echo '下单失败';
  4678. }
  4679. }
  4680. //流量主
  4681. public function doPageLlz() {
  4682. global $_W, $_GPC;
  4683. $where = " where uniacid=:uniacid and status=1 and type=" . $_GPC['type'];
  4684. if ($_GPC['cityname']) {
  4685. $where .= " and (cityname LIKE concat('%', :name,'%') or cityname='')";
  4686. $data[':name'] = $_GPC['cityname'];
  4687. }
  4688. $data[':uniacid'] = $_W['uniacid'];
  4689. $sql = "select * from " . tablename('zhtc_llz') . $where;
  4690. $res = pdo_fetchall($sql, $data);
  4691. echo json_encode($res);
  4692. }
  4693. //查看我的formid
  4694. public function doPageMyFormId() {
  4695. global $_W, $_GPC;
  4696. $time = time() - 60 * 60 * 24 * 7;
  4697. $sql = "select count(*) as count from " . tablename("zhtc_userformid") . " where user_id={$_GPC['user_id']} and UNIX_TIMESTAMP(time)>={$time}";
  4698. $res = pdo_fetch($sql);
  4699. echo $res['count'];
  4700. }
  4701. //发货模板消息
  4702. public function doPageFhMessage() {
  4703. global $_W, $_GPC;
  4704. function getaccess_token($_W) {
  4705. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4706. $appid = $res['appid'];
  4707. $secret = $res['appsecret'];
  4708. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4709. $ch = curl_init();
  4710. curl_setopt($ch, CURLOPT_URL, $url);
  4711. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4712. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4713. $data = curl_exec($ch);
  4714. curl_close($ch);
  4715. $data = json_decode($data, true);
  4716. return $data['access_token'];
  4717. }
  4718. //设置与发送模板信息
  4719. function set_msg($_W, $_GPC) {
  4720. $access_token = getaccess_token($_W);
  4721. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  4722. $order = pdo_get('zhtc_order', array('id' => $_GPC['order_id']));
  4723. $user = pdo_get('zhtc_user', array('id' => $order['user_id']));
  4724. $time = time() - 60 * 60 * 24 * 7;
  4725. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$order['user_id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  4726. $formwork = '{
  4727. "touser": "' . $user["openid"] . '",
  4728. "template_id": "' . $res["fh_tid"] . '",
  4729. "page":"zh_tcwq/pages/index/index",
  4730. "form_id":"' . $form['form_id'] . '",
  4731. "data": {
  4732. "keyword1": {
  4733. "value": "您的订单已发货!",
  4734. "color": "#173177"
  4735. },
  4736. "keyword2": {
  4737. "value":"' . $order['order_num'] . '",
  4738. "color": "#173177"
  4739. },
  4740. "keyword3": {
  4741. "value": "' . $order['good_name'] . '",
  4742. "color": "#173177"
  4743. },
  4744. "keyword4": {
  4745. "value": "' . $order['money'] . '",
  4746. "color": "#173177"
  4747. },
  4748. "keyword5": {
  4749. "value": "' . $order['kd_name'] . '",
  4750. "color": "#173177"
  4751. },
  4752. "keyword6": {
  4753. "value": "' . $order['kd_num'] . '",
  4754. "color": "#173177"
  4755. },
  4756. "keyword7": {
  4757. "value": "' . $order['user_name'] . '",
  4758. "color": "#173177"
  4759. },
  4760. "keyword8": {
  4761. "value": "' . $order['tel'] . '",
  4762. "color": "#173177"
  4763. },
  4764. "keyword9": {
  4765. "value": "' . $order['address'] . '",
  4766. "color": "#173177"
  4767. }
  4768. },
  4769. "emphasis_keyword": "keyword1.DATA"
  4770. }';
  4771. // $formwork=$data;
  4772. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  4773. $ch = curl_init();
  4774. curl_setopt($ch, CURLOPT_URL, $url);
  4775. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4776. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4777. curl_setopt($ch, CURLOPT_POST, 1);
  4778. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  4779. $data = curl_exec($ch);
  4780. curl_close($ch);
  4781. //return $data;
  4782. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  4783. }
  4784. echo set_msg($_W, $_GPC);
  4785. }
  4786. //下单模板消息
  4787. public function doPageXdMessage() {
  4788. global $_W, $_GPC;
  4789. function getaccess_token($_W) {
  4790. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4791. $appid = $res['appid'];
  4792. $secret = $res['appsecret'];
  4793. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4794. $ch = curl_init();
  4795. curl_setopt($ch, CURLOPT_URL, $url);
  4796. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4797. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4798. $data = curl_exec($ch);
  4799. curl_close($ch);
  4800. $data = json_decode($data, true);
  4801. return $data['access_token'];
  4802. }
  4803. //设置与发送模板信息
  4804. function set_msg($_W, $_GPC) {
  4805. $access_token = getaccess_token($_W);
  4806. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  4807. $order = pdo_get('zhtc_order', array('id' => $_GPC['order_id']));
  4808. $store = pdo_get('zhtc_store', array('id' => $order['store_id']));
  4809. $user = pdo_get('zhtc_user', array('id' => $store['user_id']));
  4810. if ($order['note']) {
  4811. $order['note'] = $order['note'];
  4812. } else {
  4813. $order['note'] = '无';
  4814. }
  4815. $time = time() - 60 * 60 * 24 * 7;
  4816. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$store['user_id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  4817. $formwork = '{
  4818. "touser": "' . $user["openid"] . '",
  4819. "template_id": "' . $res["gm_tid"] . '",
  4820. "page":"zh_tcwq/pages/index/index",
  4821. "form_id":"' . $form['form_id'] . '",
  4822. "data": {
  4823. "keyword1": {
  4824. "value": "您有新的订单",
  4825. "color": "#173177"
  4826. },
  4827. "keyword2": {
  4828. "value": "' . $order['order_num'] . '",
  4829. "color": "#173177"
  4830. },
  4831. "keyword3": {
  4832. "value":"' . $order['good_name'] . '",
  4833. "color": "#173177"
  4834. },
  4835. "keyword4": {
  4836. "value": "' . $order['money'] . '",
  4837. "color": "#173177"
  4838. },
  4839. "keyword5": {
  4840. "value": "已支付",
  4841. "color": "#173177"
  4842. },
  4843. "keyword6": {
  4844. "value": "' . date("Y-m-d H:i:s", $order['pay_time']) . '",
  4845. "color": "#173177"
  4846. },
  4847. "keyword7": {
  4848. "value": "' . $order['user_name'] . '",
  4849. "color": "#173177"
  4850. },
  4851. "keyword8": {
  4852. "value": "' . $order['tel'] . '",
  4853. "color": "#173177"
  4854. },
  4855. "keyword9": {
  4856. "value": "' . $order['address'] . '",
  4857. "color": "#173177"
  4858. }
  4859. },
  4860. "emphasis_keyword": "keyword1.DATA"
  4861. }';
  4862. // $formwork=$data;
  4863. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  4864. $ch = curl_init();
  4865. curl_setopt($ch, CURLOPT_URL, $url);
  4866. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4867. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4868. curl_setopt($ch, CURLOPT_POST, 1);
  4869. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  4870. $data = curl_exec($ch);
  4871. curl_close($ch);
  4872. //return $data;
  4873. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  4874. }
  4875. echo set_msg($_W, $_GPC);
  4876. }
  4877. //点赞模板消息
  4878. public function doPageDzMessage() {
  4879. global $_W, $_GPC;
  4880. function getaccess_token($_W) {
  4881. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4882. $appid = $res['appid'];
  4883. $secret = $res['appsecret'];
  4884. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4885. $ch = curl_init();
  4886. curl_setopt($ch, CURLOPT_URL, $url);
  4887. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4888. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4889. $data = curl_exec($ch);
  4890. curl_close($ch);
  4891. $data = json_decode($data, true);
  4892. return $data['access_token'];
  4893. }
  4894. //设置与发送模板信息
  4895. function set_msg($_W, $_GPC) {
  4896. $access_token = getaccess_token($_W);
  4897. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  4898. $information = pdo_get('zhtc_information', array('id' => $_GPC['information_id']));
  4899. $dzuser = pdo_get('zhtc_user', array('id' => $_GPC['user_id']));
  4900. $user = pdo_get('zhtc_user', array('id' => $information['user_id']));
  4901. $time = time() - 60 * 60 * 24 * 7;
  4902. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  4903. $formwork = '{
  4904. "touser": "' . $user["openid"] . '",
  4905. "template_id": "' . $res["dz_tid"] . '",
  4906. "page":"zh_tcwq/pages/index/index",
  4907. "form_id":"' . $form['form_id'] . '",
  4908. "data": {
  4909. "keyword1": {
  4910. "value": "' . $dzuser['name'] . '",
  4911. "color": "#173177"
  4912. },
  4913. "keyword2": {
  4914. "value": "' . date('Y-m-d H:i:s') . '",
  4915. "color": "#173177"
  4916. },
  4917. "keyword3": {
  4918. "value":"' . $information['details'] . '",
  4919. "color": "#173177"
  4920. }
  4921. }
  4922. }';
  4923. // $formwork=$data;
  4924. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  4925. $ch = curl_init();
  4926. curl_setopt($ch, CURLOPT_URL, $url);
  4927. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4928. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4929. curl_setopt($ch, CURLOPT_POST, 1);
  4930. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  4931. $data = curl_exec($ch);
  4932. curl_close($ch);
  4933. //return $data;
  4934. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  4935. }
  4936. echo set_msg($_W, $_GPC);
  4937. }
  4938. //审核通过模板消息
  4939. public function doPageTgMessage() {
  4940. global $_W, $_GPC;
  4941. function getaccess_token($_W) {
  4942. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  4943. $appid = $res['appid'];
  4944. $secret = $res['appsecret'];
  4945. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  4946. $ch = curl_init();
  4947. curl_setopt($ch, CURLOPT_URL, $url);
  4948. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4949. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4950. $data = curl_exec($ch);
  4951. curl_close($ch);
  4952. $data = json_decode($data, true);
  4953. return $data['access_token'];
  4954. }
  4955. //设置与发送模板信息
  4956. function set_msg($_W, $_GPC) {
  4957. $access_token = getaccess_token($_W);
  4958. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  4959. $information = pdo_get('zhtc_information', array('id' => $_GPC['information_id']));
  4960. $user = pdo_get('zhtc_user', array('id' => $information['user_id']));
  4961. $time = time() - 60 * 60 * 24 * 7;
  4962. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  4963. $formwork = '{
  4964. "touser": "' . $user["openid"] . '",
  4965. "template_id": "' . $res["tg_tid"] . '",
  4966. "page":"zh_tcwq/pages/index/index",
  4967. "form_id":"' . $form['form_id'] . '",
  4968. "data": {
  4969. "keyword1": {
  4970. "value": "帖子已发布成功",
  4971. "color": "#173177"
  4972. },
  4973. "keyword2": {
  4974. "value": "' . $information['details'] . '",
  4975. "color": "#173177"
  4976. },
  4977. "keyword3": {
  4978. "value":"' . $user['name'] . '",
  4979. "color": "#173177"
  4980. },
  4981. "keyword4": {
  4982. "value":"' . date("Y-m-d H:i:s", $information['sh_time']) . '",
  4983. "color": "#173177"
  4984. },
  4985. "keyword5": {
  4986. "value":"恭喜您,发表的帖子已审核通过",
  4987. "color": "#173177"
  4988. }
  4989. },
  4990. "emphasis_keyword": "keyword1.DATA"
  4991. }';
  4992. // $formwork=$data;
  4993. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  4994. $ch = curl_init();
  4995. curl_setopt($ch, CURLOPT_URL, $url);
  4996. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4997. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  4998. curl_setopt($ch, CURLOPT_POST, 1);
  4999. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  5000. $data = curl_exec($ch);
  5001. curl_close($ch);
  5002. //return $data;
  5003. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  5004. }
  5005. echo set_msg($_W, $_GPC);
  5006. }
  5007. //回评通过模板消息
  5008. public function doPageHpMessage() {
  5009. global $_W, $_GPC;
  5010. function getaccess_token($_W) {
  5011. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5012. $appid = $res['appid'];
  5013. $secret = $res['appsecret'];
  5014. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  5015. $ch = curl_init();
  5016. curl_setopt($ch, CURLOPT_URL, $url);
  5017. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5018. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5019. $data = curl_exec($ch);
  5020. curl_close($ch);
  5021. $data = json_decode($data, true);
  5022. return $data['access_token'];
  5023. }
  5024. //设置与发送模板信息
  5025. function set_msg($_W, $_GPC) {
  5026. $access_token = getaccess_token($_W);
  5027. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  5028. $comments = pdo_get('zhtc_comments', array('id' => $_GPC['id']));
  5029. $information = pdo_get('zhtc_information', array('id' => $comments['information_id']));
  5030. $user = pdo_get('zhtc_user', array('id' => $comments['user_id']));
  5031. $hfuser = pdo_get('zhtc_user', array('id' => $information['user_id']));
  5032. $hfstore = pdo_get('zhtc_store', array('id' => $information['store_id']));
  5033. if ($hfuser) {
  5034. $hf = $hfuser['name'];
  5035. } elseif ($hfstore) {
  5036. $hf = $hfuser['store_name'];
  5037. }
  5038. $time = time() - 60 * 60 * 24 * 7;
  5039. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  5040. $formwork = '{
  5041. "touser": "' . $user["openid"] . '",
  5042. "template_id": "' . $res["hp_tid"] . '",
  5043. "page":"zh_tcwq/pages/index/index",
  5044. "form_id":"' . $form['form_id'] . '",
  5045. "data": {
  5046. "keyword1": {
  5047. "value": "' . $hf . '",
  5048. "color": "#173177"
  5049. },
  5050. "keyword2": {
  5051. "value":"' . $comments['reply'] . '",
  5052. "color": "#173177"
  5053. },
  5054. "keyword3": {
  5055. "value":"' . date("Y-m-d H:i:s", $comments['hf_time']) . '",
  5056. "color": "#173177"
  5057. }
  5058. }
  5059. }';
  5060. // $formwork=$data;
  5061. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  5062. $ch = curl_init();
  5063. curl_setopt($ch, CURLOPT_URL, $url);
  5064. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5065. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5066. curl_setopt($ch, CURLOPT_POST, 1);
  5067. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  5068. $data = curl_exec($ch);
  5069. curl_close($ch);
  5070. //return $data;
  5071. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  5072. }
  5073. echo set_msg($_W, $_GPC);
  5074. }
  5075. //回评通过模板消息
  5076. public function doPageHpMessage2() {
  5077. global $_W, $_GPC;
  5078. function getaccess_token($_W) {
  5079. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5080. $appid = $res['appid'];
  5081. $secret = $res['appsecret'];
  5082. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  5083. $ch = curl_init();
  5084. curl_setopt($ch, CURLOPT_URL, $url);
  5085. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5086. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5087. $data = curl_exec($ch);
  5088. curl_close($ch);
  5089. $data = json_decode($data, true);
  5090. return $data['access_token'];
  5091. }
  5092. //设置与发送模板信息
  5093. function set_msg($_W, $_GPC) {
  5094. $access_token = getaccess_token($_W);
  5095. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  5096. $comments = pdo_get('zhtc_comments', array('id' => $_GPC['id']));
  5097. $information = pdo_get('zhtc_information', array('id' => $comments['information_id']));
  5098. $hfzuser = pdo_get('zhtc_user', array('id' => $comments['user_id']));
  5099. if ($comments['bid'] > 0 and $comments['hf_id'] == 0) {
  5100. //回复层主
  5101. $hfid = pdo_get('zhtc_comments', array('id' => $comments['bid']));
  5102. $userid = $hfid['user_id'];
  5103. $lr = $hfid['details'];
  5104. $sj = date("Y-m-d H:i:s", $hfid['time']);
  5105. } elseif ($comments['hf_id'] > 0) {
  5106. //回复用户
  5107. $hfid = pdo_get('zhtc_comments', array('id' => $comments['hf_id']));
  5108. $userid = $hfid['user_id'];
  5109. $lr = $hfid['details'];
  5110. $sj = date("Y-m-d H:i:s", $hfid['time']);
  5111. }
  5112. $hftime = date("Y-m-d H:i:s", $comments['time']);
  5113. $user = pdo_get('zhtc_user', array('id' => $userid));
  5114. $time = time() - 60 * 60 * 24 * 7;
  5115. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$userid} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  5116. $formwork = '{
  5117. "touser": "' . $user["openid"] . '",
  5118. "template_id": "' . $res["hp_tid"] . '",
  5119. "page":"zh_tcwq/pages/infodetial/infodetial?id=' . $comments['information_id'] . '",
  5120. "form_id":"' . $form['form_id'] . '",
  5121. "data": {
  5122. "keyword1": {
  5123. "value": "' . $hfzuser['name'] . '",
  5124. "color": "#173177"
  5125. },
  5126. "keyword2": {
  5127. "value":"' . $comments['details'] . '",
  5128. "color": "#173177"
  5129. },
  5130. "keyword3": {
  5131. "value":"' . $hftime . '",
  5132. "color": "#173177"
  5133. }
  5134. },
  5135. "emphasis_keyword": "keyword1.DATA"
  5136. }';
  5137. // $formwork=$data;
  5138. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  5139. $ch = curl_init();
  5140. curl_setopt($ch, CURLOPT_URL, $url);
  5141. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5142. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5143. curl_setopt($ch, CURLOPT_POST, 1);
  5144. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  5145. $data = curl_exec($ch);
  5146. curl_close($ch);
  5147. //return $data;
  5148. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  5149. }
  5150. echo set_msg($_W, $_GPC);
  5151. }
  5152. //关键词
  5153. public function doPageGetSensitive() {
  5154. global $_W, $_GPC;
  5155. $res = pdo_get('zhtc_sensitive', array('uniacid' => $_W['uniacid']));
  5156. echo json_encode($res);
  5157. }
  5158. //抢购分类
  5159. public function doPageQgType() {
  5160. global $_W, $_GPC;
  5161. $res = pdo_getall('zhtc_qgtype', array('uniacid' => $_W['uniacid'], 'state' => 1));
  5162. echo json_encode($res);
  5163. }
  5164. //抢购商品
  5165. public function doPageQgGoods() {
  5166. global $_W, $_GPC;
  5167. $time = time();
  5168. if ($_GPC['type_id']) {
  5169. $where = " and a.type_id=" . $_GPC['type_id'];
  5170. }
  5171. if ($_GPC['store_id']) {
  5172. $where = " and a.store_id=" . $_GPC['store_id'];
  5173. }
  5174. if ($_GPC['cityname']) {
  5175. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='' || a.cityname='全国版') ";
  5176. $data[':name'] = $_GPC['cityname'];
  5177. }
  5178. $pageindex = max(1, intval($_GPC['page']));
  5179. $pagesize = $_GPC['pagesize'];
  5180. if ($_GPC['type'] == 1) {
  5181. $sql = "select a.*,b.store_name,b.address,b.tel from " . tablename("zhtc_qggoods") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id where a.uniacid={$_W['uniacid']} and UNIX_TIMESTAMP(a.start_time)<={$time} and UNIX_TIMESTAMP(a.end_time)>{$time} and a.state=1 and a.state2=1 and a.is_tg=2 " . $where . " order by a.num asc";
  5182. } else {
  5183. $sql = "select a.*,b.store_name,b.address,b.tel from " . tablename("zhtc_qggoods") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id where a.uniacid={$_W['uniacid']} and UNIX_TIMESTAMP(a.start_time)<={$time} and UNIX_TIMESTAMP(a.end_time)>{$time} and a.state=1 and a.is_tg=2 " . $where . " order by a.num asc";
  5184. }
  5185. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5186. $res = pdo_fetchall($select_sql, $data);
  5187. echo json_encode($res);
  5188. }
  5189. //商品详情
  5190. public function doPageQgGoodInfo() {
  5191. global $_W, $_GPC;
  5192. pdo_update('zhtc_qggoods', array('hot +=' => 1), array('id' => $_GPC['id']));
  5193. $sql = "select a.*,b.store_name,b.address,b.tel from " . tablename("zhtc_qggoods") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id where a.id={$_GPC['id']} order by a.num asc";
  5194. $res = pdo_fetch($sql);
  5195. $res['start_time'] = strtotime($res['start_time']);
  5196. $res['end_time'] = strtotime($res['end_time']);
  5197. echo json_encode($res);
  5198. }
  5199. //查看购买人数
  5200. public function doPageQgPeople() {
  5201. global $_W, $_GPC;
  5202. $sql = "select a.pay_time,b.name as user_name,b.img as user_img from " . tablename("zhtc_qgorder") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id where a.good_id={$_GPC['good_id']} and a.state in(2,3) order by a.id DESC";
  5203. $res = pdo_fetchall($sql);
  5204. echo json_encode($res);
  5205. }
  5206. //抢购下单
  5207. public function doPageQgOrder() {
  5208. global $_W, $_GPC;
  5209. $good = pdo_get('zhtc_qggoods', array('id' => $_GPC['good_id']));
  5210. if ($good['surplus'] > 0) {
  5211. //还有剩余
  5212. $data['order_num'] = date('YmdHis', time()) . rand(1111, 9999); //订单号
  5213. $data['user_id'] = $_GPC['user_id'];
  5214. $data['user_name'] = $_GPC['user_name'];
  5215. $data['user_tel'] = $_GPC['user_tel'];
  5216. $data['store_id'] = $_GPC['store_id'];
  5217. $data['money'] = $_GPC['money'];
  5218. $data['good_id'] = $_GPC['good_id'];
  5219. $data['good_name'] = $_GPC['good_name'];
  5220. $data['good_logo'] = $_GPC['good_logo'];
  5221. $data['pay_type'] = $_GPC['pay_type'];
  5222. $data['uniacid'] = $_W['uniacid'];
  5223. $data['state'] = 1;
  5224. $data['note'] = $_GPC['note'];
  5225. $res = pdo_insert('zhtc_qgorder', $data);
  5226. $id = pdo_insertid();
  5227. if ($res) {
  5228. //pdo_update('zhtc_qggoods',array('surplus -='=>1),array('id'=>$_GPC['good_id']));
  5229. echo $id;
  5230. } else {
  5231. echo '下单失败';
  5232. }
  5233. } else {
  5234. //没有剩余
  5235. echo '下手慢了';
  5236. }
  5237. }
  5238. //抢购支付
  5239. public function doPageQgPay() {
  5240. global $_W, $_GPC;
  5241. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  5242. // $res=pdo_get('zhtc_pay',array('uniacid'=>$_W['uniacid']));
  5243. $res2 = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5244. if ($res2['pt_name']) {
  5245. $res2['pt_name'] = $res2['pt_name'];
  5246. } else {
  5247. $res2['pt_name'] = '同城小程序';
  5248. }
  5249. $appid = $res2['appid'];
  5250. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  5251. $mch_id = $res2['mchid'];
  5252. $key = $res2['wxkey'];
  5253. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  5254. $out_trade_no = time() . $user['id'];
  5255. $root = $_W['siteroot'];
  5256. pdo_update('zhtc_qgorder', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  5257. $order = pdo_get('zhtc_qgorder', array('id' => $_GPC['order_id']));
  5258. $total_fee = $order['money'];
  5259. if (empty($total_fee)) //押金
  5260. {
  5261. $body = $res2['pt_name'];
  5262. $total_fee = floatval(99 * 100);
  5263. } else {
  5264. $body = $res2['pt_name'];
  5265. $total_fee = floatval($total_fee * 100);
  5266. }
  5267. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  5268. $return = $weixinpay->pay();
  5269. echo json_encode($return);
  5270. }
  5271. //查看我的订单
  5272. public function doPageMyQgOrder() {
  5273. global $_W, $_GPC;
  5274. if ($_GPC['state']) {
  5275. $where = " and a.state=" . $_GPC['state'];
  5276. }
  5277. if ($_GPC['type'] == 1) {
  5278. $where = " and a.dq_time<" . time();
  5279. }
  5280. $pageindex = max(1, intval($_GPC['page']));
  5281. $pagesize = $_GPC['pagesize'];
  5282. $sql = "select a.*,b.store_name,b.address,b.tel,b.logo as store_logo from " . tablename("zhtc_qgorder") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id where a.uniacid={$_W['uniacid']} and a.user_id={$_GPC['user_id']} and a.state!=1 and a.del!=1 " . $where . " order by a.id DESC";
  5283. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5284. $res = pdo_fetchall($select_sql);
  5285. echo json_encode($res);
  5286. }
  5287. //查看是否购买
  5288. public function doPageIsPay() {
  5289. global $_W, $_GPC;
  5290. $res = pdo_get('zhtc_qgorder', array('user_id' => $_GPC['user_id'], 'good_id' => $_GPC['good_id'], 'state' => array(2, 3)));
  5291. if ($res) {
  5292. echo '1';
  5293. } else {
  5294. echo '2';
  5295. }
  5296. }
  5297. //订单二维码
  5298. public function doPageQgOrderCode() {
  5299. global $_W, $_GPC;
  5300. function getCoade($order_id) {
  5301. function getaccess_token() {
  5302. global $_W, $_GPC;
  5303. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5304. $appid = $res['appid'];
  5305. $secret = $res['appsecret'];
  5306. // print_r($res);die;
  5307. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  5308. $ch = curl_init();
  5309. curl_setopt($ch, CURLOPT_URL, $url);
  5310. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5311. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5312. $data = curl_exec($ch);
  5313. curl_close($ch);
  5314. $data = json_decode($data, true);
  5315. return $data['access_token'];
  5316. }
  5317. function set_msg($order_id) {
  5318. $access_token = getaccess_token();
  5319. $data2 = array(
  5320. "scene" => $order_id,
  5321. "page" => "zh_tcwq/pages/xsqg/qghx",
  5322. "width" => 400,
  5323. );
  5324. $data2 = json_encode($data2);
  5325. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  5326. $ch = curl_init();
  5327. curl_setopt($ch, CURLOPT_URL, $url);
  5328. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5329. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5330. curl_setopt($ch, CURLOPT_POST, 1);
  5331. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  5332. $data = curl_exec($ch);
  5333. curl_close($ch);
  5334. return $data;
  5335. }
  5336. $img = set_msg($order_id);
  5337. $img = base64_encode($img);
  5338. return $img;
  5339. }
  5340. echo getCoade($_GPC['order_id']);
  5341. }
  5342. //核销订单
  5343. public function doPageQgHx() {
  5344. global $_W, $_GPC;
  5345. $order = pdo_get('zhtc_qgorder', array('id' => $_GPC['order_id']));
  5346. $store = pdo_get('zhtc_store', array('id' => $order['store_id']));
  5347. if ($order['store_id'] == $_GPC['store_id'] || $store['user_id'] == $_GPC['user_id']) {
  5348. if ($order['state'] == 3) {
  5349. echo '已经核销过了';
  5350. } elseif ($order['dq_time'] < time()) {
  5351. echo '商品已失效';
  5352. } else {
  5353. $res = pdo_update('zhtc_qgorder', array('state' => 3, 'hx_time' => date('Y-m-d H:i:s')), array('id' => $_GPC['order_id']));
  5354. if ($res) {
  5355. echo '核销成功';
  5356. } else {
  5357. echo '核销失败';
  5358. }
  5359. }
  5360. } else {
  5361. echo '暂无核销权限';
  5362. }
  5363. }
  5364. //删除
  5365. public function doPageDelQgOrder() {
  5366. global $_W, $_GPC;
  5367. $res = pdo_update('zhtc_qgorder', array('del' => 1), array('id' => $_GPC['order_id']));
  5368. if ($res) {
  5369. echo '1';
  5370. } else {
  5371. echo '2';
  5372. }
  5373. }
  5374. //商家抢购订单
  5375. public function doPageStoreQgOrder() {
  5376. global $_W, $_GPC;
  5377. $where = " where a.uniacid={$_W['uniacid']} and a.state!=1 and a.store_id=" . $_GPC['store_id'];
  5378. if ($_GPC['state']) {
  5379. $where .= " and a.state=" . $_GPC['state'];
  5380. }
  5381. if ($_GPC['keywords']) {
  5382. $where .= " and (a.user_name LIKE concat('%', :name,'%') || a.order_num LIKE concat('%', :name,'%') || b.store_name LIKE concat('%', :name,'%'))";
  5383. $data[':name'] = $_GPC['keywords'];
  5384. }
  5385. $pageindex = max(1, intval($_GPC['page']));
  5386. $pagesize = $_GPC['pagesize'];
  5387. $sql = "select a.*,b.store_name,b.address,b.tel,b.logo as store_logo from " . tablename("zhtc_qgorder") . " a" . " left join " . tablename("zhtc_store") . " b on b.id=a.store_id " . $where . " order by a.id DESC";
  5388. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5389. $res = pdo_fetchall($select_sql, $data);
  5390. echo json_encode($res);
  5391. }
  5392. //最新抢购订单
  5393. public function doPageZbOrder() {
  5394. global $_W, $_GPC;
  5395. $sql = "select * from " . tablename("zhtc_qgorder") . " where uniacid={$_W['uniacid']} and state in(2,3) order by pay_time DESC LIMIT 0,10";
  5396. $res = pdo_fetchall($sql);
  5397. for ($i = 0; $i < count($res); $i++) {
  5398. $time = time() - strtotime($res[$i]['pay_time']);
  5399. if (($time / 60) > 1440) {
  5400. $time = floor($time / 60 / 60 / 24) . '天';
  5401. } elseif (($time / 60) > 60) {
  5402. $time = floor($time / 60 / 60) . '小时';
  5403. } else {
  5404. $time = floor($time / 60) . '分钟';
  5405. }
  5406. $res[$i]['time2'] = $time;
  5407. }
  5408. // / print_r($res);die;
  5409. echo json_encode($res);
  5410. }
  5411. //发布抢购商品
  5412. public function doPageAddQgGood() {
  5413. global $_W, $_GPC;
  5414. $store = pdo_get('zhtc_store', array('id' => $_GPC['store_id']));
  5415. if ($_GPC['state']) {
  5416. $data['state'] = $_GPC['state'];
  5417. } else {
  5418. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5419. $data['name'] = $_GPC['name'];
  5420. $data['logo'] = $_GPC['logo'];
  5421. $data['price'] = $_GPC['price'];
  5422. $data['money'] = $_GPC['money'];
  5423. $data['number'] = $_GPC['number'];
  5424. $data['surplus'] = $_GPC['number'];
  5425. $data['start_time'] = $_GPC['start_time'];
  5426. $data['end_time'] = $_GPC['end_time'];
  5427. $data['consumption_time'] = $_GPC['consumption_time'];
  5428. $data['details'] = $_GPC['details'];
  5429. $data['store_id'] = $_GPC['store_id'];
  5430. $data['type_id'] = $_GPC['type_id'];
  5431. $data['img'] = $_GPC['img'];
  5432. $data['num'] = $_GPC['num'];
  5433. $data['cityname'] = $store['cityname'];
  5434. $data['content'] = $_GPC['content'];
  5435. $data['details_img'] = $_GPC['details_img'];
  5436. $data['uniacid'] = $_W['uniacid'];
  5437. $data['time'] = date("Y-m-d H:i:s");
  5438. if ($system['xgsh'] == 2) {
  5439. $data['is_tg'] = 2;
  5440. }
  5441. }
  5442. if ($_GPC['id']) {
  5443. $res = pdo_update('zhtc_qggoods', $data, array('id' => $_GPC['id']));
  5444. } else {
  5445. $res = pdo_insert('zhtc_qggoods', $data);
  5446. }
  5447. if ($res) {
  5448. echo '1';
  5449. } else {
  5450. echo '2';
  5451. }
  5452. }
  5453. //抢购商品列表
  5454. public function doPageStoreGood() {
  5455. global $_W, $_GPC;
  5456. $where = " where uniacid={$_W['uniacid']} and store_id={$_GPC['store_id']} and is_tg=" . $_GPC['is_tg'];
  5457. $pageindex = max(1, intval($_GPC['page']));
  5458. $pagesize = $_GPC['pagesize'];
  5459. $sql = "select * from " . tablename("zhtc_qggoods") . " " . $where . " order by id DESC";
  5460. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5461. $res = pdo_fetchall($select_sql, $data);
  5462. echo json_encode($res);
  5463. }
  5464. //删除
  5465. public function doPageDelQgGood() {
  5466. global $_W, $_GPC;
  5467. $res = pdo_delete('zhtc_qggoods', array('id' => $_GPC['id']));
  5468. if ($res) {
  5469. echo '1';
  5470. } else {
  5471. echo '2';
  5472. }
  5473. }
  5474. /////////////////////////////////////////////////////////////////////
  5475. //以下拼团
  5476. //拼团分类
  5477. public function doPageGroupType() {
  5478. global $_W, $_GPC;
  5479. $res = pdo_getall('zhtc_grouptype', array('uniacid' => $_W['uniacid']), array(), '', 'num ASC');
  5480. echo json_encode($res);
  5481. }
  5482. //保存拼团商品
  5483. public function doPageSaveGroupGoods() {
  5484. global $_W, $_GPC;
  5485. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), 'ggoods_set');
  5486. $store = pdo_get('zhtc_store', array('id' => $_GPC['store_id']));
  5487. if ($system['ggoods_set'] == 1) {
  5488. $data['state'] = 1;
  5489. }
  5490. if ($system['ggoods_set'] == 2) {
  5491. $data['state'] = 2;
  5492. }
  5493. $data['logo'] = $_GPC['logo'];
  5494. $data['name'] = $_GPC['name'];
  5495. $data['img'] = $_GPC['img'];
  5496. $data['type_id'] = $_GPC['type_id'];
  5497. $data['inventory'] = $_GPC['inventory'];
  5498. $data['start_time'] = strtotime($_GPC['start_time']);
  5499. $data['end_time'] = strtotime($_GPC['end_time']);
  5500. $data['xf_time'] = strtotime($_GPC['xf_time']);
  5501. $data['pt_price'] = $_GPC['pt_price'];
  5502. $data['y_price'] = $_GPC['y_price'];
  5503. $data['dd_price'] = $_GPC['dd_price'];
  5504. $data['ycd_num'] = $_GPC['ycd_num'];
  5505. $data['ysc_num'] = $_GPC['ysc_num'];
  5506. $data['people'] = $_GPC['people'];
  5507. $data['is_shelves'] = $_GPC['is_shelves'];
  5508. $data['store_id'] = $_GPC['store_id'];
  5509. $data['details'] = html_entity_decode($_GPC['details']);
  5510. $data['details_img'] = $_GPC['details_img'];
  5511. $data['num'] = $_GPC['num'];
  5512. $data['introduction'] = $_GPC['introduction'];
  5513. $data['time'] = time();
  5514. $data['cityname'] = $store['cityname'];
  5515. $data['uniacid'] = $_W['uniacid'];
  5516. if ($_GPC['id']) {
  5517. $res = pdo_update('zhtc_groupgoods', $data, array('id' => $_GPC['id']));
  5518. } else {
  5519. $res = pdo_insert('zhtc_groupgoods', $data);
  5520. }
  5521. if ($res) {
  5522. echo '1';
  5523. } else {
  5524. echo '2';
  5525. }
  5526. }
  5527. //拼团商品
  5528. public function doPageGroupGoods() {
  5529. global $_W, $_GPC;
  5530. $time = time();
  5531. $where = " where a.uniacid={$_W['uniacid']} and a.end_time >{$time} and a.is_shelves=1 and a.state=2";
  5532. if ($_GPC['type_id']) {
  5533. $where .= " and a.type_id=" . $_GPC['type_id'];
  5534. }
  5535. if ($_GPC['store_id']) {
  5536. $where .= " and a.store_id=" . $_GPC['store_id'];
  5537. }
  5538. if ($_GPC['display']) {
  5539. $where .= " and a.display=1";
  5540. }
  5541. if ($_GPC['cityname']) {
  5542. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='' || a.cityname='全国版') ";
  5543. $data[':name'] = $_GPC['cityname'];
  5544. }
  5545. $pageindex = max(1, intval($_GPC['page']));
  5546. $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  5547. $sql = "select a.*,b.store_name ,b.address,b.tel,b.logo as store_logo from " . tablename("zhtc_groupgoods") . " a left join " . tablename("zhtc_store") . " b on b.id=a.store_id" . $where . " order by num asc";
  5548. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5549. $res = pdo_fetchall($select_sql, $data);
  5550. echo json_encode($res);
  5551. file_get_contents("" . $_W['siteroot'] . "app/index.php?i=" . $_W['uniacid'] . "&c=entry&a=wxapp&do=UpdateGroup&m=zh_tcwq&store_id=" . $_GPC['store_id']); //模板
  5552. }
  5553. //商品详情
  5554. public function doPageGoodsInfo() {
  5555. global $_W, $_GPC;
  5556. $gsql = " select a.*,b.logo as store_logo from" . tablename('zhtc_groupgoods') . " a left join " . tablename('zhtc_store') . " b on a.store_id=b.id where a.id=:id";
  5557. $goods = pdo_fetch($gsql, array(':id' => $_GPC['goods_id']));
  5558. //拼团情况
  5559. $sql = " select a.id,a.kt_num,a.yg_num,a.user_id,b.name,b.img from" . tablename('zhtc_group') . " a left join " . tablename('zhtc_user') . " b on a.user_id=b.id where a.goods_id=:goods_id and a.state=1 and a.uniacid=:uniacid";
  5560. $group = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid'], ':goods_id' => $_GPC['goods_id']));
  5561. $goodsInfo['goods'] = $goods;
  5562. $goodsInfo['group'] = $group;
  5563. echo json_encode($goodsInfo);
  5564. }
  5565. //下单
  5566. public function doPageSaveGroupOrder() {
  5567. global $_W, $_GPC;
  5568. $good = pdo_get('zhtc_groupgoods', array('id' => $_GPC['goods_id']));
  5569. if ($good['inventory'] >= $_GPC['goods_num']) {
  5570. if ($_GPC['type'] == 1) {
  5571. $data['order_num'] = date('YmdHis', time()) . rand(1111, 9999); //订单号
  5572. $data['user_id'] = $_GPC['user_id'];
  5573. $data['goods_id'] = $_GPC['goods_id'];
  5574. $data['group_id'] = 0;
  5575. $data['logo'] = $_GPC['logo'];
  5576. $data['store_id'] = $_GPC['store_id'];
  5577. $data['goods_name'] = $_GPC['goods_name'];
  5578. $data['goods_type'] = $_GPC['goods_type'];
  5579. $data['goods_name'] = $_GPC['goods_name'];
  5580. $data['price'] = $_GPC['price'];
  5581. $data['goods_num'] = $_GPC['goods_num'];
  5582. $data['money'] = $_GPC['money'];
  5583. $data['receive_name'] = $_GPC['receive_name'];
  5584. $data['receive_tel'] = $_GPC['receive_tel'];
  5585. $data['receive_address'] = $_GPC['receive_address'];
  5586. $data['note'] = $_GPC['note'];
  5587. $data['time'] = time();
  5588. $data['xf_time'] = $_GPC['xf_time'];
  5589. $data['uniacid'] = $_W['uniacid'];
  5590. $data['pay_type'] = $_GPC['pay_type'];
  5591. $data['state'] = 1;
  5592. $res = pdo_insert('zhtc_grouporder', $data);
  5593. $id = pdo_insertid();
  5594. if ($res) {
  5595. echo $id;
  5596. } else {
  5597. echo '下单失败';
  5598. }
  5599. }
  5600. if ($_GPC['type'] == 2) {
  5601. //生产团
  5602. if ($_GPC['group_id'] == '') {
  5603. $data2['store_id'] = $_GPC['store_id'];
  5604. $data2['goods_id'] = $_GPC['goods_id'];
  5605. $data2['goods_logo'] = $_GPC['logo'];
  5606. $data2['goods_name'] = $_GPC['goods_name'];
  5607. $data2['kt_num'] = $_GPC['kt_num'];
  5608. $data2['kt_time'] = time();
  5609. $data2['dq_time'] = $_GPC['dq_time'];
  5610. $data2['state'] = 0;
  5611. $data2['user_id'] = $_GPC['user_id'];
  5612. $data2['uniacid'] = $_W['uniacid'];
  5613. $rst = pdo_insert('zhtc_group', $data2);
  5614. $group_id = pdo_insertid();
  5615. } else {
  5616. $group = pdo_get('zhtc_group', array('id' => $_GPC['group_id']));
  5617. }
  5618. if ($_GPC['group_id'] == '' && $rst or $_GPC['group_id'] && $group['state'] == 1) {
  5619. $data['order_num'] = date('YmdHis', time()) . rand(1111, 9999); //订单号
  5620. $data['user_id'] = $_GPC['user_id'];
  5621. $data['goods_id'] = $_GPC['goods_id'];
  5622. $data['group_id'] = empty($_GPC['group_id']) ? $group_id : $_GPC['group_id'];
  5623. $data['logo'] = $_GPC['logo'];
  5624. $data['store_id'] = $_GPC['store_id'];
  5625. $data['goods_name'] = $_GPC['goods_name'];
  5626. $data['goods_type'] = $_GPC['goods_type'];
  5627. $data['goods_name'] = $_GPC['goods_name'];
  5628. $data['price'] = $_GPC['price'];
  5629. $data['goods_num'] = $_GPC['goods_num'];
  5630. $data['money'] = $_GPC['money'];
  5631. $data['receive_name'] = $_GPC['receive_name'];
  5632. $data['receive_tel'] = $_GPC['receive_tel'];
  5633. $data['receive_address'] = $_GPC['receive_address'];
  5634. $data['note'] = $_GPC['note'];
  5635. $data['time'] = time();
  5636. $data['xf_time'] = $_GPC['xf_time'];
  5637. $data['uniacid'] = $_W['uniacid'];
  5638. $data['pay_type'] = $_GPC['pay_type'];
  5639. $data['state'] = 1;
  5640. $res = pdo_insert('zhtc_grouporder', $data);
  5641. $id = pdo_insertid();
  5642. if ($res) {
  5643. echo $id;
  5644. } else {
  5645. echo '下单失败';
  5646. }
  5647. } else {
  5648. //没有剩余
  5649. echo '商品已销售完毕或拼团已失效';
  5650. }
  5651. }
  5652. } else {
  5653. echo '商品已销售完毕或拼团已失效';
  5654. }
  5655. }
  5656. //拼团支付
  5657. public function doPageGroupPay() {
  5658. global $_W, $_GPC;
  5659. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  5660. $res2 = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5661. if ($res2['pt_name']) {
  5662. $res2['pt_name'] = $res2['pt_name'];
  5663. } else {
  5664. $res2['pt_name'] = '同城小程序';
  5665. }
  5666. $appid = $res2['appid'];
  5667. $openid = $_GPC['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  5668. $mch_id = $res2['mchid'];
  5669. $key = $res2['wxkey'];
  5670. $user = pdo_get('zhtc_user', array('openid' => $_GPC['openid']));
  5671. $out_trade_no = time() . $user['id'];
  5672. $root = $_W['siteroot'];
  5673. pdo_update('zhtc_grouporder', array('code' => $out_trade_no), array('id' => $_GPC['order_id']));
  5674. $order = pdo_get('zhtc_grouporder', array('id' => $_GPC['order_id']));
  5675. $total_fee = $order['money'];
  5676. if (empty($total_fee)) //押金
  5677. {
  5678. $body = $res2['pt_name'];
  5679. $total_fee = floatval(99 * 100);
  5680. } else {
  5681. $body = $res2['pt_name'];
  5682. $total_fee = floatval($total_fee * 100);
  5683. }
  5684. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  5685. $return = $weixinpay->pay();
  5686. echo json_encode($return);
  5687. }
  5688. //查看团员信息
  5689. public function doPageGetGroupUserInfo() {
  5690. global $_W, $_GPC;
  5691. $sql = " select a.id,b.name,b.img from" . tablename('zhtc_grouporder') . " a left join " . tablename('zhtc_user') . "b on a.user_id=b.id where a.group_id=:group_id and a.state=2";
  5692. $group = pdo_fetchall($sql, array(':group_id' => $_GPC['group_id']));
  5693. echo json_encode($group);
  5694. }
  5695. //分销二维码
  5696. public function doPageGoodsCode() {
  5697. global $_W, $_GPC;
  5698. function getCoade($goods_id, $group_id) {
  5699. function getaccess_token() {
  5700. global $_W, $_GPC;
  5701. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5702. $appid = $res['appid'];
  5703. $secret = $res['appsecret'];
  5704. // print_r($res);die;
  5705. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  5706. $ch = curl_init();
  5707. curl_setopt($ch, CURLOPT_URL, $url);
  5708. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5709. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5710. $data = curl_exec($ch);
  5711. curl_close($ch);
  5712. $data = json_decode($data, true);
  5713. return $data['access_token'];
  5714. }
  5715. function set_msg($goods_id, $group_id) {
  5716. $access_token = getaccess_token();
  5717. $data2 = array(
  5718. "scene" => $goods_id . "," . $group_id,
  5719. "page" => "zh_tcwq/pages/collage/info",
  5720. "width" => 400,
  5721. );
  5722. $data2 = json_encode($data2);
  5723. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  5724. $ch = curl_init();
  5725. curl_setopt($ch, CURLOPT_URL, $url);
  5726. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5727. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5728. curl_setopt($ch, CURLOPT_POST, 1);
  5729. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  5730. $data = curl_exec($ch);
  5731. curl_close($ch);
  5732. return $data;
  5733. }
  5734. $img = set_msg($goods_id, $group_id);
  5735. $img = base64_encode($img);
  5736. return $img;
  5737. }
  5738. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['goods_id'], $_GPC['group_id'] = '');
  5739. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  5740. $type = $result[2];
  5741. $new_file = IA_ROOT . "/addons/zh_tcwq/img/";
  5742. if (!file_exists($new_file)) {
  5743. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  5744. mkdir($new_file, 0777);
  5745. }
  5746. $wname = "pt{$_GPC['goods_id']}" . ".{$type}";
  5747. //$wname="1511.jpeg";
  5748. $new_file = $new_file . $wname;
  5749. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  5750. }
  5751. echo "/addons/zh_tcwq/img/" . $wname;
  5752. }
  5753. //团详情
  5754. public function doPageGroupInfo() {
  5755. global $_W, $_GPC;
  5756. $sql = "select a.*,b.img,b.name from" . tablename('zhtc_group') . " a left join" . tablename('zhtc_user') . " b on a.user_id=b.id where a.id=:group_id";
  5757. $group = pdo_fetch($sql, array(':group_id' => $_GPC['group_id']));
  5758. echo json_encode($group);
  5759. }
  5760. //我的团购订单
  5761. public function doPageMyGroupOrder() {
  5762. global $_W, $_GPC;
  5763. $where = " where a.uniacid={$_W['uniacid']} and a.user_id={$_GPC['user_id']} and a.state!=1 ";
  5764. if ($_GPC['state']) {
  5765. $where .= " and b.state=" . $_GPC['state'];
  5766. }
  5767. if ($_GPC['type']) {
  5768. //单独够订单
  5769. $where .= " and a.group_id=0";
  5770. }
  5771. $pageindex = max(1, intval($_GPC['page']));
  5772. $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  5773. $sql = "select a.*,b.state as g_state,c.store_name from " . tablename("zhtc_grouporder") . " a left join " . tablename('zhtc_group') . " b on a.group_id=b.id left join " . tablename('zhtc_store') . " c on a.store_id=c.id" . $where . " order by a.id DESC";
  5774. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5775. $res = pdo_fetchall($select_sql);
  5776. echo json_encode($res);
  5777. pdo_update('zhtc_grouporder', array('state' => 5, 'cz_time' => time()), array('xf_time <=' => time(), 'uniacid' => $_W['uniacid'], 'state' => 2));
  5778. }
  5779. //订单详情
  5780. public function doPageGroupOrderInfo() {
  5781. global $_W, $_GPC;
  5782. $sql = "select a.*,b.state as g_state from " . tablename("zhtc_grouporder") . " a left join " . tablename('zhtc_group') . " b on a.group_id=b.id where a.id=:order_id ";
  5783. $res = pdo_fetchall($sql, array(':order_id' => $_GPC['order_id']));
  5784. echo json_encode($res);
  5785. }
  5786. //订单二维码
  5787. public function doPageOrderCode() {
  5788. global $_W, $_GPC;
  5789. function getCoade($order_id) {
  5790. function getaccess_token() {
  5791. global $_W, $_GPC;
  5792. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5793. $appid = $res['appid'];
  5794. $secret = $res['appsecret'];
  5795. // print_r($res);die;
  5796. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  5797. $ch = curl_init();
  5798. curl_setopt($ch, CURLOPT_URL, $url);
  5799. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5800. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5801. $data = curl_exec($ch);
  5802. curl_close($ch);
  5803. $data = json_decode($data, true);
  5804. return $data['access_token'];
  5805. }
  5806. function set_msg($order_id) {
  5807. $access_token = getaccess_token();
  5808. $data2 = array(
  5809. "scene" => $order_id,
  5810. "page" => "zh_tcwq/pages/collage/yz_code",
  5811. "width" => 400,
  5812. );
  5813. $data2 = json_encode($data2);
  5814. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  5815. $ch = curl_init();
  5816. curl_setopt($ch, CURLOPT_URL, $url);
  5817. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  5818. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  5819. curl_setopt($ch, CURLOPT_POST, 1);
  5820. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  5821. $data = curl_exec($ch);
  5822. curl_close($ch);
  5823. return $data;
  5824. }
  5825. $img = set_msg($order_id);
  5826. $img = base64_encode($img);
  5827. return $img;
  5828. }
  5829. echo getCoade($_GPC['order_id']);
  5830. }
  5831. //核销订单
  5832. public function doPageGroupVerification() {
  5833. global $_W, $_GPC;
  5834. $order = pdo_get('zhtc_grouporder', array('id' => $_GPC['order_id']));
  5835. $store = pdo_get('zhtc_store', array('id' => $order['store_id']));
  5836. if ($order['store_id'] == $_GPC['store_id'] || $store['user_id'] == $_GPC['user_id']) {
  5837. if ($order['state'] == 3 or $order['state'] == 5) {
  5838. echo '已经核销过了或订单已失效';
  5839. } else {
  5840. $res = pdo_update('zhtc_grouporder', array('state' => 3, 'cz_time' => time()), array('id' => $_GPC['order_id']));
  5841. if ($res) {
  5842. echo '核销成功';
  5843. } else {
  5844. echo '核销失败';
  5845. }
  5846. }
  5847. } else {
  5848. echo '暂无核销权限';
  5849. }
  5850. }
  5851. //拼团失败退款
  5852. public function doPageUpdateGroup() {
  5853. global $_W, $_GPC;
  5854. $ids = pdo_getall('zhtc_group', array('dq_time <=' => time(), 'state' => 1, 'uniacid' => $_W['uniacid'], 'store_id' => $_GPC['store_id']), 'id');
  5855. //var_dump($ids);die;
  5856. if ($ids) {
  5857. $uids = array_map('array_shift', $ids);
  5858. $orders = pdo_getall('zhtc_grouporder', array('group_id' => $uids, 'state' => 2, 'pay_type' => 1), 'id');
  5859. foreach ($orders as $key => $value) {
  5860. include_once IA_ROOT . '/addons/zh_tcwq/cert/WxPay.Api.php';
  5861. load()->model('account');
  5862. load()->func('communication');
  5863. $refund_order = pdo_get('zhtc_grouporder', array('id' => $value));
  5864. $WxPayApi = new WxPayApi();
  5865. $input = new WxPayRefund();
  5866. $path_cert = IA_ROOT . "/addons/zh_tcwq/cert/" . 'apiclient_cert_' . $_W['uniacid'] . '.pem';
  5867. $path_key = IA_ROOT . "/addons/zh_tcwq/cert/" . 'apiclient_key_' . $_W['uniacid'] . '.pem';
  5868. $account_info = $_W['account'];
  5869. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  5870. $appid = $system['appid'];
  5871. $key = $system['wxkey'];
  5872. $mchid = $system['mchid'];
  5873. $out_trade_no = $refund_order['code'];
  5874. $fee = $refund_order['money'] * 100;
  5875. $input->SetAppid($appid);
  5876. $input->SetMch_id($mchid);
  5877. $input->SetOp_user_id($mchid);
  5878. $input->SetRefund_fee($fee);
  5879. $input->SetTotal_fee($fee);
  5880. // $input->SetTransaction_id($refundid);
  5881. $input->SetOut_refund_no($refund_order['order_num']);
  5882. $input->SetOut_trade_no($out_trade_no);
  5883. $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
  5884. ////////////////////////////////////
  5885. if ($result['result_code'] == 'SUCCESS') {
  5886. //退款成功
  5887. //更改订单操作
  5888. pdo_update('zhtc_grouporder', array('state' => 4), array('id' => $value));
  5889. }
  5890. }
  5891. $group = pdo_update('zhtc_group', array('state' => 3), array('id' => $uids));
  5892. }
  5893. }
  5894. public function GETSiteroot() {
  5895. global $_W, $_GPC;
  5896. echo $_W['siteroot'];
  5897. }
  5898. ///////////////////////////////
  5899. //手机后台
  5900. //商家商品列表
  5901. public function doPageGroupGoodsList() {
  5902. global $_W, $_GPC;
  5903. $where = " where uniacid={$_W['uniacid']} and store_id={$_GPC['store_id']} and state=" . $_GPC['state'];
  5904. $pageindex = max(1, intval($_GPC['page']));
  5905. $pagesize = $_GPC['pagesize'];
  5906. $sql = "select * from " . tablename("zhtc_groupgoods") . " " . $where . " order by id DESC";
  5907. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5908. $res = pdo_fetchall($select_sql, $data);
  5909. echo json_encode($res);
  5910. }
  5911. //下架商品
  5912. public function doPageOperateGood() {
  5913. global $_W, $_GPC;
  5914. $res = pdo_update('zhtc_groupgoods', array('is_shelves' => $_GPC['is_shelves']), array('id' => $_GPC['goods_id']));
  5915. if ($res) {
  5916. echo '1';
  5917. } else {
  5918. echo '2';
  5919. }
  5920. }
  5921. //删除
  5922. public function doPageDelGroupGood() {
  5923. global $_W, $_GPC;
  5924. $res = pdo_delete('zhtc_groupgoods', array('id' => $_GPC['goods_id']));
  5925. if ($res) {
  5926. echo '1';
  5927. } else {
  5928. echo '2';
  5929. }
  5930. }
  5931. //商品详情
  5932. public function doPageGetGoodDetails() {
  5933. global $_W, $_GPC;
  5934. $res = pdo_get('zhtc_groupgoods', array('id' => $_GPC['goods_id']));
  5935. echo json_encode($res);
  5936. }
  5937. public function doPageInsertStoreWallet() {
  5938. global $_W, $_GPC;
  5939. if ($_GPC['group_id'] > 0) {
  5940. $res = pdo_get('zhtc_grouporder', array('group_id' => $_GPC['group_id']), array('sum(money) as total', 'store_id'));
  5941. } else {
  5942. $res = pdo_get('zhtc_grouporder', array('id' => $_GPC['order_id']), array('sum(money) as total', 'store_id'));
  5943. }
  5944. pdo_update('zhtc_store', array('wallet +=' => $res['total']), array('id' => $res['store_id']));
  5945. $data['store_id'] = $res['store_id'];
  5946. $data['money'] = $res['total'];
  5947. $data['note'] = '拼团订单';
  5948. $data['type'] = 1;
  5949. $data['time'] = date("Y-m-d H:i:s");
  5950. pdo_insert('zhtc_store_wallet', $data);
  5951. }
  5952. //商家订单
  5953. public function doPagePtStoreOrderList() {
  5954. global $_W, $_GPC;
  5955. $data[':uniacid'] = $_W['uniacid'];
  5956. $where = " where uniacid=:uniacid and store_id={$_GPC['store_id']}";
  5957. if ($_GPC['state']) {
  5958. $where .= " and state=" . $_GPC['state'];
  5959. }
  5960. if ($_GPC['keywords']) {
  5961. $where .= " and (goods_name LIKE concat('%', :keywords,'%') || order_num LIKE concat('%', :keywords,'%') || receive_name LIKE concat('%', :keywords,'%'))";
  5962. $data[':keywords'] = $_GPC['keywords'];
  5963. }
  5964. $pageindex = max(1, intval($_GPC['page']));
  5965. $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  5966. $sql = "select * from " . tablename("zhtc_grouporder") . $where . " order by id DESC";
  5967. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5968. $res = pdo_fetchall($select_sql, $data);
  5969. echo json_encode($res);
  5970. }
  5971. //商家团
  5972. public function doPagePtStoreGroupList() {
  5973. global $_W, $_GPC;
  5974. $where = " where uniacid=:uniacid and store_id={$_GPC['store_id']} and state !=0";
  5975. $data[':uniacid'] = $_W['uniacid'];
  5976. if ($_GPC['state']) {
  5977. $where .= " and state=" . $_GPC['state'];
  5978. }
  5979. if ($_GPC['keywords']) {
  5980. $where .= " and (goods_name LIKE concat('%',:keywords,'%'))";
  5981. $data[':keywords'] = $_GPC['keywords'];
  5982. }
  5983. $pageindex = max(1, intval($_GPC['page']));
  5984. $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  5985. $sql = "select * from " . tablename("zhtc_group") . $where . " order by id DESC";
  5986. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  5987. $res = pdo_fetchall($select_sql, $data);
  5988. echo json_encode($res);
  5989. }
  5990. //团订单
  5991. public function doPagePtGroupOrderInfo() {
  5992. global $_W, $_GPC;
  5993. $sql = " select a.*,b.name as nick_name,b.img,c.store_name from" . tablename('zhtc_group') . " a left join " . tablename('zhtc_user') . " b on a.user_id=b.id left join " . tablename('zhtc_store') . " c on a.store_id=c.id where a.id=:id";
  5994. $group = pdo_fetch($sql, array(':id' => $_GPC['group_id']));
  5995. $sql2 = " select a.*,b.name as nick_name from" . tablename('zhtc_grouporder') . " a left join " . tablename('zhtc_user') . " b on a.user_id=b.id where a.group_id=:id";
  5996. $order = pdo_fetchall($sql2, array(':id' => $_GPC['group_id']));
  5997. $info['group'] = $group;
  5998. $info['order'] = $order;
  5999. echo json_encode($info);
  6000. }
  6001. //优惠券分类
  6002. public function doPageCouponType() {
  6003. global $_W, $_GPC;
  6004. $res = pdo_getall('zhtc_coupontype', array('uniacid' => $_W['uniacid'], 'state' => 1));
  6005. echo json_encode($res);
  6006. }
  6007. //优惠券列表
  6008. public function doPageCouponList() {
  6009. global $_W, $_GPC;
  6010. $where = " where b.uniacid={$_W['uniacid']} and a.is_show=1 and a.is_pt=1 and a.state=2 and a.del=2";
  6011. if ($_GPC['type_id']) {
  6012. $where .= " and a.type_id=" . $_GPC['type_id'] . " and a.is_pt=1 ";
  6013. }
  6014. if ($_GPC['store_id']) {
  6015. $where .= " and a.store_id=" . $_GPC['store_id'];
  6016. }
  6017. if ($_GPC['cityname']) {
  6018. $where .= " and (a.cityname LIKE concat('%', :name,'%') || a.cityname='' || a.cityname='全国版') ";
  6019. $data[':name'] = $_GPC['cityname'];
  6020. }
  6021. $pageindex = max(1, intval($_GPC['page']));
  6022. $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  6023. $sql = "select a.*,b.store_name ,b.address,b.tel,b.logo as store_logo from " . tablename("zhtc_coupons") . " a left join " . tablename("zhtc_store") . " b on b.id=a.store_id" . $where;
  6024. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  6025. $res = pdo_fetchall($select_sql, $data);
  6026. echo json_encode($res);
  6027. }
  6028. //最新领券
  6029. public function doPageZbCoupons() {
  6030. global $_W, $_GPC;
  6031. $sql = "select a.*,b.name as coupon_name,c.name as user_name from " . tablename("zhtc_usercoupons") . " a left join " . tablename("zhtc_coupons") . " b on b.id=a.coupons_id left join " . tablename("zhtc_user") . " c on c.id=a.user_id where c.uniacid={$_W['uniacid']} and a.pay_type=2 order by a.id DESC LIMIT 0,10";
  6032. $res = pdo_fetchall($sql);
  6033. for ($i = 0; $i < count($res); $i++) {
  6034. $time = time() - strtotime($res[$i]['time']);
  6035. if (($time / 60) > 1440) {
  6036. $time = floor($time / 60 / 60 / 24) . '天';
  6037. } elseif (($time / 60) > 60) {
  6038. $time = floor($time / 60 / 60) . '小时';
  6039. } else {
  6040. $time = floor($time / 60) . '分钟';
  6041. }
  6042. $res[$i]['time2'] = $time;
  6043. }
  6044. echo json_encode($res);
  6045. }
  6046. //添加分类
  6047. public function doPageAddType() {
  6048. global $_W, $_GPC;
  6049. $data['type_name'] = $_GPC['type_name'];
  6050. $data['store_id'] = $_GPC['store_id'];
  6051. $data['order_by'] = $_GPC['order_by'];
  6052. $data['uniacid'] = $_W['uniacid'];
  6053. $res = pdo_insert('zhtc_goodtype', $data);
  6054. if ($res) {
  6055. echo '1';
  6056. } else {
  6057. echo '2';
  6058. }
  6059. }
  6060. //分类列表
  6061. public function doPageGoodType() {
  6062. global $_W, $_GPC;
  6063. $res = pdo_getall('zhtc_goodtype', array('store_id' => $_GPC['store_id'], 'uniacid' => $_W['uniacid']));
  6064. echo json_encode($res);
  6065. }
  6066. //商品列表
  6067. public function doPageGoodsList() {
  6068. global $_W, $_GPC;
  6069. $sql = " select * from" . tablename('zhtc_goodtype') . " where uniacid={$_W['uniacid']} and store_id={$_GPC['store_id']} and is_open=1 and id in(select type_id from" . tablename('zhtc_goods') . " where uniacid={$_W['uniacid']} and is_show=1 and type !={$_GPC['type']} and store_id={$_GPC['store_id']}) order by order_by asc";
  6070. $type = pdo_fetchall($sql);
  6071. $list = pdo_getall('zhtc_goods', array('uniacid' => $_W['uniacid'], 'is_show' => 1, 'state' => 2, 'store_id' => $_GPC['store_id']), array(), '', 'num ASC');
  6072. $data2 = array();
  6073. for ($i = 0; $i < count($type); $i++) {
  6074. $data = array();
  6075. for ($k = 0; $k < count($list); $k++) {
  6076. if ($type[$i]['id'] == $list[$k]['type_id']) {
  6077. $data[] = $list[$k];
  6078. }
  6079. }
  6080. $data2[] = array('id' => $type[$i]['id'], 'type_name' => $type[$i]['type_name'], 'good' => $data);
  6081. }
  6082. echo json_encode($data2);
  6083. }
  6084. //抢购模板消息
  6085. public function doPageQgMessage() {
  6086. global $_W, $_GPC;
  6087. function getaccess_token($_W) {
  6088. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6089. $appid = $res['appid'];
  6090. $secret = $res['appsecret'];
  6091. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  6092. $ch = curl_init();
  6093. curl_setopt($ch, CURLOPT_URL, $url);
  6094. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6095. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6096. $data = curl_exec($ch);
  6097. curl_close($ch);
  6098. $data = json_decode($data, true);
  6099. return $data['access_token'];
  6100. }
  6101. //设置与发送模板信息
  6102. function set_msg($_W, $_GPC) {
  6103. $access_token = getaccess_token($_W);
  6104. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  6105. $qgorder = pdo_get('zhtc_qgorder', array('id' => $_GPC['order_id']));
  6106. $store = pdo_get('zhtc_store', array('id' => $qgorder['store_id']));
  6107. $user = pdo_get('zhtc_user', array('id' => $qgorder['user_id']));
  6108. $time = time() - 60 * 60 * 24 * 7;
  6109. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  6110. $formwork = '{
  6111. "touser": "' . $user["openid"] . '",
  6112. "template_id": "' . $res["qg_tid"] . '",
  6113. "page":"zh_tcwq/pages/index/index",
  6114. "form_id":"' . $form['form_id'] . '",
  6115. "data": {
  6116. "keyword1": {
  6117. "value": "' . $qgorder['good_name'] . '",
  6118. "color": "#173177"
  6119. },
  6120. "keyword2": {
  6121. "value": "' . $qgorder['money'] . '",
  6122. "color": "#173177"
  6123. },
  6124. "keyword3": {
  6125. "value":"' . $qgorder['pay_time'] . '",
  6126. "color": "#173177"
  6127. },
  6128. "keyword4": {
  6129. "value":"1个",
  6130. "color": "#173177"
  6131. },
  6132. "keyword5": {
  6133. "value":"' . $qgorder['order_num'] . '",
  6134. "color": "#173177"
  6135. },
  6136. "keyword6": {
  6137. "value":"' . date("Y-m-d H:i:s", $qgorder['dq_time']) . '",
  6138. "color": "#173177"
  6139. },
  6140. "keyword7": {
  6141. "value":"' . $store['store_name'] . '",
  6142. "color": "#173177"
  6143. }
  6144. }
  6145. }';
  6146. // $formwork=$data;
  6147. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  6148. $ch = curl_init();
  6149. curl_setopt($ch, CURLOPT_URL, $url);
  6150. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6151. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6152. curl_setopt($ch, CURLOPT_POST, 1);
  6153. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  6154. $data = curl_exec($ch);
  6155. curl_close($ch);
  6156. //return $data;
  6157. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  6158. }
  6159. echo set_msg($_W, $_GPC);
  6160. }
  6161. //活动参与成功模板消息
  6162. public function doPageHdMessage() {
  6163. global $_W, $_GPC;
  6164. function getaccess_token($_W) {
  6165. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6166. $appid = $res['appid'];
  6167. $secret = $res['appsecret'];
  6168. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  6169. $ch = curl_init();
  6170. curl_setopt($ch, CURLOPT_URL, $url);
  6171. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6172. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6173. $data = curl_exec($ch);
  6174. curl_close($ch);
  6175. $data = json_decode($data, true);
  6176. return $data['access_token'];
  6177. }
  6178. //设置与发送模板信息
  6179. function set_msg($_W, $_GPC) {
  6180. $access_token = getaccess_token($_W);
  6181. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  6182. $joinlist = pdo_get('zhtc_joinlist', array('id' => $_GPC['id']));
  6183. $activity = pdo_get('zhtc_activity', array('id' => $joinlist['act_id']));
  6184. $acttype = pdo_get('zhtc_acttype', array('id' => $activity['type_id']));
  6185. $user = pdo_get('zhtc_user', array('id' => $joinlist['user_id']));
  6186. $time = time() - 60 * 60 * 24 * 7;
  6187. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  6188. $formwork = '{
  6189. "touser": "' . $user["openid"] . '",
  6190. "template_id": "' . $res["hd_tid"] . '",
  6191. "page":"zh_tcwq/pages/index/index",
  6192. "form_id":"' . $joinlist['form_id'] . '",
  6193. "data": {
  6194. "keyword1": {
  6195. "value": "' . $activity['title'] . '",
  6196. "color": "#173177"
  6197. },
  6198. "keyword2": {
  6199. "value": "' . $acttype['type_name'] . '",
  6200. "color": "#173177"
  6201. },
  6202. "keyword3": {
  6203. "value":"' . $activity['address'] . '",
  6204. "color": "#173177"
  6205. },
  6206. "keyword4": {
  6207. "value":"' . $activity['start_time'] . '---' . $activity['end_time'] . '",
  6208. "color": "#173177"
  6209. },
  6210. "keyword5": {
  6211. "value":"' . $activity['tel'] . '",
  6212. "color": "#173177"
  6213. },
  6214. "keyword6": {
  6215. "value":"' . $joinlist['money'] . '",
  6216. "color": "#173177"
  6217. }
  6218. }
  6219. }';
  6220. // $formwork=$data;
  6221. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  6222. $ch = curl_init();
  6223. curl_setopt($ch, CURLOPT_URL, $url);
  6224. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6225. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6226. curl_setopt($ch, CURLOPT_POST, 1);
  6227. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  6228. $data = curl_exec($ch);
  6229. curl_close($ch);
  6230. //return $data;
  6231. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  6232. }
  6233. echo set_msg($_W, $_GPC);
  6234. }
  6235. //卡券领取成功模板消息
  6236. public function doPageKqMessage() {
  6237. global $_W, $_GPC;
  6238. function getaccess_token($_W) {
  6239. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6240. $appid = $res['appid'];
  6241. $secret = $res['appsecret'];
  6242. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  6243. $ch = curl_init();
  6244. curl_setopt($ch, CURLOPT_URL, $url);
  6245. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6246. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6247. $data = curl_exec($ch);
  6248. curl_close($ch);
  6249. $data = json_decode($data, true);
  6250. return $data['access_token'];
  6251. }
  6252. //设置与发送模板信息
  6253. function set_msg($_W, $_GPC) {
  6254. $access_token = getaccess_token($_W);
  6255. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  6256. $usercoupons = pdo_get('zhtc_usercoupons', array('id' => $_GPC['id']));
  6257. $coupons = pdo_get('zhtc_coupons', array('id' => $usercoupons['coupons_id']));
  6258. $user = pdo_get('zhtc_user', array('id' => $usercoupons['user_id']));
  6259. $store = pdo_get('zhtc_store', array('id' => $coupons['store_id']));
  6260. $time = time() - 60 * 60 * 24 * 7;
  6261. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  6262. $formwork = '{
  6263. "touser": "' . $user["openid"] . '",
  6264. "template_id": "' . $res["kq_tid"] . '",
  6265. "page":"zh_tcwq/pages/index/index",
  6266. "form_id":"' . $form['form_id'] . '",
  6267. "data": {
  6268. "keyword1": {
  6269. "value": "' . $user['name'] . '",
  6270. "color": "#173177"
  6271. },
  6272. "keyword2": {
  6273. "value":"满' . $coupons['full'] . '减' . $coupons['reduce'] . '",
  6274. "color": "#173177"
  6275. },
  6276. "keyword3": {
  6277. "value":"' . $usercoupons['time'] . '",
  6278. "color": "#173177"
  6279. },
  6280. "keyword4": {
  6281. "value":"请在' . $coupons['end_time'] . '前使用",
  6282. "color": "#173177"
  6283. },
  6284. "keyword5": {
  6285. "value":"' . $store['store_name'] . '",
  6286. "color": "#173177"
  6287. }
  6288. }
  6289. }';
  6290. // $formwork=$data;
  6291. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  6292. $ch = curl_init();
  6293. curl_setopt($ch, CURLOPT_URL, $url);
  6294. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6295. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6296. curl_setopt($ch, CURLOPT_POST, 1);
  6297. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  6298. $data = curl_exec($ch);
  6299. curl_close($ch);
  6300. //return $data;
  6301. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  6302. }
  6303. echo set_msg($_W, $_GPC);
  6304. }
  6305. //拼团成功消息
  6306. public function doPagePtMessage() {
  6307. global $_W, $_GPC;
  6308. function getaccess_token($_W) {
  6309. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6310. $appid = $res['appid'];
  6311. $secret = $res['appsecret'];
  6312. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  6313. $ch = curl_init();
  6314. curl_setopt($ch, CURLOPT_URL, $url);
  6315. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6316. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6317. $data = curl_exec($ch);
  6318. curl_close($ch);
  6319. $data = json_decode($data, true);
  6320. return $data['access_token'];
  6321. }
  6322. //设置与发送模板信息
  6323. function set_msg($_W, $_GPC, $user_id, $group_id, $order_num, $goods_name, $goods_num, $price, $pay_time) {
  6324. $access_token = getaccess_token($_W);
  6325. $res = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  6326. $group = pdo_get('zhtc_group', array('id' => $group_id));
  6327. $store = pdo_get('zhtc_store', array('id' => $group['store_id']));
  6328. $user = pdo_get('zhtc_user', array('id' => $user_id));
  6329. $time = time() - 60 * 60 * 24 * 7;
  6330. $pay_time = date('Y-m-d H:i:s', $pay_time);
  6331. $form = pdo_fetch("select * from " . tablename('zhtc_userformid') . " where user_id={$user['id']} and UNIX_TIMESTAMP(time)>={$time} order by id asc");
  6332. $formwork = '{
  6333. "touser": "' . $user["openid"] . '",
  6334. "template_id": "' . $res["pt_tid"] . '",
  6335. "page":"zh_tcwq/pages/index/index",
  6336. "form_id":"' . $form['form_id'] . '",
  6337. "data": {
  6338. "keyword1": {
  6339. "value":"' . $order_num . '",
  6340. "color": "#173177"
  6341. },
  6342. "keyword2": {
  6343. "value": "' . $goods_name . '",
  6344. "color": "#173177"
  6345. },
  6346. "keyword3": {
  6347. "value": "' . $group['kt_num'] . '",
  6348. "color": "#173177"
  6349. },
  6350. "keyword4": {
  6351. "value":"' . $goods_num . '",
  6352. "color": "#173177"
  6353. },
  6354. "keyword5": {
  6355. "value":"' . $price . '",
  6356. "color": "#173177"
  6357. },
  6358. "keyword6": {
  6359. "value":"' . $price . '",
  6360. "color": "#173177"
  6361. },
  6362. "keyword7": {
  6363. "value":"' . $pay_time . '",
  6364. "color": "#173177"
  6365. },
  6366. "keyword8": {
  6367. "value":"' . $store['store_name'] . '",
  6368. "color": "#173177"
  6369. },
  6370. "keyword9": {
  6371. "value":"' . $store['address'] . '",
  6372. "color": "#173177"
  6373. }
  6374. },
  6375. "emphasis_keyword": "keyword1.DATA"
  6376. }';
  6377. // $formwork=$data;
  6378. $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=" . $access_token . "";
  6379. $ch = curl_init();
  6380. curl_setopt($ch, CURLOPT_URL, $url);
  6381. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6382. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6383. curl_setopt($ch, CURLOPT_POST, 1);
  6384. curl_setopt($ch, CURLOPT_POSTFIELDS, $formwork);
  6385. $data = curl_exec($ch);
  6386. curl_close($ch);
  6387. //return $data;
  6388. pdo_delete('zhtc_userformid', array('id' => $form['id']));
  6389. }
  6390. $order = pdo_getall('zhtc_grouporder', array('group_id' => $_GPC['group_id']));
  6391. foreach ($order as $key => $value) {
  6392. echo set_msg($_W, $_GPC, $value['user_id'], $_GPC['group_id'], $value['order_num'], $value['goods_name'], $value['goods_num'], $value['price'], $value['pay_time']);
  6393. }
  6394. }
  6395. //抢购商品二维码
  6396. public function doPageQgCode() {
  6397. global $_W, $_GPC;
  6398. function getCoade($order_id) {
  6399. function getaccess_token() {
  6400. global $_W, $_GPC;
  6401. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6402. $appid = $res['appid'];
  6403. $secret = $res['appsecret'];
  6404. // print_r($res);die;
  6405. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  6406. $ch = curl_init();
  6407. curl_setopt($ch, CURLOPT_URL, $url);
  6408. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6409. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6410. $data = curl_exec($ch);
  6411. curl_close($ch);
  6412. $data = json_decode($data, true);
  6413. return $data['access_token'];
  6414. }
  6415. function set_msg($order_id) {
  6416. $access_token = getaccess_token();
  6417. $data2 = array(
  6418. "scene" => $order_id,
  6419. "page" => "zh_tcwq/pages/xsqg/xsqgxq",
  6420. "width" => 400,
  6421. );
  6422. $data2 = json_encode($data2);
  6423. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  6424. $ch = curl_init();
  6425. curl_setopt($ch, CURLOPT_URL, $url);
  6426. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6427. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6428. curl_setopt($ch, CURLOPT_POST, 1);
  6429. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  6430. $data = curl_exec($ch);
  6431. curl_close($ch);
  6432. return $data;
  6433. }
  6434. $img = set_msg($order_id);
  6435. $img = base64_encode($img);
  6436. return $img;
  6437. }
  6438. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['id']);
  6439. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  6440. $type = $result[2];
  6441. $new_file = IA_ROOT . "/addons/zh_tcwq/img/";
  6442. if (!file_exists($new_file)) {
  6443. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  6444. mkdir($new_file, 0777);
  6445. }
  6446. $wname = "qg{$_GPC['id']}" . ".{$type}";
  6447. //$wname="1511.jpeg";
  6448. $new_file = $new_file . $wname;
  6449. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  6450. }
  6451. echo $_W['siteroot'] . "addons/zh_tcwq/img/" . $wname;
  6452. }
  6453. //抢购商品二维码
  6454. public function doPageHdCode() {
  6455. global $_W, $_GPC;
  6456. function getCoade($order_id) {
  6457. function getaccess_token() {
  6458. global $_W, $_GPC;
  6459. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6460. $appid = $res['appid'];
  6461. $secret = $res['appsecret'];
  6462. // print_r($res);die;
  6463. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $secret . "";
  6464. $ch = curl_init();
  6465. curl_setopt($ch, CURLOPT_URL, $url);
  6466. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6467. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6468. $data = curl_exec($ch);
  6469. curl_close($ch);
  6470. $data = json_decode($data, true);
  6471. return $data['access_token'];
  6472. }
  6473. function set_msg($order_id) {
  6474. $access_token = getaccess_token();
  6475. $data2 = array(
  6476. "scene" => $order_id,
  6477. "page" => "zh_tcwq/pages/hdzx/hdzxinfo",
  6478. "width" => 400,
  6479. );
  6480. $data2 = json_encode($data2);
  6481. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token . "";
  6482. $ch = curl_init();
  6483. curl_setopt($ch, CURLOPT_URL, $url);
  6484. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6485. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  6486. curl_setopt($ch, CURLOPT_POST, 1);
  6487. curl_setopt($ch, CURLOPT_POSTFIELDS, $data2);
  6488. $data = curl_exec($ch);
  6489. curl_close($ch);
  6490. return $data;
  6491. }
  6492. $img = set_msg($order_id);
  6493. $img = base64_encode($img);
  6494. return $img;
  6495. }
  6496. $base64_image_content = "data:image/jpeg;base64," . getCoade($_GPC['id']);
  6497. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
  6498. $type = $result[2];
  6499. $new_file = IA_ROOT . "/addons/zh_tcwq/img/";
  6500. if (!file_exists($new_file)) {
  6501. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  6502. mkdir($new_file, 0777);
  6503. }
  6504. $wname = "hd{$_GPC['id']}" . ".{$type}";
  6505. //$wname="1511.jpeg";
  6506. $new_file = $new_file . $wname;
  6507. file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)));
  6508. }
  6509. echo $_W['siteroot'] . "addons/zh_tcwq/img/" . $wname;
  6510. }
  6511. //删除114
  6512. public function doPageDelYellowStore() {
  6513. global $_W, $_GPC;
  6514. $res = pdo_update('zhtc_yellowstore', array('is_delete' => 1), array('id' => $_GPC['y_id']));
  6515. if ($res) {
  6516. echo 1;
  6517. } else {
  6518. echo 2;
  6519. }
  6520. }
  6521. //删除拼车
  6522. public function doPageDelCar() {
  6523. global $_W, $_GPC;
  6524. $res = pdo_update('zhtc_car', array('is_delete' => 1), array('id' => $_GPC['car_id']));
  6525. if ($res) {
  6526. echo 1;
  6527. } else {
  6528. echo 2;
  6529. }
  6530. }
  6531. //查找电话金额
  6532. public function doPageGetTelMoney() {
  6533. global $_W, $_GPC;
  6534. if ($_GPC['type_id']) {
  6535. $res = pdo_get('zhtc_type', array('id' => $_GPC['type_id']), 'tel_money');
  6536. }
  6537. if ($_GPC['type_id']) {
  6538. $res = pdo_get('zhtc_type2', array('id' => $_GPC['type2_id']), 'tel_money');
  6539. }
  6540. echo json_encode($res);
  6541. }
  6542. //电话支付记录
  6543. public function doPageSaveTelPayLog() {
  6544. global $_W, $_GPC;
  6545. $data['tz_id'] = $_GPC['tz_id'];
  6546. $data['user_id'] = $_GPC['user_id'];
  6547. $data['money'] = $_GPC['tel_money'];
  6548. $data['time'] = date('Y-m-d H:i:s');
  6549. $data['uniacid'] = $_W['uniacid'];
  6550. $res = pdo_insert('zhtc_telpaylog', $data);
  6551. }
  6552. //板块导航
  6553. public function doPageGetPlate() {
  6554. global $_GPC, $_W;
  6555. $res = pdo_getall('zhtc_plate', array('uniacid' => $_W['uniacid']), array(), '', 'sort asc');
  6556. echo json_encode($res);
  6557. }
  6558. //商家列表
  6559. public function doPageStoreGoodsList() {
  6560. global $_W, $_GPC;
  6561. $time = time();
  6562. $where = " where uniacid=:uniacid and time_over !=1 and state=2";
  6563. $data[':uniacid'] = $_W['uniacid'];
  6564. $lat = empty($_GPC['lat']) ? '30.592760' : $_GPC['lat'];
  6565. $lng = empty($_GPC['lng']) ? '114.305250' : $_GPC['lng'];
  6566. $pageindex = max(1, intval($_GPC['page']));
  6567. $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  6568. if ($_GPC['cityname']) {
  6569. $where .= " and (cityname LIKE concat('%', :name,'%') || cityname='')";
  6570. $data[':name'] = $_GPC['cityname'];
  6571. }
  6572. $sql = "select id,store_name,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($lat*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)/2),2)+COS($lat*3.1415926/180)*COS(SUBSTRING_INDEX(coordinates, ',', 1)*3.1415926/180)*POW(SIN(($lng*3.1415926/180-SUBSTRING_INDEX(coordinates, ',', -1)*3.1415926/180)/2),2)))*1000) AS juli from" . tablename('zhtc_store') . $where . " order by is_top asc,juli asc";
  6573. $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  6574. $res = pdo_fetchall($select_sql, $data);
  6575. //var_dump($res);die;
  6576. foreach ($res as $key => $value) {
  6577. $store_id = $value['id'];
  6578. $sql2 = "select * from " . tablename("zhtc_qggoods") . " where UNIX_TIMESTAMP(start_time)<={$time} and UNIX_TIMESTAMP(end_time)>{$time} and state=1 and state2=1 and is_tg=2 and store_id={$store_id} order by num asc";
  6579. $res2 = pdo_fetch($sql2);
  6580. if ($res2) {
  6581. $res[$key]['goodsInfo'] = $res2;
  6582. } else {
  6583. unset($res[$key]);
  6584. }
  6585. }
  6586. $res = array_values($res);
  6587. echo json_encode($res);
  6588. }
  6589. //导航
  6590. public function doPageGetBottom() {
  6591. global $_W, $_GPC;
  6592. $res = pdo_getall('zhtc_bottom', array('uniacid' => $_W['uniacid'], 'state' => 1), array(), '', 'num asc');
  6593. echo json_encode($res);
  6594. }
  6595. public function doPageAliyun($phone, $code) {
  6596. global $_W, $_GPC;
  6597. require_once dirname(__DIR__) . "/zh_tcwq/SignatureHelper.php";
  6598. $sms = pdo_get('zhtc_sms', array('uniacid' => $_W['uniacid']));
  6599. // echo $code;die;
  6600. $params = array();
  6601. // *** 需用户填写部分 ***
  6602. // fixme 必填:是否启用https
  6603. $security = false;
  6604. // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
  6605. $accessKeyId = $sms['aliyun_appkey'];
  6606. $accessKeySecret = $sms['aliyun_appsecret'];
  6607. // fixme 必填: 短信接收号码
  6608. $params["PhoneNumbers"] = $phone;
  6609. // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
  6610. $params["SignName"] = $sms['aliyun_sign'];
  6611. // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
  6612. $params["TemplateCode"] = $sms['tpl_id'];
  6613. // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
  6614. $params['TemplateParam'] = Array(
  6615. "code" => $code,
  6616. );
  6617. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  6618. if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  6619. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  6620. }
  6621. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  6622. $helper = new SignatureHelper();
  6623. // 此处可能会抛出异常,注意catch
  6624. $content = $helper->request(
  6625. $accessKeyId,
  6626. $accessKeySecret,
  6627. "dysmsapi.aliyuncs.com",
  6628. array_merge($params, array(
  6629. "RegionId" => "cn-hangzhou",
  6630. "Action" => "SendSms",
  6631. "Version" => "2017-05-25",
  6632. )),
  6633. $security
  6634. );
  6635. return $content;
  6636. }
  6637. public function doPageAliyun2($tel, $aliyun_appkey, $aliyun_appsecret, $aliyun_sign, $tpl_id) {
  6638. global $_W, $_GPC;
  6639. require_once dirname(__DIR__) . "/zh_tcwq/SignatureHelper.php";
  6640. // echo $code;die;
  6641. $params = array();
  6642. // *** 需用户填写部分 ***
  6643. // fixme 必填:是否启用https
  6644. $security = false;
  6645. // fixme 必填: 请参阅 https://ak-console.aliyun.com/ 取得您的AK信息
  6646. $accessKeyId = $aliyun_appkey;
  6647. $accessKeySecret = $aliyun_appsecret;
  6648. // fixme 必填: 短信接收号码
  6649. $params["PhoneNumbers"] = $tel;
  6650. // fixme 必填: 短信签名,应严格按"签名名称"填写,请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/sign
  6651. $params["SignName"] = $aliyun_sign;
  6652. // fixme 必填: 短信模板Code,应严格按"模板CODE"填写, 请参考: https://dysms.console.aliyun.com/dysms.htm#/develop/template
  6653. $params["TemplateCode"] = $tpl_id;
  6654. // fixme 可选: 设置模板参数, 假如模板中存在变量需要替换则为必填项
  6655. // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
  6656. if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
  6657. $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
  6658. }
  6659. // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
  6660. $helper = new SignatureHelper();
  6661. // 此处可能会抛出异常,注意catch
  6662. $content = $helper->request(
  6663. $accessKeyId,
  6664. $accessKeySecret,
  6665. "dysmsapi.aliyuncs.com",
  6666. array_merge($params, array(
  6667. "RegionId" => "cn-hangzhou",
  6668. "Action" => "SendSms",
  6669. "Version" => "2017-05-25",
  6670. )),
  6671. $security
  6672. );
  6673. return $content;
  6674. }
  6675. public function doPageIsCall() {
  6676. global $_W, $_GPC;
  6677. $call = pdo_get('zhtc_call', array('post_id' => $_GPC['id'], 'state' => 2, 'user_id' => $_GPC['user_id']));
  6678. echo $call ? true : false;
  6679. }
  6680. //电话付费
  6681. public function doPageCall() {
  6682. global $_W, $_GPC;
  6683. $system = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']), array('callProportion'));
  6684. $postId = $_GPC['post_id'];
  6685. $post = pdo_get('zhtc_information', array('id' => $postId));
  6686. if (!$post) {
  6687. echo '信息不存在';die;
  6688. }
  6689. $type = pdo_get('zhtc_type', array('id' => $post['type_id']));
  6690. $data['post_id'] = $_GPC['post_id'];
  6691. $data['type'] = 1;
  6692. $data['money'] = $type['tel_money'] ? $type['tel_money'] : 0;
  6693. $data['code'] = date('YmdHis') . mt_rand(100000, 999999);
  6694. $data['state'] = 1;
  6695. $data['time'] = time();
  6696. $data['uniacid'] = $_W['uniacid'];
  6697. $data['user_id'] = $_GPC['user_id'];
  6698. $data['userMoney'] = bcmul($system['callProportion'] / 100, $data['money'], 2);
  6699. $res = pdo_insert('zhtc_call', $data);
  6700. $id = pdo_insertid();
  6701. if ($res) {
  6702. echo $id;
  6703. } else {
  6704. echo '失败';
  6705. }
  6706. }
  6707. //查看电话支付
  6708. public function doPageCallPay() {
  6709. global $_W, $_GPC;
  6710. include IA_ROOT . '/addons/zh_tcwq/wxpay.php';
  6711. $res = pdo_get('zhtc_system', array('uniacid' => $_W['uniacid']));
  6712. if ($res['pt_name']) {
  6713. $res['pt_name'] = $res['pt_name'];
  6714. } else {
  6715. $res['pt_name'] = '同城小程序';
  6716. }
  6717. $order = pdo_get('zhtc_call', array('id' => $_GPC['order_id']));
  6718. $user = pdo_get('zhtc_user', array('id' => $order['user_id']), array(), '', 'id DESC');
  6719. $appid = $res['appid'];
  6720. $openid = $user['openid']; //oQKgL0ZKHwzAY-KhiyEEAsakW5Zg
  6721. $mch_id = $res['mchid'];
  6722. $key = $res['wxkey'];
  6723. $out_trade_no = $order['code'];
  6724. $total_fee = $order['money'];
  6725. if (empty($total_fee)) //押金
  6726. {
  6727. $body = $res['pt_name'];
  6728. $total_fee = floatval(99 * 100);
  6729. } else {
  6730. $body = $res['pt_name'];
  6731. $total_fee = floatval($total_fee * 100);
  6732. }
  6733. $root = $_W['siteroot'];
  6734. $weixinpay = new WeixinPay($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee, $root);
  6735. $return = $weixinpay->pay();
  6736. echo json_encode($return);
  6737. }
  6738. //查看电话记录
  6739. public function doPageCallList() {
  6740. global $_W, $_GPC;
  6741. $where = " where a.post_id=:post_id and a.state=2";
  6742. $data[':post_id'] = $_GPC['post_id'];
  6743. // $pageindex = max(1, intval($_GPC['page']));
  6744. // $pagesize = empty($_GPC['pagesize']) ? 10 : $_GPC['pagesize'];
  6745. $sql = "select a.post_id,a.money,a.time,b.name as userName,b.img from " . tablename("zhtc_call") . " a" . " left join " . tablename("zhtc_user") . " b on b.id=a.user_id " . $where . " ORDER BY a.id DESC";
  6746. // $select_sql = $sql . " LIMIT " . ($pageindex - 1) * $pagesize . "," . $pagesize;
  6747. $res = pdo_fetchall($sql, $data);
  6748. echo json_encode($res);
  6749. }
  6750. } /////////////////////////////////////////////