Usercenter.php 53 KB

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