Usercenter.php 57 KB

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