Usercenter.php 59 KB

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