UserController.php 183 KB

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