Usercenter.php 57 KB

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