Usercenter.php 72 KB

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