UserController.php 184 KB

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