Usercenter.php 54 KB

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