Usercenter.php 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\model\wallet;
  6. use Redis;
  7. /**
  8. * 会员中心,不是个人中心
  9. */
  10. class Usercenter extends Api
  11. {
  12. protected $noNeedLogin = ['test','testredis'];
  13. protected $noNeedRight = '*';
  14. protected $allowFields = [
  15. 'id',
  16. 'username',
  17. 'nickname',
  18. //'truename',//
  19. 'email',
  20. 'mobile',
  21. 'avatar',
  22. 'real_status',
  23. 'gender',
  24. 'height',
  25. 'weight',
  26. 'birthday',
  27. 'bio',
  28. 'audio_bio',
  29. //'alipay_account',//
  30. 'idcard_status',
  31. 'is_active',
  32. 'longitude',
  33. 'latitude',
  34. 'cityname',
  35. 'photo_images',
  36. 'education_id',
  37. 'hobby_ids',
  38. 'job_id',
  39. 'marital_id',
  40. 'tag_ids',
  41. 'wages_id',
  42. 'hometown_cityid',
  43. 'wechat_account',
  44. 'secretvideo_status',
  45. 'character_id',
  46. 'constellation_id',
  47. 'stature_id',
  48. 'is_appointment',
  49. 'chat_price',
  50. 'voice_price',
  51. 'video_price',
  52. 'greet_voice',
  53. 'greet_chat',
  54. 'is_kefu',
  55. 'is_hideaddress', 'is_recommend','is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'
  56. ];
  57. public function testredis(){
  58. //redis_matching_set(1,125);
  59. dump(redis_matching_get(1));
  60. $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
  61. dump($a);
  62. }
  63. public function test(){
  64. $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
  65. $b = [1,10,7,102];
  66. $c = [10,102];
  67. //dump(array_intersect($a,$b));
  68. $data = array_merge($c,$b);
  69. dump($data);
  70. dump(array_flip(array_flip($data)));
  71. dump(array_flip([]));
  72. }
  73. //获取他人用户信息,留下足迹
  74. public function getuserinfo(){
  75. $uid = input_post('uid',0);
  76. $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
  77. if(!$userinfo){
  78. $this->error('不存在的用户');
  79. }
  80. //用户数据
  81. $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
  82. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find();
  83. $secretvideo = Db::name('user_secretvideo')->where('user_id',$uid)->find();
  84. $new_data = [
  85. 'age' => birthtime_to_age($userinfo['birthday']),
  86. 'truename' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '',
  87. 'alipay_account' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
  88. // 'secretvideo' => ($userinfo['secretvideo_status'] == 1 && isset($secretvideo['secretvideo'])) ? $secretvideo['secretvideo'] : '',
  89. ];
  90. //亲密度,登录用户给当前用户花了多少钱
  91. /* $gift_map = [
  92. 'user_id' => $this->auth->id,
  93. 'user_to_id' => $uid,
  94. ];
  95. $gift_user_typing = Db::name('gift_user_typing')->where($gift_map)->sum('price');//文字聊天送礼物
  96. $gift_user_party = Db::name('gift_user_party')->where($gift_map)->sum('value');//派对音聊送礼物
  97. $gift_user_livebc = Db::name('gift_user_livebc')->where($gift_map)->sum('price');//直播送礼物
  98. $match_map_str = '(user_id = '.$this->auth->id.' and to_user_id = '.$uid.') or (user_id = '.$uid.' and to_user_id = '.$this->auth->id.')';
  99. $match_typing = Db::name('user_match_typing_log')->where($match_map_str)->sum('price'); //聊天
  100. $match_audio = Db::name('user_match_audio_log')->where($match_map_str)->sum('price'); //语音
  101. $match_video = Db::name('user_match_video_log')->where($match_map_str)->sum('price'); //视频
  102. $new_data['qinmi_sum'] = $qinmi_sum = $gift_user_typing + $gift_user_party + $gift_user_livebc + $match_typing + $match_audio + $match_video;*/
  103. if ($this->auth->gender == 1) {
  104. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $this->auth->id, 'other_uid' => $uid])->value('value');
  105. } elseif ($this->auth->gender == 0) {
  106. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $this->auth->id])->value('value');
  107. } else {
  108. $qinmi_sum = 0;
  109. }
  110. $new_data['qinmi_sum'] = $qinmi_sum ? :0;
  111. //解锁开关
  112. /*$new_data['isshow_unlock_wechataccount'] = $qinmi_sum >= 15 ? 1 : 0; //满足15亲密值才展示
  113. if(config('site.open_unlock_wechataccount') == 0){
  114. $new_data['isshow_unlock_wechataccount'] = 0; //总开关,强制隐藏
  115. }
  116. $new_data['isshow_unlock_secretvideo'] = $qinmi_sum >= 15 ? 1 : 0; //满足15亲密值才展示
  117. $new_data['isshow_unlock_secretvideo'] = 1; //又不受限制了
  118. //上次解锁过期日期
  119. $check_map = [
  120. 'user_id' => $this->auth->id,
  121. 'to_user_id' => $uid,
  122. ];
  123. $order_secretvideo = Db::name('order_secretvideo')->where($check_map)->order('id desc')->value('endtime');
  124. $order_wechataccount = Db::name('order_wechataccount')->where($check_map)->order('id desc')->value('endtime');
  125. $new_data['unlock_secretvideo_endtime'] = !empty($order_secretvideo) ? $order_secretvideo : 0;
  126. $new_data['unlock_secretvideo_status'] = $new_data['unlock_secretvideo_endtime'] > time() ? 1 : 0;
  127. $new_data['unlock_wechataccount_endtime'] = !empty($order_wechataccount) ? $order_wechataccount : 0;
  128. $new_data['unlock_wechataccount_status'] = $new_data['unlock_wechataccount_endtime'] > time() ? 1 : 0;*/
  129. //提示语而已
  130. /* $new_data['unlock_secretvideo_notice'] = '是否花费'.config('site.unlock_secretvideo').'金币解锁一周(或年费vip可每日免费解锁一次)?';
  131. $new_data['unlock_wechataccount_notice'] = '是否花费'.config('site.unlock_wechataccount').'金币解锁一周(或年费vip可每日免费解锁一次)?';*/
  132. //合并
  133. $userinfo = array_merge($userinfo,$new_data);
  134. //枚举
  135. $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
  136. $userinfo['education'] = $userinfo['education'] ? : '';
  137. $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
  138. $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
  139. $userinfo['job'] = $userinfo['job'] ? : '';
  140. $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
  141. $userinfo['marital'] = $userinfo['marital'] ? : '';
  142. $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
  143. $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
  144. $userinfo['wages'] = $userinfo['wages'] ? : '';
  145. $userinfo['character'] = Db::name('enum_character')->where('id',$userinfo['character_id'])->value('name');
  146. $userinfo['character'] = $userinfo['character'] ? : '';
  147. $userinfo['constellation'] = Db::name('enum_constellation')->where('id',$userinfo['constellation_id'])->value('name');
  148. $userinfo['constellation'] = $userinfo['constellation'] ? : '';
  149. $userinfo['stature'] = Db::name('enum_stature')->where('id',$userinfo['stature_id'])->value('name');
  150. $userinfo['stature'] = $userinfo['stature'] ? : '';
  151. $userinfo['live'] = Db::name('enum_live')->where('id',$userinfo['live_id'])->value('name');
  152. $userinfo['live'] = $userinfo['live'] ? : '';
  153. $userinfo['car'] = Db::name('enum_car')->where('id',$userinfo['car_id'])->value('name');
  154. $userinfo['car'] = $userinfo['car'] ? : '';
  155. $userinfo['chest'] = Db::name('enum_chest')->where('id',$userinfo['chest_id'])->value('name');
  156. $userinfo['chest'] = $userinfo['chest'] ? : '';
  157. //家乡
  158. $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
  159. $userinfo['hometown_city'] = ($userinfo['hometown_city'] && $userinfo['is_hideaddress'] == 0) ? $userinfo['hometown_city'] : '';
  160. //vip
  161. $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
  162. $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
  163. //是否喜欢和关注
  164. $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
  165. $userinfo['is_follow'] = $is_follow ? 1 : 0;
  166. $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
  167. $userinfo['is_like'] = $is_like ? 1 : 0;
  168. //是否拉黑
  169. $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
  170. $userinfo['is_black'] = $is_black ? 1 : 0;
  171. //关注人数,粉丝人数
  172. $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
  173. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
  174. $userinfo['follow_num'] = $follow_num;
  175. $userinfo['fans_num'] = $fans_num;
  176. //查询是否打过招呼
  177. $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  178. if ($count) {
  179. $userinfo['is_chat'] = 1; //是否打过招呼: 1是 0否
  180. } else {
  181. $userinfo['is_chat'] = 0; //是否打过招呼: 1是 0否
  182. }
  183. //守护数量和是否已经守护
  184. $userinfo['guard_num'] = Db::name('user_guard')->where(['user_to_id' => $uid])->count('id');
  185. $userinfo['is_guard'] = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  186. //查询财富等级和魅力等级
  187. $wallet_info = Db::name('user_wallet')->where(['user_id' => $uid])->find();
  188. $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  189. if ($wealth_level) {
  190. $userinfo['wealth_level'] = $wealth_level['name'];
  191. } else {
  192. $userinfo['wealth_level'] = '';
  193. }
  194. $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  195. if ($charm_level) {
  196. $userinfo['charm_level'] = $charm_level['name'];
  197. } else {
  198. $userinfo['charm_level'] = '';
  199. }
  200. //开通守护消耗金币数量
  201. $userinfo['guard_price'] = config('site.guard_price') ? : 0;
  202. //男性非会员是否已开通聊天
  203. // $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  204. // $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  205. // if ($this->auth->gender == 0 || $vip_endtime > time() || $user_chat_unlock) {
  206. $userinfo['is_chat_unlock'] = 1; //已解锁
  207. // } else {
  208. // $userinfo['is_chat_unlock'] = 0;
  209. // }
  210. //男性非会员解锁聊天所需金币数量
  211. $userinfo['unlock_chat_gold'] = config('site.unlock_chat_gold') > 0 ? config('site.unlock_chat_gold') : 10;
  212. //动态信息
  213. $dongtai = Db::name('topic_dongtai')->field('type, images')->where(['user_id' => $uid, 'is_hidden' => 0, 'type' => ['in', [1, 2]], 'status' => 0, 'auit_status' => 1])->order('id desc')->limit(3)->select();
  214. if ($dongtai) {
  215. $dongtai_image = [];
  216. foreach ($dongtai as &$v) {
  217. $arr['type'] = $v['type'];
  218. if ($v['type'] == 1) {
  219. //图片
  220. $images_url = explode(',', $v['images']);
  221. foreach ($images_url as &$value) {
  222. $arr['images'] = one_domain_image($value);
  223. array_push($dongtai_image, $arr);
  224. if (count($dongtai_image) == 3) {
  225. break 2;
  226. }
  227. }
  228. } else {
  229. //视频
  230. $images_url = explode('.', $v['images']);
  231. unset($images_url[count($images_url) - 1]);
  232. $arr['images'] = join('.', $images_url) . '_0.jpg';
  233. $arr['images'] = one_domain_image($arr['images']);
  234. array_push($dongtai_image, $arr);
  235. if (count($dongtai_image) == 3) {
  236. break;
  237. }
  238. }
  239. }
  240. $userinfo['dongtai_image'] = $dongtai_image;
  241. // $dongtai = join(',', $dongtai);
  242. // $dongtai = explode(',', $dongtai);
  243. // $dongtai = array_slice($dongtai, 0, 3);
  244. // $dongtai = join(',', $dongtai);
  245. // $userinfo['dongtai_image'] = one_domain_image($dongtai);
  246. // $userinfo['dongtai_image'] = explode(',', $userinfo['dongtai_image']);
  247. } else {
  248. $userinfo['dongtai_image'] = [];
  249. }
  250. if ($this->auth->id != $uid) {
  251. //查看别人信息,就要留下痕迹
  252. $data = [
  253. 'uid' => $this->auth->id,
  254. 'to_uid' => $uid,
  255. ];
  256. $check = Db::name('user_visit')->where($data)->find();
  257. if ($check) {
  258. Db::name('user_visit')->where($data)->update(['number' => $check['number'] + 1, 'updatetime' => time()]);
  259. } else {
  260. $data['number'] = 1;
  261. $data['updatetime'] = time();
  262. Db::name('user_visit')->insertGetId($data);
  263. }
  264. }
  265. $this->success('success',$userinfo);
  266. }
  267. //这里不用连user_active表,完全使用user表的active_time,user_active表只做离线用
  268. //同城
  269. public function samecity(){
  270. $gender = input_post('gender','all');
  271. $agemin = input_post('agemin',0);
  272. $agemax = input_post('agemax',100);
  273. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  274. // $this->success('success',[]);
  275. }
  276. $map = [
  277. 'user.status' => 1,
  278. // 'user.cityname' => $this->auth->cityname,
  279. 'user.id' => ['neq',$this->auth->id],
  280. // 'user.longitude' => ['neq',''],
  281. // 'user.latitude' => ['neq',''],
  282. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  283. 'user.active_time' => ['gt',time()-86400],
  284. ];
  285. if($gender != 'all'){
  286. $map['user.gender'] = $gender;
  287. }
  288. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  289. //dump($map);
  290. $field = [
  291. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
  292. ];
  293. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
  294. //dump($list);
  295. $list = list_domain_image($list,['avatar']);
  296. foreach($list as $key => $one){
  297. $one['age'] = birthtime_to_age($one['birthday']);
  298. // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  299. $one['distance'] = rand(0,10).'km';
  300. //状态
  301. $one['active_text'] = '刚刚离线';
  302. if($one['active_time'] > time()-21600){
  303. $one['active_text'] = '1小时内在线';
  304. }
  305. if($one['active_time'] > time()-3600){
  306. $one['active_text'] = '在线';
  307. }
  308. $list[$key] = $one;
  309. }
  310. $this->success('success',$list);
  311. }
  312. //附近
  313. public function nearuser(){
  314. $gender = input_post('gender','all');
  315. $agemin = input_post('agemin',0);
  316. $agemax = input_post('agemax',100);
  317. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  318. // $this->success('success',[]);
  319. }
  320. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  321. $map = [
  322. 'user.status' => 1,
  323. ////'user.cityname' => $this->auth->cityname,
  324. 'user.id' => ['neq',$this->auth->id],
  325. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  326. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  327. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  328. 'user.active_time' => ['gt',time()-86400],
  329. ];
  330. if($gender != 'all'){
  331. $map['user.gender'] = $gender;
  332. }
  333. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  334. //dump($map);
  335. $field = [
  336. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
  337. ];
  338. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
  339. //dump($list);exit;
  340. $list = list_domain_image($list,['avatar']);
  341. foreach($list as $key => $one){
  342. $one['age'] = birthtime_to_age($one['birthday']);
  343. //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  344. $one['distance'] = rand(0,10).'km';
  345. //状态
  346. $one['active_text'] = '刚刚离线';
  347. if($one['active_time'] > time()-21600){
  348. $one['active_text'] = '1小时内在线';
  349. }
  350. if($one['active_time'] > time()-3600){
  351. $one['active_text'] = '在线';
  352. }
  353. $list[$key] = $one;
  354. }
  355. $this->success('success',$list);
  356. }
  357. //因为接受者拿不到发起者的uid,废弃了
  358. //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
  359. public function video_audio_moneycheck(){
  360. //检测用户,发起方的uid
  361. $to_user_id = input_post('from_user_id');
  362. $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
  363. if(!$to_user_info){
  364. $this->error('不存在的用户');
  365. }
  366. //扣费金币
  367. $type = input_post('type','video'); //类型
  368. $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
  369. //发起用户的分数,被发起用户的分数。按性别给分
  370. $auth_level = 0;
  371. $tous_level = 0;
  372. //打分
  373. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  374. $auth_level = 30;//实名女最高
  375. }
  376. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  377. $auth_level = 20;//未实名女次之
  378. }
  379. if($this->auth->gender == 1){
  380. $auth_level = 10;//男性最低
  381. }
  382. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  383. $tous_level = 30;
  384. }
  385. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  386. $tous_level = 20;
  387. }
  388. if($to_user_info['gender'] == 1){
  389. $tous_level = 10;
  390. }
  391. //同性不收钱
  392. //都是男的,不扣钱
  393. //都是实名认证的女性,不扣钱
  394. //都是未实名认证的女性,不扣钱
  395. if($auth_level == $tous_level){
  396. $price = 0;
  397. $this->success('success');
  398. }
  399. //扣钱uid,收钱uid,收钱free_video
  400. //分数少扣钱,分数多收益
  401. if($auth_level < $tous_level){
  402. $kou_user = $this->auth->id;
  403. }else{
  404. $kou_user = $to_user_info['id'];
  405. }
  406. //需要扣我的(接收方的)钱,判断钱是否够
  407. if($price > 0 && $kou_user == $this->auth->id){
  408. Db::startTrans();
  409. $gold = model('wallet')->getWallet($kou_user,'gold');
  410. if(bccomp($price,$gold) == 1){
  411. Db::rollback();
  412. $this->error('金币不足');
  413. }
  414. Db::commit();
  415. }
  416. $this->success('success');
  417. }
  418. //视频通话每分钟调用一次
  419. public function video_onemin(){
  420. //检测用户
  421. $to_user_id = input_post('to_user_id');
  422. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  423. if(!$to_user_info){
  424. $this->error('不存在的用户');
  425. }
  426. //正常价格
  427. $price = config('site.video_min_price'); //扣费金币
  428. $bili = config('site.money_to_gold'); //兑换比例
  429. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  430. $money = bcdiv($price,$bili,2); //对应人民币
  431. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  432. //发起用户的分数,被发起用户的分数。按性别给分
  433. $auth_level = 0;
  434. $tous_level = 0;
  435. //打分
  436. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  437. $auth_level = 30;//实名女最高
  438. }
  439. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  440. $auth_level = 20;//未实名女次之
  441. }
  442. if($this->auth->gender == 1){
  443. $auth_level = 10;//男性最低
  444. }
  445. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  446. $tous_level = 30;
  447. }
  448. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  449. $tous_level = 20;
  450. }
  451. if($to_user_info['gender'] == 1){
  452. $tous_level = 10;
  453. }
  454. //同性不收钱
  455. //都是男的,不扣钱
  456. //都是实名认证的女性,不扣钱
  457. //都是未实名认证的女性,不扣钱
  458. if($auth_level == $tous_level){
  459. $price = 0;$money = 0;
  460. }
  461. Db::startTrans();
  462. //记录日志
  463. $data = [
  464. 'user_id' => $this->auth->id,
  465. 'price' => $price,
  466. 'createtime' => time(),
  467. 'to_user_id' => $to_user_id,
  468. 'money' => $money,
  469. ];
  470. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  471. if(!$log_id){
  472. Db::rollback();
  473. $this->error('扣费失败');
  474. }
  475. //同性别,提前结束
  476. if($auth_level == $tous_level){
  477. Db::commit();
  478. $this->success('success');
  479. }
  480. //扣钱uid,收钱uid,收钱free_video
  481. //分数少扣钱,分数多收益
  482. if($auth_level < $tous_level){
  483. $kou_user = $this->auth->id;
  484. $get_user = $to_user_info['id'];
  485. $get_user_free = $to_user_info['free_video'];
  486. }else{
  487. $kou_user = $to_user_info['id'];
  488. $get_user = $this->auth->id;
  489. $get_user_free = $this->auth->free_video;
  490. }
  491. //需要扣别人的钱,判断钱是否购
  492. if($price > 0 && $kou_user != $this->auth->id){
  493. $gold = model('wallet')->getWallet($kou_user,'gold');
  494. if(bccomp($price,$gold) == 1){
  495. Db::rollback();
  496. $this->error('对方金币不足');
  497. }
  498. }
  499. //有性别差,扣费
  500. if($price > 0){
  501. $rs = model('wallet')->lockChangeAccountRemain($kou_user, $get_user,'gold',-$price,11,'','user_match_video_log',$log_id);
  502. if($rs['status'] === false){
  503. Db::rollback();
  504. $this->error($rs['msg']);
  505. }
  506. }
  507. //另一方加钱,0收费
  508. if($money > 0 && $get_user_free == 0){
  509. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,21,'','user_match_video_log',$log_id);
  510. if($rs['status'] === false){
  511. Db::rollback();
  512. $this->error($rs['msg']);
  513. }
  514. }
  515. Db::commit();
  516. $this->success('success');
  517. }
  518. //语音通话每分钟调用一次
  519. public function audio_onemin(){
  520. //检测用户
  521. $to_user_id = input_post('to_user_id');
  522. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  523. if(!$to_user_info){
  524. $this->error('不存在的用户');
  525. }
  526. //正常价格
  527. $price = config('site.audio_min_price'); //扣费金币
  528. $bili = config('site.money_to_gold'); //兑换比例
  529. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  530. $money = bcdiv($price,$bili,2); //对应人民币
  531. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  532. //发起用户的分数,被发起用户的分数。按性别给分
  533. $auth_level = 0;
  534. $tous_level = 0;
  535. //打分
  536. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  537. $auth_level = 30;//实名女最高
  538. }
  539. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  540. $auth_level = 20;//未实名女次之
  541. }
  542. if($this->auth->gender == 1){
  543. $auth_level = 10;//男性最低
  544. }
  545. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  546. $tous_level = 30;
  547. }
  548. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  549. $tous_level = 20;
  550. }
  551. if($to_user_info['gender'] == 1){
  552. $tous_level = 10;
  553. }
  554. //同性不收钱
  555. //都是男的,不扣钱
  556. //都是实名认证的女性,不扣钱
  557. //都是未实名认证的女性,不扣钱
  558. if($auth_level == $tous_level){
  559. $price = 0;$money = 0;
  560. }
  561. Db::startTrans();
  562. //记录日志
  563. $data = [
  564. 'user_id' => $this->auth->id,
  565. 'price' => $price,
  566. 'createtime' => time(),
  567. 'to_user_id' => $to_user_id,
  568. 'money' => $money,
  569. ];
  570. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  571. if(!$log_id){
  572. Db::rollback();
  573. $this->error('扣费失败');
  574. }
  575. //同性别,提前结束
  576. if($auth_level == $tous_level){
  577. Db::commit();
  578. $this->success('success');
  579. }
  580. //扣钱uid,收钱uid,收钱free_video
  581. //分数少扣钱,分数多收益
  582. if($auth_level < $tous_level){
  583. $kou_user = $this->auth->id;
  584. $get_user = $to_user_info['id'];
  585. $get_user_free = $to_user_info['free_audio'];
  586. }else{
  587. $kou_user = $to_user_info['id'];
  588. $get_user = $this->auth->id;
  589. $get_user_free = $this->auth->free_audio;
  590. }
  591. //需要扣别人的钱,判断钱是否购
  592. if($price > 0 && $kou_user != $this->auth->id){
  593. $gold = model('wallet')->getWallet($kou_user,'gold');
  594. if(bccomp($price,$gold) == 1){
  595. Db::rollback();
  596. $this->error('对方金币不足');
  597. }
  598. }
  599. //有性别差,扣费
  600. if($price > 0){
  601. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
  602. if($rs['status'] === false){
  603. Db::rollback();
  604. $this->error($rs['msg']);
  605. }
  606. }
  607. //另一方加钱,0收费
  608. if($money > 0 && $get_user_free == 0){
  609. $rs = model('wallet')->lockChangeAccountRemain($get_user, $kou_user,'money',$money,22,'','user_match_audio_log',$log_id);
  610. if($rs['status'] === false){
  611. Db::rollback();
  612. $this->error($rs['msg']);
  613. }
  614. }
  615. Db::commit();
  616. $this->success('success');
  617. }
  618. //打字聊天每句话调用一次
  619. public function typing_once(){
  620. //检测用户
  621. $to_user_id = input_post('to_user_id');
  622. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  623. if(!$to_user_info){
  624. $this->error('不存在的用户');
  625. }
  626. //正常价格
  627. $price = config('site.typing_min_price'); //扣费金币
  628. $bili = config('site.money_to_gold'); //兑换比例
  629. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  630. $money = bcdiv($price,$bili,2); //对应人民币
  631. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  632. //发起用户的分数,被发起用户的分数。按性别给分
  633. $auth_level = 0;
  634. $tous_level = 0;
  635. //打分
  636. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  637. $auth_level = 30;//实名女最高
  638. }
  639. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  640. $auth_level = 20;//未实名女次之
  641. }
  642. if($this->auth->gender == 1){
  643. $auth_level = 10;//男性最低
  644. }
  645. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  646. $tous_level = 30;
  647. }
  648. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  649. $tous_level = 20;
  650. }
  651. if($to_user_info['gender'] == 1){
  652. $tous_level = 10;
  653. }
  654. //同性不收钱
  655. //都是男的,不扣钱
  656. //都是实名认证的女性,不扣钱
  657. //都是未实名认证的女性,不扣钱
  658. if($auth_level == $tous_level){
  659. $price = 0;$money = 0;
  660. }
  661. //性别优势的人发起,免费
  662. if($auth_level > $tous_level){
  663. $price = 0;$money = 0;
  664. }
  665. Db::startTrans();
  666. //记录日志
  667. $data = [
  668. 'user_id' => $this->auth->id,
  669. 'price' => $price,
  670. 'createtime' => time(),
  671. 'to_user_id' => $to_user_id,
  672. 'money' => $money,
  673. ];
  674. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  675. if(!$log_id){
  676. Db::rollback();
  677. $this->error('扣费失败');
  678. }
  679. //同性别,提前结束
  680. if($auth_level == $tous_level){
  681. Db::commit();
  682. $this->success('success');
  683. }
  684. //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
  685. if($price == 0 && $money == 0){
  686. Db::commit();
  687. $this->success('success');
  688. }
  689. //扣钱uid,收钱uid,收钱free_video
  690. //分数少扣钱,分数多收益
  691. if($auth_level < $tous_level){
  692. $kou_user = $this->auth->id;
  693. $get_user = $to_user_info['id'];
  694. $get_user_free = $to_user_info['free_typing'];
  695. }else{
  696. //这种已经没有了
  697. $kou_user = $to_user_info['id'];
  698. $get_user = $this->auth->id;
  699. $get_user_free = $this->auth->free_typing;
  700. }
  701. //有性别差,扣费
  702. if($price > 0){
  703. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
  704. if($rs['status'] === false){
  705. Db::rollback();
  706. $this->error($rs['msg']);
  707. }
  708. }
  709. //另一方加钱,0收费
  710. if($money > 0 && $get_user_free == 0){
  711. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,23,'','user_match_typing_log',$log_id);
  712. if($rs['status'] === false){
  713. Db::rollback();
  714. $this->error($rs['msg']);
  715. }
  716. }
  717. //tag任务赠送金币
  718. //搭讪奖励
  719. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  720. if($task_rs === false){
  721. Db::rollback();
  722. $this->error('完成任务赠送奖励失败');
  723. }
  724. Db::commit();
  725. $this->success('success');
  726. }
  727. //语音匹配
  728. public function getaudiouser(){
  729. //判断资格
  730. /*$start = strtotime(date('Y-m-d'));
  731. $end = $start + 86399;
  732. $map = [
  733. 'user_id' => $this->auth->id,
  734. 'createtime' => ['between',[$start,$end]],
  735. 'price' => 0,
  736. ];
  737. $check = Db::name('user_match_audio_log')->where($map)->find();*/
  738. $check = true;
  739. //已经用掉免费的了,判断金额
  740. if($check){
  741. $price = config('site.audio_min_price');
  742. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  743. if($gold < $price){
  744. $this->error('您的金币已经不足,请充值');
  745. }
  746. }
  747. //找到互关的人,排除
  748. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  749. //dump($follow_me);
  750. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  751. //dump($my_follow);exit;
  752. //给出备选用户
  753. $map = [
  754. 'status' =>1, //未封禁用户
  755. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  756. 'is_online' => 0, //不在语聊间的
  757. 'is_livebc' => 0, //不在直播的
  758. 'is_active' => 1, //在线的
  759. //'real_status' => 1, //真人认证
  760. //'idcard_status' => 1, //实名认证
  761. 'open_match_audio' => 1, //打开语聊开关
  762. //'id' => ['NOT IN',$my_follow] //不是好友的
  763. ];
  764. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  765. $lists = $this->fliter_user($lists,10);
  766. $result = [];
  767. if(!empty($lists)){
  768. foreach($lists as $key => $val){
  769. $result[] = ['id'=>$val];
  770. }
  771. }
  772. //tag任务赠送金币
  773. //语音匹配奖励 +5金币
  774. if(!empty($result)){
  775. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  776. if($task_rs === false){
  777. $this->error('完成任务赠送奖励失败');
  778. }
  779. }
  780. $this->success('success',$result);
  781. }
  782. //视频匹配
  783. public function getvideouser(){
  784. //判断资格
  785. /*$start = strtotime(date('Y-m-d'));
  786. $end = $start + 86399;
  787. $map = [
  788. 'user_id' => $this->auth->id,
  789. 'createtime' => ['between',[$start,$end]],
  790. 'price' => 0,
  791. ];
  792. $check = Db::name('user_match_video_log')->where($map)->find();*/
  793. $check = true;
  794. //已经用掉免费的了,判断金额
  795. if($check){
  796. $price = config('site.video_min_price');
  797. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  798. if($gold < $price){
  799. $this->error('您的金币已经不足,请充值');
  800. }
  801. }
  802. //找到互关的人,排除
  803. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  804. //dump($follow_me);
  805. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  806. //dump($my_follow);exit;
  807. //给出备选用户
  808. $map = [
  809. 'status' =>1, //未封禁用户
  810. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  811. 'is_online' => 0, //不在语聊间的
  812. 'is_livebc' => 0, //不在直播的
  813. 'is_active' => 1, //在线的
  814. //'real_status' => 1, //真人认证
  815. //'idcard_status' => 1, //实名认证
  816. 'open_match_video' => 1, //打开视频开关的
  817. // 'id' => ['NOT IN',$my_follow] //不是好友的
  818. ];
  819. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  820. $lists = $this->fliter_user($lists,10);
  821. $result = [];
  822. if(!empty($lists)){
  823. foreach($lists as $key => $val){
  824. $result[] = ['id'=>$val];
  825. }
  826. }
  827. //tag任务赠送金币
  828. //视频匹配奖励 +5金币
  829. if(!empty($result)){
  830. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  831. if($task_rs === false){
  832. $this->error('完成任务赠送奖励失败');
  833. }
  834. }
  835. $this->success('success',$result);
  836. }
  837. //聊天匹配
  838. public function gettypinguser(){
  839. //找到互关的人,排除
  840. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  841. //dump($follow_me);
  842. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  843. //dump($my_follow);exit;
  844. //给出备选用户
  845. $map = [
  846. 'status' =>1, //未封禁用户
  847. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  848. //'real_status' => 1, //真人认证
  849. //'idcard_status' => 1, //实名认证
  850. //'is_active' => 1, //在线的
  851. //打开聊天开关的
  852. 'open_match_typing' => 1, //打开文字聊天开关的
  853. //'id' => ['NOT IN',$my_follow] //不是好友的
  854. ];
  855. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  856. //$lists = $this->fliter_user($lists,100);
  857. $lists = array_column($lists,'id');
  858. $result = [];
  859. if(!empty($lists)){
  860. /*foreach($lists as $key => $val){
  861. $result[] = ['id'=>$val];
  862. }*/
  863. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  864. $result = list_domain_image($result,['avatar,audio_bio']);
  865. }
  866. //tag任务赠送金币
  867. //缘分匹配奖励 +5金币
  868. if(!empty($result)){
  869. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  870. if($task_rs === false){
  871. $this->error('完成任务赠送奖励失败');
  872. }
  873. }
  874. $this->success('success',$result);
  875. }
  876. //过滤规则
  877. private function fliter_user($lists,$number = 1){
  878. if(empty($lists)){
  879. return $lists;
  880. }
  881. //dump($lists);
  882. //过滤掉通话中的
  883. foreach($lists as $key => $val){
  884. if(redis_matching_get($val['id']) == 1){
  885. unset($lists[$key]);
  886. }
  887. }
  888. //预留全部
  889. $all_result = array_column($lists,'id');
  890. //dump($all_result);
  891. //提取同城的
  892. $citydata = [];
  893. foreach($lists as $key => $val){
  894. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  895. $citydata[] = $val['id'];
  896. }
  897. }
  898. //dump($citydata);
  899. //有标签交集的
  900. $tagdata = [];
  901. foreach($lists as $key => $val){
  902. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  903. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  904. $val_tag_ids = explode(',',$val['tag_ids']);
  905. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  906. $tagdata[] = $val['id'];
  907. }
  908. }
  909. }
  910. //dump($tagdata);
  911. //双条件都满足
  912. $double_data = [];
  913. if(!empty($citydata) && !empty($tagdata)){
  914. $double_data = array_intersect($citydata,$tagdata);
  915. }
  916. //dump($double_data);
  917. if(count($double_data) >= $number){
  918. return $double_data;
  919. }
  920. //两种条件合并,去重。空数组合并没影响
  921. $merge_data = array_merge($citydata,$tagdata);
  922. $merge_data = array_flip(array_flip($merge_data));
  923. //dump($merge_data);
  924. if(count($merge_data) >= $number){
  925. return $merge_data;
  926. }
  927. return $all_result;
  928. }
  929. /**
  930. * 是否关注
  931. */
  932. public function isFollows() {
  933. $user_id = $this->request->request("user_id",0,"intval");
  934. if (!$user_id || $user_id<=0) {
  935. $this->error(__('Invalid parameters'));
  936. }
  937. $map = [
  938. 'uid' => $this->auth->id,
  939. 'follow_uid' => $user_id,
  940. ];
  941. $check = Db::name('user_follow')->where($map)->find();
  942. $data = [];
  943. if($check){
  944. $data["is_show_follow"] = 0;
  945. }else{
  946. $data["is_show_follow"] = 1;
  947. }
  948. $this->success("获取成功!",$data);
  949. }
  950. /**
  951. * 获取主播技能分类
  952. */
  953. public function getAnchorType() {
  954. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  955. }
  956. /**
  957. * 主播申请
  958. */
  959. public function anchorApply() {
  960. $this->error('不需要申请');
  961. /*$type_id = $this->request->request('type_id'); // 技能分类ID
  962. $desc = $this->request->request('desc'); // 申请备注
  963. if (!$type_id && !$desc) {
  964. $this->error(__('Invalid parameters'));
  965. }
  966. $useranchorModel = new \app\common\model\UserAnchor();
  967. $data = [];
  968. $data["user_id"] = $this->auth->id;
  969. $data["type_id"] = $type_id;
  970. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  971. $data["desc"] = $desc;
  972. $data["createtime"] = time();
  973. $res = $useranchorModel->insertGetId($data);
  974. if($res) {
  975. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  976. $this->success("申请发送成功!");
  977. } else {
  978. $this->error("网络错误,请稍后重试");
  979. }*/
  980. }
  981. /**
  982. * 获取当前用户信息
  983. */
  984. public function getMyUserInfo() {
  985. $userInfo = $this->auth->getUserinfo();
  986. //当月消费金额
  987. $redis = new Redis();
  988. $redisconfig = config("redis");
  989. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  990. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  991. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  992. $this->success("获取成功!",$userInfo);
  993. }
  994. /**
  995. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  996. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  997. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  998. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  999. * @return float | false | string
  1000. */
  1001. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  1002. if( empty( $point_1 ) || empty( $point_2 ) ){
  1003. return false;
  1004. }
  1005. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  1006. $p1_x = $point_1[0];
  1007. $p1_y = $point_1[1];
  1008. $p2_x = $point_2[0];
  1009. $p2_y = $point_2[1];
  1010. if(
  1011. $p1_x < -180 || $p1_x > 180
  1012. || $p2_x < -180 || $p2_x > 180
  1013. || $p1_y < -90 || $p1_y > 90
  1014. || $p2_y < -90 || $p2_y > 90
  1015. ){
  1016. return '0公里';
  1017. }
  1018. // 根据2点各自的坐标,计算2点之间直线距离的公式
  1019. $distance = round(6378.138*2*asin(sqrt(pow(sin(( $p1_x *pi()/180-$p2_x*pi()/180)/2),2)+cos( $p1_x *pi()/180)*cos($p2_x*pi()/180)* pow(sin(( $p1_y *pi()/180-$p2_y*pi()/180)/2),2)))*1000);
  1020. // 是否计算为字符串公里距离
  1021. if( !$calc_as_string ){
  1022. return (string)round( $distance / 1000 , 1 ) . '公里';
  1023. }
  1024. // 如果计算为字符串公里距离
  1025. if( $distance / 1000 > 1 ){
  1026. $k = (string)round( $distance / 1000 , 1 );
  1027. $m = (string)$distance % 1000 ;
  1028. $distance = "{$k}公里{$m}米";
  1029. }
  1030. else{
  1031. $distance = "{$distance}米";
  1032. }
  1033. return $distance;
  1034. }
  1035. //地图api,根据两地坐标,获得两地距离,打卡用的
  1036. //type=0直线,type=1开车
  1037. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  1038. $result = 0;
  1039. $apiurl = 'https://restapi.amap.com/v3/distance?';
  1040. $param = [
  1041. 'key' => '398c424811d1a59beac2f915323d334e',
  1042. 'origins' => $start_lon.','.$start_lat,
  1043. 'destination' => $end_lon.','.$end_lat,
  1044. 'type' => $type,
  1045. 'output' => 'json',
  1046. ];
  1047. $apiurl .= http_build_query($param);
  1048. $request_rs = json_decode(curl_get($apiurl),true);
  1049. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  1050. if(isset($request_rs['results'][0]['distance']))
  1051. {
  1052. $result = $request_rs['results'][0]['distance'];
  1053. }
  1054. }
  1055. //dump($result);
  1056. return $result;
  1057. }
  1058. public function distance()
  1059. {
  1060. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  1061. dump($a);
  1062. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  1063. dump($a);
  1064. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  1065. dump($b);
  1066. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  1067. dump($b);
  1068. }
  1069. //开通守护
  1070. public function addguard() {
  1071. // 接口防并发
  1072. if (!$this->apiLimit(1, 1000)) {
  1073. $this->error(__('Operation frequently'));
  1074. }
  1075. $user_id = input('user_id', 0, 'intval');// 守护对象
  1076. if (!$user_id) {
  1077. $this->error();
  1078. }
  1079. // 不可以守护给自己
  1080. if($this->auth->id == $user_id) {
  1081. $this->error("不可以守护自己");
  1082. }
  1083. //查询是否开通守护
  1084. $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  1085. if ($count) {
  1086. $this->error('已经开通守护了');
  1087. }
  1088. $giftvalue = config('site.guard_price');
  1089. if ($giftvalue <= 0) {
  1090. $this->error('守护金额异常~');
  1091. }
  1092. //被守护人信息
  1093. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  1094. if (!$touserinfo) {
  1095. $this->error("不存在的用户");
  1096. }
  1097. // 判断当前用户余额
  1098. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  1099. if($user_gold < $giftvalue) {
  1100. $this->error("您的金币余额不足");
  1101. }
  1102. Db::startTrans();
  1103. // 添加礼物守护记录表
  1104. $data = [
  1105. 'user_id' => $this->auth->id,
  1106. 'user_to_id' => $user_id,
  1107. 'price' => $giftvalue,
  1108. 'createtime' => time(),
  1109. ];
  1110. $log_id = Db::name('user_guard')->insertGetId($data);
  1111. if(!$log_id){
  1112. Db::rollback();
  1113. $this->error('守护失败');
  1114. }
  1115. if($giftvalue > 0){
  1116. // 扣除当前用户余额
  1117. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
  1118. if($wallet_rs['status'] === false){
  1119. Db::rollback();
  1120. $this->error($wallet_rs['msg']);
  1121. }
  1122. // 添加守护用户余额
  1123. $money_to_gold = config('site.money_to_gold');
  1124. $gift_plat_scale = config('site.gift_plat_scale');
  1125. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  1126. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  1127. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
  1128. if($wallet_rs['status'] === false){
  1129. Db::rollback();
  1130. $this->error($wallet_rs['msg']);
  1131. }
  1132. //增加赠送用户上级余额
  1133. if ($touserinfo['intro_uid']) {
  1134. //获取返利比率
  1135. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1136. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1137. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1138. //上级获得金额
  1139. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1140. if ($intro_uid_money > 0) {
  1141. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
  1142. if($intro_result['status']===false)
  1143. {
  1144. Db::rollback();
  1145. $this->error($intro_result['msg']);
  1146. }
  1147. }
  1148. }
  1149. }
  1150. }
  1151. //tag任务守护金币
  1152. //搭讪奖励
  1153. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  1154. // if($task_rs === false){
  1155. // Db::rollback();
  1156. // $this->error('完成任务守护奖励失败');
  1157. // }
  1158. Db::commit();
  1159. $this->success('守护成功');
  1160. }
  1161. //守护列表
  1162. public function guardlist(){
  1163. $user_id = input('user_id', 0, 'intval');
  1164. if (!$user_id) {
  1165. $this->error('您的网络开小差啦~');
  1166. }
  1167. $list = Db::name('user_guard')
  1168. ->alias('a')
  1169. ->join('user','a.user_id = user.id','LEFT')
  1170. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  1171. ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
  1172. if (!$list) {
  1173. $this->success('success', $list);
  1174. }
  1175. $list = list_domain_image($list,['avatar']);
  1176. $time = time();
  1177. foreach ($list as &$v) {
  1178. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  1179. }
  1180. $this->success('success',$list);
  1181. }
  1182. //我的守护
  1183. public function myguardlist(){
  1184. $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
  1185. if (!in_array($type, [1, 2])) {
  1186. $this->error('您的网络开小差了');
  1187. }
  1188. $where = [];
  1189. if ($type == 1) {
  1190. $join = 'a.user_to_id = user.id';
  1191. $where['a.user_id'] = $this->auth->id;
  1192. } else {
  1193. $join = 'a.user_id = user.id';
  1194. $where['a.user_to_id'] = $this->auth->id;
  1195. }
  1196. $list = Db::name('user_guard')
  1197. ->alias('a')
  1198. ->join('user',$join,'LEFT')
  1199. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  1200. ->where($where)->order('a.id desc')->autopage()->select();
  1201. if (!$list) {
  1202. $this->success('success', $list);
  1203. }
  1204. $list = list_domain_image($list,['avatar']);
  1205. $time = time();
  1206. foreach ($list as &$v) {
  1207. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  1208. }
  1209. $this->success('success',$list);
  1210. }
  1211. //打字聊天每句话调用一次
  1212. public function chat_once(){
  1213. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1214. $this->success('success',array('money'=>''));
  1215. }
  1216. if ($this->auth->gender == 0) { //女生不花钱
  1217. $this->error('您的网络开小差啦~');
  1218. }
  1219. //检测用户
  1220. $to_user_id = input_post('to_user_id');
  1221. $to_user_info = Db::name('user')->field('id,intro_uid,real_status,gender,free_video,free_audio,free_typing,chat_price,is_kefu')->where('id',$to_user_id)->find();
  1222. if(!$to_user_info){
  1223. $this->error('不存在的用户');
  1224. }
  1225. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1226. $this->success('success',array('money'=>''));
  1227. }
  1228. if ($to_user_info['gender'] != 0) {
  1229. $this->error('同性不能聊天~');
  1230. }
  1231. //验证金额
  1232. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1233. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1234. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  1235. //获取折扣
  1236. $vip_chat_discount = config('site.vip_chat_discount');
  1237. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1238. $price = ceil($price * $vip_chat_discount / 10);
  1239. }
  1240. } else {
  1241. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  1242. }
  1243. //正常价格
  1244. $bili = config('site.money_to_gold'); //兑换比例
  1245. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1246. $money = bcdiv($price,$bili,2); //对应人民币
  1247. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1248. $resArray['money'] = $money; //返回给前端的计算结果
  1249. Db::startTrans();
  1250. //记录日志
  1251. $data = [
  1252. 'user_id' => $this->auth->id,
  1253. 'price' => $price,
  1254. 'createtime' => time(),
  1255. 'to_user_id' => $to_user_id,
  1256. 'money' => $money,
  1257. ];
  1258. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  1259. if(!$log_id){
  1260. Db::rollback();
  1261. $this->error('扣费失败');
  1262. }
  1263. //有性别差,扣费
  1264. if($price > 0){
  1265. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
  1266. if($rs['status'] === false){
  1267. Db::rollback();
  1268. $this->error($rs['msg']);
  1269. }
  1270. }
  1271. //另一方加钱,0收费
  1272. if($money > 0){
  1273. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
  1274. if($rs['status'] === false){
  1275. Db::rollback();
  1276. $this->error($rs['msg']);
  1277. }
  1278. $touserinfo = $to_user_info;
  1279. //增加赠送用户上级余额
  1280. if ($touserinfo['intro_uid']) {
  1281. //获取返利比率
  1282. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1283. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1284. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1285. //上级获得金额
  1286. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1287. if ($intro_uid_money > 0) {
  1288. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
  1289. if($intro_result['status']===false)
  1290. {
  1291. Db::rollback();
  1292. $this->error($intro_result['msg']);
  1293. }
  1294. }
  1295. }
  1296. }
  1297. }
  1298. //增加亲密度
  1299. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1300. if (!$user_intimacy_rs['status']) {
  1301. Db::rollback();
  1302. $this->error('您的网络开小差啦~');
  1303. }
  1304. //tag任务赠送金币
  1305. //私信5名异性奖励
  1306. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  1307. if($task_rs === false){
  1308. Db::rollback();
  1309. $this->error('完成任务赠送奖励失败');
  1310. }
  1311. /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
  1312. if($task_rs === false){
  1313. Db::rollback();
  1314. $this->error('完成任务赠送奖励失败');
  1315. }*/
  1316. Db::commit();
  1317. //发送消息
  1318. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1319. $tenim = new \app\api\controller\Tenim;
  1320. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1321. }
  1322. $this->success('success',$resArray);
  1323. }
  1324. //语音通话每分钟调用一次
  1325. public function voice_onemin(){
  1326. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1327. $this->success('success');
  1328. }
  1329. if ($this->auth->gender == 0) { //女生不花钱
  1330. $this->error('您的网络开小差啦~');
  1331. }
  1332. //检测用户
  1333. $to_user_id = input_post('to_user_id');
  1334. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1335. $to_user_info = Db::name('user')->field('id,intro_uid,real_status,gender,free_video,free_audio,free_typing,voice_price,is_kefu')->where('id',$to_user_id)->find();
  1336. if(!$to_user_info){
  1337. $this->error('不存在的用户');
  1338. }
  1339. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1340. $this->success('success');
  1341. }
  1342. if ($to_user_info['gender'] != 0) {
  1343. $this->error('同性不能聊天~');
  1344. }
  1345. //验证金额
  1346. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1347. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1348. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1349. //获取折扣
  1350. $vip_video_discount = config('site.vip_video_discount');
  1351. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1352. $price = ceil($price * $vip_video_discount / 10);
  1353. }
  1354. } else {
  1355. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1356. }
  1357. //正常价格
  1358. $bili = config('site.money_to_gold'); //兑换比例
  1359. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1360. $money = bcdiv($price,$bili,2); //对应人民币
  1361. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1362. Db::startTrans();
  1363. //查询是否有匹配记录
  1364. $user_match_audio_log_info = [];
  1365. if ($request_id) {
  1366. $user_match_audio_log_info = Db::name('user_match_audio_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
  1367. }
  1368. if ($user_match_audio_log_info) {
  1369. //修改记录日志
  1370. $data = [
  1371. 'price' => $user_match_audio_log_info['price'] + $price,
  1372. 'createtime' => time(),
  1373. 'money' => $user_match_audio_log_info['money'] + $money,
  1374. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  1375. ];
  1376. $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id'], 'createtime' => $user_match_audio_log_info['createtime']])->setField($data);
  1377. if (!$log_id) {
  1378. Db::rollback();
  1379. $this->error('扣费失败');
  1380. }
  1381. } else {
  1382. //添加记录日志
  1383. $data = [
  1384. 'user_id' => $this->auth->id,
  1385. 'price' => $price,
  1386. 'createtime' => time(),
  1387. 'to_user_id' => $to_user_id,
  1388. 'money' => $money,
  1389. 'request_id' => $request_id,
  1390. 'call_minutes' => 1
  1391. ];
  1392. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  1393. if (!$log_id) {
  1394. Db::rollback();
  1395. $this->error('扣费失败');
  1396. }
  1397. }
  1398. //有性别差,扣费
  1399. if($price > 0){
  1400. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,12,'语音通话消费' . $data['call_minutes'] . '分钟','user_match_audio_log',$log_id, 0, $request_id);
  1401. if($rs['status'] === false){
  1402. Db::rollback();
  1403. $this->error($rs['msg']);
  1404. }
  1405. }
  1406. //另一方加钱,0收费
  1407. if($money > 0){
  1408. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,22,'语音通话收益' . $data['call_minutes'] . '分钟','user_match_audio_log',$log_id,2, $request_id);
  1409. if($rs['status'] === false){
  1410. Db::rollback();
  1411. $this->error($rs['msg']);
  1412. }
  1413. $touserinfo = $to_user_info;
  1414. //增加赠送用户上级余额
  1415. if ($touserinfo['intro_uid']) {
  1416. //获取返利比率
  1417. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1418. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1419. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1420. //上级获得金额
  1421. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1422. if ($intro_uid_money > 0) {
  1423. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人语音聊天获赠奖励' . $data['call_minutes'] . '分钟','gift_user_typing',$log_id, 0, $request_id);
  1424. if($intro_result['status']===false)
  1425. {
  1426. Db::rollback();
  1427. $this->error($intro_result['msg']);
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. //增加亲密度
  1434. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1435. if (!$user_intimacy_rs['status']) {
  1436. Db::rollback();
  1437. $this->error('您的网络开小差啦~');
  1438. }
  1439. //tag任务赠送金币
  1440. //与1名异性语音通话奖励
  1441. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
  1442. if($task_rs === false){
  1443. Db::rollback();
  1444. $this->error('完成任务赠送奖励失败');
  1445. }
  1446. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
  1447. if($task_rs === false){
  1448. Db::rollback();
  1449. $this->error('完成任务赠送奖励失败');
  1450. }
  1451. //发送消息
  1452. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1453. $tenim = new \app\api\controller\Tenim;
  1454. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1455. }
  1456. Db::commit();
  1457. $this->success('success');
  1458. }
  1459. //视频通话每分钟调用一次
  1460. public function videochat_onemin(){
  1461. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1462. $this->success('success');
  1463. }
  1464. if ($this->auth->gender == 0) { //女生不花钱
  1465. $this->error('您的网络开小差啦~');
  1466. }
  1467. //检测用户
  1468. $to_user_id = input_post('to_user_id');
  1469. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1470. $to_user_info = Db::name('user')->field('id,intro_uid,real_status,gender,free_video,free_audio,free_typing,video_price,is_kefu')->where('id',$to_user_id)->find();
  1471. if(!$to_user_info){
  1472. $this->error('不存在的用户');
  1473. }
  1474. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1475. $this->success('success');
  1476. }
  1477. if ($to_user_info['gender'] != 0) {
  1478. $this->error('同性不能聊天~');
  1479. }
  1480. /* //检查是否免费过
  1481. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1482. if (!$count) {
  1483. //记录日志
  1484. $data = [
  1485. 'user_id' => $this->auth->id,
  1486. 'price' => 0,
  1487. 'createtime' => time(),
  1488. 'to_user_id' => $to_user_id,
  1489. 'money' => 0,
  1490. ];
  1491. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1492. if(!$log_id){
  1493. $this->error('扣费失败');
  1494. }
  1495. $this->success('success');
  1496. }*/
  1497. //验证金额
  1498. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1499. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1500. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1501. //获取折扣
  1502. $vip_video_discount = config('site.vip_video_discount');
  1503. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1504. $price = ceil($price * $vip_video_discount / 10);
  1505. }
  1506. } else {
  1507. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1508. }
  1509. //正常价格
  1510. $bili = config('site.money_to_gold'); //兑换比例
  1511. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1512. $money = bcdiv($price,$bili,2); //对应人民币
  1513. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1514. Db::startTrans();
  1515. //查询是否有匹配记录
  1516. $user_match_video_log_info = [];
  1517. if ($request_id) {
  1518. $user_match_video_log_info = Db::name('user_match_video_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
  1519. }
  1520. if ($user_match_video_log_info) {
  1521. //修改记录日志
  1522. $data = [
  1523. 'price' => $user_match_video_log_info['price'] + $price,
  1524. 'createtime' => time(),
  1525. 'money' => $user_match_video_log_info['money'] + $money,
  1526. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  1527. ];
  1528. $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id'], 'createtime' => $user_match_video_log_info['createtime']])->setField($data);
  1529. if (!$log_id) {
  1530. Db::rollback();
  1531. $this->error('扣费失败');
  1532. }
  1533. } else {
  1534. //添加记录日志
  1535. $data = [
  1536. 'user_id' => $this->auth->id,
  1537. 'price' => $price,
  1538. 'createtime' => time(),
  1539. 'to_user_id' => $to_user_id,
  1540. 'money' => $money,
  1541. 'request_id' => $request_id,
  1542. 'call_minutes' => 1
  1543. ];
  1544. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  1545. if (!$log_id) {
  1546. Db::rollback();
  1547. $this->error('扣费失败');
  1548. }
  1549. }
  1550. //有性别差,扣费
  1551. if($price > 0){
  1552. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,11,'视频通话消费' . $data['call_minutes'] . '分钟','user_match_video_log',$log_id, 0, $request_id);
  1553. if($rs['status'] === false){
  1554. Db::rollback();
  1555. $this->error($rs['msg']);
  1556. }
  1557. }
  1558. //另一方加钱,0收费
  1559. if($money > 0){
  1560. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,21,'视频通话收益' . $data['call_minutes'] . '分钟','user_match_video_log',$log_id,2, $request_id);
  1561. if($rs['status'] === false){
  1562. Db::rollback();
  1563. $this->error($rs['msg']);
  1564. }
  1565. $touserinfo = $to_user_info;
  1566. //增加赠送用户上级余额
  1567. if ($touserinfo['intro_uid']) {
  1568. //获取返利比率
  1569. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1570. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1571. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1572. //上级获得金额
  1573. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1574. if ($intro_uid_money > 0) {
  1575. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人视频聊天获赠奖励' . $data['call_minutes'] . '分钟','gift_user_typing',$log_id, 0, $request_id);
  1576. if($intro_result['status']===false)
  1577. {
  1578. Db::rollback();
  1579. $this->error($intro_result['msg']);
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. //增加亲密度
  1586. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1587. if (!$user_intimacy_rs['status']) {
  1588. Db::rollback();
  1589. $this->error('您的网络开小差啦~');
  1590. }
  1591. //tag任务赠送金币
  1592. //与1名异性视频通话奖励
  1593. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
  1594. if($task_rs === false){
  1595. Db::rollback();
  1596. $this->error('完成任务赠送奖励失败');
  1597. }
  1598. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
  1599. if($task_rs === false){
  1600. Db::rollback();
  1601. $this->error('完成任务赠送奖励失败');
  1602. }
  1603. Db::commit();
  1604. //发送消息
  1605. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1606. $tenim = new \app\api\controller\Tenim;
  1607. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1608. }
  1609. $this->success('success');
  1610. }
  1611. //消息列表好友/密友
  1612. public function intimacyfriends() {
  1613. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  1614. $where = [];
  1615. /*if ($type == 0) {
  1616. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  1617. $mt_user = Db::name('user');
  1618. // $mt_user_follow = Db::name('user_follow');
  1619. $mt_user_intimacy = Db::name('user_intimacy');
  1620. foreach ($list as &$v) {
  1621. //查询亲密度
  1622. if ($this->auth->gender == 1) {
  1623. $where['uid'] = $this->auth->id;
  1624. $where['other_uid'] = $v['user_id'];
  1625. } else {
  1626. $where['other_uid'] = $this->auth->id;
  1627. $where['uid'] = $v['user_id'];
  1628. }
  1629. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  1630. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  1631. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  1632. //查询对方信息
  1633. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  1634. $v['nickname'] = $user_info['nickname'];
  1635. $v['avatar'] = one_domain_image($user_info['avatar']);
  1636. $v['updatetime'] = get_last_time($v['updatetime']);
  1637. $v['age'] = birthtime_to_age($user_info['birthday']);
  1638. $v['gender'] = $user_info['gender'];
  1639. $v['real_status'] = $user_info['real_status'];
  1640. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1641. $v['status'] = 1;
  1642. }
  1643. } else {*/
  1644. if ($this->auth->gender == 1) {
  1645. $where['uid'] = $this->auth->id;
  1646. $field = 'other_uid user_id, value, updatetime';
  1647. } else {
  1648. $where['other_uid'] = $this->auth->id;
  1649. $field = 'uid user_id, value, updatetime';
  1650. }
  1651. if ($type == 1) { //密友
  1652. $where['value'] = ['egt', 1000];
  1653. } elseif ($type == 2) { //好友
  1654. $where['value'] = ['egt', 100];
  1655. } else { //消息列表好友
  1656. $where['value'] = ['egt', 10];
  1657. }
  1658. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  1659. $mt_user = Db::name('user');
  1660. $mt_user_follow = Db::name('user_follow');
  1661. foreach ($list as &$v) {
  1662. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  1663. $v['nickname'] = $user_info['nickname'];
  1664. $v['avatar'] = one_domain_image($user_info['avatar']);
  1665. $v['updatetime'] = get_last_time($v['updatetime']);
  1666. $v['age'] = birthtime_to_age($user_info['birthday']);
  1667. $v['gender'] = $user_info['gender'];
  1668. $v['real_status'] = $user_info['real_status'];
  1669. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1670. $v['is_active'] = $user_info['is_active'];
  1671. }
  1672. // }
  1673. $this->success('success',$list);
  1674. }
  1675. //消息列表通话
  1676. public function calllist() {
  1677. if ($this->auth->gender == 1) {
  1678. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
  1679. } elseif ($this->auth->gender == 0) {
  1680. $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
  1681. } else {
  1682. $this->success('success', []);
  1683. }
  1684. if (!$list) {
  1685. $this->success('success', $list);
  1686. }
  1687. $arr = [];
  1688. $mt_user_match_audio_log = Db::name('user_match_audio_log');
  1689. $mt_user_match_video_log = Db::name('user_match_video_log');
  1690. $mt_user = Db::name('user');
  1691. foreach ($list as &$v) {
  1692. $data = [];
  1693. if ($this->auth->gender == 1) {
  1694. if ($v['log_type'] == 11) { //视频通话
  1695. $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1696. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1697. } else { //语音通话
  1698. $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1699. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1700. }
  1701. } else {
  1702. if ($v['log_type'] == 21) { //视频通话
  1703. $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1704. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1705. } else { //语音通话
  1706. $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1707. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1708. }
  1709. }
  1710. $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
  1711. $data['user_id'] = $log_info['user_id'];
  1712. $data['nickname'] = $user_info['nickname'];
  1713. $data['avatar'] = one_domain_image($user_info['avatar']);
  1714. $data['createtime'] = get_last_time($log_info['createtime']);
  1715. $data['is_active'] = $user_info['is_active'];
  1716. $arr[] = $data;
  1717. }
  1718. $this->success('success', $arr);
  1719. }
  1720. //查询对方用户收费价格和我的余额
  1721. public function otheruserinfo(){
  1722. $user_id = input('user_id', 0, 'intval');
  1723. if (!$user_id) {
  1724. $this->error('您的网络开小差啦~');
  1725. }
  1726. $field = [
  1727. 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
  1728. ];
  1729. $info = Db::name('user')->field($field)->where('id',$user_id)->find();
  1730. if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
  1731. if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
  1732. $this->error('性别存在问题');
  1733. }
  1734. }
  1735. if ($this->auth->gender == 0) { //收费价格按照女号
  1736. $info['chat_price'] = $this->auth->chat_price;
  1737. $info['voice_price'] = $this->auth->voice_price;
  1738. $info['video_price'] = $this->auth->video_price;
  1739. $info['open_match_audio'] = $this->auth->open_match_audio;
  1740. $info['open_match_video'] = $this->auth->open_match_video;
  1741. }
  1742. $info['chat_price_vip'] = $info['chat_price']; //vip价格
  1743. $info['voice_price_vip'] = $info['voice_price'];
  1744. $info['video_price_vip'] = $info['video_price'];
  1745. $info['is_vip'] = 0; //是否vip: 0否 1是
  1746. //获取聊天折扣
  1747. $vip_chat_discount = config('site.vip_chat_discount');
  1748. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1749. $info['vip_chat_discount'] = $vip_chat_discount;
  1750. } else {
  1751. $info['vip_chat_discount'] = 10;
  1752. }
  1753. //获取语音视频折扣
  1754. $vip_video_discount = config('site.vip_video_discount');
  1755. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1756. $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
  1757. $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
  1758. } else {
  1759. $info['vip_voice_discount'] = 10;
  1760. $info['vip_video_discount'] = 10;
  1761. }
  1762. //获取聊天折扣
  1763. $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
  1764. //获取语音折扣
  1765. $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
  1766. //获取视频折扣
  1767. $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
  1768. if ($this->auth->gender == 0) { //查询男号余额和vip
  1769. $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
  1770. } else {
  1771. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1772. }
  1773. if ($wallet_info['vip_endtime'] >= time()) {
  1774. $info['is_vip'] = 1;
  1775. }
  1776. $info['gold'] = $wallet_info['gold'];
  1777. $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
  1778. $info['money_to_gold'] = config('site.money_to_gold'); //一元人民币兑换金币数量
  1779. $this->success('success',$info);
  1780. }
  1781. //亲密度等级信息
  1782. public function intimacylevel() {
  1783. $user_id = input('user_id', 0, 'intval'); //对方id
  1784. if (!$user_id) {
  1785. $this->error('参数缺失');
  1786. }
  1787. if ($this->auth->gender == 0) { //女用户
  1788. $where['uid'] = $user_id;
  1789. $where['other_uid'] = $this->auth->id;
  1790. } else { //男用户
  1791. $where['uid'] = $this->auth->id;
  1792. $where['other_uid'] = $user_id;
  1793. }
  1794. $level = 0; //当前等级
  1795. $level_name = ''; //当前等级名称
  1796. $qinmi_sum = 0; //当前亲密度
  1797. $next_level_diff = 0; //距下一等级亲密度差值
  1798. //亲密度等级列表
  1799. $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
  1800. //当前亲密度信息
  1801. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  1802. if ($user_intimacy_info) {
  1803. //当前亲密度
  1804. $qinmi_sum = $user_intimacy_info['value'];
  1805. if ($list) {
  1806. //当前等级信息
  1807. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
  1808. if ($level_info) {
  1809. $level = $level_info['level'];
  1810. $level_name = $level_info['name'];
  1811. }
  1812. //下一等级信息
  1813. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  1814. if ($next_level_info) {
  1815. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  1816. }
  1817. }
  1818. } else {
  1819. $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
  1820. }
  1821. if ($list) {
  1822. foreach ($list as &$v) {
  1823. if ($v['level'] < $level) {
  1824. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  1825. } elseif ($v['level'] == $level) {
  1826. $v['is_unlock'] = 2;
  1827. } else {
  1828. $v['is_unlock'] = 3;
  1829. }
  1830. }
  1831. }
  1832. $data['level'] = $level; //当前等级
  1833. $data['level_name'] = $level_name; //当前等级名称
  1834. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  1835. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  1836. $data['level_list'] = $list; //等级列表
  1837. $this->success('亲密度等级信息', $data);
  1838. }
  1839. //语音视频随聊
  1840. public function getrandomuser() {
  1841. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1842. if (!in_array($type, [1, 2, 3])) {
  1843. $this->error('您的网络开小差了');
  1844. }
  1845. //找到互关的人,排除
  1846. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  1847. //dump($follow_me);
  1848. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  1849. //dump($my_follow);exit;
  1850. //给出备选用户
  1851. $map = [
  1852. 'status' =>1, //未封禁用户
  1853. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1854. // 'is_online' => 0, //不在语聊间的
  1855. 'is_livebc' => 0, //不在直播的
  1856. 'is_active' => 1, //在线的
  1857. // 'real_status' => 1, //真人认证
  1858. // 'idcard_status' => 1, //实名认证
  1859. // 'id' => ['NOT IN',$my_follow] //不是好友的
  1860. 'is_kefu' => 0, //不是客服
  1861. ];
  1862. if ($this->auth->gender == 1) {
  1863. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1864. }
  1865. if ($type == 1) {
  1866. $map['open_match_audio'] = 1;
  1867. } elseif ($type == 2) {
  1868. $map['open_match_video'] = 1;
  1869. }
  1870. $lists = Db::name('user')->field('id,nickname,username,avatar')->where($map)->order('is_active desc, active_time desc')/*->page($this->page,100)*/->select();
  1871. //$lists = $this->fliter_user($lists,100);
  1872. // 排除已经搭讪过的用户 2023年12月1日 11点35分
  1873. // $userGreetIds = Db::name('user_greet')->where('user_id',$this->auth->id)->column('user_to_id');
  1874. //
  1875. // $lists = Db::name('user')
  1876. // ->field('id,nickname,username,avatar')
  1877. // ->where($map)
  1878. // ->whereNotIn('id',$userGreetIds)
  1879. // ->order('is_active desc, active_time desc')
  1880. // /*->page($this->page,100)*/
  1881. // ->select();
  1882. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1883. $mt_user_greet_content = Db::name('user_greet_content');
  1884. foreach ($lists as &$v) {
  1885. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1886. if ($info) {
  1887. if ($info['type'] == 0) {
  1888. $v['greet_content'] = $info['content'];
  1889. } elseif ($info['type'] == 1) {
  1890. $v['greet_content'] = '[语音]';
  1891. } elseif ($info['type'] == 2) {
  1892. $v['greet_content'] = '[图片]';
  1893. }
  1894. } else {
  1895. $v['greet_content'] = '';
  1896. }
  1897. }
  1898. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1899. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1900. $return_data['list'] = $lists;
  1901. $this->success('success',$return_data);
  1902. }
  1903. //查询免费体验视频通话用户信息
  1904. public function getfreevideouserinfo() {
  1905. $to_user_id = input('to_user_id', 0, 'intval');
  1906. $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
  1907. if(!$to_user_info){
  1908. $this->error('不存在的用户');
  1909. }
  1910. if ($to_user_info['gender'] == $this->auth->gender) {
  1911. $this->error('同性不能聊天~');
  1912. }
  1913. $to_user_info['desc'] = '';
  1914. $age = birthtime_to_age($to_user_info['birthday']);
  1915. if ($age > 0) {
  1916. $to_user_info['desc'] = $age . '岁';
  1917. } else {
  1918. $to_user_info['desc'] = '18岁';
  1919. }
  1920. if ($to_user_info['height']) {
  1921. $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
  1922. }
  1923. //查询是否免费过
  1924. $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1925. $this->success('信息', $to_user_info);
  1926. }
  1927. //免费体验视频通话1分钟
  1928. public function videochat_onemin_free(){
  1929. $this->success('success');
  1930. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1931. $this->success('success');
  1932. }
  1933. //检查是否免费过
  1934. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1935. if ($count) {
  1936. $this->error('已经免费体验过');
  1937. }
  1938. //检测用户
  1939. $to_user_id = input_post('to_user_id');
  1940. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing,video_price,is_kefu')->where('id',$to_user_id)->find();
  1941. if(!$to_user_info){
  1942. $this->error('不存在的用户');
  1943. }
  1944. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1945. $this->success('success');
  1946. }
  1947. if ($to_user_info['gender'] == $this->auth->gender) {
  1948. $this->error('同性不能聊天~');
  1949. }
  1950. //记录日志
  1951. $data = [
  1952. 'user_id' => $this->auth->id,
  1953. 'price' => 0,
  1954. 'createtime' => time(),
  1955. 'to_user_id' => $to_user_id,
  1956. 'money' => 0,
  1957. ];
  1958. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1959. if(!$log_id){
  1960. $this->error('扣费失败');
  1961. }
  1962. $this->success('success');
  1963. }
  1964. //男性非会员解锁聊天
  1965. public function unlockchat() {
  1966. // 接口防并发
  1967. if (!$this->apiLimit(1, 1000)) {
  1968. $this->error(__('Operation frequently'));
  1969. }
  1970. //男性非会员是否已开通聊天
  1971. if ($this->auth->gender == 0) {
  1972. $this->error('不需要解锁');
  1973. }
  1974. $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  1975. if ($vip_endtime > time()) {
  1976. $this->error('不需要解锁');
  1977. }
  1978. $user_id = input('user_id', 0, 'intval');//对方id
  1979. if (!$user_id) {
  1980. $this->error();
  1981. }
  1982. // 不可以守护给自己
  1983. if($this->auth->id == $user_id) {
  1984. $this->error("不可以解锁自己");
  1985. }
  1986. //查询是否解锁过
  1987. $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  1988. if ($user_chat_unlock) {
  1989. $this->error('已经解锁过了');
  1990. }
  1991. $giftvalue = config('site.unlock_chat_gold');
  1992. if ($giftvalue <= 0) {
  1993. $this->error('解锁金额异常~');
  1994. }
  1995. //被解锁人信息
  1996. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  1997. if (!$touserinfo) {
  1998. $this->error("不存在的用户");
  1999. }
  2000. // 判断当前用户余额
  2001. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  2002. if($user_gold < $giftvalue) {
  2003. $this->error("您的金币余额不足");
  2004. }
  2005. Db::startTrans();
  2006. //添加解锁记录表
  2007. $data = [
  2008. 'user_id' => $this->auth->id,
  2009. 'user_to_id' => $user_id,
  2010. 'price' => $giftvalue,
  2011. 'createtime' => time(),
  2012. ];
  2013. $log_id = Db::name('user_chat_unlock')->insertGetId($data);
  2014. if(!$log_id){
  2015. Db::rollback();
  2016. $this->error('解锁失败');
  2017. }
  2018. if($giftvalue > 0){
  2019. // 扣除当前用户余额
  2020. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_chat_unlock',$log_id);
  2021. if($wallet_rs['status'] === false){
  2022. Db::rollback();
  2023. $this->error($wallet_rs['msg']);
  2024. }
  2025. // 添加守护用户余额
  2026. $money_to_gold = config('site.money_to_gold');
  2027. $gift_plat_scale = config('site.gift_plat_scale');
  2028. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  2029. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  2030. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_chat_unlock',$log_id,2);
  2031. if($wallet_rs['status'] === false){
  2032. Db::rollback();
  2033. $this->error($wallet_rs['msg']);
  2034. }
  2035. //增加赠送用户上级余额
  2036. if ($touserinfo['intro_uid']) {
  2037. //获取返利比率
  2038. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  2039. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  2040. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  2041. //上级获得金额
  2042. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  2043. if ($intro_uid_money > 0) {
  2044. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人解锁聊天获赠奖励','gift_user_typing',$log_id);
  2045. if($intro_result['status']===false)
  2046. {
  2047. Db::rollback();
  2048. $this->error($intro_result['msg']);
  2049. }
  2050. }
  2051. }
  2052. }
  2053. }
  2054. //tag任务守护金币
  2055. //搭讪奖励
  2056. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  2057. // if($task_rs === false){
  2058. // Db::rollback();
  2059. // $this->error('完成任务守护奖励失败');
  2060. // }
  2061. Db::commit();
  2062. $this->success('解锁成功');
  2063. }
  2064. }