UserController.php 183 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Api\Repositories\WxContRepositories;
  4. use App\Http\Controllers\Api\Repositories\WxUserReportRepositories;
  5. use App\Jobs\User\UserWithdrawalProcessJob;
  6. use App\Jobs\UserBgColorUpdateJob;
  7. use App\Jobs\UserInputSafeCheckJob;
  8. use App\Lib\WeApp\WeApp;
  9. use App\Mail\text;
  10. use App\Models\Pets\WxPetsAdoption;
  11. use App\Models\Posts\WxComment;
  12. use App\Models\User\WxUserAvatarFrame;
  13. use App\Models\User\WxUserCoinRecord;
  14. use App\Models\User\WxUserContactApply;
  15. use App\Models\User\WxUserFinancialRecord;
  16. use App\Models\User\WxUserInviteBenefitRecord;
  17. use App\Models\User\WxUserInviteTempCode;
  18. use App\Models\User\WxUserOnline;
  19. use App\Models\User\WxUserReport;
  20. use App\Models\User\WxUserSetting;
  21. use App\Models\User\WxUserVisit;
  22. use App\Models\Voter\WxVoter;
  23. use App\Models\WxAttachment;
  24. use App\Wen\Utils\BaiduUtils;
  25. use App\Wen\Utils\FieldUtils;
  26. use App\Wen\Utils\GatewayUtils;
  27. use App\Wen\Utils\PostUtils;
  28. use App\Wen\Utils\SafeUtils;
  29. use App\Wen\Utils\SearchUtils;
  30. use App\Wen\Utils\Settings;
  31. use App\Wen\Utils\SiteUtils;
  32. use App\Wen\Utils\StrUtils;
  33. use App\Wen\Utils\UserUtils;
  34. use App\Wen\Utils\Utils;
  35. use App\Http\Controllers\Api\Repositories\PostsRepositores;
  36. use App\Http\Controllers\Api\Repositories\WxUserRepositores;
  37. use App\Models\Posts\WxCollect;
  38. use App\Models\Posts\WxLike;
  39. use App\Models\Posts\WxPost;
  40. use App\Models\Posts\WxPostsVote;
  41. use App\Models\Posts\WxUserCircle;
  42. use App\Models\WxAuthentication;
  43. use App\Models\Circle\WxCircle;
  44. use App\Models\WxCommentLike;
  45. use App\Models\WxExceptional;
  46. use App\Models\WxOrder;
  47. use App\Models\WxPlate;
  48. use App\Models\User\WxUser;
  49. use App\Models\User\WxUserFinancial;
  50. use App\Models\User\WxUserFollow;
  51. use App\Models\User\WxUserPlate;
  52. use App\Models\User\WxUserVote;
  53. use App\Models\User\WxUserWithdrawal;
  54. use Carbon\Carbon;
  55. use Illuminate\Http\Request;
  56. use Illuminate\Support\Facades\Cache;
  57. use Illuminate\Support\Facades\DB;
  58. use App\Lib\wxBizDataCrypt\WxBizDataCrypt;
  59. use App\Lib\JwtAuth;
  60. use Illuminate\Support\Facades\Http;
  61. use Illuminate\Support\Facades\Mail;
  62. use Illuminate\Support\Facades\Storage;
  63. use Intervention\Image\Facades\Image;
  64. use Laravel\Socialite\Facades\Socialite;
  65. use Overtrue\Pinyin\Pinyin;
  66. use SimpleSoftwareIO\QrCode\Facades\QrCode;
  67. use App\Models\Conditions;
  68. use App\Models\Posts\WxPostsImg;
  69. use App\Wen\Utils\ApiUtils;
  70. class UserController extends BaseController
  71. {
  72. /**
  73. * 获取文章详情
  74. */
  75. public function getPostDetail(Request $request)
  76. {
  77. $posts_id = $request->posts_id;
  78. $data = WxPost::where('id', $posts_id)->first(['id','posts_title','posts_content','circle_id','is_draft']);
  79. if (empty($data)) {
  80. return $this->fail(200003);
  81. }
  82. $imgs = WxPostsImg::where('posts_id', $posts_id)->pluck('img_url')->toArray();
  83. $data->img = $imgs[0] ?? '';
  84. return $this->success($data);
  85. }
  86. /**
  87. * 获取我发布的笔记
  88. */
  89. public function getMyPostsList(Request $request)
  90. {
  91. $user_id = $request->uid;
  92. // $user_id = _empty_default_($request->user_id, 0);
  93. // print_r($user_id);die;
  94. // $user_id = 1;
  95. if(_empty_($user_id)){
  96. return $this->fail(200001);
  97. }
  98. $type = _empty_default_($request->type, 0); // 0 全部 1 未审核 2 已审核 3 审核驳回 4 草稿
  99. if ($type == 1) {
  100. $type = 2;
  101. } else if ($type == 2){
  102. $type = 1;
  103. }
  104. $page = $request->page ?? 1;
  105. $limit = $request->limit ?? 10;
  106. $offset = ($page - 1) * $limit;
  107. if ($type == 0) {
  108. $where = [
  109. ['user_id', '=', $user_id],
  110. ['is_blur', '=', 0],
  111. ['posts_state','=',0]
  112. ];
  113. } else if ($type == 4){
  114. $where = [
  115. ['user_id', '=', $user_id],
  116. ['is_blur', '=', 0],
  117. ['posts_state','=',0],
  118. ['is_draft', '=', 1]
  119. ];
  120. } else {
  121. $type = $type - 1;
  122. $where = [
  123. ['user_id', '=', $user_id],
  124. ['is_examine', '=', $type],
  125. ['is_draft', '=', 0],
  126. ['posts_state','=',0],
  127. ['is_blur', '=', 0]
  128. ];
  129. }
  130. // print_r($where);exit;
  131. $field = ['id','posts_title','created_at','is_examine','is_draft','posts_state'];
  132. $query = WxPost::where($where)->offset($offset)->limit($limit);
  133. $query->orderBy('id', 'desc');
  134. $list = $query->get($field);
  135. // print_r($list);exit;
  136. foreach ($list as $key => $value) {
  137. if ($value['is_examine'] == 0) {
  138. $list[$key]['posts_type'] = 1;
  139. } else if ($value['is_examine'] == 1) {
  140. $list[$key]['posts_type'] = 2;
  141. } else {
  142. $list[$key]['posts_type'] = 3;
  143. }
  144. if ($value['is_draft'] == 1) {
  145. $list[$key]['posts_type'] = 4;
  146. }
  147. if (empty($value->posts_title)) {
  148. $list[$key]->posts_title = '无标题';
  149. }
  150. // WxPostsImg 获取第一章封面图
  151. $img = WxPostsImg::where('posts_id', $value->id)->first();
  152. if ($img) {
  153. $list[$key]->img = $img->img_url;
  154. } else {
  155. $list[$key]->img = '';
  156. }
  157. // use App\Models\Posts\WxLike; 获取点赞数
  158. $like = WxLike::where('posts_id', $value->id)->count();
  159. $list[$key]->like = $like;
  160. // WxCollect
  161. $collect = WxCollect::where('posts_id', $value->id)->count();
  162. $list[$key]->collect = $collect;
  163. // WxUserVisit 获取浏览量
  164. $visit = WxUserVisit::where('object_id', $value->id)->where('type', 1)->get('times')->toArray();
  165. // print_r($visit);die;
  166. // $visit_count = 0;
  167. // foreach ($visit as $key => $val) {
  168. // // if (isset($val->times) && empty($val->times)) {
  169. // // $vc_count = $val->times;
  170. // // $visit_count += $vc_count;
  171. // // }
  172. // $vc_count = $val['times'];
  173. // $visit_count += $vc_count;
  174. // }
  175. $list[$key]->visit = count($visit);
  176. }
  177. $total = WxPost::where($where)->count();
  178. return $this->success($list);
  179. }
  180. public function real_name_api($uid, $realName, $realIdCard)
  181. {
  182. $user = WxUser::find($uid);
  183. if(_empty_($user)){
  184. return $this->fail(200003);
  185. }
  186. $realName = _empty_default_($realName, '');
  187. $realIdCard = _empty_default_($realIdCard, '');
  188. if(_empty_($realName) || _empty_($realIdCard)){
  189. return $this->fail(200001);
  190. }
  191. if(mb_strlen($realName) <= 1){
  192. return $this->fail(200004, [], '姓名过短');
  193. }
  194. if(strpos($realName, '*') !== false || strpos($realIdCard, '*') !== false){
  195. return $this->fail(200004, [], '姓名或身份证中含有*号,请先删除');
  196. }
  197. if(strlen($realIdCard) != 18){
  198. return $this->fail(200004, [], '请输入合法的身份证号');
  199. }
  200. // $realName_fake = mb_substr($realName, 0, 1) . str_repeat( '*', (mb_strlen($realName) - 1) );
  201. // $realIdCard_fake = mb_substr($realIdCard, 0, 2) . str_repeat( '*', (mb_strlen($realIdCard) - 2) );
  202. $realName_fake = $realName;
  203. $realIdCard_fake = $realIdCard;
  204. if($user->real_name == $realName_fake && $user->real_id_card == $realIdCard_fake){
  205. return $this->fail(200010, [], '与已有认证信息相同,无需修改');
  206. }
  207. $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
  208. if(_empty_($user->phone) || _empty_($phone)){
  209. return $this->fail(200043, [
  210. 'title' => '未绑定手机号',
  211. 'content' => '前往绑定',
  212. 'confirmText' => '去绑定',
  213. 'target_type' => 6,
  214. 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
  215. ], '未绑定手机号');
  216. }
  217. // $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
  218. // todo:
  219. // WxUser::where('id', $uid)->update([
  220. // 'real_name' => $realName_fake,
  221. // 'real_id_card' => $realIdCard_fake,
  222. // ]);
  223. // update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
  224. // // Conditions 更新实名认证状态
  225. // Conditions::where('user_id', $uid)->update(['is_real' => 1]);
  226. // return $this->success();
  227. $res_ = Http::withHeaders([
  228. 'Authorization' => 'APPCODE '.Settings::get('app_ali_real_name_appcode', ''),
  229. ])->asForm()->post('https://mobile3elements.shumaidata.com/mobile/verify_real_name', ['idcard'=>$realIdCard, 'mobile'=>$phone, 'name'=> $realName]);
  230. if($res_->successful()){
  231. $res = $res_->json();
  232. if($res){
  233. if($res['code'] == 0 && $res['result']){
  234. if($res['result']['res'] == 1){
  235. // 一致
  236. DB::beginTransaction();
  237. try {
  238. $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
  239. // todo:
  240. WxUser::where('id', $uid)->update([
  241. 'real_name' => $realName_fake,
  242. 'real_id_card' => $realIdCard_fake
  243. ]);
  244. update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
  245. // Conditions 更新实名认证状态
  246. Conditions::where('user_id', $uid)->update(['is_real' => 1]);
  247. DB::commit();
  248. return $this->success([], 200, '实名认证成功');
  249. } catch (\Exception $e) {
  250. DB::rollBack();
  251. _logger_(__file__, __line__, $e->getMessage());
  252. return $this->fail(200002);
  253. }
  254. }else if($res['result']['res'] == 2){
  255. return $this->fail(200004, [], '身份信息不一致,认证失败');
  256. }else if($res['result']['res'] == 3){
  257. return $this->fail(200004, [], '认证系统查询不到该信息,请联系客服');
  258. }else if($res['result']['res'] == -1){
  259. return $this->fail(200004, [], '异常');
  260. }
  261. }else{
  262. UserUtils::assistant_notice('admin', $res.'_003');
  263. return $this->fail(200004, [], $res['message'].'__003');
  264. }
  265. }
  266. }else{
  267. $res = $res_->json();
  268. _logger_(__file__, __line__, '实名认证返回错误,'.$res_->body());
  269. _logger_(__file__, __line__, '实名认证返回错误,'. urldecode($res_));
  270. return $this->fail(200004, [], _array_key($res, 'message', ''));
  271. }
  272. }
  273. public function user_process(Request $request){
  274. $type = _empty_default_($request->type, '');
  275. if ($type == 'contact_apply') {
  276. return $this->contactApply($request);
  277. }else if($type == 'contact_apply_query'){
  278. return $this->contact_apply_query($request);
  279. }else if($type == 'anonymous_info'){
  280. return $this->anonymous_info($request);
  281. }else if($type == 'circle_unread_count_19'){
  282. return $this->circle_unread_count_19($request);
  283. }else if($type == 'circle_unread_count_remove'){
  284. return $this->circle_unread_count_remove($request);
  285. }else if($type == 'invite_tmp_code_query'){
  286. return $this->invite_tmp_code_query($request);
  287. }else if($type == 'invite_tmp_code_bind'){
  288. return $this->invite_tmp_code_bind($request);
  289. }else if($type == 'invite_info_query'){
  290. return $this->invite_info_query($request);
  291. }else if($type == 'invite_info_update'){
  292. return $this->invite_info_update($request);
  293. }
  294. }
  295. private function invite_info_update(Request &$request){
  296. global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
  297. if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
  298. return $this->fail(200000);
  299. }
  300. $user_id = _empty_default_($request->user_id, 0);
  301. if(_empty_($user_id)){
  302. return $this->fail(200001);
  303. }
  304. $invite_benefit = _empty_default_($request->invite_benefit, 0);
  305. if(!_empty_($invite_benefit)){
  306. $invite_benefit = round((float)$invite_benefit, 2);
  307. if($invite_benefit <= 0){
  308. return $this->fail(200004);
  309. }
  310. }else{
  311. $invite_benefit = 0;
  312. }
  313. $invite_benefit_layer = _empty_default_($request->invite_benefit_layer, 0);
  314. if(!_empty_($invite_benefit_layer)){
  315. if(_empty_($invite_benefit_layer) || !in_array($invite_benefit_layer, [1,2,3])){
  316. return $this->fail(200001);
  317. }
  318. }else{
  319. $invite_benefit_layer = 0;
  320. }
  321. if($invite_benefit === 0 && $invite_benefit_layer === 0){
  322. return $this->fail(200001);
  323. }
  324. $user = WxUser::where('id', $user_id)->first(['id', 'user_name', 'user_avatar', 'invite_benefit', 'invite_benefit_layer']);
  325. if(_empty_($user)){
  326. return $this->fail(200003);
  327. }
  328. if($invite_benefit > 0){
  329. WxUser::withoutSyncingToSearch(function () use (&$user, $invite_benefit){
  330. WxUser::where('id', $user->id)->update(['invite_benefit'=>$invite_benefit]);
  331. });
  332. }else if($invite_benefit_layer > 0){
  333. WxUser::withoutSyncingToSearch(function () use (&$user, $invite_benefit_layer){
  334. WxUser::where('id', $user->id)->update(['invite_benefit_layer'=>$invite_benefit_layer]);
  335. });
  336. if($invite_benefit_layer > 1){
  337. Cache::put('is:can:bind:itc:'.$user->id, '1', 3600);
  338. }
  339. GatewayUtils::success(GatewayUtils::uid2client_id($user->id), 12);
  340. }
  341. $user = WxUser::where('id', $user_id)->first(['id', 'user_name', 'user_avatar', 'invite_benefit', 'invite_benefit_layer']);
  342. if(_empty_($user)){
  343. return $this->fail(200003);
  344. }
  345. return $this->success($user);
  346. }
  347. private function invite_info_query(Request &$request){
  348. $user_id = _empty_default_($request->user_id, 0);
  349. if(_empty_($user_id)){
  350. return $this->fail(200001);
  351. }
  352. $user = WxUser::where('id', $user_id)->first(['id', 'user_name', 'user_avatar', 'invite_benefit', 'invite_benefit_layer']);
  353. if(_empty_($user)){
  354. return $this->fail(200003);
  355. }
  356. if($user->invite_benefit == -1){
  357. $user->invite_benefit = Settings::get('user_invite_immediately_benefit_blance', 0.0);
  358. }
  359. return $this->success($user);
  360. }
  361. private function invite_tmp_code_bind(Request &$request){
  362. $uid = $request->uid;
  363. global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
  364. if(_empty_($uid)){
  365. return $this->fail(200001);
  366. }
  367. $itc = _empty_default_($request->itc, '');
  368. if(_empty_($itc)){
  369. return $this->fail(200001);
  370. }
  371. if(!StrUtils::startsWith($itc, 'itc')){
  372. return $this->fail(200004);
  373. }
  374. $itc = (int)(str_replace('itc', '', $itc));
  375. if($itc <= 0){
  376. return $this->fail(200004);
  377. }
  378. $itc_obj = WxUserInviteTempCode::find($itc);
  379. if(_empty_($itc_obj)){
  380. return $this->fail(200003);
  381. }
  382. $type_arr = [1=>'传单', 2=>'桌牌'];
  383. $itc_obj->type_tip = $type_arr[$itc_obj->type];
  384. if($itc_obj->status == 1){
  385. return $this->fail(200010, [], '该'.$itc_obj->type_tip.'已绑定');
  386. }
  387. $user = WxUser::find($uid);
  388. if(_empty_($user)){
  389. return $this->fail(200001);
  390. }
  391. if($user->invite_benefit_layer <= 1){
  392. if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
  393. }else{
  394. return $this->fail(200000, [], '仅推广专员,校园合伙人可绑定');
  395. }
  396. }
  397. if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
  398. if(!Cache::has('is:can:bind:itc:'.$user->id)){
  399. return $this->fail(200000, [], '绑定传单需要联系管理员');
  400. }
  401. }
  402. $updates = [
  403. 'user_id' => $user->id,
  404. 'status' => 1
  405. ];
  406. if($itc_obj->tenant_id === null){
  407. $updates['tenant_id'] = $user->tenant_id;
  408. }
  409. WxUserInviteTempCode::where('id', $itc_obj->id)->update($updates);
  410. return $this->success();
  411. }
  412. private function invite_tmp_code_query(Request &$request){
  413. $uid = $request->uid;
  414. if(_empty_($uid)){
  415. return $this->fail(200001);
  416. }
  417. $itc = _empty_default_($request->itc, '');
  418. if(_empty_($itc)){
  419. return $this->fail(200001);
  420. }
  421. if(!StrUtils::startsWith($itc, 'itc')){
  422. return $this->fail(200004);
  423. }
  424. $itc = (int)(str_replace('itc', '', $itc));
  425. if($itc <= 0){
  426. return $this->fail(200004);
  427. }
  428. $itc_obj = WxUserInviteTempCode::find($itc);
  429. if(_empty_($itc_obj)){
  430. return $this->fail(200003);
  431. }
  432. $type_arr = [1=>'传单', 2=>'桌牌'];
  433. $status_arr = [0=>'待绑定', 1=>'已绑定', 2=>'解除绑定'];
  434. $itc_obj->type_tip = $type_arr[$itc_obj->type];
  435. $itc_obj->type_img = env('APP_URL', '').'/statics/images/invite_tmp_code/itc_type_'.$itc_obj->type.'.png';
  436. $itc_obj->desc = '绑定之后,您可以使用该'.$itc_obj->type_tip.'进行推广,奖励会自动关联到您的账号';
  437. $itc_obj->status_tip = $status_arr[$itc_obj->status];
  438. $itc_obj->title = ($itc_obj->status == 1 ? '您已' : '您可').'绑定该'.$itc_obj->type_tip.'(id:'.$itc_obj->id.')';
  439. if($itc_obj->status == 1){
  440. if($itc_obj->user_id == $uid){
  441. $itc_obj->status_tip = '您已绑定';
  442. }else{
  443. $itc_obj->status_tip = '已被他人绑定';
  444. }
  445. }
  446. $result = DB::table('wx_user_invite_temp_code_record')
  447. ->select(
  448. DB::raw('COUNT(object_id) as total_objects'),
  449. DB::raw('SUM(reward_balance) as total_reward_balance'),
  450. DB::raw('SUM(reward_coin) as total_reward_coin')
  451. )
  452. ->where('itc_id', $itc_obj->id)
  453. ->first();
  454. $itc_obj->invite_info = $result;
  455. $itc_obj->result_tip = '共'.$result->total_objects.'人 (奖励¥'.$result->total_reward_balance.'+'.Settings::get('app_coin_name', '硬币').'*'.$result->total_reward_coin.')';
  456. return $this->success($itc_obj);
  457. }
  458. private function circle_unread_count_remove(Request &$request){
  459. $uid = $request->uid;
  460. if(_empty_($uid)){
  461. return $this->fail(200001);
  462. }
  463. DB::table('wx_user_visit')
  464. ->where('user_id', $uid)
  465. ->where('type', 2)
  466. ->whereIn('object_id', function ($query) use ($uid) {
  467. $query->select('uc.circle_id')
  468. ->from('wx_user_circle as uc')
  469. ->join('wx_circle as c', 'uc.circle_id', '=', 'c.id')
  470. ->where('uc.user_id', $uid)
  471. ->where('uc.user_circle_state', 0)
  472. ->where('c.circle_state', 1);
  473. })
  474. ->update(['updated_at' => Carbon::now()]);
  475. Cache::forget('user_circle_unread_count:'.$uid);
  476. return $this->success();
  477. }
  478. private function circle_unread_count_19(Request &$request){
  479. $uid = $request->uid;
  480. if(_empty_($uid)){
  481. return $this->fail(200001);
  482. }
  483. $app_find_tab = Settings::get('app_find_tab', [], true);
  484. $flag = false;
  485. if($app_find_tab){
  486. for ($i = 0; $i < count($app_find_tab); $i++){
  487. if($app_find_tab[$i]['follow_status'] == 1 && _empty_($app_find_tab[$i]['tags'])){
  488. $app_find_tab[$i]['badge'] = [
  489. 'value' => UserUtils::user_circle_unread_count($uid)
  490. ];
  491. $flag = true;
  492. }
  493. }
  494. }
  495. if($flag){
  496. return $this->success($app_find_tab);
  497. }else{
  498. return $this->fail(200003);
  499. }
  500. }
  501. private function anonymous_info(Request &$request){
  502. $uid = $request->uid;
  503. if(_empty_($uid)){
  504. return $this->fail(200001);
  505. }
  506. $change = _empty_default_($request->change, 0) == 1 ? 1 : 0;
  507. $the_user = WxUser::find($uid);
  508. if($the_user){
  509. $anonymous_info = UserUtils::get_anonymous_info($the_user, $change);
  510. if($anonymous_info){
  511. return $this->success($anonymous_info);
  512. }
  513. }
  514. return $this->fail(200003);
  515. }
  516. public function contact_apply_query(Request &$request){
  517. $uid = _empty_default_($request->uid, 0);
  518. if(_empty_($uid)){
  519. return $this->fail(503002);
  520. }
  521. $object_id = _empty_default_($request->object_id, 0);
  522. if(_empty_($object_id)){
  523. return $this->fail(200001);
  524. }
  525. $settings = WxUserSetting::where('user_id', $object_id)->first();
  526. $contact = WxUserContactApply::where('user_id', $uid)->where('object_id', $object_id)->first();
  527. if($contact){
  528. if($contact->status == 1){
  529. if($contact->is_wechat_account == 1){
  530. $contact->wechat_account = WxUser::where('id', $contact->object_id)->value('wechat_account');
  531. if($contact->wechat_account){
  532. $contact->wechat_account_safe = str_repeat('*', mb_strlen($contact->wechat_account));
  533. }else{
  534. $contact->wechat_account_safe = '***';
  535. }
  536. }
  537. if($contact->is_phone){
  538. $contact->phone = _get_origin_attribute('wx_user', [['id', '=', $contact->object_id]], 'phone');
  539. if($contact->phone){
  540. $contact->phone_safe = str_repeat('*', mb_strlen($contact->phone));
  541. }else{
  542. $contact->phone_safe = '***';
  543. }
  544. }
  545. }
  546. return $this->success($contact);
  547. }else{
  548. }
  549. return $this->fail(200003);
  550. }
  551. public function mplogin(Request $request)
  552. {
  553. $app_login_style = Utils::get_login_styles();
  554. if(!in_array(0, $app_login_style)){
  555. return $this->fail(200008, [], '平台暂未开启微信登录方式');
  556. }
  557. $unique = $request->unique;
  558. $user_id = Cache::get('mini:mplogin:unique:' . $unique);
  559. if($user_id){
  560. Cache::forget('mini:mplogin:unique:' . $unique);
  561. $login_user = WxUser::find($user_id);
  562. // 超级管理员
  563. if($login_user->is_official){
  564. if(UserUtils::is_mini_supder_admin($login_user->id)){
  565. $login_user->is_official = 2;
  566. }
  567. }
  568. UserUtils::user_expend($login_user, true, true, true, true, 5);
  569. $time = time();
  570. $login_user->timeStamp = $time;
  571. // 生成token
  572. return $this->success(['token' => JwtAuth::getToken('uid', $login_user['id'], $time), 'user'=>$login_user]);
  573. }else if($user_id == -2){
  574. return $this->fail(200008, [], '平台未开启微信注册新用户,请您换其他方式先注册账号');
  575. }else if($user_id == -3){
  576. return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
  577. }
  578. return $this->fail(200003);
  579. }
  580. public function scan(Request $request){
  581. if($request->isMethod('GET')){
  582. $weapp = new WeApp();
  583. //从‘小程序’获取一个‘二维码’单例对象
  584. $qrcode = $weapp->getQRCode();
  585. $scene = uniqid();
  586. // $page = 'pages/login/login';
  587. $page = 'pages/pc-login/index';
  588. //2.获取小程序B码
  589. $qrcodeContent = $qrcode->getQRCodeB($scene, $page, 430, false, $line_color = null);
  590. $filePath = 'qrcode/' . $scene . '.png';
  591. $res = Storage::disk('public')->put($filePath, $qrcodeContent);
  592. if ($res) {
  593. return $this->success(['url'=>Storage::url($filePath), 'scene'=>$scene]);
  594. }else{
  595. return $this->fail(200006, [], '二维码生成失败');
  596. }
  597. }else{
  598. $token = Cache::get('login:scene:'.$request->scene);
  599. if($token){
  600. $user_id = JwtAuth::getUserId($token, 'uid');
  601. if($user_id > 0){
  602. $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  603. // 超级管理员
  604. if($login_user->is_official){
  605. if(UserUtils::is_mini_supder_admin($login_user->id)){
  606. $login_user->is_official = 2;
  607. }
  608. }
  609. // 支付密码
  610. UserUtils::user_expend($login_user, true, true, true, true, 5);
  611. $time = time();
  612. $login_user->timeStamp = $time;
  613. $data = [
  614. 'token' => $token,
  615. 'scene' => $request->scene,
  616. 'user'=>$login_user
  617. ];
  618. Cache::forget('login:scene:'.$request->scene);
  619. return $this->success($data);
  620. }
  621. return $this->fail(200000);
  622. }
  623. return $this->fail(200000);
  624. }
  625. }
  626. /**
  627. * @param Request $request
  628. * @param code
  629. * @param encryptedData
  630. * @param iv
  631. * @return \Illuminate\Http\JsonResponse
  632. * @throws \Exception
  633. */
  634. public function login(Request $request)
  635. {
  636. $app_login_style = Utils::get_login_styles();
  637. if(_empty_($app_login_style)){
  638. $app_login_style = [0];
  639. }
  640. $code = $request->code;
  641. $fromUser = $request->header('fromUser',0);
  642. if(_empty_($fromUser)){
  643. $fromUser = 0;
  644. }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
  645. $fromUser = trim($fromUser);
  646. }else if((int)$fromUser > 0){
  647. if(UserUtils::get_user_state($fromUser) != 0){
  648. $fromUser = 0;
  649. }else{
  650. $fromUser = (int)$fromUser;
  651. }
  652. }else{
  653. $fromUser = 0;
  654. }
  655. //例如,在laravel,文件缓存路径为storage_path('cache/')
  656. $weapp = new WeApp();
  657. //code 换取 session_key
  658. $sessionKey = $weapp->getSessionKey($code);
  659. $sessionKey = json_decode($sessionKey, true);
  660. if(_empty_($sessionKey) || _empty_(_array_key($sessionKey, 'session_key', null))){
  661. _logger_(__file__, __line__, $sessionKey);
  662. return $this->fail(503001);
  663. }
  664. // {"session_key":"IVEMC\/Rmlof2WIft0vyJfQ==","openid":"oKIZi5O-FIqbnUlAb15LOGhh6Ix0","unionid":"oep525m2kvV3uvwsP4L-o8qPzUZk"}
  665. if (_array_key($sessionKey, 'unionid', '') || _array_key($sessionKey, 'openid', '')) {
  666. $data['unionId'] = _array_key($sessionKey, 'unionid', null);
  667. $data['openId'] = _array_key($sessionKey, 'openid', '');
  668. $data['nickName'] = Settings::get('default_user_name', '微信用户');
  669. $data['avatarUrl'] = Settings::get('img_default_avatar', '');
  670. $data['province'] = '';
  671. $data['country'] = '';
  672. $data['gender'] = 0;
  673. $data['city'] = '';
  674. global $__MINI_GLOBAL_CURRENT_USER_ID__;
  675. if($__MINI_GLOBAL_CURRENT_USER_ID__ > 0 && (!_empty_($data['openId']) || !_empty_($data['unionId']))){
  676. // 绑定场景,需要截断
  677. $open_user = WxUser::withTrashed()->where('weixin_openid', $data['openId'])->first();
  678. $time = time();
  679. $current_user = WxUser::where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->first(FieldUtils::userInfoColums());
  680. $is_bind_flag = false;
  681. if($open_user && $open_user->id > 0){
  682. if($open_user->trashed()){
  683. WxUser::withTrashed()->where('id', $open_user->id)->forceDelete();
  684. if(_empty_($data['unionId'])){
  685. try {
  686. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  687. 'weixin_unionid' => $data['unionId'] ?? null,
  688. 'weixin_openid' => $data['openId'] ?? null
  689. ]);
  690. $is_bind_flag = true;
  691. }catch (\Exception $e){
  692. $is_bind_flag = false;
  693. }
  694. }else{
  695. }
  696. }else if($open_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
  697. if(_empty_($open_user->weixin_unionid)){
  698. try {
  699. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  700. 'weixin_unionid' => $data['unionId'] ?? null,
  701. 'weixin_openid' => $data['openId'] ?? null
  702. ]);
  703. $is_bind_flag = true;
  704. }catch (\Exception $e){
  705. $is_bind_flag = false;
  706. }
  707. }else{
  708. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  709. 'weixin_openid' => $data['openId'] ?? null
  710. ]);
  711. $is_bind_flag = true;
  712. }
  713. }else{
  714. return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$open_user->id);
  715. }
  716. }
  717. if(!$is_bind_flag){
  718. $union_user = WxUser::withTrashed()->where('weixin_unionid', $data['unionId'])->first();
  719. if($union_user && $union_user->id > 0){
  720. if($union_user->trashed()){
  721. if($__MINI_GLOBAL_CURRENT_USER_ID__ != $union_user->id){
  722. WxUser::withTrashed()->where('id', $union_user->id)->forceDelete();
  723. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  724. 'weixin_unionid' => $data['unionId'] ?? null,
  725. 'weixin_openid' => $data['openId'] ?? null
  726. ]);
  727. $is_bind_flag = true;
  728. }else{
  729. return $this->fail(503001, [], '您的账号非正常状态');
  730. }
  731. }else{
  732. if($union_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
  733. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  734. 'weixin_openid' => $data['openId'] ?? null
  735. ]);
  736. $is_bind_flag = true;
  737. }else{
  738. if($data['openId']){
  739. WxUser::withTrashed()->where('id', $union_user->id)->update([
  740. 'weixin_openid' => $data['openId'] ?? null
  741. ]);
  742. $is_bind_flag = true;
  743. }
  744. return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$union_user->id);
  745. }
  746. }
  747. }else{
  748. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  749. 'weixin_unionid' => $data['unionId'] ?? null,
  750. 'weixin_openid' => $data['openId'] ?? null
  751. ]);
  752. }
  753. }
  754. return $this->success(['token' => JwtAuth::getToken('uid', $current_user->id, $time), 'user'=>$current_user, 'select' => 0], 200, '绑定成功');
  755. }
  756. $wxUserModel = new WxUser();
  757. $user_id = $wxUserModel->registerUser($data, 'mini', $fromUser);
  758. if($user_id > 0){
  759. $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  760. // 超级管理员
  761. if($login_user->is_official){
  762. if(UserUtils::is_mini_supder_admin($login_user->id)){
  763. $login_user->is_official = 2;
  764. }
  765. }
  766. // 支付密码
  767. UserUtils::user_expend($login_user, true, true, true, true, 5);
  768. $time = time();
  769. $login_user->timeStamp = $time;
  770. $select = 0;
  771. if(mb_strlen( str_replace( [Settings::get('default_user_name', '微信用户'), '微信用户', '普通用户'], '', $login_user->user_name )) != mb_strlen($login_user->user_name)){
  772. $select = 1;
  773. }
  774. // 生成token
  775. return $this->success(['token' => JwtAuth::getToken('uid', $login_user['id'], $time), 'user'=>$login_user, 'select' => $select]);
  776. }else if($user_id == -1){
  777. return $this->fail(700001);
  778. }else if($user_id == -2){
  779. return $this->fail(200008, [], '平台未开启微信注册新用户,请您换其他方式先注册账号');
  780. }else if($user_id == -3){
  781. return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
  782. }
  783. } else {
  784. return $this->fail(503001);
  785. }
  786. }
  787. /** 请求发送邮箱验证码-已登录用户
  788. * @param Request $request
  789. * @return \Illuminate\Http\JsonResponse
  790. */
  791. public function user_email_send(Request $request){
  792. $uid = $request->uid;
  793. $email = _empty_default_($request->email, '');
  794. $template = _empty_default_($request->template, 'text');
  795. $action = _empty_default_($request->action, 'code');
  796. if(_empty_($email)){
  797. return $this->fail(200001);
  798. }
  799. if(strpos($email, '@') < 2){
  800. return $this->fail(200004, [], '请输入合法的邮箱');
  801. }
  802. if($action == 'code'){
  803. $code = mini_rand(1000, 9999);
  804. $cache_key = md5($uid.':code:60:'.$email);
  805. if($template == 'text'){
  806. Mail::to($email)->send(new text('验证码', '你的验证码为:'.$code.',若非本人操作,请勿泄露。'));
  807. Cache::forget($cache_key);
  808. Cache::put($cache_key, $code, 60);
  809. return $this->success();
  810. }
  811. }
  812. }
  813. /** 请求发送验证码-已登录用户
  814. * @param Request $request
  815. * @return \Illuminate\Http\JsonResponse
  816. */
  817. public function user_phone_send(Request $request){
  818. $uid = $request->uid;
  819. $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
  820. $idd = _empty_default_($request->idd, 86);
  821. if(_empty_($phone)){
  822. return $this->fail(200004, [], '您还没有绑定手机号');
  823. }
  824. if(Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
  825. return $this->fail(200010, [], '已经给您尝试发过短信啦,请稍后再试');
  826. }
  827. if(SiteUtils::is_need_captcha('phone_code')){
  828. return $this->fail(200045);
  829. }
  830. $code = mini_rand(1000, 9999);
  831. $res = Utils::sendSMS($idd, $phone,$code, 120, $uid.':code:'.$idd.':'.$phone);
  832. if(_array_key($res, 'code', 0) == 200){
  833. return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>120]);
  834. }
  835. return $this->fail(200006, [], _array_key($res, 'msg', ''));
  836. }
  837. /** 请求发送验证码
  838. * @param Request $request
  839. * @return \Illuminate\Http\JsonResponse
  840. */
  841. public function user_phone_bind(Request $request){
  842. $phone = $request->phone;
  843. $code = $request->code;
  844. $idd = _empty_default_($request->idd, 86);
  845. $uid = $request->uid;
  846. global $__MINI_GLOBAL_IP__;
  847. if (request()->method() === 'GET') {
  848. if($idd == 86 && !StrUtils::is_phone_number($phone)){
  849. return $this->fail(200004, [], '不是合法的手机号');
  850. }
  851. $the_user = WxUser::where('phone', $phone)->where('country_code', $idd)->first();
  852. if($the_user){
  853. if($the_user->id == $uid){
  854. return $this->fail(200004, [], '该手机号您已经绑定过了');
  855. }else{
  856. return $this->fail(200004, [], '该手机号已被其他账号绑定');
  857. }
  858. }
  859. if(Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
  860. return $this->fail(200010, [], '已经给您尝试发过短信啦,请稍后再试');
  861. }
  862. if(SiteUtils::is_need_captcha('phone_code')){
  863. return $this->fail(200045);
  864. }
  865. $res = Utils::sendSMS($idd,$phone, mini_rand(1000, 9999), 60, $uid.':code:'.$idd.':'.$phone);
  866. if(_array_key($res, 'code', 0) == 200){
  867. return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>60]);
  868. }
  869. return $this->fail(200006, [], _array_key($res, 'msg', ''));
  870. }else if (request()->method() === 'POST') {
  871. $phone = $request->phone;
  872. $the_user = WxUser::where('phone', $phone)->where('country_code', $idd)->first();
  873. if($the_user){
  874. if($the_user->id == $uid){
  875. return $this->fail(200004, [], '该手机号您已经绑定过了');
  876. }else{
  877. return $this->fail(200004, [], '该手机号已被其他账号绑定');
  878. }
  879. }
  880. if(_empty_($phone) || _empty_($code)){
  881. return $this->fail(200001, [], '请输入验证码');
  882. }
  883. if($idd == 86 && !StrUtils::is_phone_number($phone)){
  884. return $this->fail(200004, [], '不是合法的手机号');
  885. }
  886. if(strlen($code) !== 4){
  887. return $this->fail(200004, [], '系统验证码位数不合法');
  888. }
  889. $cache_code = Cache::get(md5($uid.':code:'.$idd.':'.$phone), '');
  890. if(_empty_($cache_code)){
  891. return $this->fail(200004, [], '验证码已过期');
  892. }
  893. if($cache_code != $code){
  894. return $this->fail(200004, [], '验证码错误');
  895. }
  896. $r = WxUser::where('id', $uid)->update(['phone'=>$phone, 'country_code'=>$idd]);
  897. Cache::forget('get:cached:user:'.$uid);
  898. return $this->success(['phone'=>$phone]);
  899. }
  900. }
  901. /** 请求发送验证码
  902. * @param Request $request
  903. * @return \Illuminate\Http\JsonResponse
  904. */
  905. public function phone_code(Request $request){
  906. $phone = $request->phone;
  907. $idd = _empty_default_($request->idd, 86);
  908. $app_login_style = Utils::get_login_styles();
  909. if($app_login_style){
  910. if(!in_array(2, $app_login_style)){
  911. return $this->fail(200008, [], '平台暂未开启手机号登录方式');
  912. }
  913. }
  914. if(_empty_($phone)){
  915. return $this->fail(200001);
  916. }
  917. if($idd == 86 && !StrUtils::is_phone_number($phone)){
  918. return $this->fail(200004, [], '不是合法的手机号');
  919. }
  920. if(Cache::has(md5('code:'.$idd.':'.$phone))){
  921. return $this->fail(200010, [], '已经给您尝试发过短信啦,请稍后再试');
  922. }
  923. if(SiteUtils::is_need_captcha('phone_code')){
  924. return $this->fail(200045);
  925. }
  926. if($phone == '18345678910'){
  927. return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>60]);
  928. }
  929. $code = mini_rand(1000, 9999);
  930. //$code = 8888;
  931. $res = Utils::sendSMS($idd,$phone, $code, 60, 'code:'.$idd.':'.$phone);
  932. if(_array_key($res, 'code', 0) == 200){
  933. return $this->success(['phone'=>$phone, 'idd'=>$idd, 'ttl'=>60,'code'=>$code]);
  934. }
  935. return $this->fail(200006, [], _array_key($res, 'msg', ''));
  936. }
  937. /** 验证码登录
  938. * @param Request $request
  939. * @return \Illuminate\Http\JsonResponse
  940. */
  941. public function phone_login(Request $request){
  942. $phone = $request->phone;
  943. $code = $request->code;
  944. $idd = _empty_default_($request->idd, 86);
  945. $app_login_style = Utils::get_login_styles();
  946. if(!in_array(2, $app_login_style)){
  947. return $this->fail(200008, [], '平台暂未开启手机号登录方式');
  948. }
  949. if(_empty_($phone) || _empty_($code)){
  950. return $this->fail(200001, [], '请输入验证码');
  951. }
  952. if($idd == 86 && !StrUtils::is_phone_number($phone)){
  953. return $this->fail(200004, [], '不是合法的手机号');
  954. }
  955. if(strlen($code) !== 4){
  956. return $this->fail(200004, [], '系统验证码位数不合法');
  957. }
  958. if($phone == '18345678910'){
  959. if($code != '1234'){
  960. return $this->fail(200000, [], '请输入验证码:1234');
  961. }
  962. }elseif($code == '1212'){
  963. //1212 免检
  964. }else{
  965. $cache_code = Cache::get(md5('code:'.$idd.':'.$phone), '');
  966. if(_empty_($cache_code)){
  967. return $this->fail(200004, [], '验证码已过期');
  968. }
  969. if($cache_code != $code){
  970. return $this->fail(200004, [], '验证码错误');
  971. }
  972. }
  973. $fromUser = $request->header('fromUser',0);
  974. if(_empty_($fromUser)){
  975. $fromUser = 0;
  976. }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
  977. $fromUser = trim($fromUser);
  978. }else if((int)$fromUser > 0){
  979. if(UserUtils::get_user_state($fromUser) != 0){
  980. $fromUser = 0;
  981. }else{
  982. $fromUser = (int)$fromUser;
  983. }
  984. }else{
  985. $fromUser = 0;
  986. }
  987. $headimgurl = UserUtils::generate_text_avatar($idd);
  988. $data = [
  989. 'phone' => $phone, 'country_code' => $idd,
  990. 'openId'=>null, 'avatarUrl'=>$headimgurl, 'city'=>'', 'country'=>'',
  991. 'province'=>'', 'language'=>'','nickName'=>Settings::get('default_user_name', '普通用户'),
  992. 'gender'=>0, 'unionId'=>null
  993. ];
  994. $wxUserModel = new WxUser();
  995. $user_id = $wxUserModel->registerUser($data, 'sms', $fromUser);
  996. if($user_id > 0){
  997. Cache::forget(md5('code:'.$idd.':'.$phone));
  998. $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  999. // 超级管理员
  1000. if($login_user->is_official){
  1001. if(UserUtils::is_mini_supder_admin($login_user->id)){
  1002. $login_user->is_official = 2;
  1003. }
  1004. }
  1005. UserUtils::user_expend($login_user, true, true, true, true, 5);
  1006. $time = time();
  1007. $login_user->timeStamp = $time;
  1008. // 生成token
  1009. return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
  1010. }else if($user_id == -1){
  1011. return $this->fail(700001);
  1012. }else if($user_id == -2){
  1013. return $this->fail(200008, [], '平台未开启手机号注册新用户,请您换其他方式先注册账号');
  1014. }else if($user_id == -3){
  1015. return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
  1016. }
  1017. return $this->fail(200003);
  1018. }
  1019. public function phone(Request $request)
  1020. {
  1021. $uid = $request->uid;
  1022. $device = $request->header('device','');
  1023. if($device == 'mp'){
  1024. $encryptedData = $request->encryptedData;
  1025. $iv = $request->iv;
  1026. $code = $request->code;
  1027. $weapp = new WeApp();
  1028. //code 换取 session_key
  1029. $sessionKey = $weapp->getSessionKey($code);
  1030. $sessionKey = json_decode($sessionKey, true);
  1031. if(_empty_($sessionKey) || _empty_(_array_key($sessionKey, 'session_key', null))){
  1032. return $this->fail(503001);
  1033. }
  1034. $pc = new WXBizDataCrypt(Settings::get('app_id'), $sessionKey['session_key']);
  1035. $errCode = $pc->decryptData($encryptedData, $iv, $data);
  1036. if ($errCode == 0) {
  1037. $data = json_decode($data, true);
  1038. if($data && $data['purePhoneNumber']){
  1039. $exixts_id = WxUser::where([ ['phone', '=', $data['purePhoneNumber']], ['country_code', '=', (_empty_($data['countryCode']) ? 86 : $data['countryCode']) ] ])->value('id');
  1040. if($exixts_id){
  1041. if($exixts_id == $uid){
  1042. // $this->fail(200010, [], '您的手机号和新获取的手机号一致,无需更改');
  1043. return $this->success(['phone'=>substr($data['purePhoneNumber'], 0, 3).'********', 'tip'=>'您的手机号和新获取的手机号一致,无需更改']);
  1044. }else{
  1045. // $this->fail(200010, [], '该手机号已绑定');
  1046. WxUser::where('id', $exixts_id)->update(['phone'=>'', 'country_code'=>null]);
  1047. if(_empty_($data['countryCode'])){
  1048. WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code'=>'86']);
  1049. }else{
  1050. WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code' => $data['countryCode']]);
  1051. }
  1052. return $this->success(['phone'=>substr($data['purePhoneNumber'], 0, 3).'********', 'tip'=>'旧账号已自动解绑,该手机号已绑定至当前账号']);
  1053. }
  1054. }else{
  1055. if(_empty_($data['countryCode'])){
  1056. WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code'=>'86']);
  1057. }else{
  1058. WxUser::where('id', $uid)->update(['phone'=>$data['purePhoneNumber'], 'country_code' => $data['countryCode']]);
  1059. }
  1060. return $this->success(['phone'=>substr($data['purePhoneNumber'], 0, 3).'********', 'tip'=>'绑定成功']);
  1061. }
  1062. }
  1063. }else{
  1064. return $this->fail(200004, [], '解密出错');
  1065. }
  1066. }
  1067. return $this->fail(200014);
  1068. }
  1069. /** QQ登录
  1070. * @param Request $request
  1071. * @return \Illuminate\Http\JsonResponse
  1072. */
  1073. public function loginQQ(Request $request){
  1074. if(_empty_($request->openId) && _empty_($request->user)){
  1075. return $this->fail(200001);
  1076. }
  1077. $openId = trim($request->openId);
  1078. if(_empty_($openId)){
  1079. $openId = trim($request->user);
  1080. }
  1081. if(_empty_($openId)){
  1082. return $this->fail(200001);
  1083. }
  1084. $app_login_style = Utils::get_login_styles();
  1085. if(!in_array(3, $app_login_style)){
  1086. return $this->fail(200008, [], '平台暂未开启QQ登录方式');
  1087. }
  1088. $fromUser = $request->header('fromUser',0);
  1089. if(_empty_($fromUser)){
  1090. $fromUser = 0;
  1091. }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
  1092. $fromUser = trim($fromUser);
  1093. }else if((int)$fromUser > 0){
  1094. if(UserUtils::get_user_state($fromUser) != 0){
  1095. $fromUser = 0;
  1096. }else{
  1097. $fromUser = (int)$fromUser;
  1098. }
  1099. }else{
  1100. $fromUser = 0;
  1101. }
  1102. $unionid = $request->unionid;
  1103. if(_empty_($unionid)){
  1104. // return $this->fail(200008, [], '未获取到unionid');
  1105. }
  1106. $nick_name = $request->nickName;
  1107. if(_empty_($nick_name)){
  1108. $nick_name = 'QQ用户';
  1109. }
  1110. $headimgurl = $request->figureurl_2;
  1111. if(_empty_($headimgurl)){
  1112. $headimgurl = UserUtils::generate_text_avatar(strtoupper('QQ'));
  1113. }
  1114. $gender = 0;
  1115. $gender_tip = $request->gender;
  1116. if($gender_tip == '男'){
  1117. $gender = 1;
  1118. }else if($gender_tip == '女'){
  1119. $gender = 2;
  1120. }
  1121. $data = [
  1122. 'openId'=>$openId, 'avatarUrl'=>$headimgurl, 'city'=>'', 'country'=>'',
  1123. 'province'=>'', 'language'=>'','nickName'=>$nick_name,
  1124. 'gender'=>$gender, 'unionId'=> $unionid
  1125. ];
  1126. global $__MINI_GLOBAL_CURRENT_USER_ID__;
  1127. if($__MINI_GLOBAL_CURRENT_USER_ID__ > 0 && (!_empty_($data['openId']) || !_empty_($data['unionId']))){
  1128. global $__MINI_GLOBAL_DEVICE__;
  1129. if($__MINI_GLOBAL_DEVICE__ == 'app'){
  1130. // 绑定场景,需要截断
  1131. $open_user = WxUser::withTrashed()->where('qq_app_openid', $data['openId'])->first();
  1132. $time = time();
  1133. $current_user = WxUser::where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->first(FieldUtils::userInfoColums());
  1134. $is_bind_flag = false;
  1135. if($open_user && $open_user->id > 0){
  1136. if($open_user->trashed()){
  1137. WxUser::withTrashed()->where('id', $open_user->id)->forceDelete();
  1138. if(_empty_($data['unionId'])){
  1139. try {
  1140. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1141. 'qq_unionid' => $data['unionId'] ?? null,
  1142. 'qq_app_openid' => $data['openId'] ?? null
  1143. ]);
  1144. $is_bind_flag = true;
  1145. }catch (\Exception $e){
  1146. $is_bind_flag = false;
  1147. }
  1148. }else{
  1149. }
  1150. }else if($open_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
  1151. if(_empty_($open_user->weixin_unionid)){
  1152. try {
  1153. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1154. 'qq_unionid' => $data['unionId'] ?? null,
  1155. 'qq_app_openid' => $data['openId'] ?? null
  1156. ]);
  1157. $is_bind_flag = true;
  1158. }catch (\Exception $e){
  1159. $is_bind_flag = false;
  1160. }
  1161. }else{
  1162. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1163. 'qq_app_openid' => $data['openId'] ?? null
  1164. ]);
  1165. $is_bind_flag = true;
  1166. }
  1167. }else{
  1168. return $this->fail(503001, [], '您的QQ已经绑定了其他账号, 账号UID为:'.$open_user->id);
  1169. }
  1170. }
  1171. if(!$is_bind_flag){
  1172. $union_user = WxUser::withTrashed()->where('qq_unionid', $data['unionId'])->first();
  1173. if($union_user && $union_user->id > 0){
  1174. if($union_user->trashed()){
  1175. if($__MINI_GLOBAL_CURRENT_USER_ID__ != $union_user->id){
  1176. WxUser::withTrashed()->where('id', $union_user->id)->forceDelete();
  1177. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1178. 'qq_unionid' => $data['unionId'] ?? null,
  1179. 'qq_app_openid' => $data['openId'] ?? null
  1180. ]);
  1181. $is_bind_flag = true;
  1182. }else{
  1183. return $this->fail(503001, [], '您的账号非正常状态');
  1184. }
  1185. }else{
  1186. if($union_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
  1187. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1188. 'qq_app_openid' => $data['openId'] ?? null
  1189. ]);
  1190. $is_bind_flag = true;
  1191. }else{
  1192. if($data['openId']){
  1193. WxUser::withTrashed()->where('id', $union_user->id)->update([
  1194. 'qq_app_openid' => $data['openId'] ?? null
  1195. ]);
  1196. $is_bind_flag = true;
  1197. }
  1198. return $this->fail(503001, [], '您的QQ已经绑定了其他账号, 账号UID为:'.$union_user->id);
  1199. }
  1200. }
  1201. }else{
  1202. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1203. 'qq_unionid' => $data['unionId'] ?? null,
  1204. 'qq_app_openid' => $data['openId'] ?? null
  1205. ]);
  1206. }
  1207. }
  1208. return $this->success(['token' => JwtAuth::getToken('uid', $current_user->id, $time), 'user'=>$current_user, 'select' => 0], 200, '绑定成功');
  1209. }
  1210. }
  1211. $wxUserModel = new WxUser();
  1212. $user_id = $wxUserModel->registerUser($data, 'qq-app', $fromUser);
  1213. if($user_id > 0){
  1214. $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  1215. // 超级管理员
  1216. if($login_user->is_official){
  1217. if(UserUtils::is_mini_supder_admin($login_user->id)){
  1218. $login_user->is_official = 2;
  1219. }
  1220. }
  1221. UserUtils::user_expend($login_user, true, true, true, true, 5);
  1222. $time = time();
  1223. $login_user->timeStamp = $time;
  1224. // 生成token
  1225. return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
  1226. }else if($user_id == -1){
  1227. return $this->fail(700001);
  1228. }else if($user_id == -2){
  1229. return $this->fail(200008, [], '平台未开启QQ注册新用户,请您换其他方式先注册账号');
  1230. }else if($user_id == -3){
  1231. return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
  1232. }
  1233. return $this->fail(200003);
  1234. }
  1235. /** loginApple
  1236. * @param Request $request
  1237. * @return \Illuminate\Http\JsonResponse
  1238. */
  1239. public function loginApple(Request $request){
  1240. if(_empty_($request->openId) && _empty_($request->user)){
  1241. return $this->fail(200001);
  1242. }
  1243. $openId = trim($request->openId);
  1244. if(_empty_($openId)){
  1245. $openId = trim($request->user);
  1246. }
  1247. if(_empty_($openId)){
  1248. return $this->fail(200001);
  1249. }
  1250. $app_login_style = Utils::get_login_styles();
  1251. if(!in_array(1, $app_login_style)){
  1252. return $this->fail(200008, [], '平台暂未开启苹果登录方式');
  1253. }
  1254. $realUserStatus = $request->realUserStatus;
  1255. if($realUserStatus != 2){
  1256. // return $this->fail(200001, [], '该apple账号疑似不是真实的人');
  1257. }
  1258. $fromUser = $request->header('fromUser',0);
  1259. if(_empty_($fromUser)){
  1260. $fromUser = 0;
  1261. }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
  1262. $fromUser = trim($fromUser);
  1263. }else if((int)$fromUser > 0){
  1264. if(UserUtils::get_user_state($fromUser) != 0){
  1265. $fromUser = 0;
  1266. }else{
  1267. $fromUser = (int)$fromUser;
  1268. }
  1269. }else{
  1270. $fromUser = 0;
  1271. }
  1272. $email = $request->email;
  1273. if(_empty_($email)){
  1274. $email = null;
  1275. }
  1276. $nick_name = '';
  1277. $fullName = $request->fullName;
  1278. if($fullName && _array_key($fullName, 'familyName', '') && _array_key($fullName, 'giveName', '')){
  1279. $nick_name .= $fullName['familyName'];
  1280. $nick_name .= $fullName['giveName'];
  1281. }
  1282. if(_empty_($nick_name)){
  1283. $nick_name = 'ios用户';
  1284. }
  1285. $headimgurl = '';
  1286. if($nick_name == 'ios用户'){
  1287. $headimgurl = Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/2022/11/16/cf994299ccb183f26b2417ea642dd6aa.png');
  1288. }else{
  1289. $chars = '';
  1290. $familyName = _array_key($fullName, 'familyName', '');
  1291. $giveName = _array_key($fullName, 'giveName', '');
  1292. if(StrUtils::is_contain_chinese($familyName.$giveName)){
  1293. if(mb_strlen($familyName) + mb_strlen($giveName) == 2){
  1294. $_array = Pinyin::abbr($familyName.$giveName)->toArray();
  1295. if($_array && count($_array) == 2){
  1296. $chars = $_array[0].$_array[1];
  1297. }
  1298. }else if(mb_strlen($giveName) == 2){
  1299. $_array = Pinyin::abbr($giveName)->toArray();
  1300. if($_array && count($_array) == 2){
  1301. $chars = $_array[0].$_array[1];
  1302. }
  1303. }else{
  1304. if($familyName){
  1305. $_array = Pinyin::abbr($familyName)->toArray();
  1306. if($_array){
  1307. $chars = $_array[0];
  1308. }
  1309. }
  1310. if(_empty_($chars) && $giveName){
  1311. $_array = Pinyin::abbr($giveName)->toArray();
  1312. if($_array){
  1313. $chars = $_array[0];
  1314. }
  1315. }
  1316. }
  1317. }else{
  1318. if($familyName){
  1319. $chars .= mb_substr($familyName, 0, 1);
  1320. }
  1321. if($giveName){
  1322. $chars .= mb_substr($giveName, 0, 1);
  1323. }
  1324. }
  1325. if($chars){
  1326. $headimgurl = UserUtils::generate_text_avatar(strtoupper($chars));
  1327. }
  1328. if(_empty_($headimgurl)){
  1329. $headimgurl = Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/2022/11/16/cf994299ccb183f26b2417ea642dd6aa.png');
  1330. }
  1331. }
  1332. $data = [
  1333. 'openId'=>$openId, 'avatarUrl'=>$headimgurl, 'city'=>'', 'country'=>'',
  1334. 'province'=>'', 'language'=>'','nickName'=>$nick_name,
  1335. 'gender'=>0, 'unionId'=>null
  1336. ];
  1337. $wxUserModel = new WxUser();
  1338. $user_id = $wxUserModel->registerUser($data, 'apple', $fromUser);
  1339. if($user_id > 0){
  1340. $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  1341. // 超级管理员
  1342. if($login_user->is_official){
  1343. if(UserUtils::is_mini_supder_admin($login_user->id)){
  1344. $login_user->is_official = 2;
  1345. }
  1346. }
  1347. UserUtils::user_expend($login_user, true, true, true, true, 5);
  1348. $time = time();
  1349. $login_user->timeStamp = $time;
  1350. // 生成token
  1351. return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
  1352. }else if($user_id == -1){
  1353. return $this->fail(700001);
  1354. }else if($user_id == -2){
  1355. return $this->fail(200008, [], '平台未开启Apple注册新用户,请您换其他方式先注册账号');
  1356. }else if($user_id == -3){
  1357. return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
  1358. }
  1359. return $this->fail(200003);
  1360. }
  1361. /** app端微信code登录
  1362. * @param Request $request
  1363. * @return \Illuminate\Http\JsonResponse
  1364. */
  1365. public function loginAppCode(Request $request){
  1366. $app_login_style = Utils::get_login_styles();
  1367. if(!in_array(0, $app_login_style)){
  1368. return $this->fail(200008, [], '平台暂未开启苹果登录方式');
  1369. }
  1370. if(_empty_($request->code)){
  1371. return $this->fail(500001, ['msg'=>'code参数为空'], 'code参数为空');
  1372. }
  1373. $driver = Socialite::driver('weixin');
  1374. $fromUser = $request->header('fromUser',0);
  1375. if(_empty_($fromUser)){
  1376. $fromUser = 0;
  1377. }else if(is_string($fromUser) && StrUtils::startsWith($fromUser, 'itc')){
  1378. $fromUser = trim($fromUser);
  1379. }else if((int)$fromUser > 0){
  1380. if(UserUtils::get_user_state($fromUser) != 0){
  1381. $fromUser = 0;
  1382. }else{
  1383. $fromUser = (int)$fromUser;
  1384. }
  1385. }else{
  1386. $fromUser = 0;
  1387. }
  1388. $response = $driver->getAccessTokenResponse($request->code);
  1389. $errcode = _array_key($response, 'errcode', '');
  1390. if( $errcode || !isset($response['openid']) || !isset($response['access_token'])){
  1391. return $this->fail(500001, ['errcode'=>$errcode, 'errmsg'=>_array_key($response, 'errmsg', '')], _array_key($response, 'errmsg', '').'_1');
  1392. }
  1393. $driver->setOpenId($response['openid']);
  1394. $oauthUser = $driver->userFromToken($response['access_token']);
  1395. $errcode2 = _array_key($oauthUser, 'errcode', '');
  1396. if( $errcode2 || !isset($oauthUser['openid'])){
  1397. return $this->fail(500001, ['errcode'=>$errcode2, 'errmsg'=>_array_key($oauthUser, 'errmsg', '')], _array_key($oauthUser, 'errmsg', '').'_2');
  1398. }
  1399. $openId = $oauthUser['openid'];
  1400. $unionId = $oauthUser['unionid'];
  1401. if(_empty_($openId) && _empty_($unionId)){
  1402. return $this->fail(503001);
  1403. }
  1404. $data = [
  1405. 'openId'=>$openId, 'avatarUrl'=>$oauthUser['headimgurl'] ?: '', 'city'=>$oauthUser['city'] ?: '', 'country'=>$oauthUser['country'] ?: '',
  1406. 'province'=>$oauthUser['province'] ?: '', 'language'=>'','nickName'=>$oauthUser['nickname'] ?: '',
  1407. 'gender'=>$oauthUser['sex'] ?: 0, 'unionId'=>$unionId
  1408. ];
  1409. global $__MINI_GLOBAL_CURRENT_USER_ID__;
  1410. if($__MINI_GLOBAL_CURRENT_USER_ID__ > 0 && (!_empty_($data['openId']) || !_empty_($data['unionId']))){
  1411. // 绑定场景,需要截断
  1412. $open_user = WxUser::withTrashed()->where('weixin_openid', $data['openId'])->first();
  1413. $time = time();
  1414. $current_user = WxUser::where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->first(FieldUtils::userInfoColums());
  1415. $is_bind_flag = false;
  1416. if($open_user && $open_user->id > 0){
  1417. if($open_user->trashed()){
  1418. WxUser::withTrashed()->where('id', $open_user->id)->forceDelete();
  1419. if(_empty_($data['unionId'])){
  1420. try {
  1421. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1422. 'weixin_unionid' => $data['unionId'] ?? null,
  1423. 'weixin_openid' => $data['openId'] ?? null
  1424. ]);
  1425. $is_bind_flag = true;
  1426. }catch (\Exception $e){
  1427. $is_bind_flag = false;
  1428. }
  1429. }else{
  1430. }
  1431. }else if($open_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
  1432. if(_empty_($open_user->weixin_unionid)){
  1433. try {
  1434. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1435. 'weixin_unionid' => $data['unionId'] ?? null,
  1436. 'weixin_openid' => $data['openId'] ?? null
  1437. ]);
  1438. $is_bind_flag = true;
  1439. }catch (\Exception $e){
  1440. $is_bind_flag = false;
  1441. }
  1442. }else{
  1443. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1444. 'weixin_openid' => $data['openId'] ?? null
  1445. ]);
  1446. $is_bind_flag = true;
  1447. }
  1448. }else{
  1449. return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$open_user->id);
  1450. }
  1451. }
  1452. if(!$is_bind_flag){
  1453. $union_user = WxUser::withTrashed()->where('weixin_unionid', $data['unionId'])->first();
  1454. if($union_user && $union_user->id > 0){
  1455. if($union_user->trashed()){
  1456. if($__MINI_GLOBAL_CURRENT_USER_ID__ != $union_user->id){
  1457. WxUser::withTrashed()->where('id', $union_user->id)->forceDelete();
  1458. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1459. 'weixin_unionid' => $data['unionId'] ?? null,
  1460. 'weixin_openid' => $data['openId'] ?? null
  1461. ]);
  1462. $is_bind_flag = true;
  1463. }else{
  1464. return $this->fail(503001, [], '您的账号非正常状态');
  1465. }
  1466. }else{
  1467. if($union_user->id == $__MINI_GLOBAL_CURRENT_USER_ID__){
  1468. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1469. 'weixin_openid' => $data['openId'] ?? null
  1470. ]);
  1471. $is_bind_flag = true;
  1472. }else{
  1473. if($data['openId']){
  1474. WxUser::withTrashed()->where('id', $union_user->id)->update([
  1475. 'weixin_openid' => $data['openId'] ?? null
  1476. ]);
  1477. $is_bind_flag = true;
  1478. }
  1479. return $this->fail(503001, [], '您的微信已经绑定了其他账号, 账号UID为:'.$union_user->id);
  1480. }
  1481. }
  1482. }else{
  1483. WxUser::withTrashed()->where('id', $__MINI_GLOBAL_CURRENT_USER_ID__)->update([
  1484. 'weixin_unionid' => $data['unionId'] ?? null,
  1485. 'weixin_openid' => $data['openId'] ?? null
  1486. ]);
  1487. }
  1488. }
  1489. return $this->success(['token' => JwtAuth::getToken('uid', $current_user->id, $time), 'user'=>$current_user, 'select' => 0], 200, '绑定成功');
  1490. }
  1491. $wxUserModel = new WxUser();
  1492. $user_id = $wxUserModel->registerUser($data, 'app', $fromUser);
  1493. if($user_id > 0){
  1494. $login_user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  1495. // 超级管理员
  1496. if($login_user->is_official){
  1497. if(UserUtils::is_mini_supder_admin($login_user->id)){
  1498. $login_user->is_official = 2;
  1499. }
  1500. }
  1501. UserUtils::user_expend($login_user, true, true, true, true, 5);
  1502. $time = time();
  1503. $login_user->timeStamp = $time;
  1504. // 生成token
  1505. return $this->success(['token' => JwtAuth::getToken('uid', $login_user->id, $time), 'user'=>$login_user]);
  1506. }else if($user_id == -1){
  1507. return $this->fail(700001);
  1508. }else if($user_id == -2){
  1509. return $this->fail(200008, [], '平台未开启微信注册新用户,请您换其他方式先注册账号');
  1510. }else if($user_id == -3){
  1511. return $this->fail(200000, [], '您的账号已在系统黑名单,无法登录,客服qq:'.Settings::get('about_qq', '863627472'));
  1512. }
  1513. return $this->fail(200003);
  1514. }
  1515. /** 账号注销申请
  1516. * @param Request $request
  1517. * @return \Illuminate\Http\JsonResponse
  1518. */
  1519. public function logoff(Request $request){
  1520. $uid = $request->uid;
  1521. UserUtils::add_user_notice(4001, $uid, '账号处于注销中状态', '您于'.current_time().'开始申请注销账号,当前账号将会被标记为[非正常状态]', 100);
  1522. WxUser::where('id', $uid)->update( ['user_state'=>1] );
  1523. WxPost::where('user_id', $uid)->update(['posts_state' => 2]);
  1524. Cache::forget('user:state:'.$uid);
  1525. return $this->success();
  1526. }
  1527. public function contactApply(Request &$request)
  1528. {
  1529. $object_id = _empty_default_($request->object_id, 0);
  1530. if(_empty_($object_id)){
  1531. return $this->fail(200001);
  1532. }
  1533. $is_phone = _empty_default_($request->is_phone, 0) == 1 ? 1 : 0;
  1534. $is_wechat_account = _empty_default_($request->is_wechat_account, 0) == 1 ? 1 : 0;
  1535. $reason = _empty_default_($request->reason, '');
  1536. if(_empty_($reason)){
  1537. return $this->fail(200004, [], '请先输入申请理由');
  1538. }
  1539. DB::beginTransaction();
  1540. try {
  1541. // todo:
  1542. $uid = $request->uid;
  1543. $model = new WxUserContactApply();
  1544. $model->user_id = $uid;
  1545. $model->object_id = $object_id;
  1546. $model->is_phone = $is_phone;
  1547. $model->is_wechat_account = $is_wechat_account;
  1548. $model->reason = $reason;
  1549. $model->status = 0;
  1550. $r = $model->save();
  1551. if($r){
  1552. $r2 = WxContRepositories::add($model->user_id, $model->object_id, null, null, null, 0, null, null, $model->id);//联系信息申请
  1553. if($r2){
  1554. DB::commit();
  1555. return $this->success();
  1556. }else{
  1557. DB::rollBack();
  1558. return $this->fail(200002);
  1559. }
  1560. }else{
  1561. DB::rollBack();
  1562. return $this->fail(200002);
  1563. }
  1564. } catch (\Exception $e) {
  1565. DB::rollBack();
  1566. _logger_(__file__, __line__, $e->getMessage());
  1567. return $this->fail(200006);
  1568. }
  1569. }
  1570. /**
  1571. * 获取用户信息
  1572. * @param Request $request
  1573. * @return \Illuminate\Http\JsonResponse
  1574. */
  1575. public function userInfo(Request $request)
  1576. {
  1577. global $__MINI_GLOBAL_IP__;
  1578. // print_r($__MINI_GLOBAL_IP__);exit;
  1579. $uid = $request->uid;
  1580. $player = $request->player;
  1581. $cid = _empty_default_($request->cid, '');
  1582. $third_account = _empty_default_($request->account, 0);
  1583. $is_access_token = false;
  1584. if(!_empty_($request->get('access_token')) && !_empty_(Settings::get('mini_access_token', ''))){
  1585. if($request->get('access_token') == Settings::get('mini_access_token', '')){
  1586. $is_access_token = true;
  1587. }
  1588. }
  1589. if($third_account == 1){
  1590. // 获取第三方账号绑定信息
  1591. $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']);
  1592. if($data){
  1593. return $this->success($data);
  1594. }else{
  1595. return $this->fail(200003);
  1596. }
  1597. }
  1598. $info = (new WxUserRepositores())->info($uid);
  1599. if($info){
  1600. if($player){
  1601. $info->is_played = true;
  1602. }else{
  1603. $info->is_played = false;
  1604. }
  1605. if($info->is_official){
  1606. if(UserUtils::is_mini_supder_admin($info->id)){
  1607. $info->is_official = 2;
  1608. }
  1609. }
  1610. UserUtils::user_expend($info, true, true, true, true,5);
  1611. if($is_access_token){
  1612. $info->origin_phone = _get_origin_attribute('wx_user', [['id', '=', $info->id]], 'phone');
  1613. }
  1614. if(!_empty_($cid) && $info->push_client_id != $cid){
  1615. WxUser::withoutSyncingToSearch(function () use ($info, $cid) {
  1616. WxUser::where('id', $info->id)->update(['push_client_id'=>$cid]);
  1617. });
  1618. }
  1619. $info->timeStamp = time();
  1620. $res = _ip_address($__MINI_GLOBAL_IP__);
  1621. // // print_r($res);exit;
  1622. if(_empty_($res)){
  1623. } else {
  1624. // 更新用户的地区
  1625. $update_infos['province'] = $res['province'];
  1626. $update_infos['city'] = $res['city'];
  1627. $update_infos['district'] = $res['district'];
  1628. $update_infos['country'] = $res['country'];
  1629. WxUser::where('id', $info->id)->update($update_infos);
  1630. // 更新用户相亲表 ip 地址地区
  1631. // 判断是否存在不存在就不更新 ,如果 ip_address 相同 也不更新
  1632. $ip_address = $res['province'] .','. $res['city'] .','. $res['district'];
  1633. $conditions = Conditions::where('user_id', $info->id)->first();
  1634. if(!_empty_($conditions)){
  1635. if($conditions->ip_address != $ip_address){
  1636. Conditions::where('user_id', $info->id)->update(['ip_address' => $ip_address]);
  1637. }
  1638. }
  1639. }
  1640. if(_empty_($info->user_name)){
  1641. return $this->success($info, 200025);
  1642. }else{
  1643. return $this->success($info);
  1644. }
  1645. }else{
  1646. return $this->fail(200003);
  1647. }
  1648. }
  1649. public function userSystemInfo(Request $request)
  1650. {
  1651. $uid = $request->uid;
  1652. if(_empty_($uid)){
  1653. return $this->fail(200001);
  1654. }
  1655. $deviceModel = _empty_default_($request->deviceModel, '');
  1656. $system = _empty_default_($request->system, '');
  1657. if(request()->isMethod('POST')){
  1658. UserUtils::set_online($uid, '', $deviceModel, $system);
  1659. return $this->success();
  1660. }
  1661. }
  1662. /**
  1663. * 根据用户id获取基本用户信息
  1664. * @param Request $request
  1665. * @return \Illuminate\Http\JsonResponse
  1666. */
  1667. public function userInfoByUserId(Request $request)
  1668. {
  1669. global $__MINI_GLOBAL_IS_ADMIN_SUPER__;
  1670. $user_id = $request->user_id;
  1671. $uid = $request->uid;
  1672. $scene = $request->header('scene', 0);
  1673. if(_empty_($user_id)){
  1674. return $this->fail(200001);
  1675. }
  1676. if($user_id < 0){
  1677. $data = WxUser::where('id', _abs($user_id))->first(FieldUtils::userInfoColums());
  1678. $longtaps = [];
  1679. if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
  1680. $longtaps[] = [
  1681. 'text' => '用户管理',
  1682. 'emoji' => '🥸',
  1683. 'list' => [
  1684. [
  1685. 'name' => '真实用户',
  1686. 'action' => 'icon',
  1687. 'target_type' => 6,
  1688. 'target_id' => '/pages/user/user?id=' . _abs($user_id),
  1689. ]
  1690. ]
  1691. ];
  1692. }
  1693. // 匿名
  1694. return $this->success([
  1695. 'id' => -1,
  1696. 'user_name' => _empty_default_($data->anonymous_name, '匿名'),
  1697. 'user_avatar' => _empty_default_($data->anonymous_avatar, Settings::get('img_default_avatar', '')),
  1698. 'longtaps' => $longtaps,
  1699. 'followTotal' => 0,
  1700. 'fansTotal' => 0,
  1701. 'likeTotal' => 0,
  1702. 'user_background_maps' => Settings::get('user_background_maps', ''),
  1703. 'user_background_color' => _empty_default_(get_site_meta('user_background_color', 's'), '18, 14, 17'),
  1704. 'setting' => [
  1705. 'privacy_message_me' => 1,
  1706. 'privacy_collected_post_show' => 1,
  1707. 'privacy_my_follow_show' => 1,
  1708. 'privacy_follow_me_show' => 1,
  1709. 'privacy_get_my_wechat' => 4,
  1710. 'privacy_get_my_wechat_pay' => 0,
  1711. 'privacy_get_my_phone' => 4,
  1712. 'privacy_get_my_phone_pay' => 0,
  1713. 'privacy_personal_recommend' => 1,
  1714. 'privacy_personal_ad' => 1,
  1715. 'privacy_personal_geo_title' => 1,
  1716. 'diy_scene_1_post_list_style' => 1,
  1717. 'diy_scene_6_post_list_style' => 1,
  1718. 'diy_scene_7_post_list_style' => 1,
  1719. 'diy_scene_8_post_list_style' => 1,
  1720. 'teenage_mode_state' => 0,
  1721. ],
  1722. 'blogger_status' => '',
  1723. ]);
  1724. }
  1725. $data = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  1726. if($data){
  1727. $res = ApiUtils::ali_request(\App\Wen\Utils\Settings::get('app_ali_ip_address_appcode', ''), 'https://ips.market.alicloudapi.com/iplocaltion', ['ip'=>$data->ip]);
  1728. //print_r($res['result']['city']);exit;
  1729. if($res['code'] == 1000 && $res['result']){
  1730. $data->ip_address_a = $res['result']['city'];//归属城市
  1731. }else{
  1732. // $data->append(['ip_address']);
  1733. $data->ip_address_a = $data->city;
  1734. }
  1735. $data->append(['ip_address']);
  1736. }else{
  1737. return $this->fail(200003);
  1738. }
  1739. if($__MINI_GLOBAL_IS_ADMIN_SUPER__ && $data->is_robot > 0){
  1740. $data->user_name = $data->user_name.' 🤖';
  1741. }
  1742. UserUtils::user_expend($data, false, false, true, true,8);
  1743. $data->followTotal = WxUserFollow::where('user_id', $user_id)->count();
  1744. $data->fansTotal = WxUserFollow::where('user_follow_id', $user_id)->count();
  1745. $count1 = WxLike::where('posts_user_id', $user_id)->count();
  1746. $count2 = WxCommentLike::where('comment_user_id', $user_id)->count();
  1747. $data->likeTotal = $count1 + $count2;
  1748. if($uid > 0 && $uid != $user_id){
  1749. $data->isFollow = WxUserFollow::where('user_id', $uid)->where('user_follow_id', $user_id)->exists();
  1750. $data->isFans = WxUserFollow::where('user_id', $user_id)->where('user_follow_id', $uid)->exists();
  1751. }else{
  1752. $data->isFollow = false;
  1753. $data->isFans = false;
  1754. }
  1755. $data->user_background_color = get_user_meta($user_id, 'user_background_color');
  1756. if(_empty_($data->user_background_color)){
  1757. $data->user_background_color = UserUtils::user_bg_color_update($user_id);
  1758. if(_empty_($data->user_background_color)){
  1759. $data->user_background_color = '18, 14, 17';
  1760. }
  1761. }
  1762. $blacked = UserUtils::is_user_blacked_to($uid, $data->id);
  1763. if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
  1764. $data->actions = [
  1765. ['title' => '举报'],
  1766. ['title' => $blacked ? '取消拉黑' : '拉黑'],
  1767. ['title' => 'ta的钱包'],
  1768. ['title'=>'编辑ta的资料']
  1769. ];
  1770. }else{
  1771. $data->actions = [
  1772. ['title' => '举报'],
  1773. ['title' => $blacked ? '取消拉黑' : '拉黑'],
  1774. ];
  1775. }
  1776. if($scene == 50005 || $scene == 50004 || $scene == 50006){
  1777. $data->pets = [
  1778. 'adoption' => [
  1779. 'count'=>[
  1780. 'status0' => WxPetsAdoption::where('user_id', $user_id)->where('adopt_status', 0)->count(),
  1781. 'status1' => WxPetsAdoption::where('user_id', $user_id)->where('adopt_status', 1)->count(),
  1782. ]
  1783. ]
  1784. ];
  1785. }
  1786. if( $uid > 0 ){
  1787. update_user_visit($uid,4, $user_id);
  1788. }
  1789. //print_r($data);exit;
  1790. return $this->success($data);
  1791. }
  1792. /**
  1793. * 更新用户资料
  1794. * @param Request $request
  1795. * @return \Illuminate\Http\JsonResponse
  1796. */
  1797. public function updateInfo(Request $request)
  1798. {
  1799. $uid = $request->uid;
  1800. _limit_user('update:user:info', $uid, 20);
  1801. $data = $request->all();
  1802. $user_id = _array_key($data, 'user_id', 0);
  1803. if($user_id > 0){
  1804. if(UserUtils::is_mini_supder_admin($uid)){
  1805. $uid = $user_id;
  1806. }else{
  1807. return $this->fail(200000, [], '你还不是超级管理员,无法保存别人的资料');
  1808. }
  1809. }
  1810. // 修改 is_online_status
  1811. if (isset($data['is_online_status'])) {
  1812. // $update_online['requirement'] = $data['is_online_status'];
  1813. // $update_online['is_online_status_time'] = time();
  1814. // WxUser::where('id', $uid)->update($update_online);
  1815. // $infos = WxUser::where('id', $uid)->find($uid);
  1816. // $infos->is_online_status = $data['is_online_status'];
  1817. //$infos->save();
  1818. }
  1819. // print_r($uid);exit;
  1820. // 删除 is_online_status
  1821. //unset($data['is_online_status']);
  1822. $old_user = WxUser::find($uid);
  1823. if(_empty_($old_user)){
  1824. return $this->fail(200003);
  1825. }
  1826. $is_user_setting = _array_key($data, 'is_user_setting', false);
  1827. if($is_user_setting){
  1828. $user_setting_update_flag = false;
  1829. if(isset($data['privacy_message_me'])){
  1830. if(!in_array($data['privacy_message_me'], [1, 2, 3, 4, 5])){
  1831. return $this->fail(200004);
  1832. }
  1833. $r = WxUserSetting::where('user_id', $uid)->update(['privacy_message_me' => $data['privacy_message_me']]);
  1834. if($r){
  1835. $user_setting_update_flag = true;
  1836. }else{
  1837. return $this->fail(200002);
  1838. }
  1839. }
  1840. foreach (['wechat', 'phone'] as $wechat_or_phone){
  1841. if(isset($data['privacy_get_my_'.$wechat_or_phone])){
  1842. if(!in_array($data['privacy_get_my_'.$wechat_or_phone], [1, 2, 3, 4, 5])){
  1843. return $this->fail(200004);
  1844. }
  1845. if(($wechat_or_phone == 'wechat' && _empty_($old_user->wechat_account)) || ($wechat_or_phone == 'phone' && _empty_($old_user->phone))){
  1846. return $this->fail(200043, [
  1847. 'title' => $wechat_or_phone == 'wechat' ? '未保存微信号' : '未绑定手机号',
  1848. 'content' => '是否前往[编辑资料]进行补充',
  1849. 'confirmText' => '去补充',
  1850. 'target_type' => 6,
  1851. 'target_id' => $wechat_or_phone == 'wechat' ? '/pagesA/mine/editmine/editmine?wechat_account=1' : '/pagesA/mine/editmine/editmine?phone=1'
  1852. ], $wechat_or_phone == 'wechat' ? '未保存微信号' : '未绑定手机号');
  1853. }
  1854. $updates = [
  1855. 'privacy_get_my_'.$wechat_or_phone => $data['privacy_get_my_'.$wechat_or_phone]
  1856. ];
  1857. if($data['privacy_get_my_'.$wechat_or_phone] == 5 && WxUserSetting::where('user_id', $uid)->value('privacy_get_my_'.$wechat_or_phone.'_pay') < 1){
  1858. $updates['privacy_get_my_'.$wechat_or_phone.'_pay'] = 1;
  1859. }
  1860. $r = WxUserSetting::where('user_id', $uid)->update($updates);
  1861. if($r){
  1862. $user_setting_update_flag = true;
  1863. }else{
  1864. return $this->fail(200002);
  1865. }
  1866. }
  1867. if(isset($data['privacy_get_my_'.$wechat_or_phone.'_pay'])){
  1868. $data['privacy_get_my_'.$wechat_or_phone.'_pay'] = round((float)$data['privacy_get_my_'.$wechat_or_phone.'_pay'], 2);
  1869. if($data['privacy_get_my_'.$wechat_or_phone.'_pay'] < 1){
  1870. return $this->fail(200004, [], '付费数额不能小于1元');
  1871. }
  1872. $r = WxUserSetting::where('user_id', $uid)->update(['privacy_get_my_'.$wechat_or_phone.'_pay' => $data['privacy_get_my_'.$wechat_or_phone.'_pay']]);
  1873. if($r){
  1874. $user_setting_update_flag = true;
  1875. }else{
  1876. return $this->fail(200002);
  1877. }
  1878. }
  1879. }
  1880. // 1,2类型
  1881. 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){
  1882. if(isset($data[$key])){
  1883. if(!in_array($data[$key], [1, 2])){
  1884. return $this->fail(200004);
  1885. }
  1886. $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
  1887. if($r){
  1888. $user_setting_update_flag = true;
  1889. }else{
  1890. return $this->fail(200002);
  1891. }
  1892. }
  1893. }
  1894. // 2,3类型
  1895. 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){
  1896. if(isset($data[$key])){
  1897. if(!in_array($data[$key], [2, 3])){
  1898. return $this->fail(200004);
  1899. }
  1900. $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
  1901. if($r){
  1902. $user_setting_update_flag = true;
  1903. }else{
  1904. return $this->fail(200002);
  1905. }
  1906. }
  1907. }
  1908. // 字符串类型
  1909. foreach (['social_sph_id'] as $key){
  1910. if(!_empty_(_array_key($data, $key, ''))){
  1911. if($key == 'social_sph_id'){
  1912. if($data[$key] == 'close'){
  1913. $data[$key] = '';
  1914. }else{
  1915. if(strlen($data[$key]) != 15 || !StrUtils::startsWith($data[$key], 'sph')){
  1916. return $this->fail(200004, [], '视频号id需要以sph开头的16位字符串');
  1917. }
  1918. }
  1919. }
  1920. $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
  1921. if($r){
  1922. $user_setting_update_flag = true;
  1923. }else{
  1924. return $this->fail(200002);
  1925. }
  1926. }
  1927. }
  1928. if(isset($data['teenage_mode_password'])){
  1929. if(strlen($data['teenage_mode_password']) != 4){
  1930. return $this->fail(200004);
  1931. }
  1932. $user_setting = WxUserSetting::where('user_id', $uid)->first();
  1933. if($user_setting){
  1934. $r = false;
  1935. if($user_setting->teenage_mode_state == 1){
  1936. // 关闭
  1937. if($user_setting->teenage_mode_password == $data['teenage_mode_password']){
  1938. $r = WxUserSetting::where('user_id', $uid)->update(['teenage_mode_password' => '', 'teenage_mode_state' => 2]);
  1939. }else{
  1940. return $this->fail(200004, [], '密码错误');
  1941. }
  1942. }else{
  1943. // 打开
  1944. $r = WxUserSetting::where('user_id', $uid)->update(['teenage_mode_password' => $data['teenage_mode_password'], 'teenage_mode_state' => 1]);
  1945. }
  1946. if($r){
  1947. $user_setting_update_flag = true;
  1948. }else{
  1949. return $this->fail(200002);
  1950. }
  1951. }
  1952. }
  1953. if($user_setting_update_flag){
  1954. Cache::forget('get:cached:user:'.$uid);
  1955. $login_user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
  1956. // 超级管理员
  1957. if($login_user->is_official){
  1958. if(UserUtils::is_mini_supder_admin($login_user->id)){
  1959. $login_user->is_official = 2;
  1960. }
  1961. }
  1962. UserUtils::user_expend($login_user, true, true, true, true, 5);
  1963. $login_user->timeStamp = time();
  1964. return $this->success(['code'=>1, 'user'=>$login_user]);
  1965. }else{
  1966. return $this->fail(200004);
  1967. }
  1968. }
  1969. $data['user_name'] = str_replace([' 🤖', '🤖',' 💙🤖', ' 💗🤖', '💙🤖', '💗🤖'], '', trim(_array_key($data, 'user_name', '')));
  1970. if(_empty_($data['user_name'])){
  1971. return $this->fail(200001);
  1972. }
  1973. if(_empty_(_array_key($data, 'user_avatar', ''))){
  1974. $data['user_avatar'] = '';
  1975. }
  1976. if(_empty_(_array_key($data, 'user_name', ''))){
  1977. $data['user_name'] = '';
  1978. }
  1979. if(_empty_(_array_key($data, 'wechat_account', ''))){
  1980. $data['wechat_account'] = '';
  1981. }
  1982. if(_empty_(_array_key($data, 'user_introduce', '')) || Settings::get('app_user_introduce', '', true) == _array_key($data, 'user_introduce', '') ){
  1983. $data['user_introduce'] = '';
  1984. }
  1985. if(_empty_(_array_key($data, 'user_birthday', '')) || _array_key($data, 'user_birthday', '') == '请选择'){
  1986. $data['user_birthday'] = '';
  1987. }
  1988. if(!StrUtils::is_valid_date(_array_key($data, 'user_birthday', ''), 'Y-m-d')){
  1989. $data['user_birthday'] = '';
  1990. }else{
  1991. if(strtotime(_array_key($data, 'user_birthday', '')) >= time()){
  1992. return $this->fail(200004, [], '生日不合法');
  1993. }
  1994. }
  1995. if(_empty_(_array_key($data, 'user_background_maps', ''))){
  1996. $data['user_background_maps'] = '';
  1997. }
  1998. if(_empty_(_array_key($data, 'gender', 0)) || _array_key($data, 'gender', 0) == '请选择'
  1999. || StrUtils::is_contain_chinese(_array_key($data, 'gender', 0)) || !in_array(_array_key($data, 'gender', 0), [0, 1, 2]) ){
  2000. $data['gender'] = 0;
  2001. }
  2002. $user_labels = _array_key($data, 'user_labels', []);
  2003. if($user_labels){
  2004. if($user_labels == -1){
  2005. $data['user_labels'] = -1;
  2006. }else{
  2007. // 过滤
  2008. $user_labels_ =[];
  2009. $app_user_labels = Settings::get('app_user_labels', [], true);
  2010. foreach ($user_labels as $label){
  2011. if(in_array($label, $app_user_labels)){
  2012. $user_labels_[] = $label;
  2013. }
  2014. }
  2015. $data['user_labels'] = $user_labels_;
  2016. }
  2017. }else{
  2018. $data['user_labels'] = [];
  2019. }
  2020. if(mb_strlen($data['user_name'] ?? '' ) > 20){
  2021. return $this->fail(200004, [], '用户名过长');
  2022. }
  2023. if(!_empty_($data['user_name'])){
  2024. if(WxUser::where([['user_name','=',$data['user_name']], ['id', '<>', $uid] ])->exists()){
  2025. return $this->fail(200004, [], '用户名已存在');
  2026. }
  2027. }
  2028. $old_user_name = $old_user->user_name;
  2029. $old_user_avatar = $old_user->user_avatar;
  2030. $old_gender = $old_user->gender;
  2031. $old_user_introduce = $old_user->user_introduce;
  2032. $old_user_background_maps = $old_user->user_background_maps;
  2033. $old_wechat_account = $old_user->wechat_account;
  2034. if(_array_key($data, 'wechat_account', '')){
  2035. if($old_wechat_account == _array_key($data, 'wechat_account', '')){
  2036. $data['wechat_account'] = '';
  2037. }
  2038. }
  2039. $user_name = $data['user_name'];
  2040. $user_introduce = $data['user_introduce'] ?? '';
  2041. // 用户修改资料
  2042. // 百度审核
  2043. $need_manual_review = true;
  2044. $is_audit_user_info = Settings::get('is_audit_user_info', 0);
  2045. if ($is_audit_user_info == 2 ) {
  2046. if($old_user_name == $user_name && $old_user_introduce == $user_introduce){
  2047. $need_manual_review = false;
  2048. }else{
  2049. if($user_name || $user_introduce){
  2050. $filter_result = BaiduUtils::text_filter($user_name .' '. $user_introduce);
  2051. if($filter_result){
  2052. if($filter_result['hit_level'] == 2){
  2053. // 不合规
  2054. return $this->fail(200016, ['tip'=>$filter_result['tip_list'], 'hit_word'=>$filter_result['hit_word']]);
  2055. }else if($filter_result['hit_level'] == 0){
  2056. // 审核通过
  2057. $need_manual_review = false;
  2058. }
  2059. }
  2060. }
  2061. }
  2062. }else if($is_audit_user_info == 0){
  2063. $need_manual_review = true;
  2064. if($old_user_name == $user_name && $old_user_introduce == $user_introduce){
  2065. $need_manual_review = false;
  2066. }
  2067. }else{
  2068. $need_manual_review = false;
  2069. }
  2070. if(UserUtils::is_mini_supder_admin($uid)){
  2071. $need_manual_review = false;
  2072. }
  2073. $r = WxUserRepositores::update($uid, $data, $need_manual_review);
  2074. //var_dump($need_manual_review);exit;
  2075. if($r){
  2076. UserInputSafeCheckJob::dispatch($uid, ($user_name .' '. $user_introduce));
  2077. Utils::image_state_change([$data['user_avatar'] ?? '', $data['user_background_maps'] ?? '' ], 1);
  2078. if(_array_key($data, 'user_background_maps', '')){
  2079. if($old_user_background_maps != _array_key($data, 'user_background_maps', '')){
  2080. UserBgColorUpdateJob::dispatch($uid, false);
  2081. }
  2082. }
  2083. if($need_manual_review){
  2084. UserUtils::assistant_notice('admin', '有用户修改资料待审核');
  2085. return $this->success(['code'=>0]);
  2086. }else{
  2087. Cache::forget('get:cached:user:'.$uid);
  2088. $login_user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
  2089. // 超级管理员
  2090. if($login_user->is_official){
  2091. if(UserUtils::is_mini_supder_admin($login_user->id)){
  2092. $login_user->is_official = 2;
  2093. }
  2094. }
  2095. UserUtils::user_expend($login_user, true, true, true, true, 5);
  2096. $login_user->timeStamp = time();
  2097. return $this->success(['code'=>1, 'user'=>$login_user]);
  2098. }
  2099. }
  2100. return $this->fail(200002);
  2101. }
  2102. /**
  2103. * 我的笔记列表
  2104. * @param Request $request
  2105. * @return \Illuminate\Http\JsonResponse
  2106. */
  2107. public function getMyPosts(Request $request)
  2108. {
  2109. $uid = $request->uid;
  2110. $user_id = _empty_default_($request->user_id, 0);
  2111. $limit = $request->input('limit', 10);
  2112. $type = $request->input('type', 0);
  2113. if($type == 'shop'){
  2114. $orderBy = _empty_default_($request->orderBy, 'sort');
  2115. if(!in_array($orderBy, ['id','sort', 'buys', 'created_at', 'price'])){
  2116. return $this->fail(200004);
  2117. }
  2118. $order = _empty_default_($request->order, 'desc');
  2119. if(!in_array($order, ['desc', 'asc'])){
  2120. return $this->fail(200004);
  2121. }
  2122. if($orderBy != 'price'){
  2123. $order = 'desc';
  2124. }
  2125. }else{
  2126. $orderBy = 'id';
  2127. $order = 'desc';
  2128. }
  2129. if(is_numeric($type)){
  2130. $type_map = [
  2131. 0 => 'post',
  2132. 1 => 'collected',
  2133. 2 => 'liked',
  2134. 3 => 'exceptionaled',
  2135. 4 => 'voted'
  2136. ];
  2137. $type = $type_map[(int)$type];
  2138. }
  2139. if(!_empty_($user_id)){
  2140. if($user_id > 0 || ($user_id < 0 && $type == 'post')){
  2141. return $this->success(PostsRepositores::myPosts($user_id, $limit, $type, $orderBy, $order));
  2142. }else{
  2143. return $this->fail(200004);
  2144. }
  2145. }else{
  2146. if($uid > 0){
  2147. return $this->success(PostsRepositores::myPosts($uid, $limit, $type, $orderBy, $order));
  2148. }else{
  2149. return $this->fail(503002);
  2150. }
  2151. }
  2152. }
  2153. /**
  2154. * 用户认证
  2155. */
  2156. public function authentication(Request $request)
  2157. {
  2158. $uid = $request->uid;
  2159. $device = in_array($request->header('device',''), ['app', 'h5', 'mp', 'pc']) ? $request->header('device','') : '';
  2160. $arr = UserUtils::user_action_permissions_check($uid, 'user_authenticate');
  2161. if($arr['code'] == 0){
  2162. return $this->fail(200000, [], $arr['msg']);
  2163. }
  2164. $name = $request->name;
  2165. $contact_information = $request->contact_information;
  2166. $introduce = $request->introduce;
  2167. $identity_picture = $request->identity_picture;
  2168. if(Settings::get('app_user_authenticate_img_require', 1) == 1 && _empty_($identity_picture)){
  2169. return $this->fail(200001, [], '请上传身份信息证明图片');
  2170. }
  2171. $authenticationState = (new WxAuthentication())->where('user_id', $uid)->value('authentication_state');
  2172. $authId = (new WxAuthentication())->where('user_id', $uid)->value('id');
  2173. // 已经审核通过和驳回
  2174. if ($authenticationState == 1 || $authenticationState == 2) {
  2175. $model = (new WxAuthentication())->find($authId);
  2176. $model->name = $name;
  2177. $model->contact_information = $contact_information;
  2178. $model->introduce = $introduce;
  2179. $model->authentication_state = 0;
  2180. $model->user_id = $uid;
  2181. if(!_empty_($identity_picture)){
  2182. $model->identity_picture = $identity_picture;
  2183. }
  2184. $model->save();
  2185. }else if($authenticationState === 0){
  2186. return $this->fail(200010, [], '您的认证信息正在审核中...请勿重复提交');
  2187. }else if ($authenticationState === null) {
  2188. $model = new WxAuthentication();
  2189. $model->name = $name;
  2190. $model->contact_information = $contact_information;
  2191. $model->introduce = $introduce;
  2192. if(!_empty_($identity_picture)){
  2193. $model->identity_picture = $identity_picture;
  2194. }
  2195. $model->user_id = $uid;
  2196. $model->save();
  2197. }
  2198. Utils::image_state_change([$identity_picture], 1);
  2199. $tmplIds = [];
  2200. if($device == 'mp'){
  2201. $comment_add_id = Settings::get('mini_template_message_authentication', '');
  2202. if(!_empty_($comment_add_id)){
  2203. $tmplIds[] = $comment_add_id;
  2204. }
  2205. }
  2206. UserUtils::assistant_notice_review(109, $model->id);
  2207. return $this->success([
  2208. 'tmplIds' => $tmplIds
  2209. ]);
  2210. }
  2211. /**
  2212. * 我创建的圈子列表
  2213. */
  2214. public function myCircle(Request $request)
  2215. {
  2216. $uid = $request->uid;
  2217. $data = WxCircle::where('user_id', $uid)->get();
  2218. $data->map(function ($v) {
  2219. $v->post_count = WxPost::where('circle_id', $v->id)->count();
  2220. $v->user_circle_count = WxUserCircle::where('circle_id', $v->id)->count();
  2221. });
  2222. if(UserUtils::is_mini_supder_admin($uid)){
  2223. $data = $data->toArray();
  2224. $hall = [
  2225. [
  2226. 'id' => 0,
  2227. 'circle_name' => '大厅',
  2228. 'post_count' => WxPost::where('circle_id', 0)->count(),
  2229. 'user_circle_count' => WxPost::where('circle_id', 0)->distinct('user_id')->count('user_id'),
  2230. 'head_portrait' => Settings::get('about_logo', ''),
  2231. 'circle_introduce' => '没有选择圈子的笔记'
  2232. ]
  2233. ];
  2234. $data = array_merge($hall, $data);
  2235. }
  2236. return $this->success($data);
  2237. }
  2238. /**
  2239. * 我的支付密码
  2240. */
  2241. public function paycode(Request $request){
  2242. $uid = $request->uid;
  2243. $type = $request->type;
  2244. $password = $request->password;
  2245. if($password && strlen($password) !== 6){
  2246. return $this->fail(200004);
  2247. }
  2248. // 检查是否有支付密码
  2249. if($type == 0){
  2250. $paycode = get_user_meta($uid, 'paycode', 's');
  2251. if($paycode){
  2252. return $this->success(['status'=>1]);
  2253. }else{
  2254. return $this->success(['status'=>0]);
  2255. }
  2256. }else if($type == 1){
  2257. if($password && strlen($password) === 6){
  2258. update_user_meta($uid, 'paycode', $password, 's');
  2259. return $this->success(['status'=>1]);
  2260. }
  2261. return $this->fail(200004);
  2262. }else if($type == 2){
  2263. if(Cache::has('paycode:checked:'.$uid)){
  2264. if($password && strlen($password) === 6){
  2265. update_user_meta($uid, 'paycode', $password, 's');
  2266. Cache::forget('paycode:checked:'.$uid);
  2267. return $this->success(['status'=>1]);
  2268. }
  2269. return $this->fail(200004);
  2270. }else{
  2271. // 检测旧密码
  2272. _limit_user('paycode:check:', $uid, 20);
  2273. if($password !== get_user_meta($uid, 'paycode', 's')){
  2274. return $this->fail(200004, [], '您输入的旧密码错误');
  2275. }else{
  2276. Cache::put('paycode:checked:'.$uid, true, 600);
  2277. return $this->success();
  2278. }
  2279. }
  2280. }else if($type == 3){
  2281. $phoneCode = $request->phoneCode;
  2282. if(_empty_($phoneCode)){
  2283. return $this->fail(200001, [], '验证码为空');
  2284. }
  2285. // 手机号验证
  2286. $user = WxUser::find($uid);
  2287. if(_empty_($user)){
  2288. return $this->fail(200004, [], '用户不存在');
  2289. }
  2290. $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
  2291. $idd = $user->country_code;
  2292. if(_empty_($idd)){
  2293. $idd = 86;
  2294. }
  2295. if(!Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
  2296. return $this->fail(200009, [], '验证码已过期,请重新发送');
  2297. }
  2298. if(Cache::get(md5($uid.':code:'.$idd.':'.$phone)) != $phoneCode){
  2299. return $this->fail(200004, [], '验证码错误');
  2300. }
  2301. if($password && strlen($password) === 6){
  2302. update_user_meta($uid, 'paycode', $password, 's');
  2303. Cache::forget('paycode:checked:'.$uid);
  2304. return $this->success(['status'=>1]);
  2305. }
  2306. return $this->fail(200004);
  2307. }
  2308. }
  2309. public function avatar_frame_wear(Request $request){
  2310. $uid = $request->uid;
  2311. $avatar_frame_id = $request->id;
  2312. if(_empty_($avatar_frame_id)){
  2313. return $this->fail(200001);
  2314. }
  2315. $res = UserUtils::purchase_avatar_frame($uid, $avatar_frame_id);
  2316. if($res['code'] == 200){
  2317. return $this->success();
  2318. }else{
  2319. return $this->fail($res['code'], [], $res['msg']);
  2320. }
  2321. }
  2322. /**
  2323. * 会员页面数据
  2324. * @param Request $request
  2325. */
  2326. public function membersdata(Request $request){
  2327. $uid = $request->uid;
  2328. $benefits = Settings::get('app_vip_benefits', []);
  2329. $avatar_frame_ids = Settings::get('app_vip_user_avatar_frames', []);
  2330. $avatar_frame_ = [];
  2331. if($avatar_frame_ids){
  2332. $avatar_frame_ = WxUserAvatarFrame::whereIn('id', $avatar_frame_ids)->get();
  2333. }
  2334. $vip_consume_invitees = get_user_meta($uid, 'vip_consume_invitees', 'j');
  2335. if($vip_consume_invitees){
  2336. }else{
  2337. $vip_consume_invitees = [];
  2338. }
  2339. $invitees = WxUser::where('who', $uid)->whereNotIn('id', $vip_consume_invitees)->limit(5)->get(FieldUtils::userInfoColums());
  2340. if($invitees){
  2341. }else{
  2342. $invitees = [];
  2343. }
  2344. $result = [
  2345. 'end_time' => UserUtils::get_user_member_time($uid),
  2346. 'invitees' => $invitees,
  2347. 'benefits_title' => Settings::get('app_vip_benefits_title', '会员尊享5大特权'),
  2348. 'benefits' => $benefits,
  2349. 'avatar_frames' => $avatar_frame_,
  2350. 'invitees_5_days' => Settings::get('app_vip_5_invitees_days', 90),
  2351. 'options' => Settings::get('app_vip_options', []),
  2352. ];
  2353. return $this->success($result);
  2354. }
  2355. public function invite_list(Request $request){
  2356. $type = $request->type;
  2357. $uid = $request->uid;
  2358. if(!in_array($type, [1,2,3])){
  2359. return $this->fail(200004);
  2360. }
  2361. if($type == 1 ){
  2362. $data = WxUser::where('who', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  2363. if($data){
  2364. $data->map(function ($v) {
  2365. $v->benifit = UserUtils::get_user_invite_benifit($v->id);
  2366. });
  2367. return $this->success($data);
  2368. }
  2369. return $this->success(200003);
  2370. }else if( $type == 2 ){
  2371. $data = WxUser::whereIn('who', function ($query) use ($uid){
  2372. $query->select('id')->from('wx_user')->where('who', $uid);
  2373. })->orderBy('id', 'desc')->simplePaginate(10);
  2374. if($data){
  2375. $data->map(function ($v) {
  2376. $v->benifit = UserUtils::get_user_invite_benifit($v->id);
  2377. });
  2378. return $this->success($data);
  2379. }
  2380. return $this->success(200003);
  2381. }else if( $type == 3 ){
  2382. $first_userIds = WxUser::where('who', $uid)->pluck('id');
  2383. if($first_userIds){
  2384. $first_userIds = $first_userIds->toArray();
  2385. if($first_userIds){
  2386. $data = WxUser::whereIn('who', function ($query) use ($uid,$first_userIds){
  2387. $query->select('id')->from('wx_user')->whereIn('who', $first_userIds);
  2388. })->orderBy('id', 'desc')->simplePaginate(10);
  2389. if($data){
  2390. $data->map(function ($v) {
  2391. $v->benifit = UserUtils::get_user_invite_benifit($v->id);
  2392. });
  2393. return $this->success($data);
  2394. }
  2395. }
  2396. }
  2397. return $this->success(200003);
  2398. }
  2399. }
  2400. public function invite_info(Request $request){
  2401. $uid = $request->uid;
  2402. $result = [
  2403. 'notice' => Settings::get('user_invite_page_notice', ''),
  2404. 'benifit' => null,
  2405. 'myinviter' => null,
  2406. 'team' => [
  2407. 'total' => 0,
  2408. 'lv1_team' => 0,
  2409. 'lv2_team' => 0,
  2410. 'lv3_team' => 0,
  2411. ],
  2412. 'orders' => [
  2413. ],
  2414. 'qr' => Utils::getMiniCode('pages/tabbar/index/index', '', $uid)
  2415. ];
  2416. $result['benifit'] = UserUtils::get_user_invite_benifit($uid);
  2417. $who = WxUser::where('id', $uid)->value('who');
  2418. if($who > 0){
  2419. $inviter = WxUser::find($who, FieldUtils::userInfoColums());
  2420. if($inviter){
  2421. $inviter->benifit = UserUtils::get_user_invite_benifit($inviter->id);
  2422. $result['myinviter'] = $inviter;
  2423. }else{
  2424. $result['myinviter'] = null;
  2425. }
  2426. }
  2427. $my_inviter_users = [];
  2428. $first_userIds = WxUser::where('who', $uid)->pluck('id');
  2429. $second_userIds = null;
  2430. $third_userIds = null;
  2431. if($first_userIds){
  2432. $first_userIds = $first_userIds->toArray();
  2433. $second_userIds = WxUser::whereIn('who', $first_userIds)->pluck('id');
  2434. if($second_userIds){
  2435. $second_userIds = $second_userIds->toArray();
  2436. $third_userIds = WxUser::whereIn('who', $second_userIds)->pluck('id');
  2437. if($third_userIds){
  2438. $third_userIds = $third_userIds->toArray();
  2439. }
  2440. }
  2441. }
  2442. if($first_userIds){
  2443. foreach ($first_userIds as $user_id){
  2444. if(!isset($my_inviter_users[$user_id])){
  2445. $my_inviter_users[$user_id] = $user_id;
  2446. }
  2447. }
  2448. }
  2449. if($second_userIds){
  2450. foreach ($second_userIds as $user_id){
  2451. if(!isset($my_inviter_users[$user_id])){
  2452. $my_inviter_users[$user_id] = $user_id;
  2453. }
  2454. }
  2455. }
  2456. if($third_userIds){
  2457. foreach ($third_userIds as $user_id){
  2458. if(!isset($my_inviter_users[$user_id])){
  2459. $my_inviter_users[$user_id] = $user_id;
  2460. }
  2461. }
  2462. }
  2463. $result['team']['total'] = $my_inviter_users ? count($my_inviter_users) : 0;
  2464. $result['team']['lv1_team'] = $first_userIds ? count($first_userIds) : 0;
  2465. $result['team']['lv2_team'] = $second_userIds ? count($second_userIds) : 0;
  2466. $result['team']['lv3_team'] = $third_userIds ? count($third_userIds) : 0;
  2467. $records_ = [];
  2468. $records = WxUserInviteBenefitRecord::where('lv1_user', $uid)->orWhere('lv2_user', $uid)->orWhere('lv3_user', $uid)->orderBy('created_at', 'desc')->limit(5)->get();
  2469. if($records){
  2470. foreach ($records as $record){
  2471. $benefit = 0;
  2472. if($record->lv1_user == $uid){
  2473. $benefit = $record->lv1_benefit;
  2474. }else if($record->lv2_user == $uid){
  2475. $benefit = $record->lv2_benefit;
  2476. }else if($record->lv3_user == $uid){
  2477. $benefit = $record->lv3_benefit;
  2478. }
  2479. if($benefit < 0.01){
  2480. continue;
  2481. }
  2482. $user_name = UserUtils::get_cached_user_name($record->user_id);
  2483. if($record->shop_order_id > 0){
  2484. $str = '一笔来自「<a href="/pages/user/user?id='.(int)$record->user_id.'" target="_blank">'.$user_name.'</a>」的商城订单,您获得团队奖励¥'.$benefit;
  2485. }else if($record->order_id){
  2486. $str = '一笔来自「<a href="/pages/user/user?id='.(int)$record->user_id.'" target="_blank">'.$user_name.'</a>」的普通订单,您获得团队奖励¥'.$benefit;
  2487. }
  2488. $records_[] = $str;
  2489. }
  2490. }
  2491. $result['orders'] = $records_;
  2492. return $this->success($result);
  2493. }
  2494. /**
  2495. * 激励视频奖励
  2496. */
  2497. public function reward_gift(Request $request){
  2498. global $__MINI_GLOBAL_DEVICE__;
  2499. $action = $request->action;
  2500. $uid = $request->uid;
  2501. _limit_user('reward_gift', $uid, 20);
  2502. if($__MINI_GLOBAL_DEVICE__ == 'mp'){
  2503. $reward_every = Settings::get('ad_mp_reward_every');
  2504. }else{
  2505. $reward_every = Settings::get('ad_uni_reward_every');
  2506. }
  2507. $count = WxUserCoinRecord::where([
  2508. ['user_id', '=', $uid],
  2509. ['type', '=', 10],
  2510. ['created_at', '>=', Carbon::today()]
  2511. ])->count();
  2512. if($__MINI_GLOBAL_DEVICE__ == 'mp'){
  2513. $every_day_max = Settings::get('ad_mp_reward_every_day_times', 10);
  2514. }else{
  2515. $every_day_max = Settings::get('ad_uni_reward_every_day_times', 10);
  2516. }
  2517. if($count > $every_day_max){
  2518. return $this->fail(200010, [], '您今天获取奖励超过最大次数了,请您明天再来试试吧');
  2519. }
  2520. if($action == 'code'){
  2521. if($count <= $every_day_max){
  2522. $code = Utils::getSn(10);
  2523. Cache::put($code, 1, 80);
  2524. return $this->success($code);
  2525. }else{
  2526. return $this->fail(200010, [], '您今天获取奖励超过最大次数了,请您明天再来试试吧');
  2527. }
  2528. }else if($action == 'reward'){
  2529. $code = $request->code;
  2530. if(_empty_($code)){
  2531. return $this->fail(200001);
  2532. }
  2533. if(Cache::has($code)){
  2534. $r = UserUtils::update_user_coins($uid,10, $reward_every, '观看激励视频奖励:'.Settings::get('app_coin_name', '硬币').'(枚)*'.$reward_every);
  2535. Cache::forget($code);
  2536. return $this->success([], 200, '恭喜获得'.$reward_every.Settings::get('app_coin_name', '硬币'));
  2537. }else{
  2538. return $this->fail(200004);
  2539. }
  2540. }
  2541. }
  2542. /**
  2543. * 我的二维码卡片
  2544. */
  2545. public function codecard(Request $request){
  2546. $uid = $request->uid;
  2547. $user_id = $request->user_id;
  2548. if(_empty_($uid) && _empty_($user_id)){
  2549. return $this->fail(200001);
  2550. }
  2551. if($user_id){
  2552. $code = Utils::getMiniCode('pages/user/user', 'id='.$user_id, $uid);
  2553. $user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  2554. }else{
  2555. $code = Utils::getMiniCode('pages/user/user', 'id='.$uid, $uid);
  2556. $user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
  2557. }
  2558. if(_empty_($user->user_background_maps)){
  2559. $user->user_background_maps = Settings::get('user_background_maps', '');
  2560. }
  2561. if(_empty_($user->user_introduce)){
  2562. $user->user_introduce = Settings::get('app_user_introduce', '',true);
  2563. }
  2564. if($user){
  2565. if(Settings::get('app_user_qrcode_way', 0) == 2){
  2566. $result = [
  2567. 'user_background_maps' => $user->user_background_maps . '?imageMogr2/crop/330x200/gravity/center/thumbnail/330x/rradius/20',
  2568. 'user_avatar' => Utils::imgWithStyle($user->user_avatar, 2),
  2569. 'user_name' => mb_strlen($user->user_name) > 8 ? (mb_substr($user->user_name, 0, 8).'...') : $user->user_name,
  2570. 'id' => $user->id,
  2571. 'user_introduce' => $user->user_introduce,
  2572. 'rect' => 'https://img.mini.minisns.cn/hbx/qrcode_white_bg.png?imageMogr2/crop/330x390/gravity/center/thumbnail/330x/rradius/20',
  2573. 'code' => $code . '?imageMogr2/format/png/interlace/0',
  2574. 'logo' => Utils::imgWithStyle(Settings::get('about_logo', ''), 2),
  2575. 'way' => 2
  2576. ];
  2577. }else{
  2578. $result = [
  2579. 'user_background_maps' => Utils::imgWithStyle($user->user_background_maps, 1),
  2580. 'user_avatar' => $user->user_avatar . '?imageMogr2/crop/68x68/gravity/center/thumbnail/68x/rradius/68',
  2581. 'user_name' => mb_strlen($user->user_name) > 8 ? (mb_substr($user->user_name, 0, 8).'...') : $user->user_name,
  2582. 'id' => $user->id,
  2583. 'user_introduce' => $user->user_introduce,
  2584. 'code' => $code,
  2585. 'logo' => Utils::imgWithStyle(Settings::get('about_logo', ''), 2),
  2586. 'way' => 1
  2587. ];
  2588. }
  2589. return $this->success($result);
  2590. }
  2591. return $this->fail(200003);
  2592. }
  2593. /**
  2594. * 获取我的认证信息
  2595. */
  2596. public function getAuthentication(Request $request)
  2597. {
  2598. $uid = $request->uid;
  2599. return $this->success(WxAuthentication::where('user_id', $uid)->first());
  2600. }
  2601. /**
  2602. * 个人中心 我的笔记,收藏,喜欢,充电的文章数量
  2603. * @param Request $request
  2604. */
  2605. public function totalPost(Request $request)
  2606. {
  2607. $uid = $request->uid;
  2608. if($uid && $uid > 0){
  2609. $query = WxPost::where('user_id', $uid)->whereIn('posts_state', [0, 2]);
  2610. $data['myTotal'] = $query->count();
  2611. $postsIds = WxLike::where('user_id', $uid)->pluck('posts_id');
  2612. $data['likeTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
  2613. $postsIds = WxCollect::where('user_id', $uid)->pluck('posts_id');
  2614. $data['collecTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
  2615. $postsIds = WxExceptional::where('user_id', $uid)->pluck('posts_id');
  2616. $data['exceptionalTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
  2617. }else{
  2618. $data = [
  2619. 'myTotal' => 0,
  2620. 'likeTotal' => 0,
  2621. 'collecTotal' => 0,
  2622. 'exceptionalTotal' => 0
  2623. ];
  2624. }
  2625. return $this->success($data);
  2626. }
  2627. /**
  2628. * 我关注的用户列表
  2629. * @param Request $request
  2630. */
  2631. public function myFollowUsers(Request $request)
  2632. {
  2633. $uid = $request->uid;
  2634. $user_id = $request->user_id;
  2635. if ($user_id > 0) {
  2636. $data = WxUserFollow::with('followUser')->where('user_id', $user_id)
  2637. ->orderBy('id', 'desc')
  2638. ->simplePaginate(10);
  2639. $data->map(function ($v) use ($user_id, $uid) {
  2640. $v->is_together_follow = WxUserFollow::where('user_id', $v->user_follow_id)
  2641. ->where('user_follow_id', $user_id)->exists();// 是否相互关注
  2642. $v->user = $v->followUser;
  2643. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_follow_id);
  2644. });
  2645. return $this->success($data);
  2646. } else {
  2647. $data = WxUserFollow::with('followUser')->where('user_id', $uid)
  2648. ->orderBy('id', 'desc')
  2649. ->simplePaginate(10);
  2650. $data->map(function ($v) use ($uid) {
  2651. $v->is_together_follow = WxUserFollow::where('user_id', $v->user_follow_id)
  2652. ->where('user_follow_id', $uid)->exists();// 是否相互关注
  2653. $v->user = $v->followUser;
  2654. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_follow_id);
  2655. });
  2656. return $this->success($data);
  2657. }
  2658. }
  2659. /**
  2660. * 我的粉丝用户列表
  2661. * @param Request $request
  2662. */
  2663. public function myFansUsers(Request $request)
  2664. {
  2665. $uid = $request->uid;
  2666. $user_id = $request->user_id;
  2667. if ($user_id > 0) {
  2668. $data = WxUserFollow::with('user')->where('user_follow_id', $user_id)
  2669. ->orderBy('id', 'desc')
  2670. ->simplePaginate(15);
  2671. $data->map(function ($v) use ($user_id, $uid) {
  2672. $v->is_together_follow = WxUserFollow::where('user_id', $user_id)
  2673. ->where('user_follow_id', $v->user_id)->exists();// 是否相互关注
  2674. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_id);
  2675. });
  2676. return $this->success($data);
  2677. } else {
  2678. $data = WxUserFollow::with('user')->where('user_follow_id', $uid)
  2679. ->orderBy('id', 'desc')
  2680. ->simplePaginate(15);
  2681. $data->map(function ($v) use ($uid) {
  2682. $v->is_together_follow = WxUserFollow::where('user_id', $uid)
  2683. ->where('user_follow_id', $v->user_id)->exists();// 是否相互关注
  2684. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_id);
  2685. });
  2686. return $this->success($data);
  2687. }
  2688. }
  2689. /**
  2690. * 艾特搜索
  2691. * @param Request $request
  2692. */
  2693. public function aiteSearch(Request $request){
  2694. $keyword = $request->keyword;
  2695. $uid = $request->uid;
  2696. _limit_user('search', $uid, 60);
  2697. $limit = $request->input('limit', 10);
  2698. if(_empty_($keyword)){
  2699. $data = WxUser::whereIn('id', WxUserFollow::select('user_follow_id')->where('user_id', $uid)
  2700. ->orderBy('id', 'desc')
  2701. )->simplePaginate($limit);
  2702. }else{
  2703. $keyword_actree = null;
  2704. $data = SearchUtils::search_user($keyword_actree, $keyword, $uid, false, $limit);
  2705. }
  2706. return $this->success($data);
  2707. }
  2708. /**
  2709. * 获取用户列表
  2710. * @param Request $request
  2711. */
  2712. public function getUsers(Request $request)
  2713. {
  2714. $uid = $request->uid;
  2715. $type = $request->type;
  2716. $limit = $request->limit;
  2717. if(_empty_($limit)){
  2718. $limit = 10;
  2719. }else{
  2720. $limit = _between_($limit, 1, 100);
  2721. }
  2722. $page = _empty_default_($request->page, 1);
  2723. $object_id = _empty_default_($request->object_id, 0);
  2724. if(_empty_($type)){
  2725. return $this->fail(200001);
  2726. }
  2727. if($type == 1){
  2728. // 最近注册用户列表
  2729. $data = WxUser::where('user_state', 0)->orderBy('created_at', 'desc')->simplePaginate($limit, FieldUtils::userInfoColums());
  2730. if($data){
  2731. $data->map(function ($v) use ($uid){
  2732. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2733. if($online_item){
  2734. $v->online_time = format_datetime($online_item->online);
  2735. $v->device = $online_item->device;
  2736. }else{
  2737. $v->online_time = '暂时未知';
  2738. $v->device = '';
  2739. }
  2740. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2741. return $v;
  2742. });
  2743. }
  2744. return $this->success($data);
  2745. }else if($type == 2){
  2746. // 在线用户列表
  2747. $data = UserUtils::user_onlines(2, 5, 1);
  2748. if($data){
  2749. $data->map(function ($v) use ($uid){
  2750. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2751. if($online_item){
  2752. $v->online_time = format_datetime($online_item->online);
  2753. $v->device = $online_item->device;
  2754. }else{
  2755. $v->online_time = '暂时未知';
  2756. $v->device = '';
  2757. }
  2758. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2759. return $v;
  2760. });
  2761. }
  2762. return $this->success($data);
  2763. }else if($type == 3){
  2764. // 今日注册的用户
  2765. $data = WxUser::where('created_at', '>', Carbon::today())->orderBy('created_at', 'desc')->simplePaginate($limit, FieldUtils::userInfoColums());
  2766. if($data) {
  2767. $data->map(function ($v) use ($uid){
  2768. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2769. if ($online_item) {
  2770. $v->online_time = format_datetime($online_item->online);
  2771. $v->device = $online_item->device;
  2772. } else {
  2773. $v->online_time = '暂时未知';
  2774. $v->device = '';
  2775. }
  2776. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2777. return $v;
  2778. });
  2779. }
  2780. return $this->success($data);
  2781. }else if($type == 4){
  2782. // 余额排行
  2783. $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')
  2784. ->where('wx_user_financial.balance', '>', 0)->orderBy('wx_user_financial.balance', 'desc')->orderBy('wx_user.id')
  2785. ->simplePaginate($limit, FieldUtils::userInfoColums());
  2786. if($data){
  2787. $data->map(function ($v) use ($uid){
  2788. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2789. if ($online_item) {
  2790. $v->online_time = format_datetime($online_item->online);
  2791. $v->device = $online_item->device;
  2792. } else {
  2793. $v->online_time = '暂时未知';
  2794. $v->device = '';
  2795. }
  2796. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2797. $v->desc_tip = '拥有'.$v->balance.'余额';
  2798. return $v;
  2799. });
  2800. }
  2801. return $this->success($data);
  2802. }else if($type == 5){
  2803. // 金币排行用户
  2804. $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'])
  2805. ->leftJoin('wx_user_meta_num', function ($join) {
  2806. $join->on('wx_user.id', '=', 'wx_user_meta_num.user_id')
  2807. ->where('wx_user_meta_num.meta_key', '=', 'coins');
  2808. })->orderBy('wx_user_meta_num.meta_value', 'desc')->orderBy('wx_user.id')
  2809. ->simplePaginate($limit, FieldUtils::userInfoColums());
  2810. if($data){
  2811. $data->map(function ($v) use ($uid){
  2812. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2813. if ($online_item) {
  2814. $v->online_time = format_datetime($online_item->online);
  2815. $v->device = $online_item->device;
  2816. } else {
  2817. $v->online_time = '暂时未知';
  2818. $v->device = '';
  2819. }
  2820. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2821. $v->desc_tip = '拥有'.$v->coins.Settings::get('app_coin_name', '硬币');
  2822. return $v;
  2823. });
  2824. }
  2825. return $this->success($data);
  2826. }else if($type == 6){
  2827. // 笔记总数排行
  2828. $subQuery = DB::table('wx_posts')
  2829. ->select('user_id', DB::raw('COUNT(*) as post_count'))
  2830. ->groupBy('user_id')
  2831. ->orderByDesc('post_count')
  2832. ->toSql();
  2833. $data = WxUser::join(DB::raw("({$subQuery}) as sub"), 'wx_user.id', '=', 'sub.user_id')->orderBy('post_count', 'desc')->orderBy('id')
  2834. ->simplePaginate($limit, array_merge(FieldUtils::userInfoColums(), ['post_count']));
  2835. if($data){
  2836. $data->map(function ($v) use ($uid){
  2837. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2838. if ($online_item) {
  2839. $v->online_time = format_datetime($online_item->online);
  2840. $v->device = $online_item->device;
  2841. } else {
  2842. $v->online_time = '暂时未知';
  2843. $v->device = '';
  2844. }
  2845. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2846. $v->desc_tip = '发布了'.$v->post_count.'篇笔记';
  2847. return $v;
  2848. });
  2849. }
  2850. return $this->success($data);
  2851. }else if($type == 7){
  2852. // 我拉黑的用户
  2853. return $this->fail(200003);
  2854. }else if($type == 8){
  2855. // 不喜欢的用户
  2856. $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  2857. if($user_set){
  2858. $user_set = array_reverse($user_set);
  2859. $data = WxUser::whereIn('id', $user_set)
  2860. ->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $user_set) . '"' . ")"))->orderBy('id')->simplePaginate($limit, FieldUtils::userInfoColums());
  2861. if($data){
  2862. $data->map(function ($v) use ($uid){
  2863. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2864. if ($online_item) {
  2865. $v->online_time = format_datetime($online_item->online);
  2866. $v->device = $online_item->device;
  2867. } else {
  2868. $v->online_time = '暂时未知';
  2869. $v->device = '';
  2870. }
  2871. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2872. return $v;
  2873. });
  2874. return $this->success($data);
  2875. }
  2876. return $this->fail(200003);
  2877. }else{
  2878. return $this->fail(200003);
  2879. }
  2880. }else if($type == 9){
  2881. // 激励用户排行榜
  2882. $data = WxUserCoinRecord::query()
  2883. ->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'))
  2884. ->join('wx_user', 'wx_user.id', '=', 'wx_user_coin_record.user_id')
  2885. ->where('wx_user_coin_record.type', 10)
  2886. ->groupBy('wx_user_coin_record.user_id')
  2887. ->orderByDesc('total_incre')->orderBy('wx_user.id')
  2888. ->simplePaginate($limit, FieldUtils::userInfoColums());
  2889. if($data){
  2890. $data->map(function ($v) use ($uid){
  2891. $v->desc_tip = '支持了'.$v->coin_add_count.'次';
  2892. return $v;
  2893. });
  2894. return $this->success($data);
  2895. }
  2896. return $this->success($data);
  2897. }else if($type == 10){
  2898. // 邀请榜
  2899. $data = WxUser::query()
  2900. ->join('wx_user as inviters', 'inviters.id', '=', 'wx_user.who') // 连接wx_user表来获取邀请人信息
  2901. ->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') // 选择所需字段
  2902. ->where('wx_user.who', '>', 0) // 确保'who'字段不为空
  2903. ->groupBy('wx_user.who') // 按'who'字段分组,同时包括邀请人的信息
  2904. ->orderByDesc('total_invites')->orderBy('inviters.id') // 按邀请数降序排序
  2905. ->simplePaginate($limit);
  2906. if($data){
  2907. $data->map(function ($v) use ($uid){
  2908. $v->desc_tip = '直接邀请'.$v->total_invites.'人';
  2909. return $v;
  2910. });
  2911. return $this->success($data);
  2912. }
  2913. return $this->success($data);
  2914. }else if($type == 11){
  2915. // 粉丝排行榜
  2916. $data = WxUser::query()
  2917. ->join('wx_user_follow', 'wx_user.id', '=', 'wx_user_follow.user_follow_id')
  2918. ->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'))
  2919. ->where('wx_user_follow.user_follow_state', 0) // 只计算正常关注的情况
  2920. ->groupBy('wx_user.id')
  2921. ->orderByDesc('followers_count')->orderBy('wx_user.id') // 根据粉丝数量降序排序
  2922. ->simplePaginate($limit);
  2923. if($data){
  2924. $data->map(function ($v) use ($uid){
  2925. $v->desc_tip = '粉丝数'.$v->followers_count.'人';
  2926. return $v;
  2927. });
  2928. return $this->success($data);
  2929. }
  2930. return $this->success($data);
  2931. }else if($type == 12){
  2932. // 等级排行榜
  2933. $data = WxUser::query()
  2934. ->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')
  2935. ->joinSub(function ($query) {
  2936. $query->from('wx_user_meta_num')
  2937. ->select('user_id', 'meta_value')
  2938. ->where('meta_key', 'experience');
  2939. }, 'meta_num', 'meta_num.user_id', 'wx_user.id')
  2940. ->orderBy('experience', 'desc')->orderBy('wx_user.id') // 根据经验值降序排序
  2941. ->simplePaginate($limit);
  2942. if($data){
  2943. $data->map(function ($v) use ($uid){
  2944. $v->desc_tip = '经验值'.$v->experience;
  2945. return $v;
  2946. });
  2947. return $this->success($data);
  2948. }
  2949. return $this->success($data);
  2950. }else if($type == 13){
  2951. // 俱乐部粉丝
  2952. $data = DB::table('wx_club_follow as wcf')
  2953. ->join('wx_user as wu', 'wcf.user_id', '=', 'wu.id')
  2954. ->select('wu.*', 'wcf.created_at as follow_time')
  2955. ->where('wcf.club_id', $object_id)
  2956. ->where('wcf.status', 1) // 只获取状态为关注的记录
  2957. ->orderBy('wcf.created_at', 'desc')
  2958. ->simplePaginate($limit);
  2959. if($data){
  2960. $data->map(function ($v) use ($uid){
  2961. $v->desc_tip = '关注时间:'.$v->follow_time;
  2962. return $v;
  2963. });
  2964. return $this->success($data);
  2965. }
  2966. return $this->success($data);
  2967. }else if($type == 14){
  2968. // 关注圈子的粉丝
  2969. $data = DB::table('wx_user_circle as wcf')
  2970. ->join('wx_user as wu', 'wcf.user_id', '=', 'wu.id')
  2971. ->select('wu.*', 'wcf.created_at as follow_time')
  2972. ->where('wcf.circle_id', $object_id)
  2973. ->where('wcf.user_circle_state', 0) // 只获取状态为关注的记录
  2974. ->orderBy('wcf.created_at', 'desc')
  2975. ->simplePaginate($limit);
  2976. if($data){
  2977. $data->map(function ($v) use ($uid){
  2978. $v->desc_tip = '关注时间:'.$v->follow_time;
  2979. return $v;
  2980. });
  2981. return $this->success($data);
  2982. }
  2983. return $this->success($data);
  2984. }else if($type == 17){
  2985. // 获取传单所推广的用户
  2986. $itcId = (int)str_replace('itc', '', _empty_default_($request->itc, ''));
  2987. if(_empty_($itcId)){
  2988. return $this->fail(200001);
  2989. }
  2990. $data = DB::table('wx_user as u')
  2991. ->join('wx_user_invite_temp_code_record as r', 'u.id', '=', 'r.object_id')
  2992. ->where('r.itc_id', $itcId)
  2993. ->orderBy('r.created_at', 'desc')
  2994. ->select('u.*', 'r.created_at', 'r.*')->simplePaginate($limit);
  2995. $data->map(function ($v) use ($uid){
  2996. $v->desc_tip = $v->created_at . ' 奖励:¥' . $v->reward_balance . ($v->reward_coin > 0 ? '+'.Settings::get('app_coin_name', '硬币').'*'.$v->reward_coin : '');
  2997. return $v;
  2998. });
  2999. return $this->success($data);
  3000. }
  3001. }
  3002. /**
  3003. * 添加用户话题
  3004. * @param Request $request
  3005. */
  3006. public function addUserPlate(Request $request)
  3007. {
  3008. $plateId = $request->plate_id;
  3009. $uid = $request->uid;
  3010. if(_empty_($plateId)){
  3011. return $this->fail(200001);
  3012. }
  3013. $r = UserUtils::add_user_plate($uid, $plateId);
  3014. if($r){
  3015. return $this->success();
  3016. }
  3017. return $this->fail(200004, [], '添加分区失败');
  3018. }
  3019. public function real_name(Request $request)
  3020. {
  3021. $uid = $request->uid;
  3022. if(request()->method() === 'GET'){
  3023. $user = WxUser::where('id', $uid)->first(['id', 'real_name', 'real_id_card']);
  3024. if($user){
  3025. if(_empty_($user->real_name)){
  3026. $user->real_name = '';
  3027. }
  3028. if(_empty_($user->real_id_card)){
  3029. $user->real_id_card = '';
  3030. }
  3031. return $this->success($user);
  3032. }else{
  3033. return $this->fail(200003);
  3034. }
  3035. }else{
  3036. $user = WxUser::find($uid);
  3037. if(_empty_($user)){
  3038. return $this->fail(200003);
  3039. }
  3040. $realName = _empty_default_($request->realName, '');
  3041. $realIdCard = _empty_default_($request->realIdCard, '');
  3042. if(_empty_($realName) || _empty_($realIdCard)){
  3043. return $this->fail(200001);
  3044. }
  3045. if(mb_strlen($realName) <= 1){
  3046. return $this->fail(200004, [], '姓名过短');
  3047. }
  3048. if(strpos($realName, '*') !== false || strpos($realIdCard, '*') !== false){
  3049. return $this->fail(200004, [], '姓名或身份证中含有*号,请先删除');
  3050. }
  3051. if(strlen($realIdCard) != 18){
  3052. return $this->fail(200004, [], '请输入合法的身份证号');
  3053. }
  3054. // $realName_fake = mb_substr($realName, 0, 1) . str_repeat( '*', (mb_strlen($realName) - 1) );
  3055. // $realIdCard_fake = mb_substr($realIdCard, 0, 2) . str_repeat( '*', (mb_strlen($realIdCard) - 2) );
  3056. $realName_fake = $realName;
  3057. $realIdCard_fake = $realIdCard;
  3058. if($user->real_name == $realName_fake && $user->real_id_card == $realIdCard_fake){
  3059. return $this->fail(200010, [], '与已有认证信息相同,无需修改');
  3060. }
  3061. $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
  3062. if(_empty_($user->phone) || _empty_($phone)){
  3063. return $this->fail(200043, [
  3064. 'title' => '未绑定手机号',
  3065. 'content' => '前往绑定',
  3066. 'confirmText' => '去绑定',
  3067. 'target_type' => 6,
  3068. 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
  3069. ], '未绑定手机号');
  3070. }
  3071. // $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
  3072. // todo:
  3073. // WxUser::where('id', $uid)->update([
  3074. // 'real_name' => $realName_fake,
  3075. // 'real_id_card' => $realIdCard_fake
  3076. // ]);
  3077. // update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
  3078. // // Conditions 更新实名认证状态
  3079. // Conditions::where('user_id', $uid)->update(['is_real' => 1]);
  3080. // DB::commit();
  3081. // return $this->success([], 200, '实名认证成功');
  3082. $res_ = Http::withHeaders([
  3083. 'Authorization' => 'APPCODE '.Settings::get('app_ali_real_name_appcode', ''),
  3084. ])->asForm()->post('https://mobile3elements.shumaidata.com/mobile/verify_real_name', ['idcard'=>$realIdCard, 'mobile'=>$phone, 'name'=> $realName]);
  3085. //print_r($res_);exit;
  3086. if($res_->successful()){
  3087. $res = $res_->json();
  3088. if($res){
  3089. if($res['code'] == 0 && $res['result']){
  3090. if($res['result']['res'] == 1){
  3091. // 一致
  3092. DB::beginTransaction();
  3093. try {
  3094. $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
  3095. // todo:
  3096. WxUser::where('id', $uid)->update([
  3097. 'real_name' => $realName_fake,
  3098. 'real_id_card' => $realIdCard_fake,
  3099. 'is_real' => 1
  3100. ]);
  3101. update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
  3102. // Conditions 更新实名认证状态
  3103. Conditions::where('user_id', $uid)->update(['is_real' => 1]);
  3104. DB::commit();
  3105. return $this->success([], 200, '实名认证成功');
  3106. } catch (\Exception $e) {
  3107. DB::rollBack();
  3108. _logger_(__file__, __line__, $e->getMessage());
  3109. return $this->fail(200002);
  3110. }
  3111. }else if($res['result']['res'] == 2){
  3112. return $this->fail(200004, [], '身份信息不一致,认证失败');
  3113. }else if($res['result']['res'] == 3){
  3114. return $this->fail(200004, [], '认证系统查询不到该信息,请联系客服');
  3115. }else if($res['result']['res'] == -1){
  3116. return $this->fail(200004, [], '异常');
  3117. }
  3118. }else{
  3119. UserUtils::assistant_notice('admin', $res.'_003');
  3120. return $this->fail(200004, [], $res['message'].'__003');
  3121. }
  3122. }
  3123. }else{
  3124. $res = $res_->json();
  3125. _logger_(__file__, __line__, '实名认证返回错误,'.$res_->body());
  3126. _logger_(__file__, __line__, '实名认证返回错误,'. urldecode($res_));
  3127. return $this->fail(200004, [], _array_key($res, 'message', ''));
  3128. }
  3129. }
  3130. }
  3131. /**
  3132. * 删除用户话题
  3133. * @param Request $request
  3134. */
  3135. public function deleteUserPlate(Request $request)
  3136. {
  3137. $id = $request->id;
  3138. $uid = $request->uid;
  3139. $plate_id = $request->plate_id;
  3140. if(_empty_($plate_id)){
  3141. (new WxUserPlate())->where('user_id', $uid)->where('id', $id)->update(['status'=>2]);
  3142. }else{
  3143. (new WxUserPlate())->where('user_id', $uid)->where('plate_id', $plate_id)->update(['status'=>2]);
  3144. }
  3145. return $this->success();
  3146. }
  3147. /**
  3148. * 用户话题列表
  3149. * @param Request $request
  3150. */
  3151. public function userPlate(Request $request)
  3152. {
  3153. global $__MINI_GLOBAL_TENANT_ID__;
  3154. $uid = $request->uid;
  3155. if ($uid == 0) {
  3156. $data = [];
  3157. } else {
  3158. $data = (new WxUserPlate())->where('user_id', $uid)->where('status', 1)->orderBy('updated_at', 'asc')->get();
  3159. if(!$data->isEmpty()){
  3160. $data = $data->map(function ($item) {
  3161. $plate = WxPlate::find($item->plate_id);
  3162. if($plate){
  3163. $item->plate_name = $plate->plate_name;
  3164. $item->tenant_id = $plate->tenant_id;
  3165. return $item;
  3166. }
  3167. });
  3168. $data = $data->filter(function ($item, $key) use ($__MINI_GLOBAL_TENANT_ID__){
  3169. if($item){
  3170. return $item->tenant_id == $__MINI_GLOBAL_TENANT_ID__;
  3171. }
  3172. return false;
  3173. });
  3174. }
  3175. }
  3176. return $this->success($data);
  3177. }
  3178. /**
  3179. * 我的订单列表
  3180. */
  3181. public function myOrder(Request $request, $limit = 8)
  3182. {
  3183. $uid = $request->uid;
  3184. $type = $request->type;
  3185. if(_empty_($type)){
  3186. return $this->fail(200001);
  3187. }
  3188. if($type == 'all'){
  3189. if(!UserUtils::is_mini_supder_admin($uid)){
  3190. return $this->fail(200000);
  3191. }
  3192. $data = WxOrder::where([['order_state','=', 1], ['order_serial_number', '<>', '']])
  3193. ->orderBy('id', 'desc')->simplePaginate($limit);
  3194. }else{
  3195. $data = WxOrder::where('user_id', $uid)->where([['order_state','=', 1], ['order_serial_number', '<>', '']])
  3196. ->orderBy('id', 'desc')->simplePaginate($limit);
  3197. }
  3198. $data->map(function ($v) {
  3199. $v->type_content = WxUserRepositores::orderType($v->order_type);
  3200. $parame = unserialize($v->parame);
  3201. $v->posts_id = $parame['postsId'] ?? 0;
  3202. $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
  3203. });
  3204. return $this->success($data);
  3205. }
  3206. public function financial_process(Request $request){
  3207. $type = _empty_default_($request->type, '');
  3208. if ($type == 'my_financial') {
  3209. return $this->myFinancial($request);
  3210. }else if ($type == 'initiate_withdrawal') {
  3211. return $this->initiateWithdrawal($request);
  3212. }else if ($type == 'withdrawal_apply') {
  3213. return $this->withdrawalApply($request);
  3214. }else if ($type == 'withdrawal_list') {
  3215. return $this->withdrawalList($request);
  3216. }else if ($type == 'balance_record_list') {
  3217. return $this->balanceRecordList($request);
  3218. }else if ($type == 'coin_record_list') {
  3219. return $this->coinRecordList($request);
  3220. }
  3221. }
  3222. private function coinRecordList(Request &$request){
  3223. $uid = $request->uid;
  3224. $setUserid = $request->setUserid;
  3225. if(!_empty_($setUserid)) {
  3226. if ($setUserid && $setUserid > 0) {
  3227. if (UserUtils::is_mini_supder_admin($uid)) {
  3228. $uid = $setUserid;
  3229. } else {
  3230. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3231. }
  3232. }
  3233. }
  3234. $data = WxUserCoinRecord::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  3235. if($data){
  3236. $data->map(function ($v) {
  3237. });
  3238. return $this->success($data);
  3239. }
  3240. return $this->fail(200003);
  3241. }
  3242. private function balanceRecordList(Request &$request){
  3243. $uid = $request->uid;
  3244. $setUserid = $request->setUserid;
  3245. if(!_empty_($setUserid)) {
  3246. if ($setUserid && $setUserid > 0) {
  3247. if (UserUtils::is_mini_supder_admin($uid)) {
  3248. $uid = $setUserid;
  3249. } else {
  3250. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3251. }
  3252. }
  3253. }
  3254. $data = WxUserFinancialRecord::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  3255. if($data){
  3256. $data->map(function ($v) {
  3257. });
  3258. return $this->success($data);
  3259. }
  3260. return $this->fail(200003);
  3261. }
  3262. private function withdrawalList(Request &$request){
  3263. $uid = $request->uid;
  3264. $setUserid = $request->setUserid;
  3265. if(!_empty_($setUserid)) {
  3266. if ($setUserid && $setUserid > 0) {
  3267. if (UserUtils::is_mini_supder_admin($uid)) {
  3268. $uid = $setUserid;
  3269. } else {
  3270. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3271. }
  3272. }
  3273. }
  3274. $data = WxUserWithdrawal::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  3275. if($data){
  3276. $data->map(function ($v) {
  3277. $v->state_tip = WxUserRepositores::withdrawalType($v->state);
  3278. if(!_empty_($v->withdrawal_remark)){
  3279. $v->title = $v->withdrawal_remark;
  3280. }else if(!_empty_($v->wechat_phone)){
  3281. $v->way = 'wechat';
  3282. $v->title = '提现'.$v->pay_amount.'元到微信';
  3283. }else if(!_empty_($v->alipay_phone)){
  3284. $v->way = 'alipay';
  3285. $v->title = '提现'.$v->pay_amount.'元到支付宝';
  3286. }else if(!_empty_($v->bank_card)){
  3287. $v->way = 'bank';
  3288. $v->title = '提现'.$v->pay_amount.'元到银行卡';
  3289. }
  3290. if(_empty_($v->way)){
  3291. if(!_empty_($v->wx_batch_id)){
  3292. $v->way = 'wechat';
  3293. }else if(!_empty_($v->ali_batch_id)){
  3294. $v->way = 'alipay';
  3295. }
  3296. }
  3297. });
  3298. return $this->success($data);
  3299. }
  3300. return $this->fail(200003);
  3301. }
  3302. private function withdrawalApply(Request &$request){
  3303. $uid = $request->uid;
  3304. $id = _empty_default_($request->id, 0);
  3305. if(_empty_($id)){
  3306. return $this->fail(200001);
  3307. }
  3308. $withdrawal = WxUserWithdrawal::find($id);
  3309. if($withdrawal->user_id != $uid && !UserUtils::is_mini_supder_admin($uid)){
  3310. return $this->fail(200000);
  3311. }
  3312. $withdrawal->state_tip = WxUserRepositores::withdrawalType($withdrawal->state);
  3313. if(!_empty_($withdrawal->wechat_phone)){
  3314. $withdrawal->way = 'wechat';
  3315. }else if(!_empty_($withdrawal->alipay_phone)){
  3316. $withdrawal->way = 'alipay';
  3317. }else if(!_empty_($withdrawal->bank_card)){
  3318. $withdrawal->way = 'bank';
  3319. }else if(!_empty_($withdrawal->wx_batch_id)){
  3320. $withdrawal->way = 'wechat';
  3321. }else if(!_empty_($withdrawal->ali_batch_id)){
  3322. $withdrawal->way = 'alipay';
  3323. }
  3324. return $this->success($withdrawal);
  3325. }
  3326. /**
  3327. * 我的收益
  3328. */
  3329. public function myFinancial(Request $request)
  3330. {
  3331. $uid = $request->uid;
  3332. $setUserid = $request->setUserid;
  3333. if(!_empty_($setUserid)){
  3334. if($setUserid && $setUserid > 0){
  3335. if(UserUtils::is_mini_supder_admin($uid)){
  3336. $uid = $setUserid;
  3337. }else{
  3338. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3339. }
  3340. }
  3341. }
  3342. $result = [
  3343. 'coins' => [
  3344. 'total' => UserUtils::user_coins($uid) ?? 0
  3345. ],
  3346. 'financial' => [],
  3347. ];
  3348. $result['financial'] = WxUserFinancial::where('user_id', $uid)
  3349. ->first();
  3350. if($result['financial']) {
  3351. $result['financial']->earnings_yesterday = WxExceptional::where('posts_user_id', $result['financial']->user_id)
  3352. ->where('created_at', 'like', '%' . date("Y-m-d", strtotime("-1 day")) . '%')
  3353. ->sum('exceptional_price');
  3354. if(_empty_($result['financial']->withdrawal_price)){
  3355. $result['financial']->withdrawal_price = 0;
  3356. }
  3357. return $this->success($result);
  3358. }else{
  3359. return $this->success($result);
  3360. }
  3361. }
  3362. /**
  3363. * 发起提现
  3364. */
  3365. public function initiateWithdrawal(Request $request)
  3366. {
  3367. global $__MINI_GLOBAL_CURRENT_PLAYER_ID__;
  3368. $uid = $request->uid;
  3369. $price = $request->price;
  3370. $bank_name = _empty_default_($request->bank_name, '');
  3371. $bank_card = _empty_default_($request->bank_card, '');
  3372. $real_name = $request->real_name ?? null;
  3373. $id_card = _empty_default_($request->id_card, '');
  3374. $wechat_phone = $request->wechat_phone ?? null;
  3375. $aliay_phone = $request->aliay_phone ?? null;
  3376. $withdrawal_way = _empty_default_($request->way, 'wechat');
  3377. $device = in_array($request->header('device',''), ['app', 'h5', 'mp', 'pc']) ? $request->header('device','') : '';
  3378. if($price < Settings::get('app_balance_withdrawal_min_once', 1) || $price > Settings::get('app_balance_withdrawal_max_once', 200)){
  3379. return $this->fail(200004, [], '提现金额不合法');
  3380. }
  3381. $user = WxUser::find($uid);
  3382. // 验证资料
  3383. if(Settings::get('app_balance_withdrawal_force_bind_phone', 0) == 1){
  3384. if(_empty_($user->phone) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  3385. return $this->fail(200043, [
  3386. 'title' => '未绑定手机号',
  3387. 'content' => '前往绑定',
  3388. 'confirmText' => '去绑定',
  3389. 'target_type' => 6,
  3390. 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
  3391. ], '未绑定手机号');
  3392. }
  3393. }
  3394. if(Settings::get('app_balance_withdrawal_force_real_name', 0) == 1){
  3395. if(_empty_($user->real_name) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  3396. return $this->fail(200043, [
  3397. 'title' => '未实名认证',
  3398. 'content' => '您还没有实名认证,是否前往认证',
  3399. 'confirmText' => '去认证',
  3400. 'target_type' => 6,
  3401. 'target_id' => '/pagesA/mine/realname/realname'
  3402. ], '未实名认证');
  3403. }
  3404. }
  3405. if(Settings::get('app_balance_withdrawal_force_subscribe_mp', 0) == 1){
  3406. if(_empty_($user->weixin_mp_openid) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  3407. $weapp = new WeApp('mp');
  3408. $mpServicer = $weapp->getMpServicer();
  3409. try {
  3410. $url = $mpServicer->getQrCodeWithPara(0, 'user:bind:'.$user->id);
  3411. }catch (\Exception $e){
  3412. return $this->fail(200006, [], '生成公众号二维码失败,请检查[全局配置-支付-微信-公众号]');
  3413. }
  3414. if($url){
  3415. $qrCode = QrCode::format('png')->size(300)->generate($url);
  3416. $image = Image::make($qrCode);
  3417. $image->resizeCanvas(300, 300 + 60, 'bottom', false, '#ffffff'); // 增加高度,保持宽高比,背景色为白色
  3418. $mp_app_name = Settings::get('mp_app_name', '');
  3419. $text_tip = '关注'.$mp_app_name.'公众号,可以更方便通知到您';
  3420. if(mb_strlen($mp_app_name) > 4){
  3421. $text_tip = '关注'.$mp_app_name.'公众号';
  3422. }
  3423. $image->text($text_tip, 150, 40, function($font){
  3424. $font->file(public_path('storage/font/DingTalk_JinBuTi_Regular.ttf')); // 字体文件路径
  3425. $font->size(13); // 字体大小
  3426. $font->color('#000000'); // 字体颜色
  3427. $font->align('center'); // 水平对齐
  3428. $font->valign('top'); // 垂直对齐
  3429. });
  3430. $base64 = 'data:image/png;base64,' . base64_encode($image->encode('png')->getEncoded());
  3431. return $this->fail(200043, [
  3432. 'title' => '未关注公众号,无法实时获取通知',
  3433. 'content' => '前往关注',
  3434. 'confirmText' => '去关注',
  3435. 'target_type' => 26,
  3436. 'target_id' => $base64
  3437. ], '未关注公众号');
  3438. }
  3439. }
  3440. }
  3441. if(_empty_($real_name)){
  3442. return $this->fail(200001, [], '缺少真实姓名');
  3443. }
  3444. $financial_updates = [];
  3445. if($withdrawal_way == 'wechat'){
  3446. if(_empty_($wechat_phone) || !StrUtils::is_phone_number($wechat_phone)){
  3447. return $this->fail(200001, [], '微信手机号不合法');
  3448. }
  3449. if(_empty_($real_name)){
  3450. return $this->fail(200001, [], '姓名不完整');
  3451. }
  3452. $financial_updates['wechat_phone'] = $wechat_phone;
  3453. $financial_updates['real_name'] = $real_name;
  3454. }else if($withdrawal_way == 'alipay'){
  3455. if(_empty_($aliay_phone) || !StrUtils::is_phone_number($aliay_phone)){
  3456. return $this->fail(200001, [], '支付宝手机号不合法');
  3457. }
  3458. if(_empty_($real_name) || _empty_($id_card) || strlen($id_card) != 18){
  3459. return $this->fail(200001, [], '姓名或身份证号不完整');
  3460. }
  3461. $financial_updates['alipay_phone'] = $aliay_phone;
  3462. $financial_updates['real_name'] = $real_name;
  3463. $financial_updates['id_card'] = $id_card;
  3464. }else{
  3465. if(_empty_($bank_name) || _empty_($bank_card) || _empty_($real_name)){
  3466. return $this->fail(200001, [], '银行信息不完整');
  3467. }
  3468. $financial_updates['bank_name'] = $bank_name;
  3469. $financial_updates['bank_card'] = $bank_card;
  3470. $financial_updates['real_name'] = $real_name;
  3471. }
  3472. if(WxUserWithdrawal::where('user_id', $uid)->where('withdrawal_scene', 0)->whereDate('created_at', Carbon::today())->count() >= Settings::get('app_balance_withdrawal_day_times', 3)){
  3473. return $this->fail(200046, [], '您今天已经达到最大的提现次数了');
  3474. }
  3475. $platform_percent = _between_(Settings::get('app_withdrawal_platform_percent', 10.0), 0, 100);
  3476. $pay_amount = round(($price * ( 100 - $platform_percent )) / 100, 2);
  3477. DB::beginTransaction();
  3478. try{
  3479. $r = UserUtils::update_user_financial($uid, 2, $price, '发起余额提现¥'.$price, 0, $bank_name, $bank_card);
  3480. if($r){
  3481. $withdrawal_id = Utils::getSn(14);
  3482. // 提现记录
  3483. $userWithdrawalModel = new WxUserWithdrawal();
  3484. $userWithdrawalModel->user_id = $uid;
  3485. $userWithdrawalModel->withdrawal_id = $withdrawal_id;
  3486. $userWithdrawalModel->price = $price;
  3487. $userWithdrawalModel->pay_amount = $pay_amount;
  3488. $userWithdrawalModel->bank_name = $bank_name;
  3489. $userWithdrawalModel->bank_card = $bank_card;
  3490. $userWithdrawalModel->real_name = $real_name;
  3491. if($withdrawal_way == 'wechat'){
  3492. $userWithdrawalModel->wechat_phone = $wechat_phone;
  3493. $userWithdrawalModel->alipay_phone = null;
  3494. }else if($withdrawal_way == 'alipay'){
  3495. $userWithdrawalModel->wechat_phone = null;
  3496. $userWithdrawalModel->alipay_phone = $aliay_phone;
  3497. }
  3498. $userWithdrawalModel->state = 0;
  3499. $userWithdrawalModel->save();
  3500. UserUtils::assistant_notice('admin', '有用户(<a href="/pages/user/user?id='.$uid.'">id: '.$uid.'</a>)提交了新的提现申请。');
  3501. WxUserFinancial::where('user_id', $uid)->update($financial_updates);
  3502. UserWithdrawalProcessJob::dispatch($userWithdrawalModel->id);
  3503. $tmplIds = [];
  3504. if($device == 'mp'){
  3505. $comment_add_id = Settings::get('mini_template_message_withdrawal', '');
  3506. if(!_empty_($comment_add_id)){
  3507. $tmplIds[] = $comment_add_id;
  3508. }
  3509. }
  3510. DB::commit();
  3511. return $this->success([
  3512. 'tmplIds' => $tmplIds,
  3513. 'id' => $userWithdrawalModel->id
  3514. ]);
  3515. }
  3516. DB::rollBack();
  3517. return $this->fail(200013);
  3518. }catch (\Exception $e){
  3519. DB::rollBack();
  3520. _logger_(__file__, __line__, $e->getMessage());
  3521. return $this->fail(200013);
  3522. }
  3523. }
  3524. /**
  3525. * 我的提现记录
  3526. */
  3527. public function myUserWithdrawal(Request $request)
  3528. {
  3529. $uid = $request->uid;
  3530. $id = _empty_default_($request->id, 0);
  3531. $setUserid = $request->setUserid;
  3532. if(!_empty_($setUserid)) {
  3533. if ($setUserid && $setUserid > 0) {
  3534. if (UserUtils::is_mini_supder_admin($uid)) {
  3535. $uid = $setUserid;
  3536. } else {
  3537. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3538. }
  3539. }
  3540. }
  3541. $query = WxUserWithdrawal::where('user_id', $uid);
  3542. if($id > 0){
  3543. $query = $query->where('id', $id);
  3544. }
  3545. $data = $query
  3546. ->orderBy('id', 'desc')
  3547. ->get();
  3548. $data->map(function ($v) {
  3549. $v->status_value = WxUserRepositores::withdrawalType($v->state);
  3550. });
  3551. return $this->success($data);
  3552. }
  3553. /**
  3554. * @param Request $request
  3555. */
  3556. public function uploaded_unused_attachments(Request $request){
  3557. $uid = $request->uid;
  3558. $type = $request->type;
  3559. if($type == 'img'){
  3560. $types_ = ["jpg", "jpeg", "png", "gif"];
  3561. }else if($type == 'video'){
  3562. $types_ = ['mp4'];
  3563. }else{
  3564. return $this->fail(200004);
  3565. }
  3566. $attachments = WxAttachment::where('user_id', $uid)->where('state', 1)->WhereIn('type', $types_)->orderBy('id', 'desc')->simplePaginate(10);
  3567. if($attachments){
  3568. $attachments->map(function ($v){
  3569. $v->url = $v->domain .'/' . $v->path;
  3570. return $v;
  3571. });
  3572. return $this->success($attachments);
  3573. }
  3574. return $this->fail(200003);
  3575. }
  3576. /**
  3577. * 邀请领会员
  3578. */
  3579. public function invite_member(Request $request)
  3580. {
  3581. $uid = $request->uid;
  3582. $days = Settings::get('app_vip_5_invitees_days', 90);
  3583. if(_empty_($days)){
  3584. return $this->fail(200008);
  3585. }
  3586. $vip_consume_invitees = get_user_meta($uid, 'vip_consume_invitees', 'j');
  3587. $invitees = WxUser::where('who', $uid)->whereNotIn('id', $vip_consume_invitees)->limit(5)->get(FieldUtils::userInfoColums());
  3588. if($invitees){
  3589. }else{
  3590. $invitees = [];
  3591. }
  3592. if(_empty_($invitees) || count($invitees) < 5){
  3593. return $this->fail(200042, [], '你的邀请人数只有'.count($invitees).'个,凑够5个才能兑换会员,再接再厉');
  3594. }
  3595. // 满足条件
  3596. DB::beginTransaction();
  3597. try{
  3598. foreach ($invitees as $invitee){
  3599. $vip_consume_invitees[] = $invitee->id;
  3600. }
  3601. update_user_meta($uid, 'vip_consume_invitees', $vip_consume_invitees, 'j');
  3602. WxUserRepositores::vip($uid, $days);
  3603. DB::commit();
  3604. return $this->success(['days'=>$days]);
  3605. }catch (\Exception $e){
  3606. DB::rollBack();
  3607. _logger_(__file__, __line__, $e->getMessage());
  3608. return $this->fail(200006);
  3609. }
  3610. }
  3611. /**
  3612. * 我的收益记录
  3613. */
  3614. public function myUserExceptional(Request $request)
  3615. {
  3616. $uid = $request->uid;
  3617. $setUserid = $request->setUserid;
  3618. if(!_empty_($setUserid)) {
  3619. if ($setUserid && $setUserid > 0) {
  3620. if (UserUtils::is_mini_supder_admin($uid)) {
  3621. $uid = $setUserid;
  3622. } else {
  3623. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3624. }
  3625. }
  3626. }
  3627. $data = WxExceptional::where('posts_user_id', $uid)
  3628. ->orderBy('id', 'desc')
  3629. ->get();
  3630. $data->map(function ($v) {
  3631. $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
  3632. $v->datetime = format_datetime($v->created_at);
  3633. });
  3634. return $this->success($data);
  3635. }
  3636. public function myVisit(Request $request){
  3637. $uid = $request->uid;
  3638. $page = 1; // 从请求获取或设定默认值
  3639. $perPage = 15; // 每页显示的数量
  3640. $visits = WxUserVisit::where('type', 1)->where('user_id', $uid)
  3641. ->join('wx_posts', 'wx_user_visit.object_id', '=', 'wx_posts.id')
  3642. ->select('wx_user_visit.object_id',
  3643. DB::raw('DATE(wx_user_visit.created_at) as visit_date'),
  3644. DB::raw('SUM(wx_user_visit.times) as total_times'),
  3645. )
  3646. ->groupBy('visit_date', 'wx_user_visit.object_id')
  3647. ->orderBy('visit_date', 'desc')
  3648. ->paginate($perPage, ['*'], 'page', $page);
  3649. return $this->success($visits);
  3650. }
  3651. /**
  3652. * 我的余额记录
  3653. */
  3654. public function myUserFinancialRecord(Request $request)
  3655. {
  3656. $uid = $request->uid;
  3657. $setUserid = $request->setUserid;
  3658. if(!_empty_($setUserid)) {
  3659. if ($setUserid && $setUserid > 0) {
  3660. if (UserUtils::is_mini_supder_admin($uid)) {
  3661. $uid = $setUserid;
  3662. } else {
  3663. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3664. }
  3665. }
  3666. }
  3667. $data = WxUserFinancialRecord::where('user_id', $uid)
  3668. ->orderBy('id', 'desc')->limit(20)
  3669. ->get();
  3670. $data->map(function ($record){
  3671. $record->type_name = FieldUtils::getUserFinancialType()[(int)$record->type];
  3672. $record->date = $record->created_at->toDateTimeString();
  3673. $record->num_str = $record->num > 0 ? '+'.$record->num : $record->num;
  3674. return $record;
  3675. });
  3676. return $this->success($data);
  3677. }
  3678. /**
  3679. * 我的金币记录
  3680. */
  3681. public function myUserCoinsRecord(Request $request)
  3682. {
  3683. $uid = $request->uid;
  3684. $setUserid = $request->setUserid;
  3685. if(!_empty_($setUserid)) {
  3686. if ($setUserid && $setUserid > 0) {
  3687. if (UserUtils::is_mini_supder_admin($uid)) {
  3688. $uid = $setUserid;
  3689. } else {
  3690. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3691. }
  3692. }
  3693. }
  3694. $data = WxUserCoinRecord::where('user_id', $uid)
  3695. ->orderBy('id', 'desc')->limit(20)
  3696. ->get();
  3697. $data->map(function ($record){
  3698. $record->date = $record->created_at->toDateTimeString();
  3699. $record->num_str = $record->incre > 0 ? '+'.$record->incre : $record->incre;
  3700. return $record;
  3701. });
  3702. return $this->success($data);
  3703. }
  3704. /*
  3705. * 用户海报数据
  3706. */
  3707. public function poster(Request $request){
  3708. $userId = $request->id;
  3709. $uid = $request->uid;
  3710. if(_empty_($userId)){
  3711. return $this->fail(200001);
  3712. }
  3713. $user = WxUser::find($userId);
  3714. if(_empty_($user)){
  3715. return $this->fail(200003);
  3716. }
  3717. global $__MINI_GLOBAL_TENANT_ID__;
  3718. $mini_code = Utils::getMiniCode('/pages/user/user', 'id='.$user->id, $uid, 430, false, null, true);
  3719. if($mini_code){
  3720. $data = [
  3721. 'userdata' => [
  3722. 'avatar' => $user->user_avatar,
  3723. 'name' => $user->user_name
  3724. ],
  3725. 'swiperList' => Settings::get('app_share_poster', [], true),
  3726. 'code' => $mini_code,
  3727. 'web' => rtrim(Settings::get('app_h5_home', ''), '/') . '/#/pages/user/user?id=' . $userId . '&fph=1&from_user=' . $uid .'&tenant=' . $__MINI_GLOBAL_TENANT_ID__
  3728. ];
  3729. if(_empty_($data['swiperList'])){
  3730. return $this->fail(200008);
  3731. }
  3732. return $this->success($data);
  3733. }else{
  3734. return $this->fail(300001);
  3735. }
  3736. }
  3737. public function earningsRank(Request $request){
  3738. $userId = $request->uid;
  3739. $user = WxUser::find($userId);
  3740. if(_empty_($user)){
  3741. return $this->fail(200003);
  3742. }
  3743. $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']);
  3744. if(_empty_($r)){
  3745. return $this->fail(200003);
  3746. }
  3747. $data = [
  3748. 'one' => [],
  3749. 'two' => [],
  3750. 'three' => [],
  3751. 'others' => [
  3752. ],
  3753. 'avg' => round(WxUserFinancial::avg('sum_price'), 2),
  3754. 'bg' => Settings::get('app_earnings_rank_bg', 'https://img.mini.minisns.cn/images/rank/rank_bg.png'),
  3755. 'total' => WxUserFinancial::count()
  3756. ];
  3757. $defaut = [
  3758. 'id' => 0,
  3759. 'user_avatar' => Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/images/avatar.png'),
  3760. 'user_name' => '未知',
  3761. 'sum_price' => 0,
  3762. 'withdrawal_price' => 0,
  3763. 'is_member' => 0,
  3764. 'is_official' => 0,
  3765. 'is_authentication' => 0,
  3766. 'gender' => 0
  3767. ];
  3768. for ($i = 0; $i < 10; $i ++){
  3769. if ($i == 0){
  3770. if(isset($r[$i])){
  3771. $data['one'] = $r[$i];
  3772. }else{
  3773. $data['one'] = $defaut;
  3774. }
  3775. }else if($i == 1){
  3776. if(isset($r[$i])){
  3777. $data['two'] = $r[$i];
  3778. }else{
  3779. $data['two'] = $defaut;
  3780. }
  3781. }else if($i == 2){
  3782. if(isset($r[$i])){
  3783. $data['three'] = $r[$i];
  3784. }else{
  3785. $data['three'] = $defaut;
  3786. }
  3787. }else{
  3788. if(isset($r[$i])){
  3789. $data['others'][] = $r[$i];
  3790. }else{
  3791. $data['others'][] = $defaut;
  3792. }
  3793. }
  3794. }
  3795. return $this->success($data);
  3796. }
  3797. public function vote(Request $request){
  3798. $position = $request->position;
  3799. $uid = $request->uid;
  3800. $vote_id = $request->vote_id;
  3801. if(_empty_($vote_id) || _empty_($position) || !is_numeric($position)){
  3802. return $this->fail(200001);
  3803. }
  3804. if($position > 20 || $position < 1){
  3805. return $this->fail(200004);
  3806. }
  3807. if(WxUserVote::where([
  3808. ['user_id', '=', $uid],
  3809. ['vote_id', '=', $vote_id]
  3810. ])->exists()){
  3811. return $this->fail(200010, [], '你已经为这个内容投过票啦');
  3812. }
  3813. $WxUserVote = new WxUserVote();
  3814. $WxUserVote->user_id = $uid;
  3815. $WxUserVote->vote_id = $vote_id;
  3816. $WxUserVote->vote_option = $position;
  3817. $r = $WxUserVote->save();
  3818. if($r){
  3819. WxPostsVote::where('id', $vote_id)->increment('num'.$position);
  3820. return $this->success(PostUtils::getVoteData($vote_id, $uid));
  3821. }
  3822. return $this->fail(200002);
  3823. }
  3824. /**
  3825. * 拉黑或取消拉黑某个用户
  3826. * @param Request $request
  3827. * @return \Illuminate\Http\JsonResponse
  3828. */
  3829. public function black(Request $request){
  3830. $uid = $request->uid;
  3831. $object_id = $request->object_id;
  3832. $action = $request->action;
  3833. if(_empty_($object_id)){
  3834. return $this->fail(200001);
  3835. }
  3836. if($action == 'black'){
  3837. $user_set = get_user_meta($uid, 'user:blacked:set', 'j');
  3838. if(!in_array($object_id, $user_set)){
  3839. $user_set[] = $object_id;
  3840. update_user_meta($uid, 'user:blacked:set', array_unique($user_set), 'j');
  3841. return $this->success([], 200, '拉黑成功');
  3842. }else{
  3843. // 要删除的特定值
  3844. $user_set = array_filter($user_set, function ($value) use ($object_id) {
  3845. return $value != $object_id;
  3846. });
  3847. update_user_meta($uid, 'user:blacked:set', array_unique($user_set), 'j');
  3848. return $this->success([], 200, '取消拉黑');
  3849. }
  3850. }else{
  3851. $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  3852. if(!in_array($object_id, $user_set)){
  3853. $user_set[] = $object_id;
  3854. update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
  3855. return $this->success();
  3856. }else{
  3857. // 要删除的特定值
  3858. $user_set = array_filter($user_set, function ($value) use ($object_id) {
  3859. return $value != $object_id;
  3860. });
  3861. update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
  3862. return $this->success();
  3863. }
  3864. }
  3865. }
  3866. /**
  3867. * 用户反馈
  3868. * [0=>'post', 1=> 'comment', 2 => 'user', 3=> 'goods']
  3869. * @param Request $request
  3870. * @return \Illuminate\Http\JsonResponse
  3871. */
  3872. public function report(Request $request)
  3873. {
  3874. $uid = $request->uid;
  3875. _limit_user('add:report', $uid, 20);
  3876. $report_type = $request->report_type;
  3877. $report_content = $request->report_content;
  3878. $image_urls = $request->image_urls;
  3879. $type = $request->type;
  3880. $object_id = $request->object_id;
  3881. if(!isset($type) || !isset($object_id)){
  3882. return $this->fail(200001);
  3883. }
  3884. if(!in_array($type, [0,1,2,3,4,5,6])){
  3885. return $this->fail(200004);
  3886. }
  3887. $count = WxUserReport::where([
  3888. ['type', '=', $type],
  3889. ['object_id', '=', $object_id],
  3890. ['user_id', '=', $uid]
  3891. ])->count();
  3892. if($count > 0){
  3893. return $this->fail(200010, [], '你已经举报过了ta,再管理员反馈之前,请勿重复举报');
  3894. }
  3895. $image_urls__ = [];
  3896. if($image_urls){
  3897. foreach ($image_urls as $img_item){
  3898. $image_urls__[] = $img_item['url'];
  3899. }
  3900. }
  3901. $contact = $request->contact;
  3902. if(_empty_($report_content)){
  3903. $this->fail(200001);
  3904. }
  3905. $r = WxUserReportRepositories::add($uid,$type, $object_id, $report_type, $report_content, $image_urls__, $contact);
  3906. if($r){
  3907. $count_ = WxUserReport::where([
  3908. ['type', '=', $type],
  3909. ['object_id', '=', $object_id],
  3910. ])->count();
  3911. if($type == 0){
  3912. $app_report_safe_times_post = Settings::get('app_report_safe_times_post', 0);
  3913. if($app_report_safe_times_post == 0){
  3914. $app_report_safe_times_post = 999;
  3915. }
  3916. if(UserUtils::is_mini_admin($uid)){
  3917. if($report_type == 10){
  3918. WxPost::where('id', $object_id)->update(['is_blur'=>1]);
  3919. }else{
  3920. WxPost::where('id', $object_id)->update(['posts_state'=>2]);
  3921. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动下架。');
  3922. }
  3923. }else if($count_ > $app_report_safe_times_post){
  3924. if($report_type == 10){
  3925. WxPost::where('id', $object_id)->update(['is_blur'=>1]);
  3926. }else{
  3927. WxPost::where('id', $object_id)->update(['posts_state'=>2]);
  3928. UserUtils::assistant_notice('admin', '多名用户对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动下架。');
  3929. }
  3930. }else{
  3931. 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>)进行举报。');
  3932. }
  3933. }else if($type == 1){
  3934. $app_report_safe_times_comment = Settings::get('app_report_safe_times_comment', 0);
  3935. if($app_report_safe_times_comment == 0){
  3936. $app_report_safe_times_comment = 999;
  3937. }
  3938. $posts_id = WxComment::where('id', $object_id)->value('posts_id');
  3939. if(UserUtils::is_mini_admin($uid)){
  3940. WxComment::where('id', $object_id)->update(['comment_state'=>2]);
  3941. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动下架。');
  3942. }else if($count_ > $app_report_safe_times_comment){
  3943. WxComment::where('id', $object_id)->update(['comment_state'=>2]);
  3944. UserUtils::assistant_notice('admin', '多名用户对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动下架。');
  3945. }else{
  3946. 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>)进行举报。');
  3947. }
  3948. }else if($type == 2){
  3949. $app_report_safe_times_user = Settings::get('app_report_safe_times_user', 0);
  3950. if($app_report_safe_times_user == 0){
  3951. $app_report_safe_times_user = 999;
  3952. }
  3953. $the_user = WxUser::find($object_id);
  3954. if(UserUtils::is_mini_admin($uid)){
  3955. UserUtils::lock_user_incre($the_user, 3, 3600 * 24 * 7, '该用户被管理员举报');
  3956. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统禁言7天。');
  3957. }else if($count_ > $app_report_safe_times_user){
  3958. UserUtils::lock_user_incre($the_user, 3, 3600 * 24 * 7, '该用户被人多次举报');
  3959. UserUtils::assistant_notice('admin', '多名用户对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统禁言7天。');
  3960. }else{
  3961. 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>)进行举报。');
  3962. }
  3963. }else if($type == 3){
  3964. // 举报商品
  3965. }else if($type == 4){
  3966. // 举报圈子
  3967. $app_report_safe_times_circle = Settings::get('app_report_safe_times_circle', 0);
  3968. if($app_report_safe_times_circle == 0){
  3969. $app_report_safe_times_circle = 999;
  3970. }
  3971. if(UserUtils::is_mini_admin($uid)){
  3972. WxCircle::where('id', $object_id)->update(['circle_state'=>2]);
  3973. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动驳回。');
  3974. }else if($count_ > $app_report_safe_times_circle){
  3975. WxUser::where('id', $object_id)->update(['circle_state'=>2]);
  3976. UserUtils::assistant_notice('admin', '多名用户对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动驳回。');
  3977. }else{
  3978. 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>)进行举报。');
  3979. }
  3980. }else if($type == 6){
  3981. // 举报圈子
  3982. $app_report_safe_times_voter = Settings::get('app_report_safe_times_voter', 0);
  3983. if($app_report_safe_times_voter == 0){
  3984. $app_report_safe_times_voter = 999;
  3985. }
  3986. if(UserUtils::is_mini_admin($uid)){
  3987. WxVoter::where('id', $object_id)->update(['status'=>2]);
  3988. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动驳回。');
  3989. }else if($count_ > $app_report_safe_times_voter){
  3990. WxVoter::where('id', $object_id)->update(['status'=>2]);
  3991. UserUtils::assistant_notice('admin', '多名用户对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动驳回。');
  3992. }else{
  3993. 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>)进行举报。');
  3994. }
  3995. }
  3996. UserInputSafeCheckJob::dispatch($uid, $report_content);
  3997. Utils::image_state_change($image_urls__, 1);
  3998. return $this->success($r);
  3999. }else{
  4000. return $this->fail(200002);
  4001. }
  4002. }
  4003. }