Usercenter.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  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'=>$uid])->count('id');
  116. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$uid])->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'=>$uid])->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. //动态数量
  214. $userinfo['dongtai_num'] = Db::name('topic_dongtai')->where(['user_id' => $uid, 'is_hidden' => 0, 'type' => ['in', [1, 2]], 'status' => 0, 'auit_status' => 1])->count();
  215. $this->success('success',$userinfo);
  216. }
  217. //某用户的礼物墙
  218. private function giftwall($uid){
  219. //$uid = $this->auth->id;
  220. //聊天礼物
  221. $gift_user_typing = Db::name('gift_user_typing')->alias('log')
  222. ->join('gift', 'gift.id = log.gift_id', 'LEFT')
  223. ->field('log.gift_id,log.gift_name,sum(log.number) as number,gift.image')
  224. ->where(['log.user_to_id' => $uid])
  225. ->group('log.gift_id')
  226. ->order('gift.price desc')
  227. ->column('log.gift_id,log.gift_name,sum(log.number) as number,gift.image');
  228. $gift_user_typing = list_domain_image($gift_user_typing,['image']);
  229. //dump($gift_user_typing);
  230. //动态礼物
  231. $gift_user_dongtai = Db::name('gift_user_dongtai')->alias('log')
  232. ->join('gift', 'gift.id = log.gift_id', 'LEFT')
  233. ->field('log.gift_id,log.gift_name,sum(log.number) as number,gift.image')
  234. ->where(['log.user_to_id' => $uid])
  235. ->group('log.gift_id')
  236. ->order('gift.price desc')
  237. ->column('log.gift_id,log.gift_name,sum(log.number) as number,gift.image');
  238. $gift_user_dongtai = list_domain_image($gift_user_dongtai,['image']);
  239. //dump($gift_user_dongtai);
  240. //为空
  241. if(empty($gift_user_typing) && empty($gift_user_dongtai)){
  242. return [];
  243. }
  244. if(empty($gift_user_typing) && !empty($gift_user_dongtai)){
  245. foreach($gift_user_dongtai as $key => $val){
  246. $result[] = $val;
  247. }
  248. return $result;
  249. }
  250. if(!empty($gift_user_typing) && empty($gift_user_dongtai)){
  251. foreach($gift_user_typing as $key => $val){
  252. $result[] = $val;
  253. }
  254. return $result;
  255. }
  256. //合并
  257. foreach($gift_user_typing as $key => $val){
  258. foreach($gift_user_dongtai as $k => $v){
  259. if($key == $k){
  260. $gift_user_typing[$key]['number'] += $v['number'];
  261. }
  262. if(!isset($gift_user_typing[$k])){
  263. $gift_user_typing[$k] = $v;
  264. }
  265. }
  266. }
  267. //dump($gift_user_typing);
  268. //结果
  269. $result = [];
  270. foreach($gift_user_typing as $key => $val){
  271. $result[] = $val;
  272. }
  273. return $result;
  274. }
  275. /**
  276. * 是否关注
  277. */
  278. public function isFollows() {
  279. $user_id = $this->request->request("user_id",0,"intval");
  280. if (!$user_id || $user_id<=0) {
  281. $this->error(__('Invalid parameters'));
  282. }
  283. $map = [
  284. 'uid' => $this->auth->id,
  285. 'follow_uid' => $user_id,
  286. ];
  287. $check = Db::name('user_follow')->where($map)->find();
  288. $data = [];
  289. if($check){
  290. $data["is_show_follow"] = 0;
  291. }else{
  292. $data["is_show_follow"] = 1;
  293. }
  294. $this->success("获取成功!",$data);
  295. }
  296. /**
  297. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  298. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  299. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  300. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  301. * @return float | false | string
  302. */
  303. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  304. if( empty( $point_1 ) || empty( $point_2 ) ){
  305. return false;
  306. }
  307. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  308. $p1_x = $point_1[0];
  309. $p1_y = $point_1[1];
  310. $p2_x = $point_2[0];
  311. $p2_y = $point_2[1];
  312. if(
  313. $p1_x < -180 || $p1_x > 180
  314. || $p2_x < -180 || $p2_x > 180
  315. || $p1_y < -90 || $p1_y > 90
  316. || $p2_y < -90 || $p2_y > 90
  317. ){
  318. return '0公里';
  319. }
  320. // 根据2点各自的坐标,计算2点之间直线距离的公式
  321. $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);
  322. // 是否计算为字符串公里距离
  323. if( !$calc_as_string ){
  324. return (string)round( $distance / 1000 , 1 ) . '公里';
  325. }
  326. // 如果计算为字符串公里距离
  327. if( $distance / 1000 > 1 ){
  328. $k = (string)round( $distance / 1000 , 1 );
  329. $m = (string)$distance % 1000 ;
  330. $distance = "{$k}公里{$m}米";
  331. }
  332. else{
  333. $distance = "{$distance}米";
  334. }
  335. return $distance;
  336. }
  337. //地图api,根据两地坐标,获得两地距离,打卡用的
  338. //type=0直线,type=1开车
  339. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  340. $result = 0;
  341. $apiurl = 'https://restapi.amap.com/v3/distance?';
  342. $param = [
  343. 'key' => '398c424811d1a59beac2f915323d334e',
  344. 'origins' => $start_lon.','.$start_lat,
  345. 'destination' => $end_lon.','.$end_lat,
  346. 'type' => $type,
  347. 'output' => 'json',
  348. ];
  349. $apiurl .= http_build_query($param);
  350. $request_rs = json_decode(curl_get($apiurl),true);
  351. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  352. if(isset($request_rs['results'][0]['distance']))
  353. {
  354. $result = $request_rs['results'][0]['distance'];
  355. }
  356. }
  357. //dump($result);
  358. return $result;
  359. }
  360. public function distance()
  361. {
  362. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  363. dump($a);
  364. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  365. dump($a);
  366. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  367. dump($b);
  368. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  369. dump($b);
  370. }
  371. //开通守护
  372. public function addguard() {
  373. // 接口防并发
  374. if (!$this->apiLimit(1, 1)) {
  375. $this->error(__('Operation frequently'));
  376. }
  377. $user_id = input('user_id', 0, 'intval');// 守护对象
  378. if (!$user_id) {
  379. $this->error();
  380. }
  381. // 不可以守护给自己
  382. if($this->auth->id == $user_id) {
  383. $this->error("不可以守护自己");
  384. }
  385. //查询是否开通守护
  386. $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  387. if ($count) {
  388. $this->error('已经开通守护了');
  389. }
  390. $giftvalue = config('site.guard_price');
  391. if ($giftvalue <= 0) {
  392. $this->error('守护金额异常~');
  393. }
  394. //被守护人信息
  395. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  396. if (!$touserinfo) {
  397. $this->error("不存在的用户");
  398. }
  399. // 判断当前用户余额
  400. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  401. if($user_gold < $giftvalue) {
  402. $this->error("您的金币不足");
  403. }
  404. Db::startTrans();
  405. // 添加礼物守护记录表
  406. $data = [
  407. 'user_id' => $this->auth->id,
  408. 'user_to_id' => $user_id,
  409. 'price' => $giftvalue,
  410. 'createtime' => time(),
  411. ];
  412. $log_id = Db::name('user_guard')->insertGetId($data);
  413. if(!$log_id){
  414. Db::rollback();
  415. $this->error('守护失败');
  416. }
  417. if($giftvalue > 0){
  418. // 扣除当前用户余额
  419. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
  420. if($wallet_rs['status'] === false){
  421. Db::rollback();
  422. $this->error($wallet_rs['msg']);
  423. }
  424. // 添加守护用户余额
  425. $money_to_gold = config('site.money_to_gold');
  426. $gift_plat_scale = config('site.gift_plat_scale');
  427. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  428. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  429. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
  430. if($wallet_rs['status'] === false){
  431. Db::rollback();
  432. $this->error($wallet_rs['msg']);
  433. }
  434. //增加赠送用户上级余额
  435. if ($touserinfo['intro_uid']) {
  436. //获取返利比率
  437. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  438. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  439. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  440. //上级获得金额
  441. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  442. if ($intro_uid_money > 0) {
  443. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
  444. if($intro_result['status']===false)
  445. {
  446. Db::rollback();
  447. $this->error($intro_result['msg']);
  448. }
  449. }
  450. }
  451. }
  452. }
  453. //tag任务守护金币
  454. //搭讪奖励
  455. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  456. // if($task_rs === false){
  457. // Db::rollback();
  458. // $this->error('完成任务守护奖励失败');
  459. // }
  460. Db::commit();
  461. $this->success('守护成功');
  462. }
  463. //守护列表
  464. public function guardlist(){
  465. $user_id = input('user_id', 0, 'intval');
  466. if (!$user_id) {
  467. $this->error('您的网络开小差啦~');
  468. }
  469. $list = Db::name('user_guard')
  470. ->alias('a')
  471. ->join('user','a.user_id = user.id','LEFT')
  472. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  473. ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
  474. if (!$list) {
  475. $this->success('success', $list);
  476. }
  477. $list = list_domain_image($list,['avatar']);
  478. $time = time();
  479. foreach ($list as &$v) {
  480. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  481. }
  482. $this->success('success',$list);
  483. }
  484. //我的守护
  485. public function myguardlist(){
  486. $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
  487. if (!in_array($type, [1, 2])) {
  488. $this->error('您的网络开小差了');
  489. }
  490. $where = [];
  491. if ($type == 1) {
  492. $join = 'a.user_to_id = user.id';
  493. $where['a.user_id'] = $this->auth->id;
  494. } else {
  495. $join = 'a.user_id = user.id';
  496. $where['a.user_to_id'] = $this->auth->id;
  497. }
  498. $list = Db::name('user_guard')
  499. ->alias('a')
  500. ->join('user',$join,'LEFT')
  501. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  502. ->where($where)->order('a.id desc')->autopage()->select();
  503. if (!$list) {
  504. $this->success('success', $list);
  505. }
  506. $list = list_domain_image($list,['avatar']);
  507. $time = time();
  508. foreach ($list as &$v) {
  509. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  510. }
  511. $this->success('success',$list);
  512. }
  513. //打字聊天每句话调用一次
  514. public function chat_once(){
  515. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  516. $this->success('success',array('money'=>''));
  517. }
  518. if ($this->auth->gender == 0) { //女生不花钱
  519. $this->error('您的网络开小差啦~');
  520. }
  521. //检测用户
  522. $to_user_id = input_post('to_user_id');
  523. $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();
  524. if(!$to_user_info){
  525. $this->error('不存在的用户');
  526. }
  527. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  528. $this->success('success',array('money'=>''));
  529. }
  530. if ($to_user_info['gender'] != 0) {
  531. $this->error('同性不能聊天~');
  532. }
  533. //验证金额
  534. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  535. if ($wallet_info['vip_endtime'] >= time()) { //会员
  536. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  537. //获取折扣
  538. $vip_chat_discount = config('site.vip_chat_discount');
  539. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  540. $price = ceil($price * $vip_chat_discount / 10);
  541. }
  542. } else {
  543. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  544. }
  545. //正常价格
  546. $bili = config('site.money_to_gold'); //兑换比例
  547. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  548. $money = bcdiv($price,$bili,2); //对应人民币
  549. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  550. $resArray['money'] = $money; //返回给前端的计算结果
  551. Db::startTrans();
  552. //记录日志
  553. $data = [
  554. 'user_id' => $this->auth->id,
  555. 'price' => $price,
  556. 'createtime' => time(),
  557. 'to_user_id' => $to_user_id,
  558. 'money' => $money,
  559. ];
  560. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  561. if(!$log_id){
  562. Db::rollback();
  563. $this->error('扣费失败');
  564. }
  565. //有性别差,扣费
  566. if($price > 0){
  567. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
  568. if($rs['status'] === false){
  569. Db::rollback();
  570. $this->error($rs['msg']);
  571. }
  572. }
  573. //另一方加钱,0收费
  574. if($money > 0){
  575. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
  576. if($rs['status'] === false){
  577. Db::rollback();
  578. $this->error($rs['msg']);
  579. }
  580. $touserinfo = $to_user_info;
  581. //增加赠送用户上级余额
  582. if ($touserinfo['intro_uid']) {
  583. //获取返利比率
  584. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  585. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  586. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  587. //上级获得金额
  588. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  589. if ($intro_uid_money > 0) {
  590. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
  591. if($intro_result['status']===false)
  592. {
  593. Db::rollback();
  594. $this->error($intro_result['msg']);
  595. }
  596. }
  597. }
  598. }
  599. }
  600. //增加亲密度
  601. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  602. if (!$user_intimacy_rs['status']) {
  603. Db::rollback();
  604. $this->error('您的网络开小差啦~');
  605. }
  606. //tag任务赠送金币
  607. //私信5名异性奖励
  608. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  609. if($task_rs === false){
  610. Db::rollback();
  611. $this->error('完成任务赠送奖励失败');
  612. }
  613. /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
  614. if($task_rs === false){
  615. Db::rollback();
  616. $this->error('完成任务赠送奖励失败');
  617. }*/
  618. Db::commit();
  619. //发送消息
  620. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  621. $tenim = new \app\api\controller\Tenim;
  622. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  623. }
  624. $this->success('success',$resArray);
  625. }
  626. //语音通话每分钟调用一次
  627. public function voice_onemin(){
  628. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  629. $this->success('success');
  630. }
  631. if ($this->auth->gender == 0) { //女生不花钱
  632. $this->error('您的网络开小差啦~');
  633. }
  634. //检测用户
  635. $to_user_id = input_post('to_user_id');
  636. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  637. $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();
  638. if(!$to_user_info){
  639. $this->error('不存在的用户');
  640. }
  641. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  642. $this->success('success');
  643. }
  644. if ($to_user_info['gender'] != 0) {
  645. $this->error('同性不能聊天~');
  646. }
  647. //验证金额
  648. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  649. if ($wallet_info['vip_endtime'] >= time()) { //会员
  650. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  651. //获取折扣
  652. $vip_video_discount = config('site.vip_video_discount');
  653. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  654. $price = ceil($price * $vip_video_discount / 10);
  655. }
  656. } else {
  657. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  658. }
  659. //正常价格
  660. $bili = config('site.money_to_gold'); //兑换比例
  661. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  662. $money = bcdiv($price,$bili,2); //对应人民币
  663. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  664. Db::startTrans();
  665. //查询是否有匹配记录
  666. $user_match_audio_log_info = [];
  667. if ($request_id) {
  668. $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();
  669. }
  670. if ($user_match_audio_log_info) {
  671. //修改记录日志
  672. $data = [
  673. 'price' => $user_match_audio_log_info['price'] + $price,
  674. 'createtime' => time(),
  675. 'money' => $user_match_audio_log_info['money'] + $money,
  676. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  677. ];
  678. $log_rs = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id'], 'createtime' => $user_match_audio_log_info['createtime']])->setField($data);
  679. if (!$log_rs) {
  680. Db::rollback();
  681. $this->error('扣费失败');
  682. }
  683. $log_id = $user_match_audio_log_info['id'];
  684. } else {
  685. //添加记录日志
  686. $data = [
  687. 'user_id' => $this->auth->id,
  688. 'price' => $price,
  689. 'createtime' => time(),
  690. 'to_user_id' => $to_user_id,
  691. 'money' => $money,
  692. 'request_id' => $request_id,
  693. 'call_minutes' => 1
  694. ];
  695. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  696. if (!$log_id) {
  697. Db::rollback();
  698. $this->error('扣费失败');
  699. }
  700. }
  701. //有性别差,扣费
  702. if($price > 0){
  703. $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);
  704. if($rs['status'] === false){
  705. Db::rollback();
  706. $this->error($rs['msg']);
  707. }
  708. }
  709. //另一方加钱,0收费
  710. if($money > 0){
  711. $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);
  712. if($rs['status'] === false){
  713. Db::rollback();
  714. $this->error($rs['msg']);
  715. }
  716. $touserinfo = $to_user_info;
  717. //增加赠送用户上级余额
  718. if ($touserinfo['intro_uid']) {
  719. //获取返利比率
  720. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  721. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  722. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  723. //上级获得金额
  724. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  725. if ($intro_uid_money > 0) {
  726. $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);
  727. if($intro_result['status']===false)
  728. {
  729. Db::rollback();
  730. $this->error($intro_result['msg']);
  731. }
  732. }
  733. }
  734. }
  735. }
  736. //增加亲密度
  737. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  738. if (!$user_intimacy_rs['status']) {
  739. Db::rollback();
  740. $this->error('您的网络开小差啦~');
  741. }
  742. //tag任务赠送金币
  743. //与1名异性语音通话奖励
  744. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
  745. if($task_rs === false){
  746. Db::rollback();
  747. $this->error('完成任务赠送奖励失败');
  748. }
  749. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
  750. if($task_rs === false){
  751. Db::rollback();
  752. $this->error('完成任务赠送奖励失败');
  753. }
  754. //发送消息
  755. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  756. $tenim = new \app\api\controller\Tenim;
  757. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  758. }
  759. Db::commit();
  760. $this->success('success');
  761. }
  762. //视频通话每分钟调用一次
  763. public function videochat_onemin(){
  764. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  765. $this->success('success');
  766. }
  767. if ($this->auth->gender == 0) { //女生不花钱
  768. $this->error('您的网络开小差啦~');
  769. }
  770. //检测用户
  771. $to_user_id = input_post('to_user_id');
  772. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  773. $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();
  774. if(!$to_user_info){
  775. $this->error('不存在的用户');
  776. }
  777. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  778. $this->success('success');
  779. }
  780. if ($to_user_info['gender'] != 0) {
  781. $this->error('同性不能聊天~');
  782. }
  783. /* //检查是否免费过
  784. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  785. if (!$count) {
  786. //记录日志
  787. $data = [
  788. 'user_id' => $this->auth->id,
  789. 'price' => 0,
  790. 'createtime' => time(),
  791. 'to_user_id' => $to_user_id,
  792. 'money' => 0,
  793. ];
  794. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  795. if(!$log_id){
  796. $this->error('扣费失败');
  797. }
  798. $this->success('success');
  799. }*/
  800. //验证金额
  801. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  802. if ($wallet_info['vip_endtime'] >= time()) { //会员
  803. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  804. //获取折扣
  805. $vip_video_discount = config('site.vip_video_discount');
  806. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  807. $price = ceil($price * $vip_video_discount / 10);
  808. }
  809. } else {
  810. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  811. }
  812. //正常价格
  813. $bili = config('site.money_to_gold'); //兑换比例
  814. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  815. $money = bcdiv($price,$bili,2); //对应人民币
  816. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  817. Db::startTrans();
  818. //查询是否有匹配记录
  819. $user_match_video_log_info = [];
  820. if ($request_id) {
  821. $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();
  822. }
  823. if ($user_match_video_log_info) {
  824. //修改记录日志
  825. $data = [
  826. 'price' => $user_match_video_log_info['price'] + $price,
  827. 'createtime' => time(),
  828. 'money' => $user_match_video_log_info['money'] + $money,
  829. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  830. ];
  831. $log_rs = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id'], 'createtime' => $user_match_video_log_info['createtime']])->setField($data);
  832. if (!$log_rs) {
  833. Db::rollback();
  834. $this->error('扣费失败');
  835. }
  836. $log_id = $user_match_video_log_info['id'];
  837. } else {
  838. //添加记录日志
  839. $data = [
  840. 'user_id' => $this->auth->id,
  841. 'price' => $price,
  842. 'createtime' => time(),
  843. 'to_user_id' => $to_user_id,
  844. 'money' => $money,
  845. 'request_id' => $request_id,
  846. 'call_minutes' => 1
  847. ];
  848. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  849. if (!$log_id) {
  850. Db::rollback();
  851. $this->error('扣费失败');
  852. }
  853. }
  854. //有性别差,扣费
  855. if($price > 0){
  856. $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);
  857. if($rs['status'] === false){
  858. Db::rollback();
  859. $this->error($rs['msg']);
  860. }
  861. }
  862. //另一方加钱,0收费
  863. if($money > 0){
  864. $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);
  865. if($rs['status'] === false){
  866. Db::rollback();
  867. $this->error($rs['msg']);
  868. }
  869. $touserinfo = $to_user_info;
  870. //增加赠送用户上级余额
  871. if ($touserinfo['intro_uid']) {
  872. //获取返利比率
  873. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  874. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  875. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  876. //上级获得金额
  877. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  878. if ($intro_uid_money > 0) {
  879. $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);
  880. if($intro_result['status']===false)
  881. {
  882. Db::rollback();
  883. $this->error($intro_result['msg']);
  884. }
  885. }
  886. }
  887. }
  888. }
  889. //增加亲密度
  890. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  891. if (!$user_intimacy_rs['status']) {
  892. Db::rollback();
  893. $this->error('您的网络开小差啦~');
  894. }
  895. //tag任务赠送金币
  896. //与1名异性视频通话奖励
  897. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
  898. if($task_rs === false){
  899. Db::rollback();
  900. $this->error('完成任务赠送奖励失败');
  901. }
  902. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
  903. if($task_rs === false){
  904. Db::rollback();
  905. $this->error('完成任务赠送奖励失败');
  906. }
  907. Db::commit();
  908. //发送消息
  909. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  910. $tenim = new \app\api\controller\Tenim;
  911. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  912. }
  913. $this->success('success');
  914. }
  915. //消息列表好友/密友
  916. public function intimacyfriends() {
  917. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  918. $where = [];
  919. /*if ($type == 0) {
  920. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  921. $mt_user = Db::name('user');
  922. // $mt_user_follow = Db::name('user_follow');
  923. $mt_user_intimacy = Db::name('user_intimacy');
  924. foreach ($list as &$v) {
  925. //查询亲密度
  926. if ($this->auth->gender == 1) {
  927. $where['uid'] = $this->auth->id;
  928. $where['other_uid'] = $v['user_id'];
  929. } else {
  930. $where['other_uid'] = $this->auth->id;
  931. $where['uid'] = $v['user_id'];
  932. }
  933. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  934. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  935. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  936. //查询对方信息
  937. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  938. $v['nickname'] = $user_info['nickname'];
  939. $v['avatar'] = one_domain_image($user_info['avatar']);
  940. $v['updatetime'] = get_last_time($v['updatetime']);
  941. $v['age'] = birthtime_to_age($user_info['birthday']);
  942. $v['gender'] = $user_info['gender'];
  943. $v['real_status'] = $user_info['real_status'];
  944. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  945. $v['status'] = 1;
  946. }
  947. } else {*/
  948. if ($this->auth->gender == 1) {
  949. $where['uid'] = $this->auth->id;
  950. $field = 'other_uid user_id, value, updatetime';
  951. } else {
  952. $where['other_uid'] = $this->auth->id;
  953. $field = 'uid user_id, value, updatetime';
  954. }
  955. if ($type == 1) { //密友
  956. $where['value'] = ['egt', 1000];
  957. } elseif ($type == 2) { //好友
  958. $where['value'] = ['egt', 100];
  959. } else { //消息列表好友
  960. $where['value'] = ['egt', 10];
  961. }
  962. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  963. $mt_user = Db::name('user');
  964. $mt_user_follow = Db::name('user_follow');
  965. foreach ($list as &$v) {
  966. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  967. $v['nickname'] = $user_info['nickname'];
  968. $v['avatar'] = one_domain_image($user_info['avatar']);
  969. $v['updatetime'] = get_last_time($v['updatetime']);
  970. $v['age'] = birthtime_to_age($user_info['birthday']);
  971. $v['gender'] = $user_info['gender'];
  972. $v['real_status'] = $user_info['real_status'];
  973. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  974. $v['is_active'] = $user_info['is_active'];
  975. }
  976. // }
  977. $this->success('success',$list);
  978. }
  979. //消息列表通话
  980. public function calllist() {
  981. if ($this->auth->gender == 1) {
  982. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
  983. } elseif ($this->auth->gender == 0) {
  984. $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
  985. } else {
  986. $this->success('success', []);
  987. }
  988. if (!$list) {
  989. $this->success('success', $list);
  990. }
  991. $arr = [];
  992. $mt_user_match_audio_log = Db::name('user_match_audio_log');
  993. $mt_user_match_video_log = Db::name('user_match_video_log');
  994. $mt_user = Db::name('user');
  995. foreach ($list as &$v) {
  996. $data = [];
  997. if ($this->auth->gender == 1) {
  998. if ($v['log_type'] == 11) { //视频通话
  999. $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1000. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1001. } else { //语音通话
  1002. $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1003. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1004. }
  1005. } else {
  1006. if ($v['log_type'] == 21) { //视频通话
  1007. $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1008. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1009. } else { //语音通话
  1010. $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1011. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1012. }
  1013. }
  1014. $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
  1015. $data['user_id'] = $log_info['user_id'];
  1016. $data['nickname'] = $user_info['nickname'];
  1017. $data['avatar'] = one_domain_image($user_info['avatar']);
  1018. $data['createtime'] = get_last_time($log_info['createtime']);
  1019. $data['is_active'] = $user_info['is_active'];
  1020. $arr[] = $data;
  1021. }
  1022. $this->success('success', $arr);
  1023. }
  1024. //查询对方用户收费价格和我的余额
  1025. public function otheruserinfo(){
  1026. $user_id = input('user_id', 0, 'intval');
  1027. if (!$user_id) {
  1028. $this->error('您的网络开小差啦~');
  1029. }
  1030. $field = [
  1031. 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
  1032. ];
  1033. $info = Db::name('user')->field($field)->where('id',$user_id)->find();
  1034. if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
  1035. if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
  1036. $this->error('性别存在问题');
  1037. }
  1038. }
  1039. if ($this->auth->gender == 0) { //收费价格按照女号
  1040. $info['chat_price'] = $this->auth->chat_price;
  1041. $info['voice_price'] = $this->auth->voice_price;
  1042. $info['video_price'] = $this->auth->video_price;
  1043. $info['open_match_audio'] = $this->auth->open_match_audio;
  1044. $info['open_match_video'] = $this->auth->open_match_video;
  1045. }
  1046. $info['chat_price_vip'] = $info['chat_price']; //vip价格
  1047. $info['voice_price_vip'] = $info['voice_price'];
  1048. $info['video_price_vip'] = $info['video_price'];
  1049. $info['is_vip'] = 0; //是否vip: 0否 1是
  1050. //获取聊天折扣
  1051. $vip_chat_discount = config('site.vip_chat_discount');
  1052. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1053. $info['vip_chat_discount'] = $vip_chat_discount;
  1054. } else {
  1055. $info['vip_chat_discount'] = 10;
  1056. }
  1057. //获取语音视频折扣
  1058. $vip_video_discount = config('site.vip_video_discount');
  1059. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1060. $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
  1061. $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
  1062. } else {
  1063. $info['vip_voice_discount'] = 10;
  1064. $info['vip_video_discount'] = 10;
  1065. }
  1066. //获取聊天折扣
  1067. $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
  1068. //获取语音折扣
  1069. $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
  1070. //获取视频折扣
  1071. $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
  1072. if ($this->auth->gender == 0) { //查询男号余额和vip
  1073. $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
  1074. } else {
  1075. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1076. }
  1077. if ($wallet_info['vip_endtime'] >= time()) {
  1078. $info['is_vip'] = 1;
  1079. }
  1080. $info['gold'] = $wallet_info['gold'];
  1081. $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
  1082. $info['money_to_gold'] = config('site.money_to_gold'); //
  1083. $this->success('success',$info);
  1084. }
  1085. //亲密度等级信息
  1086. public function intimacylevel() {
  1087. $user_id = input('user_id', 0, 'intval'); //对方id
  1088. if (!$user_id) {
  1089. $this->error('参数缺失');
  1090. }
  1091. if ($this->auth->gender == 0) { //女用户
  1092. $where['uid'] = $user_id;
  1093. $where['other_uid'] = $this->auth->id;
  1094. } else { //男用户
  1095. $where['uid'] = $this->auth->id;
  1096. $where['other_uid'] = $user_id;
  1097. }
  1098. $level = 0; //当前等级
  1099. $level_name = ''; //当前等级名称
  1100. $qinmi_sum = 0; //当前亲密度
  1101. $next_level_diff = 0; //距下一等级亲密度差值
  1102. //亲密度等级列表
  1103. $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
  1104. //当前亲密度信息
  1105. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  1106. if ($user_intimacy_info) {
  1107. //当前亲密度
  1108. $qinmi_sum = $user_intimacy_info['value'];
  1109. if ($list) {
  1110. //当前等级信息
  1111. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
  1112. if ($level_info) {
  1113. $level = $level_info['level'];
  1114. $level_name = $level_info['name'];
  1115. }
  1116. //下一等级信息
  1117. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  1118. if ($next_level_info) {
  1119. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  1120. }
  1121. }
  1122. } else {
  1123. $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
  1124. }
  1125. if ($list) {
  1126. foreach ($list as &$v) {
  1127. if ($v['level'] < $level) {
  1128. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  1129. } elseif ($v['level'] == $level) {
  1130. $v['is_unlock'] = 2;
  1131. } else {
  1132. $v['is_unlock'] = 3;
  1133. }
  1134. }
  1135. }
  1136. $data['level'] = $level; //当前等级
  1137. $data['level_name'] = $level_name; //当前等级名称
  1138. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  1139. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  1140. $data['level_list'] = $list; //等级列表
  1141. $this->success('亲密度等级信息', $data);
  1142. }
  1143. //语音视频随聊
  1144. public function getrandomuser() {
  1145. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1146. if (!in_array($type, [1, 2, 3])) {
  1147. $this->error('您的网络开小差了');
  1148. }
  1149. $size = input('size',0,'intval');// 是否查 10 条
  1150. $size = $size > 0 ? 1 : 0;
  1151. //给出备选用户
  1152. $map = [
  1153. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1154. 'is_active' => 1, //在线的
  1155. 'status' =>1, //未封禁用户
  1156. 'is_kefu' => 0, //不是客服
  1157. ];
  1158. if ($this->auth->gender == 1) {
  1159. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1160. }
  1161. if ($type == 1) {
  1162. $map['open_match_audio'] = 1;
  1163. } elseif ($type == 2) {
  1164. $map['open_match_video'] = 1;
  1165. }
  1166. $key = md5(json_encode($map));// 根据搜索条件做Key
  1167. $lists = Cache::remember("getrandomuser_{$key}_{$size}",function () use ($map,$size){
  1168. $query = Db::name('user')
  1169. ->field('id,nickname,username,avatar')
  1170. ->where($map)
  1171. ->order('is_active desc, logintime desc');
  1172. if ($size == 1){
  1173. $query->limit(10);
  1174. }else{
  1175. $query->page($this->page,100);
  1176. }
  1177. $lists = $query->select();
  1178. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1179. $mt_user_greet_content = Db::name('user_greet_content');
  1180. foreach ($lists as &$v) {
  1181. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1182. if ($info) {
  1183. if ($info['type'] == 0) {
  1184. $v['greet_content'] = $info['content'];
  1185. } elseif ($info['type'] == 1) {
  1186. $v['greet_content'] = '[语音]';
  1187. } elseif ($info['type'] == 2) {
  1188. $v['greet_content'] = '[图片]';
  1189. }
  1190. } else {
  1191. $v['greet_content'] = '';
  1192. }
  1193. }
  1194. return $lists;
  1195. },2);
  1196. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1197. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1198. $return_data['list'] = $lists;
  1199. $this->success('success',$return_data);
  1200. }
  1201. //查询免费体验视频通话用户信息
  1202. public function getfreevideouserinfo() {
  1203. $to_user_id = input('to_user_id', 0, 'intval');
  1204. $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
  1205. if(!$to_user_info){
  1206. $this->error('不存在的用户');
  1207. }
  1208. if ($to_user_info['gender'] == $this->auth->gender) {
  1209. $this->error('同性不能聊天~');
  1210. }
  1211. $to_user_info['desc'] = '';
  1212. $age = birthtime_to_age($to_user_info['birthday']);
  1213. if ($age > 0) {
  1214. $to_user_info['desc'] = $age . '岁';
  1215. } else {
  1216. $to_user_info['desc'] = '18岁';
  1217. }
  1218. if ($to_user_info['height']) {
  1219. $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
  1220. }
  1221. //查询是否免费过
  1222. $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1223. $this->success('信息', $to_user_info);
  1224. }
  1225. //免费体验视频通话1分钟
  1226. public function videochat_onemin_free(){
  1227. $this->success('success');
  1228. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1229. $this->success('success');
  1230. }
  1231. //检查是否免费过
  1232. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1233. if ($count) {
  1234. $this->error('已经免费体验过');
  1235. }
  1236. //检测用户
  1237. $to_user_id = input_post('to_user_id');
  1238. $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();
  1239. if(!$to_user_info){
  1240. $this->error('不存在的用户');
  1241. }
  1242. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1243. $this->success('success');
  1244. }
  1245. if ($to_user_info['gender'] == $this->auth->gender) {
  1246. $this->error('同性不能聊天~');
  1247. }
  1248. //记录日志
  1249. $data = [
  1250. 'user_id' => $this->auth->id,
  1251. 'price' => 0,
  1252. 'createtime' => time(),
  1253. 'to_user_id' => $to_user_id,
  1254. 'money' => 0,
  1255. ];
  1256. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1257. if(!$log_id){
  1258. $this->error('扣费失败');
  1259. }
  1260. $this->success('success');
  1261. }
  1262. //男性非会员解锁聊天
  1263. public function unlockchat() {
  1264. }
  1265. }