UserController.php 183 KB

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