Usercenter.php 62 KB

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