Usercenter.php 82 KB

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