123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Api\Repositories\WxContRepositories;
- use App\Http\Controllers\Api\Repositories\WxUserReportRepositories;
- use App\Jobs\User\UserWithdrawalProcessJob;
- use App\Jobs\UserBgColorUpdateJob;
- use App\Jobs\UserInputSafeCheckJob;
- use App\Lib\WeApp\WeApp;
- use App\Mail\text;
- use App\Models\Pets\WxPetsAdoption;
- use App\Models\Posts\WxComment;
- use App\Models\User\WxUserAvatarFrame;
- use App\Models\User\WxUserCoinRecord;
- use App\Models\User\WxUserContactApply;
- use App\Models\User\WxUserFinancialRecord;
- use App\Models\User\WxUserInviteBenefitRecord;
- use App\Models\User\WxUserInviteTempCode;
- use App\Models\User\WxUserOnline;
- use App\Models\User\WxUserReport;
- use App\Models\User\WxUserSetting;
- use App\Models\User\WxUserVisit;
- use App\Models\Voter\WxVoter;
- use App\Models\WxAttachment;
- use App\Wen\Utils\BaiduUtils;
- use App\Wen\Utils\FieldUtils;
- use App\Wen\Utils\GatewayUtils;
- use App\Wen\Utils\PostUtils;
- use App\Wen\Utils\SafeUtils;
- use App\Wen\Utils\SearchUtils;
- use App\Wen\Utils\Settings;
- use App\Wen\Utils\SiteUtils;
- use App\Wen\Utils\StrUtils;
- use App\Wen\Utils\UserUtils;
- use App\Wen\Utils\Utils;
- use App\Http\Controllers\Api\Repositories\PostsRepositores;
- use App\Http\Controllers\Api\Repositories\WxUserRepositores;
- use App\Models\Posts\WxCollect;
- use App\Models\Posts\WxLike;
- use App\Models\Posts\WxPost;
- use App\Models\Posts\WxPostsVote;
- use App\Models\Posts\WxUserCircle;
- use App\Models\WxAuthentication;
- use App\Models\Circle\WxCircle;
- use App\Models\WxCommentLike;
- use App\Models\WxExceptional;
- use App\Models\WxOrder;
- use App\Models\WxPlate;
- use App\Models\User\WxUser;
- use App\Models\User\WxUserFinancial;
- use App\Models\User\WxUserFollow;
- use App\Models\User\WxUserPlate;
- use App\Models\User\WxUserVote;
- use App\Models\User\WxUserWithdrawal;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use App\Lib\wxBizDataCrypt\WxBizDataCrypt;
- use App\Lib\JwtAuth;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Mail;
- use Illuminate\Support\Facades\Storage;
- use Intervention\Image\Facades\Image;
- use Laravel\Socialite\Facades\Socialite;
- use Overtrue\Pinyin\Pinyin;
- use SimpleSoftwareIO\QrCode\Facades\QrCode;
- use App\Models\Conditions;
- use App\Models\Posts\WxPostsImg;
- use App\Wen\Utils\ApiUtils;
- class UserController extends BaseController
- {
-
- /**
- * 获取文章详情
- */
- public function getPostDetail(Request $request)
- {
- $posts_id = $request->posts_id;
- $data = WxPost::where('id', $posts_id)->first(['id','posts_title','posts_content','circle_id','is_draft']);
- if (empty($data)) {
- return $this->fail(200003);
- }
- $imgs = WxPostsImg::where('posts_id', $posts_id)->pluck('img_url')->toArray();
- $data->img = $imgs[0] ?? '';
- return $this->success($data);
- }
- /**
- * 获取我发布的笔记
- */
- public function getMyPostsList(Request $request)
- {
- $user_id = $request->uid;
- // $user_id = _empty_default_($request->user_id, 0);
- // print_r($user_id);die;
- // $user_id = 1;
- if(_empty_($user_id)){
- return $this->fail(200001);
- }
- $type = _empty_default_($request->type, 0); // 0 全部 1 未审核 2 已审核 3 审核驳回 4 草稿
- if ($type == 1) {
- $type = 2;
- } else if ($type == 2){
- $type = 1;
- }
- $page = $request->page ?? 1;
- $limit = $request->limit ?? 10;
- $offset = ($page - 1) * $limit;
- if ($type == 0) {
- $where = [
- ['user_id', '=', $user_id],
- ['is_blur', '=', 0],
- ['posts_state','=',0]
- ];
- } else if ($type == 4){
- $where = [
- ['user_id', '=', $user_id],
- ['is_blur', '=', 0],
- ['posts_state','=',0],
- ['is_draft', '=', 1]
- ];
- } else {
- $type = $type - 1;
- $where = [
- ['user_id', '=', $user_id],
- ['is_examine', '=', $type],
- ['is_draft', '=', 0],
- ['posts_state','=',0],
- ['is_blur', '=', 0]
- ];
- }
- // print_r($where);exit;
- $field = ['id','posts_title','created_at','is_examine','is_draft','posts_state'];
- $query = WxPost::where($where)->offset($offset)->limit($limit);
- $query->orderBy('id', 'desc');
- $list = $query->get($field);
- // print_r($list);exit;
- foreach ($list as $key => $value) {
- if ($value['is_examine'] == 0) {
- $list[$key]['posts_type'] = 1;
- } else if ($value['is_examine'] == 1) {
- $list[$key]['posts_type'] = 2;
- } else {
- $list[$key]['posts_type'] = 3;
- }
- if ($value['is_draft'] == 1) {
- $list[$key]['posts_type'] = 4;
- }
- if (empty($value->posts_title)) {
- $list[$key]->posts_title = '无标题';
- }
- // WxPostsImg 获取第一章封面图
- $img = WxPostsImg::where('posts_id', $value->id)->first();
- if ($img) {
- $list[$key]->img = $img->img_url;
- } else {
- $list[$key]->img = '';
- }
- // use App\Models\Posts\WxLike; 获取点赞数
- $like = WxLike::where('posts_id', $value->id)->count();
- $list[$key]->like = $like;
- // WxCollect
- $collect = WxCollect::where('posts_id', $value->id)->count();
- $list[$key]->collect = $collect;
- // WxUserVisit 获取浏览量
- $visit = WxUserVisit::where('object_id', $value->id)->where('type', 1)->get('times')->toArray();
- // print_r($visit);die;
- // $visit_count = 0;
- // foreach ($visit as $key => $val) {
- // // if (isset($val->times) && empty($val->times)) {
- // // $vc_count = $val->times;
- // // $visit_count += $vc_count;
- // // }
- // $vc_count = $val['times'];
- // $visit_count += $vc_count;
-
- // }
- $list[$key]->visit = count($visit);
- }
- $total = WxPost::where($where)->count();
- return $this->success($list);
- }
- public function real_name_api($uid, $realName, $realIdCard)
- {
-
- $user = WxUser::find($uid);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- $realName = _empty_default_($realName, '');
- $realIdCard = _empty_default_($realIdCard, '');
- if(_empty_($realName) || _empty_($realIdCard)){
- return $this->fail(200001);
- }
- if(mb_strlen($realName) <= 1){
- return $this->fail(200004, [], '姓名过短');
- }
- if(strpos($realName, '*') !== false || strpos($realIdCard, '*') !== false){
- return $this->fail(200004, [], '姓名或身份证中含有*号,请先删除');
- }
- if(strlen($realIdCard) != 18){
- return $this->fail(200004, [], '请输入合法的身份证号');
- }
- // $realName_fake = mb_substr($realName, 0, 1) . str_repeat( '*', (mb_strlen($realName) - 1) );
- // $realIdCard_fake = mb_substr($realIdCard, 0, 2) . str_repeat( '*', (mb_strlen($realIdCard) - 2) );
- $realName_fake = $realName;
- $realIdCard_fake = $realIdCard;
- if($user->real_name == $realName_fake && $user->real_id_card == $realIdCard_fake){
- return $this->fail(200010, [], '与已有认证信息相同,无需修改');
- }
- $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
- if(_empty_($user->phone) || _empty_($phone)){
- return $this->fail(200043, [
- 'title' => '未绑定手机号',
- 'content' => '前往绑定',
- 'confirmText' => '去绑定',
- 'target_type' => 6,
- 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
- ], '未绑定手机号');
- }
- // $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
- // todo:
- // WxUser::where('id', $uid)->update([
- // 'real_name' => $realName_fake,
- // 'real_id_card' => $realIdCard_fake,
-
- // ]);
- // update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
- // // Conditions 更新实名认证状态
- // Conditions::where('user_id', $uid)->update(['is_real' => 1]);
- // return $this->success();
- $res_ = Http::withHeaders([
- 'Authorization' => 'APPCODE '.Settings::get('app_ali_real_name_appcode', ''),
- ])->asForm()->post('https://mobile3elements.shumaidata.com/mobile/verify_real_name', ['idcard'=>$realIdCard, 'mobile'=>$phone, 'name'=> $realName]);
- if($res_->successful()){
- $res = $res_->json();
- if($res){
- if($res['code'] == 0 && $res['result']){
- if($res['result']['res'] == 1){
- // 一致
- DB::beginTransaction();
- try {
- $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
- // todo:
- WxUser::where('id', $uid)->update([
- 'real_name' => $realName_fake,
- 'real_id_card' => $realIdCard_fake
- ]);
- update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
- // Conditions 更新实名认证状态
- Conditions::where('user_id', $uid)->update(['is_real' => 1]);
- DB::commit();
- return $this->success([], 200, '实名认证成功');
- } catch (\Exception $e) {
- DB::rollBack();
- _logger_(__file__, __line__, $e->getMessage());
- return $this->fail(200002);
- }
- }else if($res['result']['res'] == 2){
- return $this->fail(200004, [], '身份信息不一致,认证失败');
- }else if($res['result']['res'] == 3){
- return $this->fail(200004, [], '认证系统查询不到该信息,请联系客服');
- }else if($res['result']['res'] == -1){
- return $this->fail(200004, [], '异常');
- }
- }else{
- UserUtils::assistant_notice('admin', $res.'_003');
- return $this->fail(200004, [], $res['message'].'__003');
- }
- }
- }else{
- $res = $res_->json();
- _logger_(__file__, __line__, '实名认证返回错误,'.$res_->body());
- _logger_(__file__, __line__, '实名认证返回错误,'. urldecode($res_));
- return $this->fail(200004, [], _array_key($res, 'message', ''));
- }
- }
- public function user_process(Request $request){
- $type = _empty_default_($request->type, '');
- if ($type == 'contact_apply') {
- return $this->contactApply($request);
- }else if($type == 'contact_apply_query'){
- return $this->contact_apply_query($request);
- }else if($type == 'anonymous_info'){
- return $this->anonymous_info($request);
- }else if($type == 'circle_unread_count_19'){
- return $this->circle_unread_count_19($request);
- }else if($type == 'circle_unread_count_remove'){
- return $this->circle_unread_count_remove($request);
- }else if($type == 'invite_tmp_code_query'){
- return $this->invite_tmp_code_query($request);
- }else if($type == 'invite_tmp_code_bind'){
- return $this->invite_tmp_code_bind($request);
- }else if($type == 'invite_info_query'){
- return $this->invite_info_query($request);
- }else if($type == 'invite_info_update'){
- return $this->invite_info_update($request);
- }
- }
- private function invite_info_update(Request &$request){
- global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
- if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
- return $this->fail(200000);
- }
- $user_id = _empty_default_($request->user_id, 0);
- if(_empty_($user_id)){
- return $this->fail(200001);
- }
- $invite_benefit = _empty_default_($request->invite_benefit, 0);
- if(!_empty_($invite_benefit)){
- $invite_benefit = round((float)$invite_benefit, 2);
- if($invite_benefit <= 0){
- return $this->fail(200004);
- }
- }else{
- $invite_benefit = 0;
- }
- $invite_benefit_layer = _empty_default_($request->invite_benefit_layer, 0);
- if(!_empty_($invite_benefit_layer)){
- if(_empty_($invite_benefit_layer) || !in_array($invite_benefit_layer, [1,2,3])){
- return $this->fail(200001);
- }
- }else{
- $invite_benefit_layer = 0;
- }
- if($invite_benefit === 0 && $invite_benefit_layer === 0){
- return $this->fail(200001);
- }
- $user = WxUser::where('id', $user_id)->first(['id', 'user_name', 'user_avatar', 'invite_benefit', 'invite_benefit_layer']);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- if($invite_benefit > 0){
- WxUser::withoutSyncingToSearch(function () use (&$user, $invite_benefit){
- WxUser::where('id', $user->id)->update(['invite_benefit'=>$invite_benefit]);
- });
- }else if($invite_benefit_layer > 0){
- WxUser::withoutSyncingToSearch(function () use (&$user, $invite_benefit_layer){
- WxUser::where('id', $user->id)->update(['invite_benefit_layer'=>$invite_benefit_layer]);
- });
- if($invite_benefit_layer > 1){
- Cache::put('is:can:bind:itc:'.$user->id, '1', 3600);
- }
- GatewayUtils::success(GatewayUtils::uid2client_id($user->id), 12);
- }
- $user = WxUser::where('id', $user_id)->first(['id', 'user_name', 'user_avatar', 'invite_benefit', 'invite_benefit_layer']);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- return $this->success($user);
- }
- private function invite_info_query(Request &$request){
- $user_id = _empty_default_($request->user_id, 0);
- if(_empty_($user_id)){
- return $this->fail(200001);
- }
- $user = WxUser::where('id', $user_id)->first(['id', 'user_name', 'user_avatar', 'invite_benefit', 'invite_benefit_layer']);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- if($user->invite_benefit == -1){
- $user->invite_benefit = Settings::get('user_invite_immediately_benefit_blance', 0.0);
- }
- return $this->success($user);
- }
- private function invite_tmp_code_bind(Request &$request){
- $uid = $request->uid;
- global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
- if(_empty_($uid)){
- return $this->fail(200001);
- }
- $itc = _empty_default_($request->itc, '');
- if(_empty_($itc)){
- return $this->fail(200001);
- }
- if(!StrUtils::startsWith($itc, 'itc')){
- return $this->fail(200004);
- }
- $itc = (int)(str_replace('itc', '', $itc));
- if($itc <= 0){
- return $this->fail(200004);
- }
- $itc_obj = WxUserInviteTempCode::find($itc);
- if(_empty_($itc_obj)){
- return $this->fail(200003);
- }
- $type_arr = [1=>'传单', 2=>'桌牌'];
- $itc_obj->type_tip = $type_arr[$itc_obj->type];
- if($itc_obj->status == 1){
- return $this->fail(200010, [], '该'.$itc_obj->type_tip.'已绑定');
- }
- $user = WxUser::find($uid);
- if(_empty_($user)){
- return $this->fail(200001);
- }
- if($user->invite_benefit_layer <= 1){
- if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
- }else{
- return $this->fail(200000, [], '仅推广专员,校园合伙人可绑定');
- }
- }
- if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
- if(!Cache::has('is:can:bind:itc:'.$user->id)){
- return $this->fail(200000, [], '绑定传单需要联系管理员');
- }
- }
- $updates = [
- 'user_id' => $user->id,
- 'status' => 1
- ];
- if($itc_obj->tenant_id === null){
- $updates['tenant_id'] = $user->tenant_id;
- }
- WxUserInviteTempCode::where('id', $itc_obj->id)->update($updates);
- return $this->success();
- }
- private function invite_tmp_code_query(Request &$request){
- $uid = $request->uid;
- if(_empty_($uid)){
- return $this->fail(200001);
- }
- $itc = _empty_default_($request->itc, '');
- if(_empty_($itc)){
- return $this->fail(200001);
- }
- if(!StrUtils::startsWith($itc, 'itc')){
- return $this->fail(200004);
- }
- $itc = (int)(str_replace('itc', '', $itc));
- if($itc <= 0){
- return $this->fail(200004);
- }
- $itc_obj = WxUserInviteTempCode::find($itc);
- if(_empty_($itc_obj)){
- return $this->fail(200003);
- }
- $type_arr = [1=>'传单', 2=>'桌牌'];
- $status_arr = [0=>'待绑定', 1=>'已绑定', 2=>'解除绑定'];
- $itc_obj->type_tip = $type_arr[$itc_obj->type];
- $itc_obj->type_img = env('APP_URL', '').'/statics/images/invite_tmp_code/itc_type_'.$itc_obj->type.'.png';
- $itc_obj->desc = '绑定之后,您可以使用该'.$itc_obj->type_tip.'进行推广,奖励会自动关联到您的账号';
- $itc_obj->status_tip = $status_arr[$itc_obj->status];
- $itc_obj->title = ($itc_obj->status == 1 ? '您已' : '您可').'绑定该'.$itc_obj->type_tip.'(id:'.$itc_obj->id.')';
- if($itc_obj->status == 1){
- if($itc_obj->user_id == $uid){
- $itc_obj->status_tip = '您已绑定';
- }else{
- $itc_obj->status_tip = '已被他人绑定';
- }
- }
- $result = DB::table('wx_user_invite_temp_code_record')
- ->select(
- DB::raw('COUNT(object_id) as total_objects'),
- DB::raw('SUM(reward_balance) as total_reward_balance'),
- DB::raw('SUM(reward_coin) as total_reward_coin')
- )
- ->where('itc_id', $itc_obj->id)
- ->first();
- $itc_obj->invite_info = $result;
- $itc_obj->result_tip = '共'.$result->total_objects.'人 (奖励¥'.$result->total_reward_balance.'+'.Settings::get('app_coin_name', '硬币').'*'.$result->total_reward_coin.')';
- return $this->success($itc_obj);
- }
- private function circle_unread_count_remove(Request &$request){
- $uid = $request->uid;
- if(_empty_($uid)){
- return $this->fail(200001);
- }
- DB::table('wx_user_visit')
- ->where('user_id', $uid)
- ->where('type', 2)
- ->whereIn('object_id', function ($query) use ($uid) {
- $query->select('uc.circle_id')
- ->from('wx_user_circle as uc')
- ->join('wx_circle as c', 'uc.circle_id', '=', 'c.id')
- ->where('uc.user_id', $uid)
- ->where('uc.user_circle_state', 0)
- ->where('c.circle_state', 1);
- })
- ->update(['updated_at' => Carbon::now()]);
- Cache::forget('user_circle_unread_count:'.$uid);
- return $this->success();
- }
- private function circle_unread_count_19(Request &$request){
- $uid = $request->uid;
- if(_empty_($uid)){
- return $this->fail(200001);
- }
- $app_find_tab = Settings::get('app_find_tab', [], true);
- $flag = false;
- if($app_find_tab){
- for ($i = 0; $i < count($app_find_tab); $i++){
- if($app_find_tab[$i]['follow_status'] == 1 && _empty_($app_find_tab[$i]['tags'])){
- $app_find_tab[$i]['badge'] = [
- 'value' => UserUtils::user_circle_unread_count($uid)
- ];
- $flag = true;
- }
- }
- }
- if($flag){
- return $this->success($app_find_tab);
- }else{
- return $this->fail(200003);
- }
- }
- private function anonymous_info(Request &$request){
- $uid = $request->uid;
- if(_empty_($uid)){
- return $this->fail(200001);
- }
- $change = _empty_default_($request->change, 0) == 1 ? 1 : 0;
- $the_user = WxUser::find($uid);
- if($the_user){
- $anonymous_info = UserUtils::get_anonymous_info($the_user, $change);
- if($anonymous_info){
- return $this->success($anonymous_info);
- }
- }
- return $this->fail(200003);
- }
- public function contact_apply_query(Request &$request){
- $uid = _empty_default_($request->uid, 0);
- if(_empty_($uid)){
- return $this->fail(503002);
- }
- $object_id = _empty_default_($request->object_id, 0);
- if(_empty_($object_id)){
- return $this->fail(200001);
- }
- $settings = WxUserSetting::where('user_id', $object_id)->first();
- $contact = WxUserContactApply::where('user_id', $uid)->where('object_id', $object_id)->first();
- if($contact){
- if($contact->status == 1){
- if($contact->is_wechat_account == 1){
- $contact->wechat_account = WxUser::where('id', $contact->object_id)->value('wechat_account');
- if($contact->wechat_account){
- $contact->wechat_account_safe = str_repeat('*', mb_strlen($contact->wechat_account));
- }else{
- $contact->wechat_account_safe = '***';
- }
- }
- if($contact->is_phone){
- $contact->phone = _get_origin_attribute('wx_user', [['id', '=', $contact->object_id]], 'phone');
- if($contact->phone){
- $contact->phone_safe = str_repeat('*', mb_strlen($contact->phone));
- }else{
- $contact->phone_safe = '***';
- }
- }
- }
- return $this->success($contact);
- }else{
- }
- return $this->fail(200003);
- }
- public function mplogin(Request $request)
- {
- $app_login_style = Utils::get_login_styles();
- if(!in_array(0, $app_login_style)){
- return $this->fail(200008, [], '平台暂未开启微信登录方式');
- }
- $unique = $request->unique;
- $user_id = Cache::get('mini:mplogin:unique:' . $unique);
- if($user_id){
- Cache::forget('mini:mplogin:unique:' . $unique);
- $login_user = WxUser::find($user_id);
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- // 生成token
- return $this->success(['token' => JwtAuth::getToken('uid', $login_user['id'], $time), 'user'=>$login_user]);
- }else if($user_id == -2){
- return $this->fail(200008, [], '平台未开启微信注册新用户,请您换其他方式先注册账号');
- }else if($user_id == -3){
- return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
- }
- return $this->fail(200003);
- }
- public function scan(Request $request){
- if($request->isMethod('GET')){
- $weapp = new WeApp();
- //从‘小程序’获取一个‘二维码’单例对象
- $qrcode = $weapp->getQRCode();
- $scene = uniqid();
- // $page = 'pages/login/login';
- $page = 'pages/pc-login/index';
- //2.获取小程序B码
- $qrcodeContent = $qrcode->getQRCodeB($scene, $page, 430, false, $line_color = null);
- $filePath = 'qrcode/' . $scene . '.png';
- $res = Storage::disk('public')->put($filePath, $qrcodeContent);
- if ($res) {
- return $this->success(['url'=>Storage::url($filePath), 'scene'=>$scene]);
- }else{
- return $this->fail(200006, [], '二维码生成失败');
- }
- }else{
- $token = Cache::get('login:scene:'.$request->scene);
- if($token){
- $user_id = JwtAuth::getUserId($token, 'uid');
- if($user_id > 0){
- $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- // 支付密码
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- $data = [
- 'token' => $token,
- 'scene' => $request->scene,
- 'user'=>$login_user
- ];
- Cache::forget('login:scene:'.$request->scene);
- return $this->success($data);
- }
- return $this->fail(200000);
- }
- return $this->fail(200000);
- }
- }
- /**
- * @param Request $request
- * @param code
- * @param encryptedData
- * @param iv
- * @return \Illuminate\Http\JsonResponse
- * @throws \Exception
- */
- public function login(Request $request)
- {
- $app_login_style = Utils::get_login_styles();
- if(_empty_($app_login_style)){
- $app_login_style = [0];
- }
- $code = $request->code;
- $fromUser = $request->header('fromUser',0);
- if(_empty_($fromUser)){
- $fromUser = 0;
- }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
- $fromUser = trim($fromUser);
- }else if((int)$fromUser > 0){
- if(UserUtils::get_user_state($fromUser) != 0){
- $fromUser = 0;
- }else{
- $fromUser = (int)$fromUser;
- }
- }else{
- $fromUser = 0;
- }
- //例如,在laravel,文件缓存路径为storage_path('cache/')
- $weapp = new WeApp();
- //code 换取 session_key
- $sessionKey = $weapp->getSessionKey($code);
- $sessionKey = json_decode($sessionKey, true);
- if(_empty_($sessionKey) || _empty_(_array_key($sessionKey, 'session_key', null))){
- _logger_(__file__, __line__, $sessionKey);
- return $this->fail(503001);
- }
- // {"session_key":"IVEMC\/Rmlof2WIft0vyJfQ==","openid":"oKIZi5O-FIqbnUlAb15LOGhh6Ix0","unionid":"oep525m2kvV3uvwsP4L-o8qPzUZk"}
- if (_array_key($sessionKey, 'unionid', '') || _array_key($sessionKey, 'openid', '')) {
- $data['unionId'] = _array_key($sessionKey, 'unionid', null);
- $data['openId'] = _array_key($sessionKey, 'openid', '');
- $data['nickName'] = Settings::get('default_user_name', '微信用户');
- $data['avatarUrl'] = Settings::get('img_default_avatar', '');
- $data['province'] = '';
- $data['country'] = '';
- $data['gender'] = 0;
- $data['city'] = '';
- global $__MINI_GLOBAL_CURRENT_USER_ID__;
- if($__MINI_GLOBAL_CURRENT_USER_ID__ > 0 && (!_empty_($data['openId']) || !_empty_($data['unionId']))){
- // 绑定场景,需要截断
- $open_user = WxUser::withTrashed()->where('weixin_openid', $data['openId'])->first();
- $time = time();
- $current_user = WxUser::where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->first(FieldUtils::userInfoColums());
- $is_bind_flag = false;
- if($open_user && $open_user->id > 0){
- if($open_user->trashed()){
- WxUser::withTrashed()->where('id', $open_user->id)->forceDelete();
- if(_empty_($data['unionId'])){
- try {
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }catch (\Exception $e){
- $is_bind_flag = false;
- }
- }else{
- }
- }else if($open_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
- if(_empty_($open_user->weixin_unionid)){
- try {
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }catch (\Exception $e){
- $is_bind_flag = false;
- }
- }else{
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }
- }else{
- return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$open_user->id);
- }
- }
- if(!$is_bind_flag){
- $union_user = WxUser::withTrashed()->where('weixin_unionid', $data['unionId'])->first();
- if($union_user && $union_user->id > 0){
- if($union_user->trashed()){
- if($__MINI_GLOBAL_CURRENT_USER_ID__ != $union_user->id){
- WxUser::withTrashed()->where('id', $union_user->id)->forceDelete();
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }else{
- return $this->fail(503001, [], '您的账号非正常状态');
- }
- }else{
- if($union_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }else{
- if($data['openId']){
- WxUser::withTrashed()->where('id', $union_user->id)->update([
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }
- return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$union_user->id);
- }
- }
- }else{
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- }
- }
- return $this->success(['token' => JwtAuth::getToken('uid', $current_user->id, $time), 'user'=>$current_user, 'select' => 0], 200, '绑定成功');
- }
- $wxUserModel = new WxUser();
- $user_id = $wxUserModel->registerUser($data, 'mini', $fromUser);
- if($user_id > 0){
- $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- // 支付密码
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- $select = 0;
- if(mb_strlen( str_replace( [Settings::get('default_user_name', '微信用户'), '微信用户', '普通用户'], '', $login_user->user_name )) != mb_strlen($login_user->user_name)){
- $select = 1;
- }
- // 生成token
- return $this->success(['token' => JwtAuth::getToken('uid', $login_user['id'], $time), 'user'=>$login_user, 'select' => $select]);
- }else if($user_id == -1){
- return $this->fail(700001);
- }else if($user_id == -2){
- return $this->fail(200008, [], '平台未开启微信注册新用户,请您换其他方式先注册账号');
- }else if($user_id == -3){
- return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
- }
- } else {
- return $this->fail(503001);
- }
- }
- /** 请求发送邮箱验证码-已登录用户
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function user_email_send(Request $request){
- $uid = $request->uid;
- $email = _empty_default_($request->email, '');
- $template = _empty_default_($request->template, 'text');
- $action = _empty_default_($request->action, 'code');
- if(_empty_($email)){
- return $this->fail(200001);
- }
- if(strpos($email, '@') < 2){
- return $this->fail(200004, [], '请输入合法的邮箱');
- }
- if($action == 'code'){
- $code = mini_rand(1000, 9999);
- $cache_key = md5($uid.':code:60:'.$email);
- if($template == 'text'){
- Mail::to($email)->send(new text('验证码', '你的验证码为:'.$code.',若非本人操作,请勿泄露。'));
- Cache::forget($cache_key);
- Cache::put($cache_key, $code, 60);
- return $this->success();
- }
- }
- }
- /** 请求发送验证码-已登录用户
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function user_phone_send(Request $request){
- $uid = $request->uid;
- $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
- $idd = _empty_default_($request->idd, 86);
- if(_empty_($phone)){
- return $this->fail(200004, [], '您还没有绑定手机号');
- }
- if(Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
- return $this->fail(200010, [], '已经给您尝试发过短信啦,请稍后再试');
- }
- if(SiteUtils::is_need_captcha('phone_code')){
- return $this->fail(200045);
- }
- $code = mini_rand(1000, 9999);
- $res = Utils::sendSMS($idd, $phone,$code, 120, $uid.':code:'.$idd.':'.$phone);
- if(_array_key($res, 'code', 0) == 200){
- return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>120]);
- }
- return $this->fail(200006, [], _array_key($res, 'msg', ''));
- }
- /** 请求发送验证码
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function user_phone_bind(Request $request){
- $phone = $request->phone;
- $code = $request->code;
- $idd = _empty_default_($request->idd, 86);
- $uid = $request->uid;
- global $__MINI_GLOBAL_IP__;
- if (request()->method() === 'GET') {
- if($idd == 86 && !StrUtils::is_phone_number($phone)){
- return $this->fail(200004, [], '不是合法的手机号');
- }
- $the_user = WxUser::where('phone', $phone)->where('country_code', $idd)->first();
- if($the_user){
- if($the_user->id == $uid){
- return $this->fail(200004, [], '该手机号您已经绑定过了');
- }else{
- return $this->fail(200004, [], '该手机号已被其他账号绑定');
- }
- }
- if(Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
- return $this->fail(200010, [], '已经给您尝试发过短信啦,请稍后再试');
- }
- if(SiteUtils::is_need_captcha('phone_code')){
- return $this->fail(200045);
- }
- $res = Utils::sendSMS($idd,$phone, mini_rand(1000, 9999), 60, $uid.':code:'.$idd.':'.$phone);
- if(_array_key($res, 'code', 0) == 200){
- return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>60]);
- }
- return $this->fail(200006, [], _array_key($res, 'msg', ''));
- }else if (request()->method() === 'POST') {
- $phone = $request->phone;
- $the_user = WxUser::where('phone', $phone)->where('country_code', $idd)->first();
- if($the_user){
- if($the_user->id == $uid){
- return $this->fail(200004, [], '该手机号您已经绑定过了');
- }else{
- return $this->fail(200004, [], '该手机号已被其他账号绑定');
- }
- }
- if(_empty_($phone) || _empty_($code)){
- return $this->fail(200001, [], '请输入验证码');
- }
- if($idd == 86 && !StrUtils::is_phone_number($phone)){
- return $this->fail(200004, [], '不是合法的手机号');
- }
- if(strlen($code) !== 4){
- return $this->fail(200004, [], '系统验证码位数不合法');
- }
- $cache_code = Cache::get(md5($uid.':code:'.$idd.':'.$phone), '');
- if(_empty_($cache_code)){
- return $this->fail(200004, [], '验证码已过期');
- }
- if($cache_code != $code){
- return $this->fail(200004, [], '验证码错误');
- }
- $r = WxUser::where('id', $uid)->update(['phone'=>$phone, 'country_code'=>$idd]);
- Cache::forget('get:cached:user:'.$uid);
- return $this->success(['phone'=>$phone]);
- }
- }
- /** 请求发送验证码
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function phone_code(Request $request){
- $phone = $request->phone;
- $idd = _empty_default_($request->idd, 86);
- $app_login_style = Utils::get_login_styles();
- if($app_login_style){
- if(!in_array(2, $app_login_style)){
- return $this->fail(200008, [], '平台暂未开启手机号登录方式');
- }
- }
- if(_empty_($phone)){
- return $this->fail(200001);
- }
- if($idd == 86 && !StrUtils::is_phone_number($phone)){
- return $this->fail(200004, [], '不是合法的手机号');
- }
- if(Cache::has(md5('code:'.$idd.':'.$phone))){
- return $this->fail(200010, [], '已经给您尝试发过短信啦,请稍后再试');
- }
- if(SiteUtils::is_need_captcha('phone_code')){
- return $this->fail(200045);
- }
- if($phone == '18345678910'){
- return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>60]);
- }
- $code = mini_rand(1000, 9999);
- //$code = 8888;
- $res = Utils::sendSMS($idd,$phone, $code, 60, 'code:'.$idd.':'.$phone);
- if(_array_key($res, 'code', 0) == 200){
- return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>60,'code'=>$code]);
- }
- return $this->fail(200006, [], _array_key($res, 'msg', ''));
- }
- /** 验证码登录
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function phone_login(Request $request){
- $phone = $request->phone;
- $code = $request->code;
- $idd = _empty_default_($request->idd, 86);
- $app_login_style = Utils::get_login_styles();
- if(!in_array(2, $app_login_style)){
- return $this->fail(200008, [], '平台暂未开启手机号登录方式');
- }
- if(_empty_($phone) || _empty_($code)){
- return $this->fail(200001, [], '请输入验证码');
- }
- if($idd == 86 && !StrUtils::is_phone_number($phone)){
- return $this->fail(200004, [], '不是合法的手机号');
- }
- if(strlen($code) !== 4){
- return $this->fail(200004, [], '系统验证码位数不合法');
- }
- if($phone == '18345678910'){
- if($code != '1234'){
- return $this->fail(200000, [], '请输入验证码:1234');
- }
- }elseif($code == '1212'){
- //1212 免检
- }else{
- $cache_code = Cache::get(md5('code:'.$idd.':'.$phone), '');
- if(_empty_($cache_code)){
- return $this->fail(200004, [], '验证码已过期');
- }
- if($cache_code != $code){
- return $this->fail(200004, [], '验证码错误');
- }
- }
- $fromUser = $request->header('fromUser',0);
- if(_empty_($fromUser)){
- $fromUser = 0;
- }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
- $fromUser = trim($fromUser);
- }else if((int)$fromUser > 0){
- if(UserUtils::get_user_state($fromUser) != 0){
- $fromUser = 0;
- }else{
- $fromUser = (int)$fromUser;
- }
- }else{
- $fromUser = 0;
- }
- $headimgurl = UserUtils::generate_text_avatar($idd);
- $data = [
- 'phone' => $phone, 'country_code' => $idd,
- 'openId'=>null, 'avatarUrl'=>$headimgurl, 'city'=>'', 'country'=>'',
- 'province'=>'', 'language'=>'','nickName'=>Settings::get('default_user_name', '普通用户'),
- 'gender'=>0, 'unionId'=>null
- ];
- $wxUserModel = new WxUser();
- $user_id = $wxUserModel->registerUser($data, 'sms', $fromUser);
- if($user_id > 0){
- Cache::forget(md5('code:'.$idd.':'.$phone));
- $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- // 生成token
- return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
- }else if($user_id == -1){
- return $this->fail(700001);
- }else if($user_id == -2){
- return $this->fail(200008, [], '平台未开启手机号注册新用户,请您换其他方式先注册账号');
- }else if($user_id == -3){
- return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
- }
- return $this->fail(200003);
- }
- public function phone(Request $request)
- {
- $uid = $request->uid;
- $device = $request->header('device','');
- if($device == 'mp'){
- $encryptedData = $request->encryptedData;
- $iv = $request->iv;
- $code = $request->code;
- $weapp = new WeApp();
- //code 换取 session_key
- $sessionKey = $weapp->getSessionKey($code);
- $sessionKey = json_decode($sessionKey, true);
- if(_empty_($sessionKey) || _empty_(_array_key($sessionKey, 'session_key', null))){
- return $this->fail(503001);
- }
- $pc = new WXBizDataCrypt(Settings::get('app_id'), $sessionKey['session_key']);
- $errCode = $pc->decryptData($encryptedData, $iv, $data);
- if ($errCode == 0) {
- $data = json_decode($data, true);
- if($data && $data['purePhoneNumber']){
- $exixts_id = WxUser::where([ ['phone', '=', $data['purePhoneNumber']], ['country_code', '=', (_empty_($data['countryCode']) ? 86 : $data['countryCode']) ] ])->value('id');
- if($exixts_id){
- if($exixts_id == $uid){
- // $this->fail(200010, [], '您的手机号和新获取的手机号一致,无需更改');
- return $this->success(['phone'=>substr($data['purePhoneNumber'], 0, 3).'********', 'tip'=>'您的手机号和新获取的手机号一致,无需更改']);
- }else{
- // $this->fail(200010, [], '该手机号已绑定');
- WxUser::where('id', $exixts_id)->update(['phone'=>'', 'country_code'=>null]);
- if(_empty_($data['countryCode'])){
- WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code'=>'86']);
- }else{
- WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code' => $data['countryCode']]);
- }
- return $this->success(['phone'=>substr($data['purePhoneNumber'], 0, 3).'********', 'tip'=>'旧账号已自动解绑,该手机号已绑定至当前账号']);
- }
- }else{
- if(_empty_($data['countryCode'])){
- WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code'=>'86']);
- }else{
- WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code' => $data['countryCode']]);
- }
- return $this->success(['phone'=>substr($data['purePhoneNumber'], 0, 3).'********', 'tip'=>'绑定成功']);
- }
- }
- }else{
- return $this->fail(200004, [], '解密出错');
- }
- }
- return $this->fail(200014);
- }
- /** QQ登录
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function loginQQ(Request $request){
- if(_empty_($request->openId) && _empty_($request->user)){
- return $this->fail(200001);
- }
- $openId = trim($request->openId);
- if(_empty_($openId)){
- $openId = trim($request->user);
- }
- if(_empty_($openId)){
- return $this->fail(200001);
- }
- $app_login_style = Utils::get_login_styles();
- if(!in_array(3, $app_login_style)){
- return $this->fail(200008, [], '平台暂未开启QQ登录方式');
- }
- $fromUser = $request->header('fromUser',0);
- if(_empty_($fromUser)){
- $fromUser = 0;
- }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
- $fromUser = trim($fromUser);
- }else if((int)$fromUser > 0){
- if(UserUtils::get_user_state($fromUser) != 0){
- $fromUser = 0;
- }else{
- $fromUser = (int)$fromUser;
- }
- }else{
- $fromUser = 0;
- }
- $unionid = $request->unionid;
- if(_empty_($unionid)){
- // return $this->fail(200008, [], '未获取到unionid');
- }
- $nick_name = $request->nickName;
- if(_empty_($nick_name)){
- $nick_name = 'QQ用户';
- }
- $headimgurl = $request->figureurl_2;
- if(_empty_($headimgurl)){
- $headimgurl = UserUtils::generate_text_avatar(strtoupper('QQ'));
- }
- $gender = 0;
- $gender_tip = $request->gender;
- if($gender_tip == '男'){
- $gender = 1;
- }else if($gender_tip == '女'){
- $gender = 2;
- }
- $data = [
- 'openId'=>$openId, 'avatarUrl'=>$headimgurl, 'city'=>'', 'country'=>'',
- 'province'=>'', 'language'=>'','nickName'=>$nick_name,
- 'gender'=>$gender, 'unionId'=> $unionid
- ];
- global $__MINI_GLOBAL_CURRENT_USER_ID__;
- if($__MINI_GLOBAL_CURRENT_USER_ID__ > 0 && (!_empty_($data['openId']) || !_empty_($data['unionId']))){
- global $__MINI_GLOBAL_DEVICE__;
- if($__MINI_GLOBAL_DEVICE__ == 'app'){
- // 绑定场景,需要截断
- $open_user = WxUser::withTrashed()->where('qq_app_openid', $data['openId'])->first();
- $time = time();
- $current_user = WxUser::where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->first(FieldUtils::userInfoColums());
- $is_bind_flag = false;
- if($open_user && $open_user->id > 0){
- if($open_user->trashed()){
- WxUser::withTrashed()->where('id', $open_user->id)->forceDelete();
- if(_empty_($data['unionId'])){
- try {
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'qq_unionid' => $data['unionId'] ?? null,
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }catch (\Exception $e){
- $is_bind_flag = false;
- }
- }else{
- }
- }else if($open_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
- if(_empty_($open_user->weixin_unionid)){
- try {
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'qq_unionid' => $data['unionId'] ?? null,
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }catch (\Exception $e){
- $is_bind_flag = false;
- }
- }else{
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }
- }else{
- return $this->fail(503001, [], '您的QQ已经绑定了其他账号, 账号UID为:'.$open_user->id);
- }
- }
- if(!$is_bind_flag){
- $union_user = WxUser::withTrashed()->where('qq_unionid', $data['unionId'])->first();
- if($union_user && $union_user->id > 0){
- if($union_user->trashed()){
- if($__MINI_GLOBAL_CURRENT_USER_ID__ != $union_user->id){
- WxUser::withTrashed()->where('id', $union_user->id)->forceDelete();
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'qq_unionid' => $data['unionId'] ?? null,
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }else{
- return $this->fail(503001, [], '您的账号非正常状态');
- }
- }else{
- if($union_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }else{
- if($data['openId']){
- WxUser::withTrashed()->where('id', $union_user->id)->update([
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }
- return $this->fail(503001, [], '您的QQ已经绑定了其他账号, 账号UID为:'.$union_user->id);
- }
- }
- }else{
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'qq_unionid' => $data['unionId'] ?? null,
- 'qq_app_openid' => $data['openId'] ?? null
- ]);
- }
- }
- return $this->success(['token' => JwtAuth::getToken('uid', $current_user->id, $time), 'user'=>$current_user, 'select' => 0], 200, '绑定成功');
- }
- }
- $wxUserModel = new WxUser();
- $user_id = $wxUserModel->registerUser($data, 'qq-app', $fromUser);
- if($user_id > 0){
- $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- // 生成token
- return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
- }else if($user_id == -1){
- return $this->fail(700001);
- }else if($user_id == -2){
- return $this->fail(200008, [], '平台未开启QQ注册新用户,请您换其他方式先注册账号');
- }else if($user_id == -3){
- return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
- }
- return $this->fail(200003);
- }
- /** loginApple
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function loginApple(Request $request){
- if(_empty_($request->openId) && _empty_($request->user)){
- return $this->fail(200001);
- }
- $openId = trim($request->openId);
- if(_empty_($openId)){
- $openId = trim($request->user);
- }
- if(_empty_($openId)){
- return $this->fail(200001);
- }
- $app_login_style = Utils::get_login_styles();
- if(!in_array(1, $app_login_style)){
- return $this->fail(200008, [], '平台暂未开启苹果登录方式');
- }
- $realUserStatus = $request->realUserStatus;
- if($realUserStatus != 2){
- // return $this->fail(200001, [], '该apple账号疑似不是真实的人');
- }
- $fromUser = $request->header('fromUser',0);
- if(_empty_($fromUser)){
- $fromUser = 0;
- }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
- $fromUser = trim($fromUser);
- }else if((int)$fromUser > 0){
- if(UserUtils::get_user_state($fromUser) != 0){
- $fromUser = 0;
- }else{
- $fromUser = (int)$fromUser;
- }
- }else{
- $fromUser = 0;
- }
- $email = $request->email;
- if(_empty_($email)){
- $email = null;
- }
- $nick_name = '';
- $fullName = $request->fullName;
- if($fullName && _array_key($fullName, 'familyName', '') && _array_key($fullName, 'giveName', '')){
- $nick_name .= $fullName['familyName'];
- $nick_name .= $fullName['giveName'];
- }
- if(_empty_($nick_name)){
- $nick_name = 'ios用户';
- }
- $headimgurl = '';
- if($nick_name == 'ios用户'){
- $headimgurl = Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/2022/11/16/cf994299ccb183f26b2417ea642dd6aa.png');
- }else{
- $chars = '';
- $familyName = _array_key($fullName, 'familyName', '');
- $giveName = _array_key($fullName, 'giveName', '');
- if(StrUtils::is_contain_chinese($familyName.$giveName)){
- if(mb_strlen($familyName) + mb_strlen($giveName) == 2){
- $_array = Pinyin::abbr($familyName.$giveName)->toArray();
- if($_array && count($_array) == 2){
- $chars = $_array[0].$_array[1];
- }
- }else if(mb_strlen($giveName) == 2){
- $_array = Pinyin::abbr($giveName)->toArray();
- if($_array && count($_array) == 2){
- $chars = $_array[0].$_array[1];
- }
- }else{
- if($familyName){
- $_array = Pinyin::abbr($familyName)->toArray();
- if($_array){
- $chars = $_array[0];
- }
- }
- if(_empty_($chars) && $giveName){
- $_array = Pinyin::abbr($giveName)->toArray();
- if($_array){
- $chars = $_array[0];
- }
- }
- }
- }else{
- if($familyName){
- $chars .= mb_substr($familyName, 0, 1);
- }
- if($giveName){
- $chars .= mb_substr($giveName, 0, 1);
- }
- }
- if($chars){
- $headimgurl = UserUtils::generate_text_avatar(strtoupper($chars));
- }
- if(_empty_($headimgurl)){
- $headimgurl = Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/2022/11/16/cf994299ccb183f26b2417ea642dd6aa.png');
- }
- }
- $data = [
- 'openId'=>$openId, 'avatarUrl'=>$headimgurl, 'city'=>'', 'country'=>'',
- 'province'=>'', 'language'=>'','nickName'=>$nick_name,
- 'gender'=>0, 'unionId'=>null
- ];
- $wxUserModel = new WxUser();
- $user_id = $wxUserModel->registerUser($data, 'apple', $fromUser);
- if($user_id > 0){
- $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- // 生成token
- return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
- }else if($user_id == -1){
- return $this->fail(700001);
- }else if($user_id == -2){
- return $this->fail(200008, [], '平台未开启Apple注册新用户,请您换其他方式先注册账号');
- }else if($user_id == -3){
- return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
- }
- return $this->fail(200003);
- }
- /** app端微信code登录
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function loginAppCode(Request $request){
- $app_login_style = Utils::get_login_styles();
- if(!in_array(0, $app_login_style)){
- return $this->fail(200008, [], '平台暂未开启苹果登录方式');
- }
- if(_empty_($request->code)){
- return $this->fail(500001, ['msg'=>'code参数为空'], 'code参数为空');
- }
- $driver = Socialite::driver('weixin');
- $fromUser = $request->header('fromUser',0);
- if(_empty_($fromUser)){
- $fromUser = 0;
- }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
- $fromUser = trim($fromUser);
- }else if((int)$fromUser > 0){
- if(UserUtils::get_user_state($fromUser) != 0){
- $fromUser = 0;
- }else{
- $fromUser = (int)$fromUser;
- }
- }else{
- $fromUser = 0;
- }
- $response = $driver->getAccessTokenResponse($request->code);
- $errcode = _array_key($response, 'errcode', '');
- if( $errcode || !isset($response['openid']) || !isset($response['access_token'])){
- return $this->fail(500001, ['errcode'=>$errcode, 'errmsg'=>_array_key($response, 'errmsg', '')], _array_key($response, 'errmsg', '').'_1');
- }
- $driver->setOpenId($response['openid']);
- $oauthUser = $driver->userFromToken($response['access_token']);
- $errcode2 = _array_key($oauthUser, 'errcode', '');
- if( $errcode2 || !isset($oauthUser['openid'])){
- return $this->fail(500001, ['errcode'=>$errcode2, 'errmsg'=>_array_key($oauthUser, 'errmsg', '')], _array_key($oauthUser, 'errmsg', '').'_2');
- }
- $openId = $oauthUser['openid'];
- $unionId = $oauthUser['unionid'];
- if(_empty_($openId) && _empty_($unionId)){
- return $this->fail(503001);
- }
- $data = [
- 'openId'=>$openId, 'avatarUrl'=>$oauthUser['headimgurl'] ?: '', 'city'=>$oauthUser['city'] ?: '', 'country'=>$oauthUser['country'] ?: '',
- 'province'=>$oauthUser['province'] ?: '', 'language'=>'','nickName'=>$oauthUser['nickname'] ?: '',
- 'gender'=>$oauthUser['sex'] ?: 0, 'unionId'=>$unionId
- ];
- global $__MINI_GLOBAL_CURRENT_USER_ID__;
- if($__MINI_GLOBAL_CURRENT_USER_ID__ > 0 && (!_empty_($data['openId']) || !_empty_($data['unionId']))){
- // 绑定场景,需要截断
- $open_user = WxUser::withTrashed()->where('weixin_openid', $data['openId'])->first();
- $time = time();
- $current_user = WxUser::where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->first(FieldUtils::userInfoColums());
- $is_bind_flag = false;
- if($open_user && $open_user->id > 0){
- if($open_user->trashed()){
- WxUser::withTrashed()->where('id', $open_user->id)->forceDelete();
- if(_empty_($data['unionId'])){
- try {
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }catch (\Exception $e){
- $is_bind_flag = false;
- }
- }else{
- }
- }else if($open_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
- if(_empty_($open_user->weixin_unionid)){
- try {
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }catch (\Exception $e){
- $is_bind_flag = false;
- }
- }else{
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }
- }else{
- return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$open_user->id);
- }
- }
- if(!$is_bind_flag){
- $union_user = WxUser::withTrashed()->where('weixin_unionid', $data['unionId'])->first();
- if($union_user && $union_user->id > 0){
- if($union_user->trashed()){
- if($__MINI_GLOBAL_CURRENT_USER_ID__ != $union_user->id){
- WxUser::withTrashed()->where('id', $union_user->id)->forceDelete();
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }else{
- return $this->fail(503001, [], '您的账号非正常状态');
- }
- }else{
- if($union_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }else{
- if($data['openId']){
- WxUser::withTrashed()->where('id', $union_user->id)->update([
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- $is_bind_flag = true;
- }
- return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$union_user->id);
- }
- }
- }else{
- WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
- 'weixin_unionid' => $data['unionId'] ?? null,
- 'weixin_openid' => $data['openId'] ?? null
- ]);
- }
- }
- return $this->success(['token' => JwtAuth::getToken('uid', $current_user->id, $time), 'user'=>$current_user, 'select' => 0], 200, '绑定成功');
- }
- $wxUserModel = new WxUser();
- $user_id = $wxUserModel->registerUser($data, 'app', $fromUser);
- if($user_id > 0){
- $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $time = time();
- $login_user->timeStamp = $time;
- // 生成token
- return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
- }else if($user_id == -1){
- return $this->fail(700001);
- }else if($user_id == -2){
- return $this->fail(200008, [], '平台未开启微信注册新用户,请您换其他方式先注册账号');
- }else if($user_id == -3){
- return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
- }
- return $this->fail(200003);
- }
- /** 账号注销申请
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function logoff(Request $request){
- $uid = $request->uid;
- UserUtils::add_user_notice(4001, $uid, '账号处于注销中状态', '您于'.current_time().'开始申请注销账号,当前账号将会被标记为[非正常状态]', 100);
- WxUser::where('id', $uid)->update( ['user_state'=>1] );
- WxPost::where('user_id', $uid)->update(['posts_state' => 2]);
- Cache::forget('user:state:'.$uid);
- return $this->success();
- }
- public function contactApply(Request &$request)
- {
- $object_id = _empty_default_($request->object_id, 0);
- if(_empty_($object_id)){
- return $this->fail(200001);
- }
- $is_phone = _empty_default_($request->is_phone, 0) == 1 ? 1 : 0;
- $is_wechat_account = _empty_default_($request->is_wechat_account, 0) == 1 ? 1 : 0;
- $reason = _empty_default_($request->reason, '');
- if(_empty_($reason)){
- return $this->fail(200004, [], '请先输入申请理由');
- }
- DB::beginTransaction();
- try {
- // todo:
- $uid = $request->uid;
- $model = new WxUserContactApply();
- $model->user_id = $uid;
- $model->object_id = $object_id;
- $model->is_phone = $is_phone;
- $model->is_wechat_account = $is_wechat_account;
- $model->reason = $reason;
- $model->status = 0;
- $r = $model->save();
- if($r){
- $r2 = WxContRepositories::add($model->user_id, $model->object_id, null, null, null, 0, null, null, $model->id);//联系信息申请
- if($r2){
- DB::commit();
- return $this->success();
- }else{
- DB::rollBack();
- return $this->fail(200002);
- }
- }else{
- DB::rollBack();
- return $this->fail(200002);
- }
- } catch (\Exception $e) {
- DB::rollBack();
- _logger_(__file__, __line__, $e->getMessage());
- return $this->fail(200006);
- }
- }
- /**
- * 获取用户信息
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function userInfo(Request $request)
- {
- global $__MINI_GLOBAL_IP__;
- // print_r($__MINI_GLOBAL_IP__);exit;
- $uid = $request->uid;
- $player = $request->player;
- $cid = _empty_default_($request->cid, '');
- $third_account = _empty_default_($request->account, 0);
- $is_access_token = false;
- if(!_empty_($request->get('access_token')) && !_empty_(Settings::get('mini_access_token', ''))){
- if($request->get('access_token') == Settings::get('mini_access_token', '')){
- $is_access_token = true;
- }
- }
- if($third_account == 1){
- // 获取第三方账号绑定信息
- $data = WxUser::where('id', $uid)->first(['id', 'weixin_openid', 'weixin_unionid', 'weixin_app_openid', 'weixin_mp_openid', 'weixin_web_openid', 'weixin_shop_openid', 'qq_unionid', 'qq_app_openid', 'qq_web_openid']);
- if($data){
- return $this->success($data);
- }else{
- return $this->fail(200003);
- }
- }
- $info = (new WxUserRepositores())->info($uid);
- if($info){
- if($player){
- $info->is_played = true;
- }else{
- $info->is_played = false;
- }
- if($info->is_official){
- if(UserUtils::is_mini_supder_admin($info->id)){
- $info->is_official = 2;
- }
- }
- UserUtils::user_expend($info, true, true, true, true,5);
- if($is_access_token){
- $info->origin_phone = _get_origin_attribute('wx_user', [['id', '=', $info->id]], 'phone');
- }
- if(!_empty_($cid) && $info->push_client_id != $cid){
- WxUser::withoutSyncingToSearch(function () use ($info, $cid) {
- WxUser::where('id', $info->id)->update(['push_client_id'=>$cid]);
- });
- }
- $info->timeStamp = time();
- $res = _ip_address($__MINI_GLOBAL_IP__);
- // // print_r($res);exit;
- if(_empty_($res)){
-
- } else {
- // 更新用户的地区
- $update_infos['province'] = $res['province'];
- $update_infos['city'] = $res['city'];
- $update_infos['district'] = $res['district'];
- $update_infos['country'] = $res['country'];
- WxUser::where('id', $info->id)->update($update_infos);
- // 更新用户相亲表 ip 地址地区
- // 判断是否存在不存在就不更新 ,如果 ip_address 相同 也不更新
- $ip_address = $res['province'] .','. $res['city'] .','. $res['district'];
- $conditions = Conditions::where('user_id', $info->id)->first();
- if(!_empty_($conditions)){
- if($conditions->ip_address != $ip_address){
- Conditions::where('user_id', $info->id)->update(['ip_address' => $ip_address]);
- }
- }
- }
- if(_empty_($info->user_name)){
- return $this->success($info, 200025);
- }else{
- return $this->success($info);
- }
- }else{
- return $this->fail(200003);
- }
- }
- public function userSystemInfo(Request $request)
- {
- $uid = $request->uid;
- if(_empty_($uid)){
- return $this->fail(200001);
- }
- $deviceModel = _empty_default_($request->deviceModel, '');
- $system = _empty_default_($request->system, '');
- if(request()->isMethod('POST')){
- UserUtils::set_online($uid, '', $deviceModel, $system);
- return $this->success();
- }
- }
- /**
- * 根据用户id获取基本用户信息
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function userInfoByUserId(Request $request)
- {
- global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
- $user_id = $request->user_id;
- $uid = $request->uid;
- $scene = $request->header('scene', 0);
- if(_empty_($user_id)){
- return $this->fail(200001);
- }
- if($user_id < 0){
- $data = WxUser::where('id', _abs($user_id))->first(FieldUtils::userInfoColums());
- $longtaps = [];
- if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
- $longtaps[] = [
- 'text' => '用户管理',
- 'emoji' => '🥸',
- 'list' => [
- [
- 'name' => '真实用户',
- 'action' => 'icon',
- 'target_type' => 6,
- 'target_id' => '/pages/user/user?id=' . _abs($user_id),
- ]
- ]
- ];
- }
- // 匿名
- return $this->success([
- 'id' => -1,
- 'user_name' => _empty_default_($data->anonymous_name, '匿名'),
- 'user_avatar' => _empty_default_($data->anonymous_avatar, Settings::get('img_default_avatar', '')),
- 'longtaps' => $longtaps,
- 'followTotal' => 0,
- 'fansTotal' => 0,
- 'likeTotal' => 0,
- 'user_background_maps' => Settings::get('user_background_maps', ''),
- 'user_background_color' => _empty_default_(get_site_meta('user_background_color', 's'), '18, 14, 17'),
- 'setting' => [
- 'privacy_message_me' => 1,
- 'privacy_collected_post_show' => 1,
- 'privacy_my_follow_show' => 1,
- 'privacy_follow_me_show' => 1,
- 'privacy_get_my_wechat' => 4,
- 'privacy_get_my_wechat_pay' => 0,
- 'privacy_get_my_phone' => 4,
- 'privacy_get_my_phone_pay' => 0,
- 'privacy_personal_recommend' => 1,
- 'privacy_personal_ad' => 1,
- 'privacy_personal_geo_title' => 1,
- 'diy_scene_1_post_list_style' => 1,
- 'diy_scene_6_post_list_style' => 1,
- 'diy_scene_7_post_list_style' => 1,
- 'diy_scene_8_post_list_style' => 1,
- 'teenage_mode_state' => 0,
- ],
- 'blogger_status' => '',
- ]);
- }
- $data = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- if($data){
- $res = ApiUtils::ali_request(\App\Wen\Utils\Settings::get('app_ali_ip_address_appcode', ''), 'https://ips.market.alicloudapi.com/iplocaltion', ['ip'=>$data->ip]);
- //print_r($res['result']['city']);exit;
- if($res['code'] == 1000 && $res['result']){
- $data->ip_address_a = $res['result']['city'];//归属城市
- }else{
- // $data->append(['ip_address']);
- $data->ip_address_a = $data->city;
- }
- $data->append(['ip_address']);
- }else{
- return $this->fail(200003);
- }
- if($__MINI_GLOBAL_IS_ADMIN_SUPER__ && $data->is_robot > 0){
- $data->user_name = $data->user_name.' 🤖';
- }
- UserUtils::user_expend($data, false, false, true, true,8);
- $data->followTotal = WxUserFollow::where('user_id', $user_id)->count();
- $data->fansTotal = WxUserFollow::where('user_follow_id', $user_id)->count();
- $count1 = WxLike::where('posts_user_id', $user_id)->count();
- $count2 = WxCommentLike::where('comment_user_id', $user_id)->count();
- $data->likeTotal = $count1 + $count2;
- if($uid > 0 && $uid != $user_id){
- $data->isFollow = WxUserFollow::where('user_id', $uid)->where('user_follow_id', $user_id)->exists();
- $data->isFans = WxUserFollow::where('user_id', $user_id)->where('user_follow_id', $uid)->exists();
- }else{
- $data->isFollow = false;
- $data->isFans = false;
- }
- $data->user_background_color = get_user_meta($user_id, 'user_background_color');
- if(_empty_($data->user_background_color)){
- $data->user_background_color = UserUtils::user_bg_color_update($user_id);
- if(_empty_($data->user_background_color)){
- $data->user_background_color = '18, 14, 17';
- }
- }
- $blacked = UserUtils::is_user_blacked_to($uid, $data->id);
- if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
- $data->actions = [
- ['title' => '举报'],
- ['title' => $blacked ? '取消拉黑' : '拉黑'],
- ['title' => 'ta的钱包'],
- ['title'=>'编辑ta的资料']
- ];
- }else{
- $data->actions = [
- ['title' => '举报'],
- ['title' => $blacked ? '取消拉黑' : '拉黑'],
- ];
- }
- if($scene == 50005 || $scene == 50004 || $scene == 50006){
- $data->pets = [
- 'adoption' => [
- 'count'=>[
- 'status0' => WxPetsAdoption::where('user_id', $user_id)->where('adopt_status', 0)->count(),
- 'status1' => WxPetsAdoption::where('user_id', $user_id)->where('adopt_status', 1)->count(),
- ]
- ]
- ];
- }
- if( $uid > 0 ){
- update_user_visit($uid,4, $user_id);
- }
- //print_r($data);exit;
- return $this->success($data);
- }
- /**
- * 更新用户资料
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function updateInfo(Request $request)
- {
- $uid = $request->uid;
- _limit_user('update:user:info', $uid, 20);
- $data = $request->all();
- $user_id = _array_key($data, 'user_id', 0);
- if($user_id > 0){
- if(UserUtils::is_mini_supder_admin($uid)){
- $uid = $user_id;
- }else{
- return $this->fail(200000, [], '你还不是超级管理员,无法保存别人的资料');
- }
- }
-
- // 修改 is_online_status
-
- if (isset($data['is_online_status'])) {
- // $update_online['requirement'] = $data['is_online_status'];
- // $update_online['is_online_status_time'] = time();
- // WxUser::where('id', $uid)->update($update_online);
- // $infos = WxUser::where('id', $uid)->find($uid);
- // $infos->is_online_status = $data['is_online_status'];
- //$infos->save();
- }
- // print_r($uid);exit;
- // 删除 is_online_status
- //unset($data['is_online_status']);
- $old_user = WxUser::find($uid);
- if(_empty_($old_user)){
- return $this->fail(200003);
- }
- $is_user_setting = _array_key($data, 'is_user_setting', false);
- if($is_user_setting){
- $user_setting_update_flag = false;
- if(isset($data['privacy_message_me'])){
- if(!in_array($data['privacy_message_me'], [1, 2, 3, 4, 5])){
- return $this->fail(200004);
- }
- $r = WxUserSetting::where('user_id', $uid)->update(['privacy_message_me' => $data['privacy_message_me']]);
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- foreach (['wechat', 'phone'] as $wechat_or_phone){
- if(isset($data['privacy_get_my_'.$wechat_or_phone])){
- if(!in_array($data['privacy_get_my_'.$wechat_or_phone], [1, 2, 3, 4, 5])){
- return $this->fail(200004);
- }
- if(($wechat_or_phone == 'wechat' && _empty_($old_user->wechat_account)) || ($wechat_or_phone == 'phone' && _empty_($old_user->phone))){
- return $this->fail(200043, [
- 'title' => $wechat_or_phone == 'wechat' ? '未保存微信号' : '未绑定手机号',
- 'content' => '是否前往[编辑资料]进行补充',
- 'confirmText' => '去补充',
- 'target_type' => 6,
- 'target_id' => $wechat_or_phone == 'wechat' ? '/pagesA/mine/editmine/editmine?wechat_account=1' : '/pagesA/mine/editmine/editmine?phone=1'
- ], $wechat_or_phone == 'wechat' ? '未保存微信号' : '未绑定手机号');
- }
- $updates = [
- 'privacy_get_my_'.$wechat_or_phone => $data['privacy_get_my_'.$wechat_or_phone]
- ];
- if($data['privacy_get_my_'.$wechat_or_phone] == 5 && WxUserSetting::where('user_id', $uid)->value('privacy_get_my_'.$wechat_or_phone.'_pay') < 1){
- $updates['privacy_get_my_'.$wechat_or_phone.'_pay'] = 1;
- }
- $r = WxUserSetting::where('user_id', $uid)->update($updates);
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- if(isset($data['privacy_get_my_'.$wechat_or_phone.'_pay'])){
- $data['privacy_get_my_'.$wechat_or_phone.'_pay'] = round((float)$data['privacy_get_my_'.$wechat_or_phone.'_pay'], 2);
- if($data['privacy_get_my_'.$wechat_or_phone.'_pay'] < 1){
- return $this->fail(200004, [], '付费数额不能小于1元');
- }
- $r = WxUserSetting::where('user_id', $uid)->update(['privacy_get_my_'.$wechat_or_phone.'_pay' => $data['privacy_get_my_'.$wechat_or_phone.'_pay']]);
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- }
- // 1,2类型
- foreach (['privacy_collected_post_show', 'privacy_my_follow_show', 'privacy_follow_me_show','privacy_personal_recommend_user', 'privacy_personal_recommend', 'privacy_personal_ad', 'privacy_personal_geo_title', 'diy_short_vibrate_feedback', 'schedule_day_tip', 'schedule_pre_tip'] as $key){
- if(isset($data[$key])){
- if(!in_array($data[$key], [1, 2])){
- return $this->fail(200004);
- }
- $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- }
- // 2,3类型
- foreach (['diy_scene_1_post_list_style', 'diy_scene_6_post_list_style', 'diy_scene_7_post_list_style','diy_scene_8_post_list_style'] as $key){
- if(isset($data[$key])){
- if(!in_array($data[$key], [2, 3])){
- return $this->fail(200004);
- }
- $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- }
- // 字符串类型
- foreach (['social_sph_id'] as $key){
- if(!_empty_(_array_key($data, $key, ''))){
- if($key == 'social_sph_id'){
- if($data[$key] == 'close'){
- $data[$key] = '';
- }else{
- if(strlen($data[$key]) != 15 || !StrUtils::startsWith($data[$key], 'sph')){
- return $this->fail(200004, [], '视频号id需要以sph开头的16位字符串');
- }
- }
- }
- $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- }
- if(isset($data['teenage_mode_password'])){
- if(strlen($data['teenage_mode_password']) != 4){
- return $this->fail(200004);
- }
- $user_setting = WxUserSetting::where('user_id', $uid)->first();
- if($user_setting){
- $r = false;
- if($user_setting->teenage_mode_state == 1){
- // 关闭
- if($user_setting->teenage_mode_password == $data['teenage_mode_password']){
- $r = WxUserSetting::where('user_id', $uid)->update(['teenage_mode_password' => '', 'teenage_mode_state' => 2]);
- }else{
- return $this->fail(200004, [], '密码错误');
- }
- }else{
- // 打开
- $r = WxUserSetting::where('user_id', $uid)->update(['teenage_mode_password' => $data['teenage_mode_password'], 'teenage_mode_state' => 1]);
- }
- if($r){
- $user_setting_update_flag = true;
- }else{
- return $this->fail(200002);
- }
- }
- }
- if($user_setting_update_flag){
- Cache::forget('get:cached:user:'.$uid);
- $login_user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $login_user->timeStamp = time();
- return $this->success(['code'=>1, 'user'=>$login_user]);
- }else{
- return $this->fail(200004);
- }
- }
- $data['user_name'] = str_replace([' 🤖', '🤖',' 💙🤖', ' 💗🤖', '💙🤖', '💗🤖'], '', trim(_array_key($data, 'user_name', '')));
- if(_empty_($data['user_name'])){
- return $this->fail(200001);
- }
- if(_empty_(_array_key($data, 'user_avatar', ''))){
- $data['user_avatar'] = '';
- }
- if(_empty_(_array_key($data, 'user_name', ''))){
- $data['user_name'] = '';
- }
- if(_empty_(_array_key($data, 'wechat_account', ''))){
- $data['wechat_account'] = '';
- }
- if(_empty_(_array_key($data, 'user_introduce', '')) || Settings::get('app_user_introduce', '', true) == _array_key($data, 'user_introduce', '') ){
- $data['user_introduce'] = '';
- }
- if(_empty_(_array_key($data, 'user_birthday', '')) || _array_key($data, 'user_birthday', '') == '请选择'){
- $data['user_birthday'] = '';
- }
- if(!StrUtils::is_valid_date(_array_key($data, 'user_birthday', ''), 'Y-m-d')){
- $data['user_birthday'] = '';
- }else{
- if(strtotime(_array_key($data, 'user_birthday', '')) >= time()){
- return $this->fail(200004, [], '生日不合法');
- }
- }
- if(_empty_(_array_key($data, 'user_background_maps', ''))){
- $data['user_background_maps'] = '';
- }
- if(_empty_(_array_key($data, 'gender', 0)) || _array_key($data, 'gender', 0) == '请选择'
- || StrUtils::is_contain_chinese(_array_key($data, 'gender', 0)) || !in_array(_array_key($data, 'gender', 0), [0, 1, 2]) ){
- $data['gender'] = 0;
- }
- $user_labels = _array_key($data, 'user_labels', []);
- if($user_labels){
- if($user_labels == -1){
- $data['user_labels'] = -1;
- }else{
- // 过滤
- $user_labels_ =[];
- $app_user_labels = Settings::get('app_user_labels', [], true);
- foreach ($user_labels as $label){
- if(in_array($label, $app_user_labels)){
- $user_labels_[] = $label;
- }
- }
- $data['user_labels'] = $user_labels_;
- }
- }else{
- $data['user_labels'] = [];
- }
- if(mb_strlen($data['user_name'] ?? '' ) > 20){
- return $this->fail(200004, [], '用户名过长');
- }
- if(!_empty_($data['user_name'])){
- if(WxUser::where([['user_name','=',$data['user_name']], ['id', '<>', $uid] ])->exists()){
- return $this->fail(200004, [], '用户名已存在');
- }
- }
- $old_user_name = $old_user->user_name;
- $old_user_avatar = $old_user->user_avatar;
- $old_gender = $old_user->gender;
- $old_user_introduce = $old_user->user_introduce;
- $old_user_background_maps = $old_user->user_background_maps;
- $old_wechat_account = $old_user->wechat_account;
- if(_array_key($data, 'wechat_account', '')){
- if($old_wechat_account == _array_key($data, 'wechat_account', '')){
- $data['wechat_account'] = '';
- }
- }
- $user_name = $data['user_name'];
- $user_introduce = $data['user_introduce'] ?? '';
- // 用户修改资料
- // 百度审核
- $need_manual_review = true;
- $is_audit_user_info = Settings::get('is_audit_user_info', 0);
- if ($is_audit_user_info == 2 ) {
- if($old_user_name == $user_name && $old_user_introduce == $user_introduce){
- $need_manual_review = false;
- }else{
- if($user_name || $user_introduce){
- $filter_result = BaiduUtils::text_filter($user_name .' '. $user_introduce);
- if($filter_result){
- if($filter_result['hit_level'] == 2){
- // 不合规
- return $this->fail(200016, ['tip'=>$filter_result['tip_list'], 'hit_word'=>$filter_result['hit_word']]);
- }else if($filter_result['hit_level'] == 0){
- // 审核通过
- $need_manual_review = false;
- }
- }
- }
- }
- }else if($is_audit_user_info == 0){
- $need_manual_review = true;
- if($old_user_name == $user_name && $old_user_introduce == $user_introduce){
- $need_manual_review = false;
- }
- }else{
- $need_manual_review = false;
- }
- if(UserUtils::is_mini_supder_admin($uid)){
- $need_manual_review = false;
- }
- $r = WxUserRepositores::update($uid, $data, $need_manual_review);
- //var_dump($need_manual_review);exit;
- if($r){
- UserInputSafeCheckJob::dispatch($uid, ($user_name .' '. $user_introduce));
- Utils::image_state_change([$data['user_avatar'] ?? '', $data['user_background_maps'] ?? '' ], 1);
- if(_array_key($data, 'user_background_maps', '')){
- if($old_user_background_maps != _array_key($data, 'user_background_maps', '')){
- UserBgColorUpdateJob::dispatch($uid, false);
- }
- }
- if($need_manual_review){
- UserUtils::assistant_notice('admin', '有用户修改资料待审核');
- return $this->success(['code'=>0]);
- }else{
- Cache::forget('get:cached:user:'.$uid);
- $login_user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
- // 超级管理员
- if($login_user->is_official){
- if(UserUtils::is_mini_supder_admin($login_user->id)){
- $login_user->is_official = 2;
- }
- }
- UserUtils::user_expend($login_user, true, true, true, true, 5);
- $login_user->timeStamp = time();
- return $this->success(['code'=>1, 'user'=>$login_user]);
- }
- }
- return $this->fail(200002);
- }
- /**
- * 我的笔记列表
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function getMyPosts(Request $request)
- {
- $uid = $request->uid;
- $user_id = _empty_default_($request->user_id, 0);
- $limit = $request->input('limit', 10);
- $type = $request->input('type', 0);
- if($type == 'shop'){
- $orderBy = _empty_default_($request->orderBy, 'sort');
- if(!in_array($orderBy, ['id','sort', 'buys', 'created_at', 'price'])){
- return $this->fail(200004);
- }
- $order = _empty_default_($request->order, 'desc');
- if(!in_array($order, ['desc', 'asc'])){
- return $this->fail(200004);
- }
- if($orderBy != 'price'){
- $order = 'desc';
- }
- }else{
- $orderBy = 'id';
- $order = 'desc';
- }
- if(is_numeric($type)){
- $type_map = [
- 0 => 'post',
- 1 => 'collected',
- 2 => 'liked',
- 3 => 'exceptionaled',
- 4 => 'voted'
- ];
- $type = $type_map[(int)$type];
- }
- if(!_empty_($user_id)){
- if($user_id > 0 || ($user_id < 0 && $type == 'post')){
- return $this->success(PostsRepositores::myPosts($user_id, $limit, $type, $orderBy, $order));
- }else{
- return $this->fail(200004);
- }
- }else{
- if($uid > 0){
- return $this->success(PostsRepositores::myPosts($uid, $limit, $type, $orderBy, $order));
- }else{
- return $this->fail(503002);
- }
- }
- }
- /**
- * 用户认证
- */
- public function authentication(Request $request)
- {
- $uid = $request->uid;
- $device = in_array($request->header('device',''), ['app', 'h5', 'mp', 'pc']) ? $request->header('device','') : '';
- $arr = UserUtils::user_action_permissions_check($uid, 'user_authenticate');
- if($arr['code'] == 0){
- return $this->fail(200000, [], $arr['msg']);
- }
- $name = $request->name;
- $contact_information = $request->contact_information;
- $introduce = $request->introduce;
- $identity_picture = $request->identity_picture;
- if(Settings::get('app_user_authenticate_img_require', 1) == 1 && _empty_($identity_picture)){
- return $this->fail(200001, [], '请上传身份信息证明图片');
- }
- $authenticationState = (new WxAuthentication())->where('user_id', $uid)->value('authentication_state');
- $authId = (new WxAuthentication())->where('user_id', $uid)->value('id');
- // 已经审核通过和驳回
- if ($authenticationState == 1 || $authenticationState == 2) {
- $model = (new WxAuthentication())->find($authId);
- $model->name = $name;
- $model->contact_information = $contact_information;
- $model->introduce = $introduce;
- $model->authentication_state = 0;
- $model->user_id = $uid;
- if(!_empty_($identity_picture)){
- $model->identity_picture = $identity_picture;
- }
- $model->save();
- }else if($authenticationState === 0){
- return $this->fail(200010, [], '您的认证信息正在审核中...请勿重复提交');
- }else if ($authenticationState === null) {
- $model = new WxAuthentication();
- $model->name = $name;
- $model->contact_information = $contact_information;
- $model->introduce = $introduce;
- if(!_empty_($identity_picture)){
- $model->identity_picture = $identity_picture;
- }
- $model->user_id = $uid;
- $model->save();
- }
- Utils::image_state_change([$identity_picture], 1);
- $tmplIds = [];
- if($device == 'mp'){
- $comment_add_id = Settings::get('mini_template_message_authentication', '');
- if(!_empty_($comment_add_id)){
- $tmplIds[] = $comment_add_id;
- }
- }
- UserUtils::assistant_notice_review(109, $model->id);
- return $this->success([
- 'tmplIds' => $tmplIds
- ]);
- }
- /**
- * 我创建的圈子列表
- */
- public function myCircle(Request $request)
- {
- $uid = $request->uid;
- $data = WxCircle::where('user_id', $uid)->get();
- $data->map(function ($v) {
- $v->post_count = WxPost::where('circle_id', $v->id)->count();
- $v->user_circle_count = WxUserCircle::where('circle_id', $v->id)->count();
- });
- if(UserUtils::is_mini_supder_admin($uid)){
- $data = $data->toArray();
- $hall = [
- [
- 'id' => 0,
- 'circle_name' => '大厅',
- 'post_count' => WxPost::where('circle_id', 0)->count(),
- 'user_circle_count' => WxPost::where('circle_id', 0)->distinct('user_id')->count('user_id'),
- 'head_portrait' => Settings::get('about_logo', ''),
- 'circle_introduce' => '没有选择圈子的笔记'
- ]
- ];
- $data = array_merge($hall, $data);
- }
- return $this->success($data);
- }
- /**
- * 我的支付密码
- */
- public function paycode(Request $request){
- $uid = $request->uid;
- $type = $request->type;
- $password = $request->password;
- if($password && strlen($password) !== 6){
- return $this->fail(200004);
- }
- // 检查是否有支付密码
- if($type == 0){
- $paycode = get_user_meta($uid, 'paycode', 's');
- if($paycode){
- return $this->success(['status'=>1]);
- }else{
- return $this->success(['status'=>0]);
- }
- }else if($type == 1){
- if($password && strlen($password) === 6){
- update_user_meta($uid, 'paycode', $password, 's');
- return $this->success(['status'=>1]);
- }
- return $this->fail(200004);
- }else if($type == 2){
- if(Cache::has('paycode:checked:'.$uid)){
- if($password && strlen($password) === 6){
- update_user_meta($uid, 'paycode', $password, 's');
- Cache::forget('paycode:checked:'.$uid);
- return $this->success(['status'=>1]);
- }
- return $this->fail(200004);
- }else{
- // 检测旧密码
- _limit_user('paycode:check:', $uid, 20);
- if($password !== get_user_meta($uid, 'paycode', 's')){
- return $this->fail(200004, [], '您输入的旧密码错误');
- }else{
- Cache::put('paycode:checked:'.$uid, true, 600);
- return $this->success();
- }
- }
- }else if($type == 3){
- $phoneCode = $request->phoneCode;
- if(_empty_($phoneCode)){
- return $this->fail(200001, [], '验证码为空');
- }
- // 手机号验证
- $user = WxUser::find($uid);
- if(_empty_($user)){
- return $this->fail(200004, [], '用户不存在');
- }
- $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
- $idd = $user->country_code;
- if(_empty_($idd)){
- $idd = 86;
- }
- if(!Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
- return $this->fail(200009, [], '验证码已过期,请重新发送');
- }
- if(Cache::get(md5($uid.':code:'.$idd.':'.$phone)) != $phoneCode){
- return $this->fail(200004, [], '验证码错误');
- }
- if($password && strlen($password) === 6){
- update_user_meta($uid, 'paycode', $password, 's');
- Cache::forget('paycode:checked:'.$uid);
- return $this->success(['status'=>1]);
- }
- return $this->fail(200004);
- }
- }
- public function avatar_frame_wear(Request $request){
- $uid = $request->uid;
- $avatar_frame_id = $request->id;
- if(_empty_($avatar_frame_id)){
- return $this->fail(200001);
- }
- $res = UserUtils::purchase_avatar_frame($uid, $avatar_frame_id);
- if($res['code'] == 200){
- return $this->success();
- }else{
- return $this->fail($res['code'], [], $res['msg']);
- }
- }
- /**
- * 会员页面数据
- * @param Request $request
- */
- public function membersdata(Request $request){
- $uid = $request->uid;
- $benefits = Settings::get('app_vip_benefits', []);
- $avatar_frame_ids = Settings::get('app_vip_user_avatar_frames', []);
- $avatar_frame_ = [];
- if($avatar_frame_ids){
- $avatar_frame_ = WxUserAvatarFrame::whereIn('id', $avatar_frame_ids)->get();
- }
- $vip_consume_invitees = get_user_meta($uid, 'vip_consume_invitees', 'j');
- if($vip_consume_invitees){
- }else{
- $vip_consume_invitees = [];
- }
- $invitees = WxUser::where('who', $uid)->whereNotIn('id', $vip_consume_invitees)->limit(5)->get(FieldUtils::userInfoColums());
- if($invitees){
- }else{
- $invitees = [];
- }
- $result = [
- 'end_time' => UserUtils::get_user_member_time($uid),
- 'invitees' => $invitees,
- 'benefits_title' => Settings::get('app_vip_benefits_title', '会员尊享5大特权'),
- 'benefits' => $benefits,
- 'avatar_frames' => $avatar_frame_,
- 'invitees_5_days' => Settings::get('app_vip_5_invitees_days', 90),
- 'options' => Settings::get('app_vip_options', []),
- ];
- return $this->success($result);
- }
- public function invite_list(Request $request){
- $type = $request->type;
- $uid = $request->uid;
- if(!in_array($type, [1,2,3])){
- return $this->fail(200004);
- }
- if($type == 1 ){
- $data = WxUser::where('who', $uid)->orderBy('id', 'desc')->simplePaginate(10);
- if($data){
- $data->map(function ($v) {
- $v->benifit = UserUtils::get_user_invite_benifit($v->id);
- });
- return $this->success($data);
- }
- return $this->success(200003);
- }else if( $type == 2 ){
- $data = WxUser::whereIn('who', function ($query) use ($uid){
- $query->select('id')->from('wx_user')->where('who', $uid);
- })->orderBy('id', 'desc')->simplePaginate(10);
- if($data){
- $data->map(function ($v) {
- $v->benifit = UserUtils::get_user_invite_benifit($v->id);
- });
- return $this->success($data);
- }
- return $this->success(200003);
- }else if( $type == 3 ){
- $first_userIds = WxUser::where('who', $uid)->pluck('id');
- if($first_userIds){
- $first_userIds = $first_userIds->toArray();
- if($first_userIds){
- $data = WxUser::whereIn('who', function ($query) use ($uid,$first_userIds){
- $query->select('id')->from('wx_user')->whereIn('who', $first_userIds);
- })->orderBy('id', 'desc')->simplePaginate(10);
- if($data){
- $data->map(function ($v) {
- $v->benifit = UserUtils::get_user_invite_benifit($v->id);
- });
- return $this->success($data);
- }
- }
- }
- return $this->success(200003);
- }
- }
- public function invite_info(Request $request){
- $uid = $request->uid;
- $result = [
- 'notice' => Settings::get('user_invite_page_notice', ''),
- 'benifit' => null,
- 'myinviter' => null,
- 'team' => [
- 'total' => 0,
- 'lv1_team' => 0,
- 'lv2_team' => 0,
- 'lv3_team' => 0,
- ],
- 'orders' => [
- ],
- 'qr' => Utils::getMiniCode('pages/tabbar/index/index', '', $uid)
- ];
- $result['benifit'] = UserUtils::get_user_invite_benifit($uid);
- $who = WxUser::where('id', $uid)->value('who');
- if($who > 0){
- $inviter = WxUser::find($who, FieldUtils::userInfoColums());
- if($inviter){
- $inviter->benifit = UserUtils::get_user_invite_benifit($inviter->id);
- $result['myinviter'] = $inviter;
- }else{
- $result['myinviter'] = null;
- }
- }
- $my_inviter_users = [];
- $first_userIds = WxUser::where('who', $uid)->pluck('id');
- $second_userIds = null;
- $third_userIds = null;
- if($first_userIds){
- $first_userIds = $first_userIds->toArray();
- $second_userIds = WxUser::whereIn('who', $first_userIds)->pluck('id');
- if($second_userIds){
- $second_userIds = $second_userIds->toArray();
- $third_userIds = WxUser::whereIn('who', $second_userIds)->pluck('id');
- if($third_userIds){
- $third_userIds = $third_userIds->toArray();
- }
- }
- }
- if($first_userIds){
- foreach ($first_userIds as $user_id){
- if(!isset($my_inviter_users[$user_id])){
- $my_inviter_users[$user_id] = $user_id;
- }
- }
- }
- if($second_userIds){
- foreach ($second_userIds as $user_id){
- if(!isset($my_inviter_users[$user_id])){
- $my_inviter_users[$user_id] = $user_id;
- }
- }
- }
- if($third_userIds){
- foreach ($third_userIds as $user_id){
- if(!isset($my_inviter_users[$user_id])){
- $my_inviter_users[$user_id] = $user_id;
- }
- }
- }
- $result['team']['total'] = $my_inviter_users ? count($my_inviter_users) : 0;
- $result['team']['lv1_team'] = $first_userIds ? count($first_userIds) : 0;
- $result['team']['lv2_team'] = $second_userIds ? count($second_userIds) : 0;
- $result['team']['lv3_team'] = $third_userIds ? count($third_userIds) : 0;
- $records_ = [];
- $records = WxUserInviteBenefitRecord::where('lv1_user', $uid)->orWhere('lv2_user', $uid)->orWhere('lv3_user', $uid)->orderBy('created_at', 'desc')->limit(5)->get();
- if($records){
- foreach ($records as $record){
- $benefit = 0;
- if($record->lv1_user == $uid){
- $benefit = $record->lv1_benefit;
- }else if($record->lv2_user == $uid){
- $benefit = $record->lv2_benefit;
- }else if($record->lv3_user == $uid){
- $benefit = $record->lv3_benefit;
- }
- if($benefit < 0.01){
- continue;
- }
- $user_name = UserUtils::get_cached_user_name($record->user_id);
- if($record->shop_order_id > 0){
- $str = '一笔来自「<a href="/pages/user/user?id='.(int)$record->user_id.'" target="_blank">'.$user_name.'</a>」的商城订单,您获得团队奖励¥'.$benefit;
- }else if($record->order_id){
- $str = '一笔来自「<a href="/pages/user/user?id='.(int)$record->user_id.'" target="_blank">'.$user_name.'</a>」的普通订单,您获得团队奖励¥'.$benefit;
- }
- $records_[] = $str;
- }
- }
- $result['orders'] = $records_;
- return $this->success($result);
- }
- /**
- * 激励视频奖励
- */
- public function reward_gift(Request $request){
- global $__MINI_GLOBAL_DEVICE__;
- $action = $request->action;
- $uid = $request->uid;
- _limit_user('reward_gift', $uid, 20);
- if($__MINI_GLOBAL_DEVICE__ == 'mp'){
- $reward_every = Settings::get('ad_mp_reward_every');
- }else{
- $reward_every = Settings::get('ad_uni_reward_every');
- }
- $count = WxUserCoinRecord::where([
- ['user_id', '=', $uid],
- ['type', '=', 10],
- ['created_at', '>=', Carbon::today()]
- ])->count();
- if($__MINI_GLOBAL_DEVICE__ == 'mp'){
- $every_day_max = Settings::get('ad_mp_reward_every_day_times', 10);
- }else{
- $every_day_max = Settings::get('ad_uni_reward_every_day_times', 10);
- }
- if($count > $every_day_max){
- return $this->fail(200010, [], '您今天获取奖励超过最大次数了,请您明天再来试试吧');
- }
- if($action == 'code'){
- if($count <= $every_day_max){
- $code = Utils::getSn(10);
- Cache::put($code, 1, 80);
- return $this->success($code);
- }else{
- return $this->fail(200010, [], '您今天获取奖励超过最大次数了,请您明天再来试试吧');
- }
- }else if($action == 'reward'){
- $code = $request->code;
- if(_empty_($code)){
- return $this->fail(200001);
- }
- if(Cache::has($code)){
- $r = UserUtils::update_user_coins($uid,10, $reward_every, '观看激励视频奖励:'.Settings::get('app_coin_name', '硬币').'(枚)*'.$reward_every);
- Cache::forget($code);
- return $this->success([], 200, '恭喜获得'.$reward_every.Settings::get('app_coin_name', '硬币'));
- }else{
- return $this->fail(200004);
- }
- }
- }
- /**
- * 我的二维码卡片
- */
- public function codecard(Request $request){
- $uid = $request->uid;
- $user_id = $request->user_id;
- if(_empty_($uid) && _empty_($user_id)){
- return $this->fail(200001);
- }
- if($user_id){
- $code = Utils::getMiniCode('pages/user/user', 'id='.$user_id, $uid);
- $user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
- }else{
- $code = Utils::getMiniCode('pages/user/user', 'id='.$uid, $uid);
- $user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
- }
- if(_empty_($user->user_background_maps)){
- $user->user_background_maps = Settings::get('user_background_maps', '');
- }
- if(_empty_($user->user_introduce)){
- $user->user_introduce = Settings::get('app_user_introduce', '',true);
- }
- if($user){
- if(Settings::get('app_user_qrcode_way', 0) == 2){
- $result = [
- 'user_background_maps' => $user->user_background_maps . '?imageMogr2/crop/330x200/gravity/center/thumbnail/330x/rradius/20',
- 'user_avatar' => Utils::imgWithStyle($user->user_avatar, 2),
- 'user_name' => mb_strlen($user->user_name) > 8 ? (mb_substr($user->user_name, 0, 8).'...') : $user->user_name,
- 'id' => $user->id,
- 'user_introduce' => $user->user_introduce,
- 'rect' => 'https://img.mini.minisns.cn/hbx/qrcode_white_bg.png?imageMogr2/crop/330x390/gravity/center/thumbnail/330x/rradius/20',
- 'code' => $code . '?imageMogr2/format/png/interlace/0',
- 'logo' => Utils::imgWithStyle(Settings::get('about_logo', ''), 2),
- 'way' => 2
- ];
- }else{
- $result = [
- 'user_background_maps' => Utils::imgWithStyle($user->user_background_maps, 1),
- 'user_avatar' => $user->user_avatar . '?imageMogr2/crop/68x68/gravity/center/thumbnail/68x/rradius/68',
- 'user_name' => mb_strlen($user->user_name) > 8 ? (mb_substr($user->user_name, 0, 8).'...') : $user->user_name,
- 'id' => $user->id,
- 'user_introduce' => $user->user_introduce,
- 'code' => $code,
- 'logo' => Utils::imgWithStyle(Settings::get('about_logo', ''), 2),
- 'way' => 1
- ];
- }
- return $this->success($result);
- }
- return $this->fail(200003);
- }
- /**
- * 获取我的认证信息
- */
- public function getAuthentication(Request $request)
- {
- $uid = $request->uid;
- return $this->success(WxAuthentication::where('user_id', $uid)->first());
- }
- /**
- * 个人中心 我的笔记,收藏,喜欢,充电的文章数量
- * @param Request $request
- */
- public function totalPost(Request $request)
- {
- $uid = $request->uid;
- if($uid && $uid > 0){
- $query = WxPost::where('user_id', $uid)->whereIn('posts_state', [0, 2]);
- $data['myTotal'] = $query->count();
- $postsIds = WxLike::where('user_id', $uid)->pluck('posts_id');
- $data['likeTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
- $postsIds = WxCollect::where('user_id', $uid)->pluck('posts_id');
- $data['collecTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
- $postsIds = WxExceptional::where('user_id', $uid)->pluck('posts_id');
- $data['exceptionalTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
- }else{
- $data = [
- 'myTotal' => 0,
- 'likeTotal' => 0,
- 'collecTotal' => 0,
- 'exceptionalTotal' => 0
- ];
- }
- return $this->success($data);
- }
- /**
- * 我关注的用户列表
- * @param Request $request
- */
- public function myFollowUsers(Request $request)
- {
- $uid = $request->uid;
- $user_id = $request->user_id;
- if ($user_id > 0) {
- $data = WxUserFollow::with('followUser')->where('user_id', $user_id)
- ->orderBy('id', 'desc')
- ->simplePaginate(10);
- $data->map(function ($v) use ($user_id, $uid) {
- $v->is_together_follow = WxUserFollow::where('user_id', $v->user_follow_id)
- ->where('user_follow_id', $user_id)->exists();// 是否相互关注
- $v->user = $v->followUser;
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_follow_id);
- });
- return $this->success($data);
- } else {
- $data = WxUserFollow::with('followUser')->where('user_id', $uid)
- ->orderBy('id', 'desc')
- ->simplePaginate(10);
- $data->map(function ($v) use ($uid) {
- $v->is_together_follow = WxUserFollow::where('user_id', $v->user_follow_id)
- ->where('user_follow_id', $uid)->exists();// 是否相互关注
- $v->user = $v->followUser;
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_follow_id);
- });
- return $this->success($data);
- }
- }
- /**
- * 我的粉丝用户列表
- * @param Request $request
- */
- public function myFansUsers(Request $request)
- {
- $uid = $request->uid;
- $user_id = $request->user_id;
- if ($user_id > 0) {
- $data = WxUserFollow::with('user')->where('user_follow_id', $user_id)
- ->orderBy('id', 'desc')
- ->simplePaginate(15);
- $data->map(function ($v) use ($user_id, $uid) {
- $v->is_together_follow = WxUserFollow::where('user_id', $user_id)
- ->where('user_follow_id', $v->user_id)->exists();// 是否相互关注
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_id);
- });
- return $this->success($data);
- } else {
- $data = WxUserFollow::with('user')->where('user_follow_id', $uid)
- ->orderBy('id', 'desc')
- ->simplePaginate(15);
- $data->map(function ($v) use ($uid) {
- $v->is_together_follow = WxUserFollow::where('user_id', $uid)
- ->where('user_follow_id', $v->user_id)->exists();// 是否相互关注
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_id);
- });
- return $this->success($data);
- }
- }
- /**
- * 艾特搜索
- * @param Request $request
- */
- public function aiteSearch(Request $request){
- $keyword = $request->keyword;
- $uid = $request->uid;
- _limit_user('search', $uid, 60);
- $limit = $request->input('limit', 10);
- if(_empty_($keyword)){
- $data = WxUser::whereIn('id', WxUserFollow::select('user_follow_id')->where('user_id', $uid)
- ->orderBy('id', 'desc')
- )->simplePaginate($limit);
- }else{
- $keyword_actree = null;
- $data = SearchUtils::search_user($keyword_actree, $keyword, $uid, false, $limit);
- }
- return $this->success($data);
- }
- /**
- * 获取用户列表
- * @param Request $request
- */
- public function getUsers(Request $request)
- {
- $uid = $request->uid;
- $type = $request->type;
- $limit = $request->limit;
- if(_empty_($limit)){
- $limit = 10;
- }else{
- $limit = _between_($limit, 1, 100);
- }
- $page = _empty_default_($request->page, 1);
- $object_id = _empty_default_($request->object_id, 0);
- if(_empty_($type)){
- return $this->fail(200001);
- }
- if($type == 1){
- // 最近注册用户列表
- $data = WxUser::where('user_state', 0)->orderBy('created_at', 'desc')->simplePaginate($limit, FieldUtils::userInfoColums());
- if($data){
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if($online_item){
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- }else{
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- return $v;
- });
- }
- return $this->success($data);
- }else if($type == 2){
- // 在线用户列表
- $data = UserUtils::user_onlines(2, 5, 1);
- if($data){
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if($online_item){
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- }else{
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- return $v;
- });
- }
- return $this->success($data);
- }else if($type == 3){
- // 今日注册的用户
- $data = WxUser::where('created_at', '>', Carbon::today())->orderBy('created_at', 'desc')->simplePaginate($limit, FieldUtils::userInfoColums());
- if($data) {
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if ($online_item) {
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- } else {
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- return $v;
- });
- }
- return $this->success($data);
- }else if($type == 4){
- // 余额排行
- $data = DB::table('wx_user')->select(['wx_user.id', 'wx_user.user_name', 'wx_user.user_avatar', 'wx_user.user_introduce','wx_user.user_birthday', 'wx_user.user_background_maps', 'wx_user.is_authentication', 'wx_user.is_member', 'wx_user.is_official', 'wx_user.gender', 'wx_user.country_code','wx_user.phone', 'wx_user.real_name', 'wx_user.wechat_account', 'wx_user.shop_id', 'wx_user.user_state', 'wx_user.shop_id','wx_user.country', 'wx_user.province', 'wx_user.city', 'wx_user.district','wx_user.longitude', 'wx_user.latitude', 'wx_user.weixin_unionid', 'wx_user.created_at','wx_user_financial.balance'])->leftJoin('wx_user_financial', 'wx_user.id', '=', 'wx_user_financial.user_id')
- ->where('wx_user_financial.balance', '>', 0)->orderBy('wx_user_financial.balance', 'desc')->orderBy('wx_user.id')
- ->simplePaginate($limit, FieldUtils::userInfoColums());
- if($data){
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if ($online_item) {
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- } else {
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- $v->desc_tip = '拥有'.$v->balance.'余额';
- return $v;
- });
- }
- return $this->success($data);
- }else if($type == 5){
- // 金币排行用户
- $data = DB::table('wx_user')->select(['wx_user.id', 'wx_user.id', 'wx_user.user_name', 'wx_user.user_avatar', 'wx_user.user_introduce','wx_user.user_birthday', 'wx_user.user_background_maps', 'wx_user.is_authentication', 'wx_user.is_member', 'wx_user.is_official', 'wx_user.gender', 'wx_user.country_code','wx_user.phone', 'wx_user.real_name', 'wx_user.wechat_account', 'wx_user.shop_id', 'wx_user.user_state', 'wx_user.shop_id','wx_user.country', 'wx_user.province', 'wx_user.city', 'wx_user.district','wx_user.longitude', 'wx_user.latitude', 'wx_user.weixin_unionid', 'wx_user.created_at','wx_user_meta_num.meta_value as coins'])
- ->leftJoin('wx_user_meta_num', function ($join) {
- $join->on('wx_user.id', '=', 'wx_user_meta_num.user_id')
- ->where('wx_user_meta_num.meta_key', '=', 'coins');
- })->orderBy('wx_user_meta_num.meta_value', 'desc')->orderBy('wx_user.id')
- ->simplePaginate($limit, FieldUtils::userInfoColums());
- if($data){
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if ($online_item) {
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- } else {
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- $v->desc_tip = '拥有'.$v->coins.Settings::get('app_coin_name', '硬币');
- return $v;
- });
- }
- return $this->success($data);
- }else if($type == 6){
- // 笔记总数排行
- $subQuery = DB::table('wx_posts')
- ->select('user_id', DB::raw('COUNT(*) as post_count'))
- ->groupBy('user_id')
- ->orderByDesc('post_count')
- ->toSql();
- $data = WxUser::join(DB::raw("({$subQuery}) as sub"), 'wx_user.id', '=', 'sub.user_id')->orderBy('post_count', 'desc')->orderBy('id')
- ->simplePaginate($limit, array_merge(FieldUtils::userInfoColums(), ['post_count']));
- if($data){
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if ($online_item) {
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- } else {
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- $v->desc_tip = '发布了'.$v->post_count.'篇笔记';
- return $v;
- });
- }
- return $this->success($data);
- }else if($type == 7){
- // 我拉黑的用户
- return $this->fail(200003);
- }else if($type == 8){
- // 不喜欢的用户
- $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
- if($user_set){
- $user_set = array_reverse($user_set);
- $data = WxUser::whereIn('id', $user_set)
- ->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $user_set) . '"' . ")"))->orderBy('id')->simplePaginate($limit, FieldUtils::userInfoColums());
- if($data){
- $data->map(function ($v) use ($uid){
- $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
- if ($online_item) {
- $v->online_time = format_datetime($online_item->online);
- $v->device = $online_item->device;
- } else {
- $v->online_time = '暂时未知';
- $v->device = '';
- }
- $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
- return $v;
- });
- return $this->success($data);
- }
- return $this->fail(200003);
- }else{
- return $this->fail(200003);
- }
- }else if($type == 9){
- // 激励用户排行榜
- $data = WxUserCoinRecord::query()
- ->select('wx_user.*', DB::raw('SUM(wx_user_coin_record.incre) as total_incre'), DB::raw('COUNT(wx_user_coin_record.user_id) as coin_add_count'))
- ->join('wx_user', 'wx_user.id', '=', 'wx_user_coin_record.user_id')
- ->where('wx_user_coin_record.type', 10)
- ->groupBy('wx_user_coin_record.user_id')
- ->orderByDesc('total_incre')->orderBy('wx_user.id')
- ->simplePaginate($limit, FieldUtils::userInfoColums());
- if($data){
- $data->map(function ($v) use ($uid){
- $v->desc_tip = '支持了'.$v->coin_add_count.'次';
- return $v;
- });
- return $this->success($data);
- }
- return $this->success($data);
- }else if($type == 10){
- // 邀请榜
- $data = WxUser::query()
- ->join('wx_user as inviters', 'inviters.id', '=', 'wx_user.who') // 连接wx_user表来获取邀请人信息
- ->select('wx_user.who as from_who', DB::raw('count(*) as total_invites'), 'inviters.id', 'inviters.user_name', 'inviters.user_avatar', 'inviters.user_introduce','inviters.user_birthday', 'inviters.user_background_maps', 'inviters.is_authentication', 'inviters.is_member', 'inviters.is_official', 'inviters.gender', 'inviters.country_code','inviters.phone', 'inviters.real_name', 'inviters.wechat_account', 'inviters.shop_id', 'inviters.user_state', 'inviters.shop_id','inviters.country', 'inviters.province', 'inviters.city', 'inviters.district','inviters.longitude', 'inviters.latitude', 'inviters.weixin_unionid', 'inviters.created_at') // 选择所需字段
- ->where('wx_user.who', '>', 0) // 确保'who'字段不为空
- ->groupBy('wx_user.who') // 按'who'字段分组,同时包括邀请人的信息
- ->orderByDesc('total_invites')->orderBy('inviters.id') // 按邀请数降序排序
- ->simplePaginate($limit);
- if($data){
- $data->map(function ($v) use ($uid){
- $v->desc_tip = '直接邀请'.$v->total_invites.'人';
- return $v;
- });
- return $this->success($data);
- }
- return $this->success($data);
- }else if($type == 11){
- // 粉丝排行榜
- $data = WxUser::query()
- ->join('wx_user_follow', 'wx_user.id', '=', 'wx_user_follow.user_follow_id')
- ->select('wx_user.id', 'wx_user.user_name', 'wx_user.user_avatar', 'wx_user.user_introduce','wx_user.user_birthday', 'wx_user.user_background_maps', 'wx_user.is_authentication', 'wx_user.is_member', 'wx_user.is_official', 'wx_user.gender', 'wx_user.country_code','wx_user.phone', 'wx_user.real_name', 'wx_user.wechat_account', 'wx_user.shop_id', 'wx_user.user_state', 'wx_user.shop_id','wx_user.country', 'wx_user.province', 'wx_user.city', 'wx_user.district','wx_user.longitude', 'wx_user.latitude', 'wx_user.weixin_unionid', 'wx_user.created_at', DB::raw('COUNT(wx_user_follow.user_id) as followers_count'))
- ->where('wx_user_follow.user_follow_state', 0) // 只计算正常关注的情况
- ->groupBy('wx_user.id')
- ->orderByDesc('followers_count')->orderBy('wx_user.id') // 根据粉丝数量降序排序
- ->simplePaginate($limit);
- if($data){
- $data->map(function ($v) use ($uid){
- $v->desc_tip = '粉丝数'.$v->followers_count.'人';
- return $v;
- });
- return $this->success($data);
- }
- return $this->success($data);
- }else if($type == 12){
- // 等级排行榜
- $data = WxUser::query()
- ->select('wx_user.id', 'wx_user.user_name', 'wx_user.user_avatar', 'wx_user.user_introduce','wx_user.user_birthday', 'wx_user.user_background_maps', 'wx_user.is_authentication', 'wx_user.is_member', 'wx_user.is_official', 'wx_user.gender', 'wx_user.country_code','wx_user.phone', 'wx_user.real_name', 'wx_user.wechat_account', 'wx_user.shop_id', 'wx_user.user_state', 'wx_user.shop_id','wx_user.country', 'wx_user.province', 'wx_user.city', 'wx_user.district','wx_user.longitude', 'wx_user.latitude', 'wx_user.weixin_unionid', 'wx_user.created_at', 'meta_num.meta_value as experience')
- ->joinSub(function ($query) {
- $query->from('wx_user_meta_num')
- ->select('user_id', 'meta_value')
- ->where('meta_key', 'experience');
- }, 'meta_num', 'meta_num.user_id', 'wx_user.id')
- ->orderBy('experience', 'desc')->orderBy('wx_user.id') // 根据经验值降序排序
- ->simplePaginate($limit);
- if($data){
- $data->map(function ($v) use ($uid){
- $v->desc_tip = '经验值'.$v->experience;
- return $v;
- });
- return $this->success($data);
- }
- return $this->success($data);
- }else if($type == 13){
- // 俱乐部粉丝
- $data = DB::table('wx_club_follow as wcf')
- ->join('wx_user as wu', 'wcf.user_id', '=', 'wu.id')
- ->select('wu.*', 'wcf.created_at as follow_time')
- ->where('wcf.club_id', $object_id)
- ->where('wcf.status', 1) // 只获取状态为关注的记录
- ->orderBy('wcf.created_at', 'desc')
- ->simplePaginate($limit);
- if($data){
- $data->map(function ($v) use ($uid){
- $v->desc_tip = '关注时间:'.$v->follow_time;
- return $v;
- });
- return $this->success($data);
- }
- return $this->success($data);
- }else if($type == 14){
- // 关注圈子的粉丝
- $data = DB::table('wx_user_circle as wcf')
- ->join('wx_user as wu', 'wcf.user_id', '=', 'wu.id')
- ->select('wu.*', 'wcf.created_at as follow_time')
- ->where('wcf.circle_id', $object_id)
- ->where('wcf.user_circle_state', 0) // 只获取状态为关注的记录
- ->orderBy('wcf.created_at', 'desc')
- ->simplePaginate($limit);
- if($data){
- $data->map(function ($v) use ($uid){
- $v->desc_tip = '关注时间:'.$v->follow_time;
- return $v;
- });
- return $this->success($data);
- }
- return $this->success($data);
- }else if($type == 17){
- // 获取传单所推广的用户
- $itcId = (int)str_replace('itc', '', _empty_default_($request->itc, ''));
- if(_empty_($itcId)){
- return $this->fail(200001);
- }
- $data = DB::table('wx_user as u')
- ->join('wx_user_invite_temp_code_record as r', 'u.id', '=', 'r.object_id')
- ->where('r.itc_id', $itcId)
- ->orderBy('r.created_at', 'desc')
- ->select('u.*', 'r.created_at', 'r.*')->simplePaginate($limit);
- $data->map(function ($v) use ($uid){
- $v->desc_tip = $v->created_at . ' 奖励:¥' . $v->reward_balance . ($v->reward_coin > 0 ? '+'.Settings::get('app_coin_name', '硬币').'*'.$v->reward_coin : '');
- return $v;
- });
- return $this->success($data);
- }
- }
- /**
- * 添加用户话题
- * @param Request $request
- */
- public function addUserPlate(Request $request)
- {
- $plateId = $request->plate_id;
- $uid = $request->uid;
- if(_empty_($plateId)){
- return $this->fail(200001);
- }
- $r = UserUtils::add_user_plate($uid, $plateId);
- if($r){
- return $this->success();
- }
- return $this->fail(200004, [], '添加分区失败');
- }
- public function real_name(Request $request)
- {
- $uid = $request->uid;
- if(request()->method() === 'GET'){
- $user = WxUser::where('id', $uid)->first(['id', 'real_name', 'real_id_card']);
- if($user){
- if(_empty_($user->real_name)){
- $user->real_name = '';
- }
- if(_empty_($user->real_id_card)){
- $user->real_id_card = '';
- }
- return $this->success($user);
- }else{
- return $this->fail(200003);
- }
- }else{
- $user = WxUser::find($uid);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- $realName = _empty_default_($request->realName, '');
- $realIdCard = _empty_default_($request->realIdCard, '');
- if(_empty_($realName) || _empty_($realIdCard)){
- return $this->fail(200001);
- }
- if(mb_strlen($realName) <= 1){
- return $this->fail(200004, [], '姓名过短');
- }
- if(strpos($realName, '*') !== false || strpos($realIdCard, '*') !== false){
- return $this->fail(200004, [], '姓名或身份证中含有*号,请先删除');
- }
- if(strlen($realIdCard) != 18){
- return $this->fail(200004, [], '请输入合法的身份证号');
- }
- // $realName_fake = mb_substr($realName, 0, 1) . str_repeat( '*', (mb_strlen($realName) - 1) );
- // $realIdCard_fake = mb_substr($realIdCard, 0, 2) . str_repeat( '*', (mb_strlen($realIdCard) - 2) );
- $realName_fake = $realName;
- $realIdCard_fake = $realIdCard;
- if($user->real_name == $realName_fake && $user->real_id_card == $realIdCard_fake){
- return $this->fail(200010, [], '与已有认证信息相同,无需修改');
- }
- $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
- if(_empty_($user->phone) || _empty_($phone)){
- return $this->fail(200043, [
- 'title' => '未绑定手机号',
- 'content' => '前往绑定',
- 'confirmText' => '去绑定',
- 'target_type' => 6,
- 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
- ], '未绑定手机号');
- }
- // $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
- // todo:
- // WxUser::where('id', $uid)->update([
- // 'real_name' => $realName_fake,
- // 'real_id_card' => $realIdCard_fake
- // ]);
- // update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
- // // Conditions 更新实名认证状态
- // Conditions::where('user_id', $uid)->update(['is_real' => 1]);
- // DB::commit();
- // return $this->success([], 200, '实名认证成功');
-
-
- $res_ = Http::withHeaders([
- 'Authorization' => 'APPCODE '.Settings::get('app_ali_real_name_appcode', ''),
- ])->asForm()->post('https://mobile3elements.shumaidata.com/mobile/verify_real_name', ['idcard'=>$realIdCard, 'mobile'=>$phone, 'name'=> $realName]);
- //print_r($res_);exit;
- if($res_->successful()){
- $res = $res_->json();
- if($res){
- if($res['code'] == 0 && $res['result']){
- if($res['result']['res'] == 1){
- // 一致
- DB::beginTransaction();
- try {
- $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
- // todo:
- WxUser::where('id', $uid)->update([
- 'real_name' => $realName_fake,
- 'real_id_card' => $realIdCard_fake,
- 'is_real' => 1
- ]);
- update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
- // Conditions 更新实名认证状态
- Conditions::where('user_id', $uid)->update(['is_real' => 1]);
- DB::commit();
- return $this->success([], 200, '实名认证成功');
- } catch (\Exception $e) {
- DB::rollBack();
- _logger_(__file__, __line__, $e->getMessage());
- return $this->fail(200002);
- }
- }else if($res['result']['res'] == 2){
- return $this->fail(200004, [], '身份信息不一致,认证失败');
- }else if($res['result']['res'] == 3){
- return $this->fail(200004, [], '认证系统查询不到该信息,请联系客服');
- }else if($res['result']['res'] == -1){
- return $this->fail(200004, [], '异常');
- }
- }else{
- UserUtils::assistant_notice('admin', $res.'_003');
- return $this->fail(200004, [], $res['message'].'__003');
- }
- }
- }else{
- $res = $res_->json();
- _logger_(__file__, __line__, '实名认证返回错误,'.$res_->body());
- _logger_(__file__, __line__, '实名认证返回错误,'. urldecode($res_));
- return $this->fail(200004, [], _array_key($res, 'message', ''));
- }
- }
- }
- /**
- * 删除用户话题
- * @param Request $request
- */
- public function deleteUserPlate(Request $request)
- {
- $id = $request->id;
- $uid = $request->uid;
- $plate_id = $request->plate_id;
- if(_empty_($plate_id)){
- (new WxUserPlate())->where('user_id', $uid)->where('id', $id)->update(['status'=>2]);
- }else{
- (new WxUserPlate())->where('user_id', $uid)->where('plate_id', $plate_id)->update(['status'=>2]);
- }
- return $this->success();
- }
- /**
- * 用户话题列表
- * @param Request $request
- */
- public function userPlate(Request $request)
- {
- global $__MINI_GLOBAL_TENANT_ID__;
- $uid = $request->uid;
- if ($uid == 0) {
- $data = [];
- } else {
- $data = (new WxUserPlate())->where('user_id', $uid)->where('status', 1)->orderBy('updated_at', 'asc')->get();
- if(!$data->isEmpty()){
- $data = $data->map(function ($item) {
- $plate = WxPlate::find($item->plate_id);
- if($plate){
- $item->plate_name = $plate->plate_name;
- $item->tenant_id = $plate->tenant_id;
- return $item;
- }
- });
- $data = $data->filter(function ($item, $key) use ($__MINI_GLOBAL_TENANT_ID__){
- if($item){
- return $item->tenant_id == $__MINI_GLOBAL_TENANT_ID__;
- }
- return false;
- });
- }
- }
- return $this->success($data);
- }
- /**
- * 我的订单列表
- */
- public function myOrder(Request $request, $limit = 8)
- {
- $uid = $request->uid;
- $type = $request->type;
- if(_empty_($type)){
- return $this->fail(200001);
- }
- if($type == 'all'){
- if(!UserUtils::is_mini_supder_admin($uid)){
- return $this->fail(200000);
- }
- $data = WxOrder::where([['order_state','=', 1], ['order_serial_number', '<>', '']])
- ->orderBy('id', 'desc')->simplePaginate($limit);
- }else{
- $data = WxOrder::where('user_id', $uid)->where([['order_state','=', 1], ['order_serial_number', '<>', '']])
- ->orderBy('id', 'desc')->simplePaginate($limit);
- }
- $data->map(function ($v) {
- $v->type_content = WxUserRepositores::orderType($v->order_type);
- $parame = unserialize($v->parame);
- $v->posts_id = $parame['postsId'] ?? 0;
- $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
- });
- return $this->success($data);
- }
- public function financial_process(Request $request){
- $type = _empty_default_($request->type, '');
- if ($type == 'my_financial') {
- return $this->myFinancial($request);
- }else if ($type == 'initiate_withdrawal') {
- return $this->initiateWithdrawal($request);
- }else if ($type == 'withdrawal_apply') {
- return $this->withdrawalApply($request);
- }else if ($type == 'withdrawal_list') {
- return $this->withdrawalList($request);
- }else if ($type == 'balance_record_list') {
- return $this->balanceRecordList($request);
- }else if ($type == 'coin_record_list') {
- return $this->coinRecordList($request);
- }
- }
- private function coinRecordList(Request &$request){
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $data = WxUserCoinRecord::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
- if($data){
- $data->map(function ($v) {
- });
- return $this->success($data);
- }
- return $this->fail(200003);
- }
- private function balanceRecordList(Request &$request){
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $data = WxUserFinancialRecord::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
- if($data){
- $data->map(function ($v) {
- });
- return $this->success($data);
- }
- return $this->fail(200003);
- }
- private function withdrawalList(Request &$request){
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $data = WxUserWithdrawal::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
- if($data){
- $data->map(function ($v) {
- $v->state_tip = WxUserRepositores::withdrawalType($v->state);
- if(!_empty_($v->withdrawal_remark)){
- $v->title = $v->withdrawal_remark;
- }else if(!_empty_($v->wechat_phone)){
- $v->way = 'wechat';
- $v->title = '提现'.$v->pay_amount.'元到微信';
- }else if(!_empty_($v->alipay_phone)){
- $v->way = 'alipay';
- $v->title = '提现'.$v->pay_amount.'元到支付宝';
- }else if(!_empty_($v->bank_card)){
- $v->way = 'bank';
- $v->title = '提现'.$v->pay_amount.'元到银行卡';
- }
- if(_empty_($v->way)){
- if(!_empty_($v->wx_batch_id)){
- $v->way = 'wechat';
- }else if(!_empty_($v->ali_batch_id)){
- $v->way = 'alipay';
- }
- }
- });
- return $this->success($data);
- }
- return $this->fail(200003);
- }
- private function withdrawalApply(Request &$request){
- $uid = $request->uid;
- $id = _empty_default_($request->id, 0);
- if(_empty_($id)){
- return $this->fail(200001);
- }
- $withdrawal = WxUserWithdrawal::find($id);
- if($withdrawal->user_id != $uid && !UserUtils::is_mini_supder_admin($uid)){
- return $this->fail(200000);
- }
- $withdrawal->state_tip = WxUserRepositores::withdrawalType($withdrawal->state);
- if(!_empty_($withdrawal->wechat_phone)){
- $withdrawal->way = 'wechat';
- }else if(!_empty_($withdrawal->alipay_phone)){
- $withdrawal->way = 'alipay';
- }else if(!_empty_($withdrawal->bank_card)){
- $withdrawal->way = 'bank';
- }else if(!_empty_($withdrawal->wx_batch_id)){
- $withdrawal->way = 'wechat';
- }else if(!_empty_($withdrawal->ali_batch_id)){
- $withdrawal->way = 'alipay';
- }
- return $this->success($withdrawal);
- }
- /**
- * 我的收益
- */
- public function myFinancial(Request $request)
- {
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)){
- if($setUserid && $setUserid > 0){
- if(UserUtils::is_mini_supder_admin($uid)){
- $uid = $setUserid;
- }else{
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $result = [
- 'coins' => [
- 'total' => UserUtils::user_coins($uid) ?? 0
- ],
- 'financial' => [],
- ];
- $result['financial'] = WxUserFinancial::where('user_id', $uid)
- ->first();
- if($result['financial']) {
- $result['financial']->earnings_yesterday = WxExceptional::where('posts_user_id', $result['financial']->user_id)
- ->where('created_at', 'like', '%' . date("Y-m-d", strtotime("-1 day")) . '%')
- ->sum('exceptional_price');
- if(_empty_($result['financial']->withdrawal_price)){
- $result['financial']->withdrawal_price = 0;
- }
- return $this->success($result);
- }else{
- return $this->success($result);
- }
- }
- /**
- * 发起提现
- */
- public function initiateWithdrawal(Request $request)
- {
- global $__MINI_GLOBAL_CURRENT_PLAYER_ID__;
- $uid = $request->uid;
- $price = $request->price;
- $bank_name = _empty_default_($request->bank_name, '');
- $bank_card = _empty_default_($request->bank_card, '');
- $real_name = $request->real_name ?? null;
- $id_card = _empty_default_($request->id_card, '');
- $wechat_phone = $request->wechat_phone ?? null;
- $aliay_phone = $request->aliay_phone ?? null;
- $withdrawal_way = _empty_default_($request->way, 'wechat');
- $device = in_array($request->header('device',''), ['app', 'h5', 'mp', 'pc']) ? $request->header('device','') : '';
- if($price < Settings::get('app_balance_withdrawal_min_once', 1) || $price > Settings::get('app_balance_withdrawal_max_once', 200)){
- return $this->fail(200004, [], '提现金额不合法');
- }
- $user = WxUser::find($uid);
- // 验证资料
- if(Settings::get('app_balance_withdrawal_force_bind_phone', 0) == 1){
- if(_empty_($user->phone) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
- return $this->fail(200043, [
- 'title' => '未绑定手机号',
- 'content' => '前往绑定',
- 'confirmText' => '去绑定',
- 'target_type' => 6,
- 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
- ], '未绑定手机号');
- }
- }
- if(Settings::get('app_balance_withdrawal_force_real_name', 0) == 1){
- if(_empty_($user->real_name) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
- return $this->fail(200043, [
- 'title' => '未实名认证',
- 'content' => '您还没有实名认证,是否前往认证',
- 'confirmText' => '去认证',
- 'target_type' => 6,
- 'target_id' => '/pagesA/mine/realname/realname'
- ], '未实名认证');
- }
- }
- if(Settings::get('app_balance_withdrawal_force_subscribe_mp', 0) == 1){
- if(_empty_($user->weixin_mp_openid) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
- $weapp = new WeApp('mp');
- $mpServicer = $weapp->getMpServicer();
- try {
- $url = $mpServicer->getQrCodeWithPara(0, 'user:bind:'.$user->id);
- }catch (\Exception $e){
- return $this->fail(200006, [], '生成公众号二维码失败,请检查[全局配置-支付-微信-公众号]');
- }
- if($url){
- $qrCode = QrCode::format('png')->size(300)->generate($url);
- $image = Image::make($qrCode);
- $image->resizeCanvas(300, 300 + 60, 'bottom', false, '#ffffff'); // 增加高度,保持宽高比,背景色为白色
- $mp_app_name = Settings::get('mp_app_name', '');
- $text_tip = '关注'.$mp_app_name.'公众号,可以更方便通知到您';
- if(mb_strlen($mp_app_name) > 4){
- $text_tip = '关注'.$mp_app_name.'公众号';
- }
- $image->text($text_tip, 150, 40, function($font){
- $font->file(public_path('storage/font/DingTalk_JinBuTi_Regular.ttf')); // 字体文件路径
- $font->size(13); // 字体大小
- $font->color('#000000'); // 字体颜色
- $font->align('center'); // 水平对齐
- $font->valign('top'); // 垂直对齐
- });
- $base64 = 'data:image/png;base64,' . base64_encode($image->encode('png')->getEncoded());
- return $this->fail(200043, [
- 'title' => '未关注公众号,无法实时获取通知',
- 'content' => '前往关注',
- 'confirmText' => '去关注',
- 'target_type' => 26,
- 'target_id' => $base64
- ], '未关注公众号');
- }
- }
- }
- if(_empty_($real_name)){
- return $this->fail(200001, [], '缺少真实姓名');
- }
- $financial_updates = [];
- if($withdrawal_way == 'wechat'){
- if(_empty_($wechat_phone) || !StrUtils::is_phone_number($wechat_phone)){
- return $this->fail(200001, [], '微信手机号不合法');
- }
- if(_empty_($real_name)){
- return $this->fail(200001, [], '姓名不完整');
- }
- $financial_updates['wechat_phone'] = $wechat_phone;
- $financial_updates['real_name'] = $real_name;
- }else if($withdrawal_way == 'alipay'){
- if(_empty_($aliay_phone) || !StrUtils::is_phone_number($aliay_phone)){
- return $this->fail(200001, [], '支付宝手机号不合法');
- }
- if(_empty_($real_name) || _empty_($id_card) || strlen($id_card) != 18){
- return $this->fail(200001, [], '姓名或身份证号不完整');
- }
- $financial_updates['alipay_phone'] = $aliay_phone;
- $financial_updates['real_name'] = $real_name;
- $financial_updates['id_card'] = $id_card;
- }else{
- if(_empty_($bank_name) || _empty_($bank_card) || _empty_($real_name)){
- return $this->fail(200001, [], '银行信息不完整');
- }
- $financial_updates['bank_name'] = $bank_name;
- $financial_updates['bank_card'] = $bank_card;
- $financial_updates['real_name'] = $real_name;
- }
- if(WxUserWithdrawal::where('user_id', $uid)->where('withdrawal_scene', 0)->whereDate('created_at', Carbon::today())->count() >= Settings::get('app_balance_withdrawal_day_times', 3)){
- return $this->fail(200046, [], '您今天已经达到最大的提现次数了');
- }
- $platform_percent = _between_(Settings::get('app_withdrawal_platform_percent', 10.0), 0, 100);
- $pay_amount = round(($price * ( 100 - $platform_percent )) / 100, 2);
- DB::beginTransaction();
- try{
- $r = UserUtils::update_user_financial($uid, 2, $price, '发起余额提现¥'.$price, 0, $bank_name, $bank_card);
- if($r){
- $withdrawal_id = Utils::getSn(14);
- // 提现记录
- $userWithdrawalModel = new WxUserWithdrawal();
- $userWithdrawalModel->user_id = $uid;
- $userWithdrawalModel->withdrawal_id = $withdrawal_id;
- $userWithdrawalModel->price = $price;
- $userWithdrawalModel->pay_amount = $pay_amount;
- $userWithdrawalModel->bank_name = $bank_name;
- $userWithdrawalModel->bank_card = $bank_card;
- $userWithdrawalModel->real_name = $real_name;
- if($withdrawal_way == 'wechat'){
- $userWithdrawalModel->wechat_phone = $wechat_phone;
- $userWithdrawalModel->alipay_phone = null;
- }else if($withdrawal_way == 'alipay'){
- $userWithdrawalModel->wechat_phone = null;
- $userWithdrawalModel->alipay_phone = $aliay_phone;
- }
- $userWithdrawalModel->state = 0;
- $userWithdrawalModel->save();
- UserUtils::assistant_notice('admin', '有用户(<a href="/pages/user/user?id='.$uid.'">id: '.$uid.'</a>)提交了新的提现申请。');
- WxUserFinancial::where('user_id', $uid)->update($financial_updates);
- UserWithdrawalProcessJob::dispatch($userWithdrawalModel->id);
- $tmplIds = [];
- if($device == 'mp'){
- $comment_add_id = Settings::get('mini_template_message_withdrawal', '');
- if(!_empty_($comment_add_id)){
- $tmplIds[] = $comment_add_id;
- }
- }
- DB::commit();
- return $this->success([
- 'tmplIds' => $tmplIds,
- 'id' => $userWithdrawalModel->id
- ]);
- }
- DB::rollBack();
- return $this->fail(200013);
- }catch (\Exception $e){
- DB::rollBack();
- _logger_(__file__, __line__, $e->getMessage());
- return $this->fail(200013);
- }
- }
- /**
- * 我的提现记录
- */
- public function myUserWithdrawal(Request $request)
- {
- $uid = $request->uid;
- $id = _empty_default_($request->id, 0);
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $query = WxUserWithdrawal::where('user_id', $uid);
- if($id > 0){
- $query = $query->where('id', $id);
- }
- $data = $query
- ->orderBy('id', 'desc')
- ->get();
- $data->map(function ($v) {
- $v->status_value = WxUserRepositores::withdrawalType($v->state);
- });
- return $this->success($data);
- }
- /**
- * @param Request $request
- */
- public function uploaded_unused_attachments(Request $request){
- $uid = $request->uid;
- $type = $request->type;
- if($type == 'img'){
- $types_ = ["jpg", "jpeg", "png", "gif"];
- }else if($type == 'video'){
- $types_ = ['mp4'];
- }else{
- return $this->fail(200004);
- }
- $attachments = WxAttachment::where('user_id', $uid)->where('state', 1)->WhereIn('type', $types_)->orderBy('id', 'desc')->simplePaginate(10);
- if($attachments){
- $attachments->map(function ($v){
- $v->url = $v->domain .'/' . $v->path;
- return $v;
- });
- return $this->success($attachments);
- }
- return $this->fail(200003);
- }
- /**
- * 邀请领会员
- */
- public function invite_member(Request $request)
- {
- $uid = $request->uid;
- $days = Settings::get('app_vip_5_invitees_days', 90);
- if(_empty_($days)){
- return $this->fail(200008);
- }
- $vip_consume_invitees = get_user_meta($uid, 'vip_consume_invitees', 'j');
- $invitees = WxUser::where('who', $uid)->whereNotIn('id', $vip_consume_invitees)->limit(5)->get(FieldUtils::userInfoColums());
- if($invitees){
- }else{
- $invitees = [];
- }
- if(_empty_($invitees) || count($invitees) < 5){
- return $this->fail(200042, [], '你的邀请人数只有'.count($invitees).'个,凑够5个才能兑换会员,再接再厉');
- }
- // 满足条件
- DB::beginTransaction();
- try{
- foreach ($invitees as $invitee){
- $vip_consume_invitees[] = $invitee->id;
- }
- update_user_meta($uid, 'vip_consume_invitees', $vip_consume_invitees, 'j');
- WxUserRepositores::vip($uid, $days);
- DB::commit();
- return $this->success(['days'=>$days]);
- }catch (\Exception $e){
- DB::rollBack();
- _logger_(__file__, __line__, $e->getMessage());
- return $this->fail(200006);
- }
- }
- /**
- * 我的收益记录
- */
- public function myUserExceptional(Request $request)
- {
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $data = WxExceptional::where('posts_user_id', $uid)
- ->orderBy('id', 'desc')
- ->get();
- $data->map(function ($v) {
- $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
- $v->datetime = format_datetime($v->created_at);
- });
- return $this->success($data);
- }
- public function myVisit(Request $request){
- $uid = $request->uid;
- $page = 1; // 从请求获取或设定默认值
- $perPage = 15; // 每页显示的数量
- $visits = WxUserVisit::where('type', 1)->where('user_id', $uid)
- ->join('wx_posts', 'wx_user_visit.object_id', '=', 'wx_posts.id')
- ->select('wx_user_visit.object_id',
- DB::raw('DATE(wx_user_visit.created_at) as visit_date'),
- DB::raw('SUM(wx_user_visit.times) as total_times'),
- )
- ->groupBy('visit_date', 'wx_user_visit.object_id')
- ->orderBy('visit_date', 'desc')
- ->paginate($perPage, ['*'], 'page', $page);
- return $this->success($visits);
- }
- /**
- * 我的余额记录
- */
- public function myUserFinancialRecord(Request $request)
- {
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $data = WxUserFinancialRecord::where('user_id', $uid)
- ->orderBy('id', 'desc')->limit(20)
- ->get();
- $data->map(function ($record){
- $record->type_name = FieldUtils::getUserFinancialType()[(int)$record->type];
- $record->date = $record->created_at->toDateTimeString();
- $record->num_str = $record->num > 0 ? '+'.$record->num : $record->num;
- return $record;
- });
- return $this->success($data);
- }
- /**
- * 我的金币记录
- */
- public function myUserCoinsRecord(Request $request)
- {
- $uid = $request->uid;
- $setUserid = $request->setUserid;
- if(!_empty_($setUserid)) {
- if ($setUserid && $setUserid > 0) {
- if (UserUtils::is_mini_supder_admin($uid)) {
- $uid = $setUserid;
- } else {
- return $this->fail(200000, [], '你不是超级管理员,无法查看');
- }
- }
- }
- $data = WxUserCoinRecord::where('user_id', $uid)
- ->orderBy('id', 'desc')->limit(20)
- ->get();
- $data->map(function ($record){
- $record->date = $record->created_at->toDateTimeString();
- $record->num_str = $record->incre > 0 ? '+'.$record->incre : $record->incre;
- return $record;
- });
- return $this->success($data);
- }
- /*
- * 用户海报数据
- */
- public function poster(Request $request){
- $userId = $request->id;
- $uid = $request->uid;
- if(_empty_($userId)){
- return $this->fail(200001);
- }
- $user = WxUser::find($userId);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- global $__MINI_GLOBAL_TENANT_ID__;
- $mini_code = Utils::getMiniCode('/pages/user/user', 'id='.$user->id, $uid, 430, false, null, true);
- if($mini_code){
- $data = [
- 'userdata' => [
- 'avatar' => $user->user_avatar,
- 'name' => $user->user_name
- ],
- 'swiperList' => Settings::get('app_share_poster', [], true),
- 'code' => $mini_code,
- 'web' => rtrim(Settings::get('app_h5_home', ''), '/') . '/#/pages/user/user?id=' . $userId . '&fph=1&from_user=' . $uid .'&tenant=' . $__MINI_GLOBAL_TENANT_ID__
- ];
- if(_empty_($data['swiperList'])){
- return $this->fail(200008);
- }
- return $this->success($data);
- }else{
- return $this->fail(300001);
- }
- }
- public function earningsRank(Request $request){
- $userId = $request->uid;
- $user = WxUser::find($userId);
- if(_empty_($user)){
- return $this->fail(200003);
- }
- $r = WxUserFinancial::leftJoin('wx_user', 'wx_user.id', '=', 'wx_user_financial.user_id')->orderBy('sum_price', 'desc')->limit(10)->get(['wx_user.user_avatar', 'wx_user.user_name', 'wx_user.id', 'wx_user_financial.sum_price','wx_user_financial.withdrawal_price', 'wx_user.is_member', 'wx_user.is_official', 'wx_user.is_authentication', 'wx_user.gender']);
- if(_empty_($r)){
- return $this->fail(200003);
- }
- $data = [
- 'one' => [],
- 'two' => [],
- 'three' => [],
- 'others' => [
- ],
- 'avg' => round(WxUserFinancial::avg('sum_price'), 2),
- 'bg' => Settings::get('app_earnings_rank_bg', 'https://img.mini.minisns.cn/images/rank/rank_bg.png'),
- 'total' => WxUserFinancial::count()
- ];
- $defaut = [
- 'id' => 0,
- 'user_avatar' => Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/images/avatar.png'),
- 'user_name' => '未知',
- 'sum_price' => 0,
- 'withdrawal_price' => 0,
- 'is_member' => 0,
- 'is_official' => 0,
- 'is_authentication' => 0,
- 'gender' => 0
- ];
- for ($i = 0; $i < 10; $i ++){
- if ($i == 0){
- if(isset($r[$i])){
- $data['one'] = $r[$i];
- }else{
- $data['one'] = $defaut;
- }
- }else if($i == 1){
- if(isset($r[$i])){
- $data['two'] = $r[$i];
- }else{
- $data['two'] = $defaut;
- }
- }else if($i == 2){
- if(isset($r[$i])){
- $data['three'] = $r[$i];
- }else{
- $data['three'] = $defaut;
- }
- }else{
- if(isset($r[$i])){
- $data['others'][] = $r[$i];
- }else{
- $data['others'][] = $defaut;
- }
- }
- }
- return $this->success($data);
- }
- public function vote(Request $request){
- $position = $request->position;
- $uid = $request->uid;
- $vote_id = $request->vote_id;
- if(_empty_($vote_id) || _empty_($position) || !is_numeric($position)){
- return $this->fail(200001);
- }
- if($position > 20 || $position < 1){
- return $this->fail(200004);
- }
- if(WxUserVote::where([
- ['user_id', '=', $uid],
- ['vote_id', '=', $vote_id]
- ])->exists()){
- return $this->fail(200010, [], '你已经为这个内容投过票啦');
- }
- $WxUserVote = new WxUserVote();
- $WxUserVote->user_id = $uid;
- $WxUserVote->vote_id = $vote_id;
- $WxUserVote->vote_option = $position;
- $r = $WxUserVote->save();
- if($r){
- WxPostsVote::where('id', $vote_id)->increment('num'.$position);
- return $this->success(PostUtils::getVoteData($vote_id, $uid));
- }
- return $this->fail(200002);
- }
- /**
- * 拉黑或取消拉黑某个用户
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function black(Request $request){
- $uid = $request->uid;
- $object_id = $request->object_id;
- $action = $request->action;
- if(_empty_($object_id)){
- return $this->fail(200001);
- }
- if($action == 'black'){
- $user_set = get_user_meta($uid, 'user:blacked:set', 'j');
- if(!in_array($object_id, $user_set)){
- $user_set[] = $object_id;
- update_user_meta($uid, 'user:blacked:set', array_unique($user_set), 'j');
- return $this->success([], 200, '拉黑成功');
- }else{
- // 要删除的特定值
- $user_set = array_filter($user_set, function ($value) use ($object_id) {
- return $value != $object_id;
- });
- update_user_meta($uid, 'user:blacked:set', array_unique($user_set), 'j');
- return $this->success([], 200, '取消拉黑');
- }
- }else{
- $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
- if(!in_array($object_id, $user_set)){
- $user_set[] = $object_id;
- update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
- return $this->success();
- }else{
- // 要删除的特定值
- $user_set = array_filter($user_set, function ($value) use ($object_id) {
- return $value != $object_id;
- });
- update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
- return $this->success();
- }
- }
- }
- /**
- * 用户反馈
- * [0=>'post', 1=> 'comment', 2 => 'user', 3=> 'goods']
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function report(Request $request)
- {
- $uid = $request->uid;
- _limit_user('add:report', $uid, 20);
- $report_type = $request->report_type;
- $report_content = $request->report_content;
- $image_urls = $request->image_urls;
- $type = $request->type;
- $object_id = $request->object_id;
- if(!isset($type) || !isset($object_id)){
- return $this->fail(200001);
- }
- if(!in_array($type, [0,1,2,3,4,5,6])){
- return $this->fail(200004);
- }
- $count = WxUserReport::where([
- ['type', '=', $type],
- ['object_id', '=', $object_id],
- ['user_id', '=', $uid]
- ])->count();
- if($count > 0){
- return $this->fail(200010, [], '你已经举报过了ta,再管理员反馈之前,请勿重复举报');
- }
- $image_urls__ = [];
- if($image_urls){
- foreach ($image_urls as $img_item){
- $image_urls__[] = $img_item['url'];
- }
- }
- $contact = $request->contact;
- if(_empty_($report_content)){
- $this->fail(200001);
- }
- $r = WxUserReportRepositories::add($uid,$type, $object_id, $report_type, $report_content, $image_urls__, $contact);
- if($r){
- $count_ = WxUserReport::where([
- ['type', '=', $type],
- ['object_id', '=', $object_id],
- ])->count();
- if($type == 0){
- $app_report_safe_times_post = Settings::get('app_report_safe_times_post', 0);
- if($app_report_safe_times_post == 0){
- $app_report_safe_times_post = 999;
- }
- if(UserUtils::is_mini_admin($uid)){
- if($report_type == 10){
- WxPost::where('id', $object_id)->update(['is_blur'=>1]);
- }else{
- WxPost::where('id', $object_id)->update(['posts_state'=>2]);
- UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动下架。');
- }
- }else if($count_ > $app_report_safe_times_post){
- if($report_type == 10){
- WxPost::where('id', $object_id)->update(['is_blur'=>1]);
- }else{
- WxPost::where('id', $object_id)->update(['posts_state'=>2]);
- UserUtils::assistant_notice('admin', '多名用户对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动下架。');
- }
- }else{
- UserUtils::assistant_notice('admin', '有新的用户(id: <a href="/pages/user/user?id='.$uid.'">'.$uid.'</a>)对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报。');
- }
- }else if($type == 1){
- $app_report_safe_times_comment = Settings::get('app_report_safe_times_comment', 0);
- if($app_report_safe_times_comment == 0){
- $app_report_safe_times_comment = 999;
- }
- $posts_id = WxComment::where('id', $object_id)->value('posts_id');
- if(UserUtils::is_mini_admin($uid)){
- WxComment::where('id', $object_id)->update(['comment_state'=>2]);
- UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动下架。');
- }else if($count_ > $app_report_safe_times_comment){
- WxComment::where('id', $object_id)->update(['comment_state'=>2]);
- UserUtils::assistant_notice('admin', '多名用户对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动下架。');
- }else{
- UserUtils::assistant_notice('admin', '有新的用户(id: <a href="/pages/user/user?id='.$uid.'">'.$uid.'</a>)对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报。');
- }
- }else if($type == 2){
- $app_report_safe_times_user = Settings::get('app_report_safe_times_user', 0);
- if($app_report_safe_times_user == 0){
- $app_report_safe_times_user = 999;
- }
- $the_user = WxUser::find($object_id);
- if(UserUtils::is_mini_admin($uid)){
- UserUtils::lock_user_incre($the_user, 3, 3600 * 24 * 7, '该用户被管理员举报');
- UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统禁言7天。');
- }else if($count_ > $app_report_safe_times_user){
- UserUtils::lock_user_incre($the_user, 3, 3600 * 24 * 7, '该用户被人多次举报');
- UserUtils::assistant_notice('admin', '多名用户对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统禁言7天。');
- }else{
- UserUtils::assistant_notice('admin', '有新的用户(id: <a href="/pages/user/user?id='.$uid.'">'.$uid.'</a>)对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报。');
- }
- }else if($type == 3){
- // 举报商品
- }else if($type == 4){
- // 举报圈子
- $app_report_safe_times_circle = Settings::get('app_report_safe_times_circle', 0);
- if($app_report_safe_times_circle == 0){
- $app_report_safe_times_circle = 999;
- }
- if(UserUtils::is_mini_admin($uid)){
- WxCircle::where('id', $object_id)->update(['circle_state'=>2]);
- UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动驳回。');
- }else if($count_ > $app_report_safe_times_circle){
- WxUser::where('id', $object_id)->update(['circle_state'=>2]);
- UserUtils::assistant_notice('admin', '多名用户对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动驳回。');
- }else{
- UserUtils::assistant_notice('admin', '有新的用户(id: <a href="/pages/user/user?id='.$uid.'">'.$uid.'</a>)对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报。');
- }
- }else if($type == 6){
- // 举报圈子
- $app_report_safe_times_voter = Settings::get('app_report_safe_times_voter', 0);
- if($app_report_safe_times_voter == 0){
- $app_report_safe_times_voter = 999;
- }
- if(UserUtils::is_mini_admin($uid)){
- WxVoter::where('id', $object_id)->update(['status'=>2]);
- UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动驳回。');
- }else if($count_ > $app_report_safe_times_voter){
- WxVoter::where('id', $object_id)->update(['status'=>2]);
- UserUtils::assistant_notice('admin', '多名用户对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动驳回。');
- }else{
- UserUtils::assistant_notice('admin', '有新的用户(id: <a href="/pages/user/user?id='.$uid.'">'.$uid.'</a>)对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报。');
- }
- }
- UserInputSafeCheckJob::dispatch($uid, $report_content);
- Utils::image_state_change($image_urls__, 1);
- return $this->success($r);
- }else{
- return $this->fail(200002);
- }
- }
- }
|