Usercenter.php 57 KB

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