Usercenter.php 53 KB

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