UserController.php 183 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408
  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. ]);
  1723. }
  1724. $data = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  1725. if($data){
  1726. $res = ApiUtils::ali_request(\App\Wen\Utils\Settings::get('app_ali_ip_address_appcode', ''), 'https://ips.market.alicloudapi.com/iplocaltion', ['ip'=>$data->ip]);
  1727. //print_r($res['result']['city']);exit;
  1728. if($res['code'] == 1000 && $res['result']){
  1729. $data->ip_address_a = $res['result']['city'];//归属城市
  1730. }else{
  1731. // $data->append(['ip_address']);
  1732. $data->ip_address_a = $data->city;
  1733. }
  1734. $data->append(['ip_address']);
  1735. }else{
  1736. return $this->fail(200003);
  1737. }
  1738. if($__MINI_GLOBAL_IS_ADMIN_SUPER__ && $data->is_robot > 0){
  1739. $data->user_name = $data->user_name.' 🤖';
  1740. }
  1741. UserUtils::user_expend($data, false, false, true, true,8);
  1742. $data->followTotal = WxUserFollow::where('user_id', $user_id)->count();
  1743. $data->fansTotal = WxUserFollow::where('user_follow_id', $user_id)->count();
  1744. $count1 = WxLike::where('posts_user_id', $user_id)->count();
  1745. $count2 = WxCommentLike::where('comment_user_id', $user_id)->count();
  1746. $data->likeTotal = $count1 + $count2;
  1747. if($uid > 0 && $uid != $user_id){
  1748. $data->isFollow = WxUserFollow::where('user_id', $uid)->where('user_follow_id', $user_id)->exists();
  1749. $data->isFans = WxUserFollow::where('user_id', $user_id)->where('user_follow_id', $uid)->exists();
  1750. }else{
  1751. $data->isFollow = false;
  1752. $data->isFans = false;
  1753. }
  1754. $data->user_background_color = get_user_meta($user_id, 'user_background_color');
  1755. if(_empty_($data->user_background_color)){
  1756. $data->user_background_color = UserUtils::user_bg_color_update($user_id);
  1757. if(_empty_($data->user_background_color)){
  1758. $data->user_background_color = '18, 14, 17';
  1759. }
  1760. }
  1761. $blacked = UserUtils::is_user_blacked_to($uid, $data->id);
  1762. if($__MINI_GLOBAL_IS_ADMIN_SUPER__){
  1763. $data->actions = [
  1764. ['title' => '举报'],
  1765. ['title' => $blacked ? '取消拉黑' : '拉黑'],
  1766. ['title' => 'ta的钱包'],
  1767. ['title'=>'编辑ta的资料']
  1768. ];
  1769. }else{
  1770. $data->actions = [
  1771. ['title' => '举报'],
  1772. ['title' => $blacked ? '取消拉黑' : '拉黑'],
  1773. ];
  1774. }
  1775. if($scene == 50005 || $scene == 50004 || $scene == 50006){
  1776. $data->pets = [
  1777. 'adoption' => [
  1778. 'count'=>[
  1779. 'status0' => WxPetsAdoption::where('user_id', $user_id)->where('adopt_status', 0)->count(),
  1780. 'status1' => WxPetsAdoption::where('user_id', $user_id)->where('adopt_status', 1)->count(),
  1781. ]
  1782. ]
  1783. ];
  1784. }
  1785. if( $uid > 0 ){
  1786. update_user_visit($uid,4, $user_id);
  1787. }
  1788. //print_r($data);exit;
  1789. return $this->success($data);
  1790. }
  1791. /**
  1792. * 更新用户资料
  1793. * @param Request $request
  1794. * @return \Illuminate\Http\JsonResponse
  1795. */
  1796. public function updateInfo(Request $request)
  1797. {
  1798. $uid = $request->uid;
  1799. _limit_user('update:user:info', $uid, 20);
  1800. $data = $request->all();
  1801. $user_id = _array_key($data, 'user_id', 0);
  1802. if($user_id > 0){
  1803. if(UserUtils::is_mini_supder_admin($uid)){
  1804. $uid = $user_id;
  1805. }else{
  1806. return $this->fail(200000, [], '你还不是超级管理员,无法保存别人的资料');
  1807. }
  1808. }
  1809. // 修改 is_online_status
  1810. if (isset($data['is_online_status'])) {
  1811. // $update_online['requirement'] = $data['is_online_status'];
  1812. // $update_online['is_online_status_time'] = time();
  1813. // WxUser::where('id', $uid)->update($update_online);
  1814. // $infos = WxUser::where('id', $uid)->find($uid);
  1815. // $infos->is_online_status = $data['is_online_status'];
  1816. //$infos->save();
  1817. }
  1818. // print_r($uid);exit;
  1819. // 删除 is_online_status
  1820. //unset($data['is_online_status']);
  1821. $old_user = WxUser::find($uid);
  1822. if(_empty_($old_user)){
  1823. return $this->fail(200003);
  1824. }
  1825. $is_user_setting = _array_key($data, 'is_user_setting', false);
  1826. if($is_user_setting){
  1827. $user_setting_update_flag = false;
  1828. if(isset($data['privacy_message_me'])){
  1829. if(!in_array($data['privacy_message_me'], [1, 2, 3, 4, 5])){
  1830. return $this->fail(200004);
  1831. }
  1832. $r = WxUserSetting::where('user_id', $uid)->update(['privacy_message_me' => $data['privacy_message_me']]);
  1833. if($r){
  1834. $user_setting_update_flag = true;
  1835. }else{
  1836. return $this->fail(200002);
  1837. }
  1838. }
  1839. foreach (['wechat', 'phone'] as $wechat_or_phone){
  1840. if(isset($data['privacy_get_my_'.$wechat_or_phone])){
  1841. if(!in_array($data['privacy_get_my_'.$wechat_or_phone], [1, 2, 3, 4, 5])){
  1842. return $this->fail(200004);
  1843. }
  1844. if(($wechat_or_phone == 'wechat' && _empty_($old_user->wechat_account)) || ($wechat_or_phone == 'phone' && _empty_($old_user->phone))){
  1845. return $this->fail(200043, [
  1846. 'title' => $wechat_or_phone == 'wechat' ? '未保存微信号' : '未绑定手机号',
  1847. 'content' => '是否前往[编辑资料]进行补充',
  1848. 'confirmText' => '去补充',
  1849. 'target_type' => 6,
  1850. 'target_id' => $wechat_or_phone == 'wechat' ? '/pagesA/mine/editmine/editmine?wechat_account=1' : '/pagesA/mine/editmine/editmine?phone=1'
  1851. ], $wechat_or_phone == 'wechat' ? '未保存微信号' : '未绑定手机号');
  1852. }
  1853. $updates = [
  1854. 'privacy_get_my_'.$wechat_or_phone => $data['privacy_get_my_'.$wechat_or_phone]
  1855. ];
  1856. if($data['privacy_get_my_'.$wechat_or_phone] == 5 && WxUserSetting::where('user_id', $uid)->value('privacy_get_my_'.$wechat_or_phone.'_pay') < 1){
  1857. $updates['privacy_get_my_'.$wechat_or_phone.'_pay'] = 1;
  1858. }
  1859. $r = WxUserSetting::where('user_id', $uid)->update($updates);
  1860. if($r){
  1861. $user_setting_update_flag = true;
  1862. }else{
  1863. return $this->fail(200002);
  1864. }
  1865. }
  1866. if(isset($data['privacy_get_my_'.$wechat_or_phone.'_pay'])){
  1867. $data['privacy_get_my_'.$wechat_or_phone.'_pay'] = round((float)$data['privacy_get_my_'.$wechat_or_phone.'_pay'], 2);
  1868. if($data['privacy_get_my_'.$wechat_or_phone.'_pay'] < 1){
  1869. return $this->fail(200004, [], '付费数额不能小于1元');
  1870. }
  1871. $r = WxUserSetting::where('user_id', $uid)->update(['privacy_get_my_'.$wechat_or_phone.'_pay' => $data['privacy_get_my_'.$wechat_or_phone.'_pay']]);
  1872. if($r){
  1873. $user_setting_update_flag = true;
  1874. }else{
  1875. return $this->fail(200002);
  1876. }
  1877. }
  1878. }
  1879. // 1,2类型
  1880. 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){
  1881. if(isset($data[$key])){
  1882. if(!in_array($data[$key], [1, 2])){
  1883. return $this->fail(200004);
  1884. }
  1885. $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
  1886. if($r){
  1887. $user_setting_update_flag = true;
  1888. }else{
  1889. return $this->fail(200002);
  1890. }
  1891. }
  1892. }
  1893. // 2,3类型
  1894. 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){
  1895. if(isset($data[$key])){
  1896. if(!in_array($data[$key], [2, 3])){
  1897. return $this->fail(200004);
  1898. }
  1899. $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
  1900. if($r){
  1901. $user_setting_update_flag = true;
  1902. }else{
  1903. return $this->fail(200002);
  1904. }
  1905. }
  1906. }
  1907. // 字符串类型
  1908. foreach (['social_sph_id'] as $key){
  1909. if(!_empty_(_array_key($data, $key, ''))){
  1910. if($key == 'social_sph_id'){
  1911. if($data[$key] == 'close'){
  1912. $data[$key] = '';
  1913. }else{
  1914. if(strlen($data[$key]) != 15 || !StrUtils::startsWith($data[$key], 'sph')){
  1915. return $this->fail(200004, [], '视频号id需要以sph开头的16位字符串');
  1916. }
  1917. }
  1918. }
  1919. $r = WxUserSetting::where('user_id', $uid)->update([$key => $data[$key]]);
  1920. if($r){
  1921. $user_setting_update_flag = true;
  1922. }else{
  1923. return $this->fail(200002);
  1924. }
  1925. }
  1926. }
  1927. if(isset($data['teenage_mode_password'])){
  1928. if(strlen($data['teenage_mode_password']) != 4){
  1929. return $this->fail(200004);
  1930. }
  1931. $user_setting = WxUserSetting::where('user_id', $uid)->first();
  1932. if($user_setting){
  1933. $r = false;
  1934. if($user_setting->teenage_mode_state == 1){
  1935. // 关闭
  1936. if($user_setting->teenage_mode_password == $data['teenage_mode_password']){
  1937. $r = WxUserSetting::where('user_id', $uid)->update(['teenage_mode_password' => '', 'teenage_mode_state' => 2]);
  1938. }else{
  1939. return $this->fail(200004, [], '密码错误');
  1940. }
  1941. }else{
  1942. // 打开
  1943. $r = WxUserSetting::where('user_id', $uid)->update(['teenage_mode_password' => $data['teenage_mode_password'], 'teenage_mode_state' => 1]);
  1944. }
  1945. if($r){
  1946. $user_setting_update_flag = true;
  1947. }else{
  1948. return $this->fail(200002);
  1949. }
  1950. }
  1951. }
  1952. if($user_setting_update_flag){
  1953. Cache::forget('get:cached:user:'.$uid);
  1954. $login_user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
  1955. // 超级管理员
  1956. if($login_user->is_official){
  1957. if(UserUtils::is_mini_supder_admin($login_user->id)){
  1958. $login_user->is_official = 2;
  1959. }
  1960. }
  1961. UserUtils::user_expend($login_user, true, true, true, true, 5);
  1962. $login_user->timeStamp = time();
  1963. return $this->success(['code'=>1, 'user'=>$login_user]);
  1964. }else{
  1965. return $this->fail(200004);
  1966. }
  1967. }
  1968. $data['user_name'] = str_replace([' 🤖', '🤖',' 💙🤖', ' 💗🤖', '💙🤖', '💗🤖'], '', trim(_array_key($data, 'user_name', '')));
  1969. if(_empty_($data['user_name'])){
  1970. return $this->fail(200001);
  1971. }
  1972. if(_empty_(_array_key($data, 'user_avatar', ''))){
  1973. $data['user_avatar'] = '';
  1974. }
  1975. if(_empty_(_array_key($data, 'user_name', ''))){
  1976. $data['user_name'] = '';
  1977. }
  1978. if(_empty_(_array_key($data, 'wechat_account', ''))){
  1979. $data['wechat_account'] = '';
  1980. }
  1981. if(_empty_(_array_key($data, 'user_introduce', '')) || Settings::get('app_user_introduce', '', true) == _array_key($data, 'user_introduce', '') ){
  1982. $data['user_introduce'] = '';
  1983. }
  1984. if(_empty_(_array_key($data, 'user_birthday', '')) || _array_key($data, 'user_birthday', '') == '请选择'){
  1985. $data['user_birthday'] = '';
  1986. }
  1987. if(!StrUtils::is_valid_date(_array_key($data, 'user_birthday', ''), 'Y-m-d')){
  1988. $data['user_birthday'] = '';
  1989. }else{
  1990. if(strtotime(_array_key($data, 'user_birthday', '')) >= time()){
  1991. return $this->fail(200004, [], '生日不合法');
  1992. }
  1993. }
  1994. if(_empty_(_array_key($data, 'user_background_maps', ''))){
  1995. $data['user_background_maps'] = '';
  1996. }
  1997. if(_empty_(_array_key($data, 'gender', 0)) || _array_key($data, 'gender', 0) == '请选择'
  1998. || StrUtils::is_contain_chinese(_array_key($data, 'gender', 0)) || !in_array(_array_key($data, 'gender', 0), [0, 1, 2]) ){
  1999. $data['gender'] = 0;
  2000. }
  2001. $user_labels = _array_key($data, 'user_labels', []);
  2002. if($user_labels){
  2003. if($user_labels == -1){
  2004. $data['user_labels'] = -1;
  2005. }else{
  2006. // 过滤
  2007. $user_labels_ =[];
  2008. $app_user_labels = Settings::get('app_user_labels', [], true);
  2009. foreach ($user_labels as $label){
  2010. if(in_array($label, $app_user_labels)){
  2011. $user_labels_[] = $label;
  2012. }
  2013. }
  2014. $data['user_labels'] = $user_labels_;
  2015. }
  2016. }else{
  2017. $data['user_labels'] = [];
  2018. }
  2019. if(mb_strlen($data['user_name'] ?? '' ) > 20){
  2020. return $this->fail(200004, [], '用户名过长');
  2021. }
  2022. if(!_empty_($data['user_name'])){
  2023. if(WxUser::where([['user_name','=',$data['user_name']], ['id', '<>', $uid] ])->exists()){
  2024. return $this->fail(200004, [], '用户名已存在');
  2025. }
  2026. }
  2027. $old_user_name = $old_user->user_name;
  2028. $old_user_avatar = $old_user->user_avatar;
  2029. $old_gender = $old_user->gender;
  2030. $old_user_introduce = $old_user->user_introduce;
  2031. $old_user_background_maps = $old_user->user_background_maps;
  2032. $old_wechat_account = $old_user->wechat_account;
  2033. if(_array_key($data, 'wechat_account', '')){
  2034. if($old_wechat_account == _array_key($data, 'wechat_account', '')){
  2035. $data['wechat_account'] = '';
  2036. }
  2037. }
  2038. $user_name = $data['user_name'];
  2039. $user_introduce = $data['user_introduce'] ?? '';
  2040. // 百度审核
  2041. $need_manual_review = true;
  2042. $is_audit_user_info = Settings::get('is_audit_user_info', 0);
  2043. if ($is_audit_user_info == 2 ) {
  2044. if($old_user_name == $user_name && $old_user_introduce == $user_introduce){
  2045. $need_manual_review = false;
  2046. }else{
  2047. if($user_name || $user_introduce){
  2048. $filter_result = BaiduUtils::text_filter($user_name .' '. $user_introduce);
  2049. if($filter_result){
  2050. if($filter_result['hit_level'] == 2){
  2051. // 不合规
  2052. return $this->fail(200016, ['tip'=>$filter_result['tip_list'], 'hit_word'=>$filter_result['hit_word']]);
  2053. }else if($filter_result['hit_level'] == 0){
  2054. // 审核通过
  2055. $need_manual_review = false;
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }else if($is_audit_user_info == 0){
  2061. $need_manual_review = true;
  2062. if($old_user_name == $user_name && $old_user_introduce == $user_introduce){
  2063. $need_manual_review = false;
  2064. }
  2065. }else{
  2066. $need_manual_review = false;
  2067. }
  2068. if(UserUtils::is_mini_supder_admin($uid)){
  2069. $need_manual_review = false;
  2070. }
  2071. $r = WxUserRepositores::update($uid, $data, $need_manual_review);
  2072. //var_dump($need_manual_review);exit;
  2073. if($r){
  2074. UserInputSafeCheckJob::dispatch($uid, ($user_name .' '. $user_introduce));
  2075. Utils::image_state_change([$data['user_avatar'] ?? '', $data['user_background_maps'] ?? '' ], 1);
  2076. if(_array_key($data, 'user_background_maps', '')){
  2077. if($old_user_background_maps != _array_key($data, 'user_background_maps', '')){
  2078. UserBgColorUpdateJob::dispatch($uid, false);
  2079. }
  2080. }
  2081. if($need_manual_review){
  2082. UserUtils::assistant_notice('admin', '有用户修改资料待审核');
  2083. return $this->success(['code'=>0]);
  2084. }else{
  2085. Cache::forget('get:cached:user:'.$uid);
  2086. $login_user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
  2087. // 超级管理员
  2088. if($login_user->is_official){
  2089. if(UserUtils::is_mini_supder_admin($login_user->id)){
  2090. $login_user->is_official = 2;
  2091. }
  2092. }
  2093. UserUtils::user_expend($login_user, true, true, true, true, 5);
  2094. $login_user->timeStamp = time();
  2095. return $this->success(['code'=>1, 'user'=>$login_user]);
  2096. }
  2097. }
  2098. return $this->fail(200002);
  2099. }
  2100. /**
  2101. * 我的笔记列表
  2102. * @param Request $request
  2103. * @return \Illuminate\Http\JsonResponse
  2104. */
  2105. public function getMyPosts(Request $request)
  2106. {
  2107. $uid = $request->uid;
  2108. $user_id = _empty_default_($request->user_id, 0);
  2109. $limit = $request->input('limit', 10);
  2110. $type = $request->input('type', 0);
  2111. if($type == 'shop'){
  2112. $orderBy = _empty_default_($request->orderBy, 'sort');
  2113. if(!in_array($orderBy, ['id','sort', 'buys', 'created_at', 'price'])){
  2114. return $this->fail(200004);
  2115. }
  2116. $order = _empty_default_($request->order, 'desc');
  2117. if(!in_array($order, ['desc', 'asc'])){
  2118. return $this->fail(200004);
  2119. }
  2120. if($orderBy != 'price'){
  2121. $order = 'desc';
  2122. }
  2123. }else{
  2124. $orderBy = 'id';
  2125. $order = 'desc';
  2126. }
  2127. if(is_numeric($type)){
  2128. $type_map = [
  2129. 0 => 'post',
  2130. 1 => 'collected',
  2131. 2 => 'liked',
  2132. 3 => 'exceptionaled',
  2133. 4 => 'voted'
  2134. ];
  2135. $type = $type_map[(int)$type];
  2136. }
  2137. if(!_empty_($user_id)){
  2138. if($user_id > 0 || ($user_id < 0 && $type == 'post')){
  2139. return $this->success(PostsRepositores::myPosts($user_id, $limit, $type, $orderBy, $order));
  2140. }else{
  2141. return $this->fail(200004);
  2142. }
  2143. }else{
  2144. if($uid > 0){
  2145. return $this->success(PostsRepositores::myPosts($uid, $limit, $type, $orderBy, $order));
  2146. }else{
  2147. return $this->fail(503002);
  2148. }
  2149. }
  2150. }
  2151. /**
  2152. * 用户认证
  2153. */
  2154. public function authentication(Request $request)
  2155. {
  2156. $uid = $request->uid;
  2157. $device = in_array($request->header('device',''), ['app', 'h5', 'mp', 'pc']) ? $request->header('device','') : '';
  2158. $arr = UserUtils::user_action_permissions_check($uid, 'user_authenticate');
  2159. if($arr['code'] == 0){
  2160. return $this->fail(200000, [], $arr['msg']);
  2161. }
  2162. $name = $request->name;
  2163. $contact_information = $request->contact_information;
  2164. $introduce = $request->introduce;
  2165. $identity_picture = $request->identity_picture;
  2166. if(Settings::get('app_user_authenticate_img_require', 1) == 1 && _empty_($identity_picture)){
  2167. return $this->fail(200001, [], '请上传身份信息证明图片');
  2168. }
  2169. $authenticationState = (new WxAuthentication())->where('user_id', $uid)->value('authentication_state');
  2170. $authId = (new WxAuthentication())->where('user_id', $uid)->value('id');
  2171. // 已经审核通过和驳回
  2172. if ($authenticationState == 1 || $authenticationState == 2) {
  2173. $model = (new WxAuthentication())->find($authId);
  2174. $model->name = $name;
  2175. $model->contact_information = $contact_information;
  2176. $model->introduce = $introduce;
  2177. $model->authentication_state = 0;
  2178. $model->user_id = $uid;
  2179. if(!_empty_($identity_picture)){
  2180. $model->identity_picture = $identity_picture;
  2181. }
  2182. $model->save();
  2183. }else if($authenticationState === 0){
  2184. return $this->fail(200010, [], '您的认证信息正在审核中...请勿重复提交');
  2185. }else if ($authenticationState === null) {
  2186. $model = new WxAuthentication();
  2187. $model->name = $name;
  2188. $model->contact_information = $contact_information;
  2189. $model->introduce = $introduce;
  2190. if(!_empty_($identity_picture)){
  2191. $model->identity_picture = $identity_picture;
  2192. }
  2193. $model->user_id = $uid;
  2194. $model->save();
  2195. }
  2196. Utils::image_state_change([$identity_picture], 1);
  2197. $tmplIds = [];
  2198. if($device == 'mp'){
  2199. $comment_add_id = Settings::get('mini_template_message_authentication', '');
  2200. if(!_empty_($comment_add_id)){
  2201. $tmplIds[] = $comment_add_id;
  2202. }
  2203. }
  2204. UserUtils::assistant_notice_review(109, $model->id);
  2205. return $this->success([
  2206. 'tmplIds' => $tmplIds
  2207. ]);
  2208. }
  2209. /**
  2210. * 我创建的圈子列表
  2211. */
  2212. public function myCircle(Request $request)
  2213. {
  2214. $uid = $request->uid;
  2215. $data = WxCircle::where('user_id', $uid)->get();
  2216. $data->map(function ($v) {
  2217. $v->post_count = WxPost::where('circle_id', $v->id)->count();
  2218. $v->user_circle_count = WxUserCircle::where('circle_id', $v->id)->count();
  2219. });
  2220. if(UserUtils::is_mini_supder_admin($uid)){
  2221. $data = $data->toArray();
  2222. $hall = [
  2223. [
  2224. 'id' => 0,
  2225. 'circle_name' => '大厅',
  2226. 'post_count' => WxPost::where('circle_id', 0)->count(),
  2227. 'user_circle_count' => WxPost::where('circle_id', 0)->distinct('user_id')->count('user_id'),
  2228. 'head_portrait' => Settings::get('about_logo', ''),
  2229. 'circle_introduce' => '没有选择圈子的笔记'
  2230. ]
  2231. ];
  2232. $data = array_merge($hall, $data);
  2233. }
  2234. return $this->success($data);
  2235. }
  2236. /**
  2237. * 我的支付密码
  2238. */
  2239. public function paycode(Request $request){
  2240. $uid = $request->uid;
  2241. $type = $request->type;
  2242. $password = $request->password;
  2243. if($password && strlen($password) !== 6){
  2244. return $this->fail(200004);
  2245. }
  2246. // 检查是否有支付密码
  2247. if($type == 0){
  2248. $paycode = get_user_meta($uid, 'paycode', 's');
  2249. if($paycode){
  2250. return $this->success(['status'=>1]);
  2251. }else{
  2252. return $this->success(['status'=>0]);
  2253. }
  2254. }else if($type == 1){
  2255. if($password && strlen($password) === 6){
  2256. update_user_meta($uid, 'paycode', $password, 's');
  2257. return $this->success(['status'=>1]);
  2258. }
  2259. return $this->fail(200004);
  2260. }else if($type == 2){
  2261. if(Cache::has('paycode:checked:'.$uid)){
  2262. if($password && strlen($password) === 6){
  2263. update_user_meta($uid, 'paycode', $password, 's');
  2264. Cache::forget('paycode:checked:'.$uid);
  2265. return $this->success(['status'=>1]);
  2266. }
  2267. return $this->fail(200004);
  2268. }else{
  2269. // 检测旧密码
  2270. _limit_user('paycode:check:', $uid, 20);
  2271. if($password !== get_user_meta($uid, 'paycode', 's')){
  2272. return $this->fail(200004, [], '您输入的旧密码错误');
  2273. }else{
  2274. Cache::put('paycode:checked:'.$uid, true, 600);
  2275. return $this->success();
  2276. }
  2277. }
  2278. }else if($type == 3){
  2279. $phoneCode = $request->phoneCode;
  2280. if(_empty_($phoneCode)){
  2281. return $this->fail(200001, [], '验证码为空');
  2282. }
  2283. // 手机号验证
  2284. $user = WxUser::find($uid);
  2285. if(_empty_($user)){
  2286. return $this->fail(200004, [], '用户不存在');
  2287. }
  2288. $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
  2289. $idd = $user->country_code;
  2290. if(_empty_($idd)){
  2291. $idd = 86;
  2292. }
  2293. if(!Cache::has(md5($uid.':code:'.$idd.':'.$phone))){
  2294. return $this->fail(200009, [], '验证码已过期,请重新发送');
  2295. }
  2296. if(Cache::get(md5($uid.':code:'.$idd.':'.$phone)) != $phoneCode){
  2297. return $this->fail(200004, [], '验证码错误');
  2298. }
  2299. if($password && strlen($password) === 6){
  2300. update_user_meta($uid, 'paycode', $password, 's');
  2301. Cache::forget('paycode:checked:'.$uid);
  2302. return $this->success(['status'=>1]);
  2303. }
  2304. return $this->fail(200004);
  2305. }
  2306. }
  2307. public function avatar_frame_wear(Request $request){
  2308. $uid = $request->uid;
  2309. $avatar_frame_id = $request->id;
  2310. if(_empty_($avatar_frame_id)){
  2311. return $this->fail(200001);
  2312. }
  2313. $res = UserUtils::purchase_avatar_frame($uid, $avatar_frame_id);
  2314. if($res['code'] == 200){
  2315. return $this->success();
  2316. }else{
  2317. return $this->fail($res['code'], [], $res['msg']);
  2318. }
  2319. }
  2320. /**
  2321. * 会员页面数据
  2322. * @param Request $request
  2323. */
  2324. public function membersdata(Request $request){
  2325. $uid = $request->uid;
  2326. $benefits = Settings::get('app_vip_benefits', []);
  2327. $avatar_frame_ids = Settings::get('app_vip_user_avatar_frames', []);
  2328. $avatar_frame_ = [];
  2329. if($avatar_frame_ids){
  2330. $avatar_frame_ = WxUserAvatarFrame::whereIn('id', $avatar_frame_ids)->get();
  2331. }
  2332. $vip_consume_invitees = get_user_meta($uid, 'vip_consume_invitees', 'j');
  2333. if($vip_consume_invitees){
  2334. }else{
  2335. $vip_consume_invitees = [];
  2336. }
  2337. $invitees = WxUser::where('who', $uid)->whereNotIn('id', $vip_consume_invitees)->limit(5)->get(FieldUtils::userInfoColums());
  2338. if($invitees){
  2339. }else{
  2340. $invitees = [];
  2341. }
  2342. $result = [
  2343. 'end_time' => UserUtils::get_user_member_time($uid),
  2344. 'invitees' => $invitees,
  2345. 'benefits_title' => Settings::get('app_vip_benefits_title', '会员尊享5大特权'),
  2346. 'benefits' => $benefits,
  2347. 'avatar_frames' => $avatar_frame_,
  2348. 'invitees_5_days' => Settings::get('app_vip_5_invitees_days', 90),
  2349. 'options' => Settings::get('app_vip_options', []),
  2350. ];
  2351. return $this->success($result);
  2352. }
  2353. public function invite_list(Request $request){
  2354. $type = $request->type;
  2355. $uid = $request->uid;
  2356. if(!in_array($type, [1,2,3])){
  2357. return $this->fail(200004);
  2358. }
  2359. if($type == 1 ){
  2360. $data = WxUser::where('who', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  2361. if($data){
  2362. $data->map(function ($v) {
  2363. $v->benifit = UserUtils::get_user_invite_benifit($v->id);
  2364. });
  2365. return $this->success($data);
  2366. }
  2367. return $this->success(200003);
  2368. }else if( $type == 2 ){
  2369. $data = WxUser::whereIn('who', function ($query) use ($uid){
  2370. $query->select('id')->from('wx_user')->where('who', $uid);
  2371. })->orderBy('id', 'desc')->simplePaginate(10);
  2372. if($data){
  2373. $data->map(function ($v) {
  2374. $v->benifit = UserUtils::get_user_invite_benifit($v->id);
  2375. });
  2376. return $this->success($data);
  2377. }
  2378. return $this->success(200003);
  2379. }else if( $type == 3 ){
  2380. $first_userIds = WxUser::where('who', $uid)->pluck('id');
  2381. if($first_userIds){
  2382. $first_userIds = $first_userIds->toArray();
  2383. if($first_userIds){
  2384. $data = WxUser::whereIn('who', function ($query) use ($uid,$first_userIds){
  2385. $query->select('id')->from('wx_user')->whereIn('who', $first_userIds);
  2386. })->orderBy('id', 'desc')->simplePaginate(10);
  2387. if($data){
  2388. $data->map(function ($v) {
  2389. $v->benifit = UserUtils::get_user_invite_benifit($v->id);
  2390. });
  2391. return $this->success($data);
  2392. }
  2393. }
  2394. }
  2395. return $this->success(200003);
  2396. }
  2397. }
  2398. public function invite_info(Request $request){
  2399. $uid = $request->uid;
  2400. $result = [
  2401. 'notice' => Settings::get('user_invite_page_notice', ''),
  2402. 'benifit' => null,
  2403. 'myinviter' => null,
  2404. 'team' => [
  2405. 'total' => 0,
  2406. 'lv1_team' => 0,
  2407. 'lv2_team' => 0,
  2408. 'lv3_team' => 0,
  2409. ],
  2410. 'orders' => [
  2411. ],
  2412. 'qr' => Utils::getMiniCode('pages/tabbar/index/index', '', $uid)
  2413. ];
  2414. $result['benifit'] = UserUtils::get_user_invite_benifit($uid);
  2415. $who = WxUser::where('id', $uid)->value('who');
  2416. if($who > 0){
  2417. $inviter = WxUser::find($who, FieldUtils::userInfoColums());
  2418. if($inviter){
  2419. $inviter->benifit = UserUtils::get_user_invite_benifit($inviter->id);
  2420. $result['myinviter'] = $inviter;
  2421. }else{
  2422. $result['myinviter'] = null;
  2423. }
  2424. }
  2425. $my_inviter_users = [];
  2426. $first_userIds = WxUser::where('who', $uid)->pluck('id');
  2427. $second_userIds = null;
  2428. $third_userIds = null;
  2429. if($first_userIds){
  2430. $first_userIds = $first_userIds->toArray();
  2431. $second_userIds = WxUser::whereIn('who', $first_userIds)->pluck('id');
  2432. if($second_userIds){
  2433. $second_userIds = $second_userIds->toArray();
  2434. $third_userIds = WxUser::whereIn('who', $second_userIds)->pluck('id');
  2435. if($third_userIds){
  2436. $third_userIds = $third_userIds->toArray();
  2437. }
  2438. }
  2439. }
  2440. if($first_userIds){
  2441. foreach ($first_userIds as $user_id){
  2442. if(!isset($my_inviter_users[$user_id])){
  2443. $my_inviter_users[$user_id] = $user_id;
  2444. }
  2445. }
  2446. }
  2447. if($second_userIds){
  2448. foreach ($second_userIds as $user_id){
  2449. if(!isset($my_inviter_users[$user_id])){
  2450. $my_inviter_users[$user_id] = $user_id;
  2451. }
  2452. }
  2453. }
  2454. if($third_userIds){
  2455. foreach ($third_userIds as $user_id){
  2456. if(!isset($my_inviter_users[$user_id])){
  2457. $my_inviter_users[$user_id] = $user_id;
  2458. }
  2459. }
  2460. }
  2461. $result['team']['total'] = $my_inviter_users ? count($my_inviter_users) : 0;
  2462. $result['team']['lv1_team'] = $first_userIds ? count($first_userIds) : 0;
  2463. $result['team']['lv2_team'] = $second_userIds ? count($second_userIds) : 0;
  2464. $result['team']['lv3_team'] = $third_userIds ? count($third_userIds) : 0;
  2465. $records_ = [];
  2466. $records = WxUserInviteBenefitRecord::where('lv1_user', $uid)->orWhere('lv2_user', $uid)->orWhere('lv3_user', $uid)->orderBy('created_at', 'desc')->limit(5)->get();
  2467. if($records){
  2468. foreach ($records as $record){
  2469. $benefit = 0;
  2470. if($record->lv1_user == $uid){
  2471. $benefit = $record->lv1_benefit;
  2472. }else if($record->lv2_user == $uid){
  2473. $benefit = $record->lv2_benefit;
  2474. }else if($record->lv3_user == $uid){
  2475. $benefit = $record->lv3_benefit;
  2476. }
  2477. if($benefit < 0.01){
  2478. continue;
  2479. }
  2480. $user_name = UserUtils::get_cached_user_name($record->user_id);
  2481. if($record->shop_order_id > 0){
  2482. $str = '一笔来自「<a href="/pages/user/user?id='.(int)$record->user_id.'" target="_blank">'.$user_name.'</a>」的商城订单,您获得团队奖励¥'.$benefit;
  2483. }else if($record->order_id){
  2484. $str = '一笔来自「<a href="/pages/user/user?id='.(int)$record->user_id.'" target="_blank">'.$user_name.'</a>」的普通订单,您获得团队奖励¥'.$benefit;
  2485. }
  2486. $records_[] = $str;
  2487. }
  2488. }
  2489. $result['orders'] = $records_;
  2490. return $this->success($result);
  2491. }
  2492. /**
  2493. * 激励视频奖励
  2494. */
  2495. public function reward_gift(Request $request){
  2496. global $__MINI_GLOBAL_DEVICE__;
  2497. $action = $request->action;
  2498. $uid = $request->uid;
  2499. _limit_user('reward_gift', $uid, 20);
  2500. if($__MINI_GLOBAL_DEVICE__ == 'mp'){
  2501. $reward_every = Settings::get('ad_mp_reward_every');
  2502. }else{
  2503. $reward_every = Settings::get('ad_uni_reward_every');
  2504. }
  2505. $count = WxUserCoinRecord::where([
  2506. ['user_id', '=', $uid],
  2507. ['type', '=', 10],
  2508. ['created_at', '>=', Carbon::today()]
  2509. ])->count();
  2510. if($__MINI_GLOBAL_DEVICE__ == 'mp'){
  2511. $every_day_max = Settings::get('ad_mp_reward_every_day_times', 10);
  2512. }else{
  2513. $every_day_max = Settings::get('ad_uni_reward_every_day_times', 10);
  2514. }
  2515. if($count > $every_day_max){
  2516. return $this->fail(200010, [], '您今天获取奖励超过最大次数了,请您明天再来试试吧');
  2517. }
  2518. if($action == 'code'){
  2519. if($count <= $every_day_max){
  2520. $code = Utils::getSn(10);
  2521. Cache::put($code, 1, 80);
  2522. return $this->success($code);
  2523. }else{
  2524. return $this->fail(200010, [], '您今天获取奖励超过最大次数了,请您明天再来试试吧');
  2525. }
  2526. }else if($action == 'reward'){
  2527. $code = $request->code;
  2528. if(_empty_($code)){
  2529. return $this->fail(200001);
  2530. }
  2531. if(Cache::has($code)){
  2532. $r = UserUtils::update_user_coins($uid,10, $reward_every, '观看激励视频奖励:'.Settings::get('app_coin_name', '硬币').'(枚)*'.$reward_every);
  2533. Cache::forget($code);
  2534. return $this->success([], 200, '恭喜获得'.$reward_every.Settings::get('app_coin_name', '硬币'));
  2535. }else{
  2536. return $this->fail(200004);
  2537. }
  2538. }
  2539. }
  2540. /**
  2541. * 我的二维码卡片
  2542. */
  2543. public function codecard(Request $request){
  2544. $uid = $request->uid;
  2545. $user_id = $request->user_id;
  2546. if(_empty_($uid) && _empty_($user_id)){
  2547. return $this->fail(200001);
  2548. }
  2549. if($user_id){
  2550. $code = Utils::getMiniCode('pages/user/user', 'id='.$user_id, $uid);
  2551. $user = WxUser::where('id', $user_id)->first(FieldUtils::userInfoColums());
  2552. }else{
  2553. $code = Utils::getMiniCode('pages/user/user', 'id='.$uid, $uid);
  2554. $user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums());
  2555. }
  2556. if(_empty_($user->user_background_maps)){
  2557. $user->user_background_maps = Settings::get('user_background_maps', '');
  2558. }
  2559. if(_empty_($user->user_introduce)){
  2560. $user->user_introduce = Settings::get('app_user_introduce', '',true);
  2561. }
  2562. if($user){
  2563. if(Settings::get('app_user_qrcode_way', 0) == 2){
  2564. $result = [
  2565. 'user_background_maps' => $user->user_background_maps . '?imageMogr2/crop/330x200/gravity/center/thumbnail/330x/rradius/20',
  2566. 'user_avatar' => Utils::imgWithStyle($user->user_avatar, 2),
  2567. 'user_name' => mb_strlen($user->user_name) > 8 ? (mb_substr($user->user_name, 0, 8).'...') : $user->user_name,
  2568. 'id' => $user->id,
  2569. 'user_introduce' => $user->user_introduce,
  2570. 'rect' => 'https://img.mini.minisns.cn/hbx/qrcode_white_bg.png?imageMogr2/crop/330x390/gravity/center/thumbnail/330x/rradius/20',
  2571. 'code' => $code . '?imageMogr2/format/png/interlace/0',
  2572. 'logo' => Utils::imgWithStyle(Settings::get('about_logo', ''), 2),
  2573. 'way' => 2
  2574. ];
  2575. }else{
  2576. $result = [
  2577. 'user_background_maps' => Utils::imgWithStyle($user->user_background_maps, 1),
  2578. 'user_avatar' => $user->user_avatar . '?imageMogr2/crop/68x68/gravity/center/thumbnail/68x/rradius/68',
  2579. 'user_name' => mb_strlen($user->user_name) > 8 ? (mb_substr($user->user_name, 0, 8).'...') : $user->user_name,
  2580. 'id' => $user->id,
  2581. 'user_introduce' => $user->user_introduce,
  2582. 'code' => $code,
  2583. 'logo' => Utils::imgWithStyle(Settings::get('about_logo', ''), 2),
  2584. 'way' => 1
  2585. ];
  2586. }
  2587. return $this->success($result);
  2588. }
  2589. return $this->fail(200003);
  2590. }
  2591. /**
  2592. * 获取我的认证信息
  2593. */
  2594. public function getAuthentication(Request $request)
  2595. {
  2596. $uid = $request->uid;
  2597. return $this->success(WxAuthentication::where('user_id', $uid)->first());
  2598. }
  2599. /**
  2600. * 个人中心 我的笔记,收藏,喜欢,充电的文章数量
  2601. * @param Request $request
  2602. */
  2603. public function totalPost(Request $request)
  2604. {
  2605. $uid = $request->uid;
  2606. if($uid && $uid > 0){
  2607. $query = WxPost::where('user_id', $uid)->whereIn('posts_state', [0, 2]);
  2608. $data['myTotal'] = $query->count();
  2609. $postsIds = WxLike::where('user_id', $uid)->pluck('posts_id');
  2610. $data['likeTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
  2611. $postsIds = WxCollect::where('user_id', $uid)->pluck('posts_id');
  2612. $data['collecTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
  2613. $postsIds = WxExceptional::where('user_id', $uid)->pluck('posts_id');
  2614. $data['exceptionalTotal'] = WxPost::where('is_examine', 1)->where('posts_state', 0)->whereIn('id', $postsIds)->count();
  2615. }else{
  2616. $data = [
  2617. 'myTotal' => 0,
  2618. 'likeTotal' => 0,
  2619. 'collecTotal' => 0,
  2620. 'exceptionalTotal' => 0
  2621. ];
  2622. }
  2623. return $this->success($data);
  2624. }
  2625. /**
  2626. * 我关注的用户列表
  2627. * @param Request $request
  2628. */
  2629. public function myFollowUsers(Request $request)
  2630. {
  2631. $uid = $request->uid;
  2632. $user_id = $request->user_id;
  2633. if ($user_id > 0) {
  2634. $data = WxUserFollow::with('followUser')->where('user_id', $user_id)
  2635. ->orderBy('id', 'desc')
  2636. ->simplePaginate(10);
  2637. $data->map(function ($v) use ($user_id, $uid) {
  2638. $v->is_together_follow = WxUserFollow::where('user_id', $v->user_follow_id)
  2639. ->where('user_follow_id', $user_id)->exists();// 是否相互关注
  2640. $v->user = $v->followUser;
  2641. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_follow_id);
  2642. });
  2643. return $this->success($data);
  2644. } else {
  2645. $data = WxUserFollow::with('followUser')->where('user_id', $uid)
  2646. ->orderBy('id', 'desc')
  2647. ->simplePaginate(10);
  2648. $data->map(function ($v) use ($uid) {
  2649. $v->is_together_follow = WxUserFollow::where('user_id', $v->user_follow_id)
  2650. ->where('user_follow_id', $uid)->exists();// 是否相互关注
  2651. $v->user = $v->followUser;
  2652. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_follow_id);
  2653. });
  2654. return $this->success($data);
  2655. }
  2656. }
  2657. /**
  2658. * 我的粉丝用户列表
  2659. * @param Request $request
  2660. */
  2661. public function myFansUsers(Request $request)
  2662. {
  2663. $uid = $request->uid;
  2664. $user_id = $request->user_id;
  2665. if ($user_id > 0) {
  2666. $data = WxUserFollow::with('user')->where('user_follow_id', $user_id)
  2667. ->orderBy('id', 'desc')
  2668. ->simplePaginate(15);
  2669. $data->map(function ($v) use ($user_id, $uid) {
  2670. $v->is_together_follow = WxUserFollow::where('user_id', $user_id)
  2671. ->where('user_follow_id', $v->user_id)->exists();// 是否相互关注
  2672. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_id);
  2673. });
  2674. return $this->success($data);
  2675. } else {
  2676. $data = WxUserFollow::with('user')->where('user_follow_id', $uid)
  2677. ->orderBy('id', 'desc')
  2678. ->simplePaginate(15);
  2679. $data->map(function ($v) use ($uid) {
  2680. $v->is_together_follow = WxUserFollow::where('user_id', $uid)
  2681. ->where('user_follow_id', $v->user_id)->exists();// 是否相互关注
  2682. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->user_id);
  2683. });
  2684. return $this->success($data);
  2685. }
  2686. }
  2687. /**
  2688. * 艾特搜索
  2689. * @param Request $request
  2690. */
  2691. public function aiteSearch(Request $request){
  2692. $keyword = $request->keyword;
  2693. $uid = $request->uid;
  2694. _limit_user('search', $uid, 60);
  2695. $limit = $request->input('limit', 10);
  2696. if(_empty_($keyword)){
  2697. $data = WxUser::whereIn('id', WxUserFollow::select('user_follow_id')->where('user_id', $uid)
  2698. ->orderBy('id', 'desc')
  2699. )->simplePaginate($limit);
  2700. }else{
  2701. $keyword_actree = null;
  2702. $data = SearchUtils::search_user($keyword_actree, $keyword, $uid, false, $limit);
  2703. }
  2704. return $this->success($data);
  2705. }
  2706. /**
  2707. * 获取用户列表
  2708. * @param Request $request
  2709. */
  2710. public function getUsers(Request $request)
  2711. {
  2712. $uid = $request->uid;
  2713. $type = $request->type;
  2714. $limit = $request->limit;
  2715. if(_empty_($limit)){
  2716. $limit = 10;
  2717. }else{
  2718. $limit = _between_($limit, 1, 100);
  2719. }
  2720. $page = _empty_default_($request->page, 1);
  2721. $object_id = _empty_default_($request->object_id, 0);
  2722. if(_empty_($type)){
  2723. return $this->fail(200001);
  2724. }
  2725. if($type == 1){
  2726. // 最近注册用户列表
  2727. $data = WxUser::where('user_state', 0)->orderBy('created_at', 'desc')->simplePaginate($limit, FieldUtils::userInfoColums());
  2728. if($data){
  2729. $data->map(function ($v) use ($uid){
  2730. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2731. if($online_item){
  2732. $v->online_time = format_datetime($online_item->online);
  2733. $v->device = $online_item->device;
  2734. }else{
  2735. $v->online_time = '暂时未知';
  2736. $v->device = '';
  2737. }
  2738. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2739. return $v;
  2740. });
  2741. }
  2742. return $this->success($data);
  2743. }else if($type == 2){
  2744. // 在线用户列表
  2745. $data = UserUtils::user_onlines(2, 5, 1);
  2746. if($data){
  2747. $data->map(function ($v) use ($uid){
  2748. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2749. if($online_item){
  2750. $v->online_time = format_datetime($online_item->online);
  2751. $v->device = $online_item->device;
  2752. }else{
  2753. $v->online_time = '暂时未知';
  2754. $v->device = '';
  2755. }
  2756. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2757. return $v;
  2758. });
  2759. }
  2760. return $this->success($data);
  2761. }else if($type == 3){
  2762. // 今日注册的用户
  2763. $data = WxUser::where('created_at', '>', Carbon::today())->orderBy('created_at', 'desc')->simplePaginate($limit, FieldUtils::userInfoColums());
  2764. if($data) {
  2765. $data->map(function ($v) use ($uid){
  2766. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2767. if ($online_item) {
  2768. $v->online_time = format_datetime($online_item->online);
  2769. $v->device = $online_item->device;
  2770. } else {
  2771. $v->online_time = '暂时未知';
  2772. $v->device = '';
  2773. }
  2774. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2775. return $v;
  2776. });
  2777. }
  2778. return $this->success($data);
  2779. }else if($type == 4){
  2780. // 余额排行
  2781. $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')
  2782. ->where('wx_user_financial.balance', '>', 0)->orderBy('wx_user_financial.balance', 'desc')->orderBy('wx_user.id')
  2783. ->simplePaginate($limit, FieldUtils::userInfoColums());
  2784. if($data){
  2785. $data->map(function ($v) use ($uid){
  2786. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2787. if ($online_item) {
  2788. $v->online_time = format_datetime($online_item->online);
  2789. $v->device = $online_item->device;
  2790. } else {
  2791. $v->online_time = '暂时未知';
  2792. $v->device = '';
  2793. }
  2794. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2795. $v->desc_tip = '拥有'.$v->balance.'余额';
  2796. return $v;
  2797. });
  2798. }
  2799. return $this->success($data);
  2800. }else if($type == 5){
  2801. // 金币排行用户
  2802. $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'])
  2803. ->leftJoin('wx_user_meta_num', function ($join) {
  2804. $join->on('wx_user.id', '=', 'wx_user_meta_num.user_id')
  2805. ->where('wx_user_meta_num.meta_key', '=', 'coins');
  2806. })->orderBy('wx_user_meta_num.meta_value', 'desc')->orderBy('wx_user.id')
  2807. ->simplePaginate($limit, FieldUtils::userInfoColums());
  2808. if($data){
  2809. $data->map(function ($v) use ($uid){
  2810. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2811. if ($online_item) {
  2812. $v->online_time = format_datetime($online_item->online);
  2813. $v->device = $online_item->device;
  2814. } else {
  2815. $v->online_time = '暂时未知';
  2816. $v->device = '';
  2817. }
  2818. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2819. $v->desc_tip = '拥有'.$v->coins.Settings::get('app_coin_name', '硬币');
  2820. return $v;
  2821. });
  2822. }
  2823. return $this->success($data);
  2824. }else if($type == 6){
  2825. // 笔记总数排行
  2826. $subQuery = DB::table('wx_posts')
  2827. ->select('user_id', DB::raw('COUNT(*) as post_count'))
  2828. ->groupBy('user_id')
  2829. ->orderByDesc('post_count')
  2830. ->toSql();
  2831. $data = WxUser::join(DB::raw("({$subQuery}) as sub"), 'wx_user.id', '=', 'sub.user_id')->orderBy('post_count', 'desc')->orderBy('id')
  2832. ->simplePaginate($limit, array_merge(FieldUtils::userInfoColums(), ['post_count']));
  2833. if($data){
  2834. $data->map(function ($v) use ($uid){
  2835. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2836. if ($online_item) {
  2837. $v->online_time = format_datetime($online_item->online);
  2838. $v->device = $online_item->device;
  2839. } else {
  2840. $v->online_time = '暂时未知';
  2841. $v->device = '';
  2842. }
  2843. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2844. $v->desc_tip = '发布了'.$v->post_count.'篇笔记';
  2845. return $v;
  2846. });
  2847. }
  2848. return $this->success($data);
  2849. }else if($type == 7){
  2850. // 我拉黑的用户
  2851. return $this->fail(200003);
  2852. }else if($type == 8){
  2853. // 不喜欢的用户
  2854. $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  2855. if($user_set){
  2856. $user_set = array_reverse($user_set);
  2857. $data = WxUser::whereIn('id', $user_set)
  2858. ->orderBy(DB::raw('FIND_IN_SET(id, "' . implode(",", $user_set) . '"' . ")"))->orderBy('id')->simplePaginate($limit, FieldUtils::userInfoColums());
  2859. if($data){
  2860. $data->map(function ($v) use ($uid){
  2861. $online_item = WxUserOnline::where('user_id', $v->id)->first(['online', 'device']);
  2862. if ($online_item) {
  2863. $v->online_time = format_datetime($online_item->online);
  2864. $v->device = $online_item->device;
  2865. } else {
  2866. $v->online_time = '暂时未知';
  2867. $v->device = '';
  2868. }
  2869. $v->is_follow_user = (new WxUserFollow())->isFollowUser($uid, $v->id);
  2870. return $v;
  2871. });
  2872. return $this->success($data);
  2873. }
  2874. return $this->fail(200003);
  2875. }else{
  2876. return $this->fail(200003);
  2877. }
  2878. }else if($type == 9){
  2879. // 激励用户排行榜
  2880. $data = WxUserCoinRecord::query()
  2881. ->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'))
  2882. ->join('wx_user', 'wx_user.id', '=', 'wx_user_coin_record.user_id')
  2883. ->where('wx_user_coin_record.type', 10)
  2884. ->groupBy('wx_user_coin_record.user_id')
  2885. ->orderByDesc('total_incre')->orderBy('wx_user.id')
  2886. ->simplePaginate($limit, FieldUtils::userInfoColums());
  2887. if($data){
  2888. $data->map(function ($v) use ($uid){
  2889. $v->desc_tip = '支持了'.$v->coin_add_count.'次';
  2890. return $v;
  2891. });
  2892. return $this->success($data);
  2893. }
  2894. return $this->success($data);
  2895. }else if($type == 10){
  2896. // 邀请榜
  2897. $data = WxUser::query()
  2898. ->join('wx_user as inviters', 'inviters.id', '=', 'wx_user.who') // 连接wx_user表来获取邀请人信息
  2899. ->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') // 选择所需字段
  2900. ->where('wx_user.who', '>', 0) // 确保'who'字段不为空
  2901. ->groupBy('wx_user.who') // 按'who'字段分组,同时包括邀请人的信息
  2902. ->orderByDesc('total_invites')->orderBy('inviters.id') // 按邀请数降序排序
  2903. ->simplePaginate($limit);
  2904. if($data){
  2905. $data->map(function ($v) use ($uid){
  2906. $v->desc_tip = '直接邀请'.$v->total_invites.'人';
  2907. return $v;
  2908. });
  2909. return $this->success($data);
  2910. }
  2911. return $this->success($data);
  2912. }else if($type == 11){
  2913. // 粉丝排行榜
  2914. $data = WxUser::query()
  2915. ->join('wx_user_follow', 'wx_user.id', '=', 'wx_user_follow.user_follow_id')
  2916. ->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'))
  2917. ->where('wx_user_follow.user_follow_state', 0) // 只计算正常关注的情况
  2918. ->groupBy('wx_user.id')
  2919. ->orderByDesc('followers_count')->orderBy('wx_user.id') // 根据粉丝数量降序排序
  2920. ->simplePaginate($limit);
  2921. if($data){
  2922. $data->map(function ($v) use ($uid){
  2923. $v->desc_tip = '粉丝数'.$v->followers_count.'人';
  2924. return $v;
  2925. });
  2926. return $this->success($data);
  2927. }
  2928. return $this->success($data);
  2929. }else if($type == 12){
  2930. // 等级排行榜
  2931. $data = WxUser::query()
  2932. ->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')
  2933. ->joinSub(function ($query) {
  2934. $query->from('wx_user_meta_num')
  2935. ->select('user_id', 'meta_value')
  2936. ->where('meta_key', 'experience');
  2937. }, 'meta_num', 'meta_num.user_id', 'wx_user.id')
  2938. ->orderBy('experience', 'desc')->orderBy('wx_user.id') // 根据经验值降序排序
  2939. ->simplePaginate($limit);
  2940. if($data){
  2941. $data->map(function ($v) use ($uid){
  2942. $v->desc_tip = '经验值'.$v->experience;
  2943. return $v;
  2944. });
  2945. return $this->success($data);
  2946. }
  2947. return $this->success($data);
  2948. }else if($type == 13){
  2949. // 俱乐部粉丝
  2950. $data = DB::table('wx_club_follow as wcf')
  2951. ->join('wx_user as wu', 'wcf.user_id', '=', 'wu.id')
  2952. ->select('wu.*', 'wcf.created_at as follow_time')
  2953. ->where('wcf.club_id', $object_id)
  2954. ->where('wcf.status', 1) // 只获取状态为关注的记录
  2955. ->orderBy('wcf.created_at', 'desc')
  2956. ->simplePaginate($limit);
  2957. if($data){
  2958. $data->map(function ($v) use ($uid){
  2959. $v->desc_tip = '关注时间:'.$v->follow_time;
  2960. return $v;
  2961. });
  2962. return $this->success($data);
  2963. }
  2964. return $this->success($data);
  2965. }else if($type == 14){
  2966. // 关注圈子的粉丝
  2967. $data = DB::table('wx_user_circle as wcf')
  2968. ->join('wx_user as wu', 'wcf.user_id', '=', 'wu.id')
  2969. ->select('wu.*', 'wcf.created_at as follow_time')
  2970. ->where('wcf.circle_id', $object_id)
  2971. ->where('wcf.user_circle_state', 0) // 只获取状态为关注的记录
  2972. ->orderBy('wcf.created_at', 'desc')
  2973. ->simplePaginate($limit);
  2974. if($data){
  2975. $data->map(function ($v) use ($uid){
  2976. $v->desc_tip = '关注时间:'.$v->follow_time;
  2977. return $v;
  2978. });
  2979. return $this->success($data);
  2980. }
  2981. return $this->success($data);
  2982. }else if($type == 17){
  2983. // 获取传单所推广的用户
  2984. $itcId = (int)str_replace('itc', '', _empty_default_($request->itc, ''));
  2985. if(_empty_($itcId)){
  2986. return $this->fail(200001);
  2987. }
  2988. $data = DB::table('wx_user as u')
  2989. ->join('wx_user_invite_temp_code_record as r', 'u.id', '=', 'r.object_id')
  2990. ->where('r.itc_id', $itcId)
  2991. ->orderBy('r.created_at', 'desc')
  2992. ->select('u.*', 'r.created_at', 'r.*')->simplePaginate($limit);
  2993. $data->map(function ($v) use ($uid){
  2994. $v->desc_tip = $v->created_at . ' 奖励:¥' . $v->reward_balance . ($v->reward_coin > 0 ? '+'.Settings::get('app_coin_name', '硬币').'*'.$v->reward_coin : '');
  2995. return $v;
  2996. });
  2997. return $this->success($data);
  2998. }
  2999. }
  3000. /**
  3001. * 添加用户话题
  3002. * @param Request $request
  3003. */
  3004. public function addUserPlate(Request $request)
  3005. {
  3006. $plateId = $request->plate_id;
  3007. $uid = $request->uid;
  3008. if(_empty_($plateId)){
  3009. return $this->fail(200001);
  3010. }
  3011. $r = UserUtils::add_user_plate($uid, $plateId);
  3012. if($r){
  3013. return $this->success();
  3014. }
  3015. return $this->fail(200004, [], '添加分区失败');
  3016. }
  3017. public function real_name(Request $request)
  3018. {
  3019. $uid = $request->uid;
  3020. if(request()->method() === 'GET'){
  3021. $user = WxUser::where('id', $uid)->first(['id', 'real_name', 'real_id_card']);
  3022. if($user){
  3023. if(_empty_($user->real_name)){
  3024. $user->real_name = '';
  3025. }
  3026. if(_empty_($user->real_id_card)){
  3027. $user->real_id_card = '';
  3028. }
  3029. return $this->success($user);
  3030. }else{
  3031. return $this->fail(200003);
  3032. }
  3033. }else{
  3034. $user = WxUser::find($uid);
  3035. if(_empty_($user)){
  3036. return $this->fail(200003);
  3037. }
  3038. $realName = _empty_default_($request->realName, '');
  3039. $realIdCard = _empty_default_($request->realIdCard, '');
  3040. if(_empty_($realName) || _empty_($realIdCard)){
  3041. return $this->fail(200001);
  3042. }
  3043. if(mb_strlen($realName) <= 1){
  3044. return $this->fail(200004, [], '姓名过短');
  3045. }
  3046. if(strpos($realName, '*') !== false || strpos($realIdCard, '*') !== false){
  3047. return $this->fail(200004, [], '姓名或身份证中含有*号,请先删除');
  3048. }
  3049. if(strlen($realIdCard) != 18){
  3050. return $this->fail(200004, [], '请输入合法的身份证号');
  3051. }
  3052. // $realName_fake = mb_substr($realName, 0, 1) . str_repeat( '*', (mb_strlen($realName) - 1) );
  3053. // $realIdCard_fake = mb_substr($realIdCard, 0, 2) . str_repeat( '*', (mb_strlen($realIdCard) - 2) );
  3054. $realName_fake = $realName;
  3055. $realIdCard_fake = $realIdCard;
  3056. if($user->real_name == $realName_fake && $user->real_id_card == $realIdCard_fake){
  3057. return $this->fail(200010, [], '与已有认证信息相同,无需修改');
  3058. }
  3059. $phone = _get_origin_attribute('wx_user', [['id', '=', $uid]], 'phone');
  3060. if(_empty_($user->phone) || _empty_($phone)){
  3061. return $this->fail(200043, [
  3062. 'title' => '未绑定手机号',
  3063. 'content' => '前往绑定',
  3064. 'confirmText' => '去绑定',
  3065. 'target_type' => 6,
  3066. 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
  3067. ], '未绑定手机号');
  3068. }
  3069. // $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
  3070. // todo:
  3071. // WxUser::where('id', $uid)->update([
  3072. // 'real_name' => $realName_fake,
  3073. // 'real_id_card' => $realIdCard_fake
  3074. // ]);
  3075. // update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
  3076. // // Conditions 更新实名认证状态
  3077. // Conditions::where('user_id', $uid)->update(['is_real' => 1]);
  3078. // DB::commit();
  3079. // return $this->success([], 200, '实名认证成功');
  3080. $res_ = Http::withHeaders([
  3081. 'Authorization' => 'APPCODE '.Settings::get('app_ali_real_name_appcode', ''),
  3082. ])->asForm()->post('https://mobile3elements.shumaidata.com/mobile/verify_real_name', ['idcard'=>$realIdCard, 'mobile'=>$phone, 'name'=> $realName]);
  3083. //print_r($res_);exit;
  3084. if($res_->successful()){
  3085. $res = $res_->json();
  3086. if($res){
  3087. if($res['code'] == 0 && $res['result']){
  3088. if($res['result']['res'] == 1){
  3089. // 一致
  3090. DB::beginTransaction();
  3091. try {
  3092. $encrypted = SafeUtils::mini_common_rsa_encrypt('id='.$realIdCard.':name='.$realName.':phone=('.$user->country_code.')'.$phone);
  3093. // todo:
  3094. WxUser::where('id', $uid)->update([
  3095. 'real_name' => $realName_fake,
  3096. 'real_id_card' => $realIdCard_fake,
  3097. 'is_real' => 1
  3098. ]);
  3099. update_user_meta($uid, 'real_info_encrypted', base64_encode($encrypted), 's');
  3100. // Conditions 更新实名认证状态
  3101. Conditions::where('user_id', $uid)->update(['is_real' => 1]);
  3102. DB::commit();
  3103. return $this->success([], 200, '实名认证成功');
  3104. } catch (\Exception $e) {
  3105. DB::rollBack();
  3106. _logger_(__file__, __line__, $e->getMessage());
  3107. return $this->fail(200002);
  3108. }
  3109. }else if($res['result']['res'] == 2){
  3110. return $this->fail(200004, [], '身份信息不一致,认证失败');
  3111. }else if($res['result']['res'] == 3){
  3112. return $this->fail(200004, [], '认证系统查询不到该信息,请联系客服');
  3113. }else if($res['result']['res'] == -1){
  3114. return $this->fail(200004, [], '异常');
  3115. }
  3116. }else{
  3117. UserUtils::assistant_notice('admin', $res.'_003');
  3118. return $this->fail(200004, [], $res['message'].'__003');
  3119. }
  3120. }
  3121. }else{
  3122. $res = $res_->json();
  3123. _logger_(__file__, __line__, '实名认证返回错误,'.$res_->body());
  3124. _logger_(__file__, __line__, '实名认证返回错误,'. urldecode($res_));
  3125. return $this->fail(200004, [], _array_key($res, 'message', ''));
  3126. }
  3127. }
  3128. }
  3129. /**
  3130. * 删除用户话题
  3131. * @param Request $request
  3132. */
  3133. public function deleteUserPlate(Request $request)
  3134. {
  3135. $id = $request->id;
  3136. $uid = $request->uid;
  3137. $plate_id = $request->plate_id;
  3138. if(_empty_($plate_id)){
  3139. (new WxUserPlate())->where('user_id', $uid)->where('id', $id)->update(['status'=>2]);
  3140. }else{
  3141. (new WxUserPlate())->where('user_id', $uid)->where('plate_id', $plate_id)->update(['status'=>2]);
  3142. }
  3143. return $this->success();
  3144. }
  3145. /**
  3146. * 用户话题列表
  3147. * @param Request $request
  3148. */
  3149. public function userPlate(Request $request)
  3150. {
  3151. global $__MINI_GLOBAL_TENANT_ID__;
  3152. $uid = $request->uid;
  3153. if ($uid == 0) {
  3154. $data = [];
  3155. } else {
  3156. $data = (new WxUserPlate())->where('user_id', $uid)->where('status', 1)->orderBy('updated_at', 'asc')->get();
  3157. if(!$data->isEmpty()){
  3158. $data = $data->map(function ($item) {
  3159. $plate = WxPlate::find($item->plate_id);
  3160. if($plate){
  3161. $item->plate_name = $plate->plate_name;
  3162. $item->tenant_id = $plate->tenant_id;
  3163. return $item;
  3164. }
  3165. });
  3166. $data = $data->filter(function ($item, $key) use ($__MINI_GLOBAL_TENANT_ID__){
  3167. if($item){
  3168. return $item->tenant_id == $__MINI_GLOBAL_TENANT_ID__;
  3169. }
  3170. return false;
  3171. });
  3172. }
  3173. }
  3174. return $this->success($data);
  3175. }
  3176. /**
  3177. * 我的订单列表
  3178. */
  3179. public function myOrder(Request $request, $limit = 8)
  3180. {
  3181. $uid = $request->uid;
  3182. $type = $request->type;
  3183. if(_empty_($type)){
  3184. return $this->fail(200001);
  3185. }
  3186. if($type == 'all'){
  3187. if(!UserUtils::is_mini_supder_admin($uid)){
  3188. return $this->fail(200000);
  3189. }
  3190. $data = WxOrder::where([['order_state','=', 1], ['order_serial_number', '<>', '']])
  3191. ->orderBy('id', 'desc')->simplePaginate($limit);
  3192. }else{
  3193. $data = WxOrder::where('user_id', $uid)->where([['order_state','=', 1], ['order_serial_number', '<>', '']])
  3194. ->orderBy('id', 'desc')->simplePaginate($limit);
  3195. }
  3196. $data->map(function ($v) {
  3197. $v->type_content = WxUserRepositores::orderType($v->order_type);
  3198. $parame = unserialize($v->parame);
  3199. $v->posts_id = $parame['postsId'] ?? 0;
  3200. $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
  3201. });
  3202. return $this->success($data);
  3203. }
  3204. public function financial_process(Request $request){
  3205. $type = _empty_default_($request->type, '');
  3206. if ($type == 'my_financial') {
  3207. return $this->myFinancial($request);
  3208. }else if ($type == 'initiate_withdrawal') {
  3209. return $this->initiateWithdrawal($request);
  3210. }else if ($type == 'withdrawal_apply') {
  3211. return $this->withdrawalApply($request);
  3212. }else if ($type == 'withdrawal_list') {
  3213. return $this->withdrawalList($request);
  3214. }else if ($type == 'balance_record_list') {
  3215. return $this->balanceRecordList($request);
  3216. }else if ($type == 'coin_record_list') {
  3217. return $this->coinRecordList($request);
  3218. }
  3219. }
  3220. private function coinRecordList(Request &$request){
  3221. $uid = $request->uid;
  3222. $setUserid = $request->setUserid;
  3223. if(!_empty_($setUserid)) {
  3224. if ($setUserid && $setUserid > 0) {
  3225. if (UserUtils::is_mini_supder_admin($uid)) {
  3226. $uid = $setUserid;
  3227. } else {
  3228. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3229. }
  3230. }
  3231. }
  3232. $data = WxUserCoinRecord::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  3233. if($data){
  3234. $data->map(function ($v) {
  3235. });
  3236. return $this->success($data);
  3237. }
  3238. return $this->fail(200003);
  3239. }
  3240. private function balanceRecordList(Request &$request){
  3241. $uid = $request->uid;
  3242. $setUserid = $request->setUserid;
  3243. if(!_empty_($setUserid)) {
  3244. if ($setUserid && $setUserid > 0) {
  3245. if (UserUtils::is_mini_supder_admin($uid)) {
  3246. $uid = $setUserid;
  3247. } else {
  3248. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3249. }
  3250. }
  3251. }
  3252. $data = WxUserFinancialRecord::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  3253. if($data){
  3254. $data->map(function ($v) {
  3255. });
  3256. return $this->success($data);
  3257. }
  3258. return $this->fail(200003);
  3259. }
  3260. private function withdrawalList(Request &$request){
  3261. $uid = $request->uid;
  3262. $setUserid = $request->setUserid;
  3263. if(!_empty_($setUserid)) {
  3264. if ($setUserid && $setUserid > 0) {
  3265. if (UserUtils::is_mini_supder_admin($uid)) {
  3266. $uid = $setUserid;
  3267. } else {
  3268. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3269. }
  3270. }
  3271. }
  3272. $data = WxUserWithdrawal::where('user_id', $uid)->orderBy('id', 'desc')->simplePaginate(10);
  3273. if($data){
  3274. $data->map(function ($v) {
  3275. $v->state_tip = WxUserRepositores::withdrawalType($v->state);
  3276. if(!_empty_($v->withdrawal_remark)){
  3277. $v->title = $v->withdrawal_remark;
  3278. }else if(!_empty_($v->wechat_phone)){
  3279. $v->way = 'wechat';
  3280. $v->title = '提现'.$v->pay_amount.'元到微信';
  3281. }else if(!_empty_($v->alipay_phone)){
  3282. $v->way = 'alipay';
  3283. $v->title = '提现'.$v->pay_amount.'元到支付宝';
  3284. }else if(!_empty_($v->bank_card)){
  3285. $v->way = 'bank';
  3286. $v->title = '提现'.$v->pay_amount.'元到银行卡';
  3287. }
  3288. if(_empty_($v->way)){
  3289. if(!_empty_($v->wx_batch_id)){
  3290. $v->way = 'wechat';
  3291. }else if(!_empty_($v->ali_batch_id)){
  3292. $v->way = 'alipay';
  3293. }
  3294. }
  3295. });
  3296. return $this->success($data);
  3297. }
  3298. return $this->fail(200003);
  3299. }
  3300. private function withdrawalApply(Request &$request){
  3301. $uid = $request->uid;
  3302. $id = _empty_default_($request->id, 0);
  3303. if(_empty_($id)){
  3304. return $this->fail(200001);
  3305. }
  3306. $withdrawal = WxUserWithdrawal::find($id);
  3307. if($withdrawal->user_id != $uid && !UserUtils::is_mini_supder_admin($uid)){
  3308. return $this->fail(200000);
  3309. }
  3310. $withdrawal->state_tip = WxUserRepositores::withdrawalType($withdrawal->state);
  3311. if(!_empty_($withdrawal->wechat_phone)){
  3312. $withdrawal->way = 'wechat';
  3313. }else if(!_empty_($withdrawal->alipay_phone)){
  3314. $withdrawal->way = 'alipay';
  3315. }else if(!_empty_($withdrawal->bank_card)){
  3316. $withdrawal->way = 'bank';
  3317. }else if(!_empty_($withdrawal->wx_batch_id)){
  3318. $withdrawal->way = 'wechat';
  3319. }else if(!_empty_($withdrawal->ali_batch_id)){
  3320. $withdrawal->way = 'alipay';
  3321. }
  3322. return $this->success($withdrawal);
  3323. }
  3324. /**
  3325. * 我的收益
  3326. */
  3327. public function myFinancial(Request $request)
  3328. {
  3329. $uid = $request->uid;
  3330. $setUserid = $request->setUserid;
  3331. if(!_empty_($setUserid)){
  3332. if($setUserid && $setUserid > 0){
  3333. if(UserUtils::is_mini_supder_admin($uid)){
  3334. $uid = $setUserid;
  3335. }else{
  3336. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3337. }
  3338. }
  3339. }
  3340. $result = [
  3341. 'coins' => [
  3342. 'total' => UserUtils::user_coins($uid) ?? 0
  3343. ],
  3344. 'financial' => [],
  3345. ];
  3346. $result['financial'] = WxUserFinancial::where('user_id', $uid)
  3347. ->first();
  3348. if($result['financial']) {
  3349. $result['financial']->earnings_yesterday = WxExceptional::where('posts_user_id', $result['financial']->user_id)
  3350. ->where('created_at', 'like', '%' . date("Y-m-d", strtotime("-1 day")) . '%')
  3351. ->sum('exceptional_price');
  3352. if(_empty_($result['financial']->withdrawal_price)){
  3353. $result['financial']->withdrawal_price = 0;
  3354. }
  3355. return $this->success($result);
  3356. }else{
  3357. return $this->success($result);
  3358. }
  3359. }
  3360. /**
  3361. * 发起提现
  3362. */
  3363. public function initiateWithdrawal(Request $request)
  3364. {
  3365. global $__MINI_GLOBAL_CURRENT_PLAYER_ID__;
  3366. $uid = $request->uid;
  3367. $price = $request->price;
  3368. $bank_name = _empty_default_($request->bank_name, '');
  3369. $bank_card = _empty_default_($request->bank_card, '');
  3370. $real_name = $request->real_name ?? null;
  3371. $id_card = _empty_default_($request->id_card, '');
  3372. $wechat_phone = $request->wechat_phone ?? null;
  3373. $aliay_phone = $request->aliay_phone ?? null;
  3374. $withdrawal_way = _empty_default_($request->way, 'wechat');
  3375. $device = in_array($request->header('device',''), ['app', 'h5', 'mp', 'pc']) ? $request->header('device','') : '';
  3376. if($price < Settings::get('app_balance_withdrawal_min_once', 1) || $price > Settings::get('app_balance_withdrawal_max_once', 200)){
  3377. return $this->fail(200004, [], '提现金额不合法');
  3378. }
  3379. $user = WxUser::find($uid);
  3380. // 验证资料
  3381. if(Settings::get('app_balance_withdrawal_force_bind_phone', 0) == 1){
  3382. if(_empty_($user->phone) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  3383. return $this->fail(200043, [
  3384. 'title' => '未绑定手机号',
  3385. 'content' => '前往绑定',
  3386. 'confirmText' => '去绑定',
  3387. 'target_type' => 6,
  3388. 'target_id' => '/pagesA/mine/editmine/editmine?phone=1'
  3389. ], '未绑定手机号');
  3390. }
  3391. }
  3392. if(Settings::get('app_balance_withdrawal_force_real_name', 0) == 1){
  3393. if(_empty_($user->real_name) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  3394. return $this->fail(200043, [
  3395. 'title' => '未实名认证',
  3396. 'content' => '您还没有实名认证,是否前往认证',
  3397. 'confirmText' => '去认证',
  3398. 'target_type' => 6,
  3399. 'target_id' => '/pagesA/mine/realname/realname'
  3400. ], '未实名认证');
  3401. }
  3402. }
  3403. if(Settings::get('app_balance_withdrawal_force_subscribe_mp', 0) == 1){
  3404. if(_empty_($user->weixin_mp_openid) && _empty_($__MINI_GLOBAL_CURRENT_PLAYER_ID__)){
  3405. $weapp = new WeApp('mp');
  3406. $mpServicer = $weapp->getMpServicer();
  3407. try {
  3408. $url = $mpServicer->getQrCodeWithPara(0, 'user:bind:'.$user->id);
  3409. }catch (\Exception $e){
  3410. return $this->fail(200006, [], '生成公众号二维码失败,请检查[全局配置-支付-微信-公众号]');
  3411. }
  3412. if($url){
  3413. $qrCode = QrCode::format('png')->size(300)->generate($url);
  3414. $image = Image::make($qrCode);
  3415. $image->resizeCanvas(300, 300 + 60, 'bottom', false, '#ffffff'); // 增加高度,保持宽高比,背景色为白色
  3416. $mp_app_name = Settings::get('mp_app_name', '');
  3417. $text_tip = '关注'.$mp_app_name.'公众号,可以更方便通知到您';
  3418. if(mb_strlen($mp_app_name) > 4){
  3419. $text_tip = '关注'.$mp_app_name.'公众号';
  3420. }
  3421. $image->text($text_tip, 150, 40, function($font){
  3422. $font->file(public_path('storage/font/DingTalk_JinBuTi_Regular.ttf')); // 字体文件路径
  3423. $font->size(13); // 字体大小
  3424. $font->color('#000000'); // 字体颜色
  3425. $font->align('center'); // 水平对齐
  3426. $font->valign('top'); // 垂直对齐
  3427. });
  3428. $base64 = 'data:image/png;base64,' . base64_encode($image->encode('png')->getEncoded());
  3429. return $this->fail(200043, [
  3430. 'title' => '未关注公众号,无法实时获取通知',
  3431. 'content' => '前往关注',
  3432. 'confirmText' => '去关注',
  3433. 'target_type' => 26,
  3434. 'target_id' => $base64
  3435. ], '未关注公众号');
  3436. }
  3437. }
  3438. }
  3439. if(_empty_($real_name)){
  3440. return $this->fail(200001, [], '缺少真实姓名');
  3441. }
  3442. $financial_updates = [];
  3443. if($withdrawal_way == 'wechat'){
  3444. if(_empty_($wechat_phone) || !StrUtils::is_phone_number($wechat_phone)){
  3445. return $this->fail(200001, [], '微信手机号不合法');
  3446. }
  3447. if(_empty_($real_name)){
  3448. return $this->fail(200001, [], '姓名不完整');
  3449. }
  3450. $financial_updates['wechat_phone'] = $wechat_phone;
  3451. $financial_updates['real_name'] = $real_name;
  3452. }else if($withdrawal_way == 'alipay'){
  3453. if(_empty_($aliay_phone) || !StrUtils::is_phone_number($aliay_phone)){
  3454. return $this->fail(200001, [], '支付宝手机号不合法');
  3455. }
  3456. if(_empty_($real_name) || _empty_($id_card) || strlen($id_card) != 18){
  3457. return $this->fail(200001, [], '姓名或身份证号不完整');
  3458. }
  3459. $financial_updates['alipay_phone'] = $aliay_phone;
  3460. $financial_updates['real_name'] = $real_name;
  3461. $financial_updates['id_card'] = $id_card;
  3462. }else{
  3463. if(_empty_($bank_name) || _empty_($bank_card) || _empty_($real_name)){
  3464. return $this->fail(200001, [], '银行信息不完整');
  3465. }
  3466. $financial_updates['bank_name'] = $bank_name;
  3467. $financial_updates['bank_card'] = $bank_card;
  3468. $financial_updates['real_name'] = $real_name;
  3469. }
  3470. if(WxUserWithdrawal::where('user_id', $uid)->where('withdrawal_scene', 0)->whereDate('created_at', Carbon::today())->count() >= Settings::get('app_balance_withdrawal_day_times', 3)){
  3471. return $this->fail(200046, [], '您今天已经达到最大的提现次数了');
  3472. }
  3473. $platform_percent = _between_(Settings::get('app_withdrawal_platform_percent', 10.0), 0, 100);
  3474. $pay_amount = round(($price * ( 100 - $platform_percent )) / 100, 2);
  3475. DB::beginTransaction();
  3476. try{
  3477. $r = UserUtils::update_user_financial($uid, 2, $price, '发起余额提现¥'.$price, 0, $bank_name, $bank_card);
  3478. if($r){
  3479. $withdrawal_id = Utils::getSn(14);
  3480. // 提现记录
  3481. $userWithdrawalModel = new WxUserWithdrawal();
  3482. $userWithdrawalModel->user_id = $uid;
  3483. $userWithdrawalModel->withdrawal_id = $withdrawal_id;
  3484. $userWithdrawalModel->price = $price;
  3485. $userWithdrawalModel->pay_amount = $pay_amount;
  3486. $userWithdrawalModel->bank_name = $bank_name;
  3487. $userWithdrawalModel->bank_card = $bank_card;
  3488. $userWithdrawalModel->real_name = $real_name;
  3489. if($withdrawal_way == 'wechat'){
  3490. $userWithdrawalModel->wechat_phone = $wechat_phone;
  3491. $userWithdrawalModel->alipay_phone = null;
  3492. }else if($withdrawal_way == 'alipay'){
  3493. $userWithdrawalModel->wechat_phone = null;
  3494. $userWithdrawalModel->alipay_phone = $aliay_phone;
  3495. }
  3496. $userWithdrawalModel->state = 0;
  3497. $userWithdrawalModel->save();
  3498. UserUtils::assistant_notice('admin', '有用户(<a href="/pages/user/user?id='.$uid.'">id: '.$uid.'</a>)提交了新的提现申请。');
  3499. WxUserFinancial::where('user_id', $uid)->update($financial_updates);
  3500. UserWithdrawalProcessJob::dispatch($userWithdrawalModel->id);
  3501. $tmplIds = [];
  3502. if($device == 'mp'){
  3503. $comment_add_id = Settings::get('mini_template_message_withdrawal', '');
  3504. if(!_empty_($comment_add_id)){
  3505. $tmplIds[] = $comment_add_id;
  3506. }
  3507. }
  3508. DB::commit();
  3509. return $this->success([
  3510. 'tmplIds' => $tmplIds,
  3511. 'id' => $userWithdrawalModel->id
  3512. ]);
  3513. }
  3514. DB::rollBack();
  3515. return $this->fail(200013);
  3516. }catch (\Exception $e){
  3517. DB::rollBack();
  3518. _logger_(__file__, __line__, $e->getMessage());
  3519. return $this->fail(200013);
  3520. }
  3521. }
  3522. /**
  3523. * 我的提现记录
  3524. */
  3525. public function myUserWithdrawal(Request $request)
  3526. {
  3527. $uid = $request->uid;
  3528. $id = _empty_default_($request->id, 0);
  3529. $setUserid = $request->setUserid;
  3530. if(!_empty_($setUserid)) {
  3531. if ($setUserid && $setUserid > 0) {
  3532. if (UserUtils::is_mini_supder_admin($uid)) {
  3533. $uid = $setUserid;
  3534. } else {
  3535. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3536. }
  3537. }
  3538. }
  3539. $query = WxUserWithdrawal::where('user_id', $uid);
  3540. if($id > 0){
  3541. $query = $query->where('id', $id);
  3542. }
  3543. $data = $query
  3544. ->orderBy('id', 'desc')
  3545. ->get();
  3546. $data->map(function ($v) {
  3547. $v->status_value = WxUserRepositores::withdrawalType($v->state);
  3548. });
  3549. return $this->success($data);
  3550. }
  3551. /**
  3552. * @param Request $request
  3553. */
  3554. public function uploaded_unused_attachments(Request $request){
  3555. $uid = $request->uid;
  3556. $type = $request->type;
  3557. if($type == 'img'){
  3558. $types_ = ["jpg", "jpeg", "png", "gif"];
  3559. }else if($type == 'video'){
  3560. $types_ = ['mp4'];
  3561. }else{
  3562. return $this->fail(200004);
  3563. }
  3564. $attachments = WxAttachment::where('user_id', $uid)->where('state', 1)->WhereIn('type', $types_)->orderBy('id', 'desc')->simplePaginate(10);
  3565. if($attachments){
  3566. $attachments->map(function ($v){
  3567. $v->url = $v->domain .'/' . $v->path;
  3568. return $v;
  3569. });
  3570. return $this->success($attachments);
  3571. }
  3572. return $this->fail(200003);
  3573. }
  3574. /**
  3575. * 邀请领会员
  3576. */
  3577. public function invite_member(Request $request)
  3578. {
  3579. $uid = $request->uid;
  3580. $days = Settings::get('app_vip_5_invitees_days', 90);
  3581. if(_empty_($days)){
  3582. return $this->fail(200008);
  3583. }
  3584. $vip_consume_invitees = get_user_meta($uid, 'vip_consume_invitees', 'j');
  3585. $invitees = WxUser::where('who', $uid)->whereNotIn('id', $vip_consume_invitees)->limit(5)->get(FieldUtils::userInfoColums());
  3586. if($invitees){
  3587. }else{
  3588. $invitees = [];
  3589. }
  3590. if(_empty_($invitees) || count($invitees) < 5){
  3591. return $this->fail(200042, [], '你的邀请人数只有'.count($invitees).'个,凑够5个才能兑换会员,再接再厉');
  3592. }
  3593. // 满足条件
  3594. DB::beginTransaction();
  3595. try{
  3596. foreach ($invitees as $invitee){
  3597. $vip_consume_invitees[] = $invitee->id;
  3598. }
  3599. update_user_meta($uid, 'vip_consume_invitees', $vip_consume_invitees, 'j');
  3600. WxUserRepositores::vip($uid, $days);
  3601. DB::commit();
  3602. return $this->success(['days'=>$days]);
  3603. }catch (\Exception $e){
  3604. DB::rollBack();
  3605. _logger_(__file__, __line__, $e->getMessage());
  3606. return $this->fail(200006);
  3607. }
  3608. }
  3609. /**
  3610. * 我的收益记录
  3611. */
  3612. public function myUserExceptional(Request $request)
  3613. {
  3614. $uid = $request->uid;
  3615. $setUserid = $request->setUserid;
  3616. if(!_empty_($setUserid)) {
  3617. if ($setUserid && $setUserid > 0) {
  3618. if (UserUtils::is_mini_supder_admin($uid)) {
  3619. $uid = $setUserid;
  3620. } else {
  3621. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3622. }
  3623. }
  3624. }
  3625. $data = WxExceptional::where('posts_user_id', $uid)
  3626. ->orderBy('id', 'desc')
  3627. ->get();
  3628. $data->map(function ($v) {
  3629. $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
  3630. $v->datetime = format_datetime($v->created_at);
  3631. });
  3632. return $this->success($data);
  3633. }
  3634. public function myVisit(Request $request){
  3635. $uid = $request->uid;
  3636. $page = 1; // 从请求获取或设定默认值
  3637. $perPage = 15; // 每页显示的数量
  3638. $visits = WxUserVisit::where('type', 1)->where('user_id', $uid)
  3639. ->join('wx_posts', 'wx_user_visit.object_id', '=', 'wx_posts.id')
  3640. ->select('wx_user_visit.object_id',
  3641. DB::raw('DATE(wx_user_visit.created_at) as visit_date'),
  3642. DB::raw('SUM(wx_user_visit.times) as total_times'),
  3643. )
  3644. ->groupBy('visit_date', 'wx_user_visit.object_id')
  3645. ->orderBy('visit_date', 'desc')
  3646. ->paginate($perPage, ['*'], 'page', $page);
  3647. return $this->success($visits);
  3648. }
  3649. /**
  3650. * 我的余额记录
  3651. */
  3652. public function myUserFinancialRecord(Request $request)
  3653. {
  3654. $uid = $request->uid;
  3655. $setUserid = $request->setUserid;
  3656. if(!_empty_($setUserid)) {
  3657. if ($setUserid && $setUserid > 0) {
  3658. if (UserUtils::is_mini_supder_admin($uid)) {
  3659. $uid = $setUserid;
  3660. } else {
  3661. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3662. }
  3663. }
  3664. }
  3665. $data = WxUserFinancialRecord::where('user_id', $uid)
  3666. ->orderBy('id', 'desc')->limit(20)
  3667. ->get();
  3668. $data->map(function ($record){
  3669. $record->type_name = FieldUtils::getUserFinancialType()[(int)$record->type];
  3670. $record->date = $record->created_at->toDateTimeString();
  3671. $record->num_str = $record->num > 0 ? '+'.$record->num : $record->num;
  3672. return $record;
  3673. });
  3674. return $this->success($data);
  3675. }
  3676. /**
  3677. * 我的金币记录
  3678. */
  3679. public function myUserCoinsRecord(Request $request)
  3680. {
  3681. $uid = $request->uid;
  3682. $setUserid = $request->setUserid;
  3683. if(!_empty_($setUserid)) {
  3684. if ($setUserid && $setUserid > 0) {
  3685. if (UserUtils::is_mini_supder_admin($uid)) {
  3686. $uid = $setUserid;
  3687. } else {
  3688. return $this->fail(200000, [], '你不是超级管理员,无法查看');
  3689. }
  3690. }
  3691. }
  3692. $data = WxUserCoinRecord::where('user_id', $uid)
  3693. ->orderBy('id', 'desc')->limit(20)
  3694. ->get();
  3695. $data->map(function ($record){
  3696. $record->date = $record->created_at->toDateTimeString();
  3697. $record->num_str = $record->incre > 0 ? '+'.$record->incre : $record->incre;
  3698. return $record;
  3699. });
  3700. return $this->success($data);
  3701. }
  3702. /*
  3703. * 用户海报数据
  3704. */
  3705. public function poster(Request $request){
  3706. $userId = $request->id;
  3707. $uid = $request->uid;
  3708. if(_empty_($userId)){
  3709. return $this->fail(200001);
  3710. }
  3711. $user = WxUser::find($userId);
  3712. if(_empty_($user)){
  3713. return $this->fail(200003);
  3714. }
  3715. global $__MINI_GLOBAL_TENANT_ID__;
  3716. $mini_code = Utils::getMiniCode('/pages/user/user', 'id='.$user->id, $uid, 430, false, null, true);
  3717. if($mini_code){
  3718. $data = [
  3719. 'userdata' => [
  3720. 'avatar' => $user->user_avatar,
  3721. 'name' => $user->user_name
  3722. ],
  3723. 'swiperList' => Settings::get('app_share_poster', [], true),
  3724. 'code' => $mini_code,
  3725. 'web' => rtrim(Settings::get('app_h5_home', ''), '/') . '/#/pages/user/user?id=' . $userId . '&fph=1&from_user=' . $uid .'&tenant=' . $__MINI_GLOBAL_TENANT_ID__
  3726. ];
  3727. if(_empty_($data['swiperList'])){
  3728. return $this->fail(200008);
  3729. }
  3730. return $this->success($data);
  3731. }else{
  3732. return $this->fail(300001);
  3733. }
  3734. }
  3735. public function earningsRank(Request $request){
  3736. $userId = $request->uid;
  3737. $user = WxUser::find($userId);
  3738. if(_empty_($user)){
  3739. return $this->fail(200003);
  3740. }
  3741. $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']);
  3742. if(_empty_($r)){
  3743. return $this->fail(200003);
  3744. }
  3745. $data = [
  3746. 'one' => [],
  3747. 'two' => [],
  3748. 'three' => [],
  3749. 'others' => [
  3750. ],
  3751. 'avg' => round(WxUserFinancial::avg('sum_price'), 2),
  3752. 'bg' => Settings::get('app_earnings_rank_bg', 'https://img.mini.minisns.cn/images/rank/rank_bg.png'),
  3753. 'total' => WxUserFinancial::count()
  3754. ];
  3755. $defaut = [
  3756. 'id' => 0,
  3757. 'user_avatar' => Settings::get('img_default_avatar', 'https://img.mini.minisns.cn/images/avatar.png'),
  3758. 'user_name' => '未知',
  3759. 'sum_price' => 0,
  3760. 'withdrawal_price' => 0,
  3761. 'is_member' => 0,
  3762. 'is_official' => 0,
  3763. 'is_authentication' => 0,
  3764. 'gender' => 0
  3765. ];
  3766. for ($i = 0; $i < 10; $i ++){
  3767. if ($i == 0){
  3768. if(isset($r[$i])){
  3769. $data['one'] = $r[$i];
  3770. }else{
  3771. $data['one'] = $defaut;
  3772. }
  3773. }else if($i == 1){
  3774. if(isset($r[$i])){
  3775. $data['two'] = $r[$i];
  3776. }else{
  3777. $data['two'] = $defaut;
  3778. }
  3779. }else if($i == 2){
  3780. if(isset($r[$i])){
  3781. $data['three'] = $r[$i];
  3782. }else{
  3783. $data['three'] = $defaut;
  3784. }
  3785. }else{
  3786. if(isset($r[$i])){
  3787. $data['others'][] = $r[$i];
  3788. }else{
  3789. $data['others'][] = $defaut;
  3790. }
  3791. }
  3792. }
  3793. return $this->success($data);
  3794. }
  3795. public function vote(Request $request){
  3796. $position = $request->position;
  3797. $uid = $request->uid;
  3798. $vote_id = $request->vote_id;
  3799. if(_empty_($vote_id) || _empty_($position) || !is_numeric($position)){
  3800. return $this->fail(200001);
  3801. }
  3802. if($position > 20 || $position < 1){
  3803. return $this->fail(200004);
  3804. }
  3805. if(WxUserVote::where([
  3806. ['user_id', '=', $uid],
  3807. ['vote_id', '=', $vote_id]
  3808. ])->exists()){
  3809. return $this->fail(200010, [], '你已经为这个内容投过票啦');
  3810. }
  3811. $WxUserVote = new WxUserVote();
  3812. $WxUserVote->user_id = $uid;
  3813. $WxUserVote->vote_id = $vote_id;
  3814. $WxUserVote->vote_option = $position;
  3815. $r = $WxUserVote->save();
  3816. if($r){
  3817. WxPostsVote::where('id', $vote_id)->increment('num'.$position);
  3818. return $this->success(PostUtils::getVoteData($vote_id, $uid));
  3819. }
  3820. return $this->fail(200002);
  3821. }
  3822. /**
  3823. * 拉黑或取消拉黑某个用户
  3824. * @param Request $request
  3825. * @return \Illuminate\Http\JsonResponse
  3826. */
  3827. public function black(Request $request){
  3828. $uid = $request->uid;
  3829. $object_id = $request->object_id;
  3830. $action = $request->action;
  3831. if(_empty_($object_id)){
  3832. return $this->fail(200001);
  3833. }
  3834. if($action == 'black'){
  3835. $user_set = get_user_meta($uid, 'user:blacked:set', 'j');
  3836. if(!in_array($object_id, $user_set)){
  3837. $user_set[] = $object_id;
  3838. update_user_meta($uid, 'user:blacked:set', array_unique($user_set), 'j');
  3839. return $this->success([], 200, '拉黑成功');
  3840. }else{
  3841. // 要删除的特定值
  3842. $user_set = array_filter($user_set, function ($value) use ($object_id) {
  3843. return $value != $object_id;
  3844. });
  3845. update_user_meta($uid, 'user:blacked:set', array_unique($user_set), 'j');
  3846. return $this->success([], 200, '取消拉黑');
  3847. }
  3848. }else{
  3849. $user_set = get_user_meta($uid, 'feedback:notlike:user:set', 'j');
  3850. if(!in_array($object_id, $user_set)){
  3851. $user_set[] = $object_id;
  3852. update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
  3853. return $this->success();
  3854. }else{
  3855. // 要删除的特定值
  3856. $user_set = array_filter($user_set, function ($value) use ($object_id) {
  3857. return $value != $object_id;
  3858. });
  3859. update_user_meta($uid, 'feedback:notlike:user:set', array_unique($user_set), 'j');
  3860. return $this->success();
  3861. }
  3862. }
  3863. }
  3864. /**
  3865. * 用户反馈
  3866. * [0=>'post', 1=> 'comment', 2 => 'user', 3=> 'goods']
  3867. * @param Request $request
  3868. * @return \Illuminate\Http\JsonResponse
  3869. */
  3870. public function report(Request $request)
  3871. {
  3872. $uid = $request->uid;
  3873. _limit_user('add:report', $uid, 20);
  3874. $report_type = $request->report_type;
  3875. $report_content = $request->report_content;
  3876. $image_urls = $request->image_urls;
  3877. $type = $request->type;
  3878. $object_id = $request->object_id;
  3879. if(!isset($type) || !isset($object_id)){
  3880. return $this->fail(200001);
  3881. }
  3882. if(!in_array($type, [0,1,2,3,4,5,6])){
  3883. return $this->fail(200004);
  3884. }
  3885. $count = WxUserReport::where([
  3886. ['type', '=', $type],
  3887. ['object_id', '=', $object_id],
  3888. ['user_id', '=', $uid]
  3889. ])->count();
  3890. if($count > 0){
  3891. return $this->fail(200010, [], '你已经举报过了ta,再管理员反馈之前,请勿重复举报');
  3892. }
  3893. $image_urls__ = [];
  3894. if($image_urls){
  3895. foreach ($image_urls as $img_item){
  3896. $image_urls__[] = $img_item['url'];
  3897. }
  3898. }
  3899. $contact = $request->contact;
  3900. if(_empty_($report_content)){
  3901. $this->fail(200001);
  3902. }
  3903. $r = WxUserReportRepositories::add($uid,$type, $object_id, $report_type, $report_content, $image_urls__, $contact);
  3904. if($r){
  3905. $count_ = WxUserReport::where([
  3906. ['type', '=', $type],
  3907. ['object_id', '=', $object_id],
  3908. ])->count();
  3909. if($type == 0){
  3910. $app_report_safe_times_post = Settings::get('app_report_safe_times_post', 0);
  3911. if($app_report_safe_times_post == 0){
  3912. $app_report_safe_times_post = 999;
  3913. }
  3914. if(UserUtils::is_mini_admin($uid)){
  3915. if($report_type == 10){
  3916. WxPost::where('id', $object_id)->update(['is_blur'=>1]);
  3917. }else{
  3918. WxPost::where('id', $object_id)->update(['posts_state'=>2]);
  3919. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动下架。');
  3920. }
  3921. }else if($count_ > $app_report_safe_times_post){
  3922. if($report_type == 10){
  3923. WxPost::where('id', $object_id)->update(['is_blur'=>1]);
  3924. }else{
  3925. WxPost::where('id', $object_id)->update(['posts_state'=>2]);
  3926. UserUtils::assistant_notice('admin', '多名用户对该贴(<a href="/pages/sticky/sticky?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动下架。');
  3927. }
  3928. }else{
  3929. 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>)进行举报。');
  3930. }
  3931. }else if($type == 1){
  3932. $app_report_safe_times_comment = Settings::get('app_report_safe_times_comment', 0);
  3933. if($app_report_safe_times_comment == 0){
  3934. $app_report_safe_times_comment = 999;
  3935. }
  3936. $posts_id = WxComment::where('id', $object_id)->value('posts_id');
  3937. if(UserUtils::is_mini_admin($uid)){
  3938. WxComment::where('id', $object_id)->update(['comment_state'=>2]);
  3939. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动下架。');
  3940. }else if($count_ > $app_report_safe_times_comment){
  3941. WxComment::where('id', $object_id)->update(['comment_state'=>2]);
  3942. UserUtils::assistant_notice('admin', '多名用户对评论(<a href="/pages/sticky/sticky?id='.$posts_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动下架。');
  3943. }else{
  3944. 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>)进行举报。');
  3945. }
  3946. }else if($type == 2){
  3947. $app_report_safe_times_user = Settings::get('app_report_safe_times_user', 0);
  3948. if($app_report_safe_times_user == 0){
  3949. $app_report_safe_times_user = 999;
  3950. }
  3951. $the_user = WxUser::find($object_id);
  3952. if(UserUtils::is_mini_admin($uid)){
  3953. UserUtils::lock_user_incre($the_user, 3, 3600 * 24 * 7, '该用户被管理员举报');
  3954. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统禁言7天。');
  3955. }else if($count_ > $app_report_safe_times_user){
  3956. UserUtils::lock_user_incre($the_user, 3, 3600 * 24 * 7, '该用户被人多次举报');
  3957. UserUtils::assistant_notice('admin', '多名用户对该用户(<a href="/pages/user/user?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统禁言7天。');
  3958. }else{
  3959. 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>)进行举报。');
  3960. }
  3961. }else if($type == 3){
  3962. // 举报商品
  3963. }else if($type == 4){
  3964. // 举报圈子
  3965. $app_report_safe_times_circle = Settings::get('app_report_safe_times_circle', 0);
  3966. if($app_report_safe_times_circle == 0){
  3967. $app_report_safe_times_circle = 999;
  3968. }
  3969. if(UserUtils::is_mini_admin($uid)){
  3970. WxCircle::where('id', $object_id)->update(['circle_state'=>2]);
  3971. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动驳回。');
  3972. }else if($count_ > $app_report_safe_times_circle){
  3973. WxUser::where('id', $object_id)->update(['circle_state'=>2]);
  3974. UserUtils::assistant_notice('admin', '多名用户对该圈子(<a href="/pages/circle/list?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动驳回。');
  3975. }else{
  3976. 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>)进行举报。');
  3977. }
  3978. }else if($type == 6){
  3979. // 举报圈子
  3980. $app_report_safe_times_voter = Settings::get('app_report_safe_times_voter', 0);
  3981. if($app_report_safe_times_voter == 0){
  3982. $app_report_safe_times_voter = 999;
  3983. }
  3984. if(UserUtils::is_mini_admin($uid)){
  3985. WxVoter::where('id', $object_id)->update(['status'=>2]);
  3986. UserUtils::assistant_notice('admin', '管理员id:'.$uid.'对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,已被系统自动驳回。');
  3987. }else if($count_ > $app_report_safe_times_voter){
  3988. WxVoter::where('id', $object_id)->update(['status'=>2]);
  3989. UserUtils::assistant_notice('admin', '多名用户对该选票(<a href="/pagesV/voter/detail/detail?id='.$object_id.'" target="_blank">id: '.$object_id.'</a>)进行举报,并且超过最大次数,已被系统自动驳回。');
  3990. }else{
  3991. 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>)进行举报。');
  3992. }
  3993. }
  3994. UserInputSafeCheckJob::dispatch($uid, $report_content);
  3995. Utils::image_state_change($image_urls__, 1);
  3996. return $this->success($r);
  3997. }else{
  3998. return $this->fail(200002);
  3999. }
  4000. }
  4001. }