Usercenter.php 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Cache;
  5. use think\Db;
  6. use app\common\model\wallet;
  7. use Redis;
  8. /**
  9. * 会员中心,不是个人中心
  10. */
  11. class Usercenter extends Api
  12. {
  13. protected $noNeedLogin = ['test','testredis'];
  14. protected $noNeedRight = '*';
  15. protected $allowFields = [
  16. 'id',
  17. 'username',
  18. 'nickname',
  19. //'truename',//
  20. 'email',
  21. 'mobile',
  22. 'avatar',
  23. 'real_status',
  24. 'gender',
  25. 'height',
  26. 'weight',
  27. 'birthday',
  28. 'bio',
  29. 'audio_bio',
  30. 'idcard_status',
  31. 'is_active',
  32. 'longitude',
  33. 'latitude',
  34. 'cityname',
  35. 'photo_images',
  36. 'education_id',
  37. 'hobby_ids',
  38. 'job_id',
  39. 'marital_id',
  40. 'tag_ids',
  41. 'wages_id',
  42. 'hometown_cityid',
  43. 'wechat_account',
  44. 'secretvideo_status',
  45. 'character_id',
  46. 'constellation_id',
  47. 'stature_id',
  48. 'is_appointment',
  49. 'chat_price',
  50. 'voice_price',
  51. 'video_price',
  52. 'greet_voice',
  53. 'greet_chat',
  54. 'is_kefu',
  55. 'is_hideaddress', 'is_recommend','is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'
  56. ];
  57. public function testredis(){
  58. //redis_matching_set(1,125);
  59. dump(redis_matching_get(1));
  60. $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
  61. dump($a);
  62. }
  63. public function test(){
  64. $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
  65. $b = [1,10,7,102];
  66. $c = [10,102];
  67. //dump(array_intersect($a,$b));
  68. $data = array_merge($c,$b);
  69. dump($data);
  70. dump(array_flip(array_flip($data)));
  71. dump(array_flip([]));
  72. }
  73. //获取他人用户信息,留下足迹
  74. public function getuserinfo(){
  75. $uid = input_post('uid',0);
  76. $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
  77. if(!$userinfo){
  78. $this->error('不存在的用户');
  79. }
  80. //用户数据
  81. $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
  82. $new_data = [
  83. 'age' => birthtime_to_age($userinfo['birthday']),
  84. ];
  85. if ($this->auth->gender == 1) {
  86. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $this->auth->id, 'other_uid' => $uid])->value('value');
  87. } elseif ($this->auth->gender == 0) {
  88. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $this->auth->id])->value('value');
  89. } else {
  90. $qinmi_sum = 0;
  91. }
  92. $new_data['qinmi_sum'] = $qinmi_sum ? :0;
  93. //合并
  94. $userinfo = array_merge($userinfo,$new_data);
  95. //枚举
  96. $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
  97. $userinfo['education'] = $userinfo['education'] ? : '';
  98. $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
  99. $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
  100. $userinfo['job'] = $userinfo['job'] ? : '';
  101. $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
  102. $userinfo['marital'] = $userinfo['marital'] ? : '';
  103. $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
  104. $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
  105. $userinfo['wages'] = $userinfo['wages'] ? : '';
  106. $userinfo['character'] = Db::name('enum_character')->where('id',$userinfo['character_id'])->value('name');
  107. $userinfo['character'] = $userinfo['character'] ? : '';
  108. $userinfo['constellation'] = Db::name('enum_constellation')->where('id',$userinfo['constellation_id'])->value('name');
  109. $userinfo['constellation'] = $userinfo['constellation'] ? : '';
  110. $userinfo['stature'] = Db::name('enum_stature')->where('id',$userinfo['stature_id'])->value('name');
  111. $userinfo['stature'] = $userinfo['stature'] ? : '';
  112. $userinfo['live'] = Db::name('enum_live')->where('id',$userinfo['live_id'])->value('name');
  113. $userinfo['live'] = $userinfo['live'] ? : '';
  114. $userinfo['car'] = Db::name('enum_car')->where('id',$userinfo['car_id'])->value('name');
  115. $userinfo['car'] = $userinfo['car'] ? : '';
  116. $userinfo['chest'] = Db::name('enum_chest')->where('id',$userinfo['chest_id'])->value('name');
  117. $userinfo['chest'] = $userinfo['chest'] ? : '';
  118. //家乡
  119. $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
  120. $userinfo['hometown_city'] = ($userinfo['hometown_city'] && $userinfo['is_hideaddress'] == 0) ? $userinfo['hometown_city'] : '';
  121. //vip
  122. $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
  123. $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
  124. //是否喜欢和关注
  125. $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
  126. $userinfo['is_follow'] = $is_follow ? 1 : 0;
  127. $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
  128. $userinfo['is_like'] = $is_like ? 1 : 0;
  129. //是否拉黑
  130. $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
  131. $userinfo['is_black'] = $is_black ? 1 : 0;
  132. //关注人数,粉丝人数
  133. $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
  134. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
  135. $userinfo['follow_num'] = $follow_num;
  136. $userinfo['fans_num'] = $fans_num;
  137. //访客数
  138. $visit_num = Db::name('user_visit')->where(['to_uid'=>$this->auth->id])->count('id');
  139. $userinfo['visit_num'] = $visit_num;
  140. //查询是否打过招呼
  141. $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  142. if ($count) {
  143. $userinfo['is_chat'] = 1; //是否打过招呼: 1是 0否
  144. } else {
  145. $userinfo['is_chat'] = 0; //是否打过招呼: 1是 0否
  146. }
  147. //守护数量和是否已经守护
  148. $userinfo['guard_num'] = Db::name('user_guard')->where(['user_to_id' => $uid])->count('id');
  149. $userinfo['is_guard'] = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  150. //查询财富等级和魅力等级
  151. $wallet_info = Db::name('user_wallet')->where(['user_id' => $uid])->find();
  152. $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  153. if ($wealth_level) {
  154. $userinfo['wealth_level'] = localpath_to_netpath($wealth_level['image']);
  155. } else {
  156. $userinfo['wealth_level'] = '';
  157. }
  158. $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  159. if ($charm_level) {
  160. $userinfo['charm_level'] = localpath_to_netpath($charm_level['image']);
  161. } else {
  162. $userinfo['charm_level'] = '';
  163. }
  164. //开通守护消耗金币数量
  165. $userinfo['guard_price'] = config('site.guard_price') ? : 0;
  166. //男性非会员是否已开通聊天
  167. // $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  168. // $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  169. // if ($this->auth->gender == 0 || $vip_endtime > time() || $user_chat_unlock) {
  170. $userinfo['is_chat_unlock'] = 1; //已解锁
  171. // } else {
  172. // $userinfo['is_chat_unlock'] = 0;
  173. // }
  174. //男性非会员解锁聊天所需金币数量
  175. $userinfo['unlock_chat_gold'] = config('site.unlock_chat_gold') > 0 ? config('site.unlock_chat_gold') : 10;
  176. //动态信息
  177. $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();
  178. if ($dongtai) {
  179. $dongtai_image = [];
  180. foreach ($dongtai as &$v) {
  181. $arr['type'] = $v['type'];
  182. if ($v['type'] == 1) {
  183. //图片
  184. $images_url = explode(',', $v['images']);
  185. foreach ($images_url as &$value) {
  186. $arr['images'] = one_domain_image($value);
  187. array_push($dongtai_image, $arr);
  188. if (count($dongtai_image) == 3) {
  189. break 2;
  190. }
  191. }
  192. } else {
  193. //视频
  194. $images_url = explode('.', $v['images']);
  195. unset($images_url[count($images_url) - 1]);
  196. $arr['images'] = join('.', $images_url) . '_0.jpg';
  197. $arr['images'] = one_domain_image($arr['images']);
  198. array_push($dongtai_image, $arr);
  199. if (count($dongtai_image) == 3) {
  200. break;
  201. }
  202. }
  203. }
  204. $userinfo['dongtai_image'] = $dongtai_image;
  205. // $dongtai = join(',', $dongtai);
  206. // $dongtai = explode(',', $dongtai);
  207. // $dongtai = array_slice($dongtai, 0, 3);
  208. // $dongtai = join(',', $dongtai);
  209. // $userinfo['dongtai_image'] = one_domain_image($dongtai);
  210. // $userinfo['dongtai_image'] = explode(',', $userinfo['dongtai_image']);
  211. } else {
  212. $userinfo['dongtai_image'] = [];
  213. }
  214. if ($this->auth->id != $uid) {
  215. //查看别人信息,就要留下痕迹
  216. $data = [
  217. 'uid' => $this->auth->id,
  218. 'to_uid' => $uid,
  219. ];
  220. $check = Db::name('user_visit')->where($data)->find();
  221. if ($check) {
  222. Db::name('user_visit')->where($data)->update(['number' => $check['number'] + 1, 'updatetime' => time()]);
  223. } else {
  224. $data['number'] = 1;
  225. $data['updatetime'] = time();
  226. Db::name('user_visit')->insertGetId($data);
  227. }
  228. }
  229. //礼物墙
  230. $userinfo['gift_wall'] = $this->giftwall($uid);
  231. $this->success('success',$userinfo);
  232. }
  233. //某用户的礼物墙
  234. private function giftwall($uid){
  235. //$uid = $this->auth->id;
  236. //聊天礼物
  237. $gift_user_typing = Db::name('gift_user_typing')->alias('log')
  238. ->join('gift', 'gift.id = log.gift_id', 'LEFT')
  239. ->field('log.gift_id,log.gift_name,sum(log.number) as number,gift.image')
  240. ->where(['log.user_to_id' => $uid])
  241. ->group('log.gift_id')
  242. ->order('gift.price desc')
  243. ->column('log.gift_id,log.gift_name,sum(log.number) as number,gift.image');
  244. $gift_user_typing = list_domain_image($gift_user_typing,['image']);
  245. //dump($gift_user_typing);
  246. //动态礼物
  247. $gift_user_dongtai = Db::name('gift_user_dongtai')->alias('log')
  248. ->join('gift', 'gift.id = log.gift_id', 'LEFT')
  249. ->field('log.gift_id,log.gift_name,sum(log.number) as number,gift.image')
  250. ->where(['log.user_to_id' => $uid])
  251. ->group('log.gift_id')
  252. ->order('gift.price desc')
  253. ->column('log.gift_id,log.gift_name,sum(log.number) as number,gift.image');
  254. $gift_user_dongtai = list_domain_image($gift_user_dongtai,['image']);
  255. //dump($gift_user_dongtai);
  256. //为空
  257. if(empty($gift_user_typing) && empty($gift_user_dongtai)){
  258. return [];
  259. }
  260. if(empty($gift_user_typing) && !empty($gift_user_dongtai)){
  261. return $gift_user_dongtai;
  262. }
  263. if(!empty($gift_user_typing) && empty($gift_user_dongtai)){
  264. return $gift_user_typing;
  265. }
  266. //合并
  267. foreach($gift_user_typing as $key => $val){
  268. foreach($gift_user_dongtai as $k => $v){
  269. if($key == $k){
  270. $gift_user_typing[$key]['number'] += $v['number'];
  271. }
  272. if(!isset($gift_user_typing[$k])){
  273. $gift_user_typing[$k] = $v;
  274. }
  275. }
  276. }
  277. //dump($gift_user_typing);
  278. //结果
  279. $result = [];
  280. foreach($gift_user_typing as $key => $val){
  281. $result[] = $val;
  282. }
  283. return $result;
  284. }
  285. //这里不用连user_active表,完全使用user表的active_time,user_active表只做离线用
  286. //同城
  287. public function samecity(){
  288. $gender = input_post('gender','all');
  289. $agemin = input_post('agemin',0);
  290. $agemax = input_post('agemax',100);
  291. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  292. // $this->success('success',[]);
  293. }
  294. $map = [
  295. 'user.status' => 1,
  296. // 'user.cityname' => $this->auth->cityname,
  297. 'user.id' => ['neq',$this->auth->id],
  298. // 'user.longitude' => ['neq',''],
  299. // 'user.latitude' => ['neq',''],
  300. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  301. 'user.active_time' => ['gt',time()-86400],
  302. ];
  303. if($gender != 'all'){
  304. $map['user.gender'] = $gender;
  305. }
  306. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  307. //dump($map);
  308. $field = [
  309. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
  310. ];
  311. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
  312. //dump($list);
  313. $list = list_domain_image($list,['avatar']);
  314. foreach($list as $key => $one){
  315. $one['age'] = birthtime_to_age($one['birthday']);
  316. // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  317. $one['distance'] = rand(0,10).'km';
  318. //状态
  319. $one['active_text'] = '刚刚离线';
  320. if($one['active_time'] > time()-21600){
  321. $one['active_text'] = '1小时内在线';
  322. }
  323. if($one['active_time'] > time()-3600){
  324. $one['active_text'] = '在线';
  325. }
  326. $list[$key] = $one;
  327. }
  328. $this->success('success',$list);
  329. }
  330. //附近
  331. public function nearuser(){
  332. $gender = input_post('gender','all');
  333. $agemin = input_post('agemin',0);
  334. $agemax = input_post('agemax',100);
  335. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  336. // $this->success('success',[]);
  337. }
  338. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  339. $map = [
  340. 'user.status' => 1,
  341. ////'user.cityname' => $this->auth->cityname,
  342. 'user.id' => ['neq',$this->auth->id],
  343. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  344. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  345. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  346. 'user.active_time' => ['gt',time()-86400],
  347. ];
  348. if($gender != 'all'){
  349. $map['user.gender'] = $gender;
  350. }
  351. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  352. //dump($map);
  353. $field = [
  354. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
  355. ];
  356. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
  357. //dump($list);exit;
  358. $list = list_domain_image($list,['avatar']);
  359. foreach($list as $key => $one){
  360. $one['age'] = birthtime_to_age($one['birthday']);
  361. //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  362. $one['distance'] = rand(0,10).'km';
  363. //状态
  364. $one['active_text'] = '刚刚离线';
  365. if($one['active_time'] > time()-21600){
  366. $one['active_text'] = '1小时内在线';
  367. }
  368. if($one['active_time'] > time()-3600){
  369. $one['active_text'] = '在线';
  370. }
  371. $list[$key] = $one;
  372. }
  373. $this->success('success',$list);
  374. }
  375. //因为接受者拿不到发起者的uid,废弃了
  376. //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
  377. public function video_audio_moneycheck(){
  378. //检测用户,发起方的uid
  379. $to_user_id = input_post('from_user_id');
  380. $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
  381. if(!$to_user_info){
  382. $this->error('不存在的用户');
  383. }
  384. //扣费金币
  385. $type = input_post('type','video'); //类型
  386. $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
  387. //发起用户的分数,被发起用户的分数。按性别给分
  388. $auth_level = 0;
  389. $tous_level = 0;
  390. //打分
  391. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  392. $auth_level = 30;//实名女最高
  393. }
  394. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  395. $auth_level = 20;//未实名女次之
  396. }
  397. if($this->auth->gender == 1){
  398. $auth_level = 10;//男性最低
  399. }
  400. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  401. $tous_level = 30;
  402. }
  403. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  404. $tous_level = 20;
  405. }
  406. if($to_user_info['gender'] == 1){
  407. $tous_level = 10;
  408. }
  409. //同性不收钱
  410. //都是男的,不扣钱
  411. //都是实名认证的女性,不扣钱
  412. //都是未实名认证的女性,不扣钱
  413. if($auth_level == $tous_level){
  414. $price = 0;
  415. $this->success('success');
  416. }
  417. //扣钱uid,收钱uid,收钱free_video
  418. //分数少扣钱,分数多收益
  419. if($auth_level < $tous_level){
  420. $kou_user = $this->auth->id;
  421. }else{
  422. $kou_user = $to_user_info['id'];
  423. }
  424. //需要扣我的(接收方的)钱,判断钱是否够
  425. if($price > 0 && $kou_user == $this->auth->id){
  426. Db::startTrans();
  427. $gold = model('wallet')->getWallet($kou_user,'gold');
  428. if(bccomp($price,$gold) == 1){
  429. Db::rollback();
  430. $this->error('金币不足');
  431. }
  432. Db::commit();
  433. }
  434. $this->success('success');
  435. }
  436. //语音匹配
  437. public function getaudiouser(){
  438. //判断资格
  439. /*$start = strtotime(date('Y-m-d'));
  440. $end = $start + 86399;
  441. $map = [
  442. 'user_id' => $this->auth->id,
  443. 'createtime' => ['between',[$start,$end]],
  444. 'price' => 0,
  445. ];
  446. $check = Db::name('user_match_audio_log')->where($map)->find();*/
  447. $check = true;
  448. //已经用掉免费的了,判断金额
  449. if($check){
  450. $price = config('site.audio_min_price');
  451. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  452. if($gold < $price){
  453. $this->error('您的金币已经不足,请充值');
  454. }
  455. }
  456. //找到互关的人,排除
  457. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  458. //dump($follow_me);
  459. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  460. //dump($my_follow);exit;
  461. //给出备选用户
  462. $map = [
  463. 'status' =>1, //未封禁用户
  464. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  465. 'is_online' => 0, //不在语聊间的
  466. 'is_livebc' => 0, //不在直播的
  467. 'is_active' => 1, //在线的
  468. //'real_status' => 1, //真人认证
  469. //'idcard_status' => 1, //实名认证
  470. 'open_match_audio' => 1, //打开语聊开关
  471. //'id' => ['NOT IN',$my_follow] //不是好友的
  472. ];
  473. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  474. $lists = $this->fliter_user($lists,10);
  475. $result = [];
  476. if(!empty($lists)){
  477. foreach($lists as $key => $val){
  478. $result[] = ['id'=>$val];
  479. }
  480. }
  481. //tag任务赠送金币
  482. //语音匹配奖励 +5金币
  483. if(!empty($result)){
  484. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  485. if($task_rs === false){
  486. $this->error('完成任务赠送奖励失败');
  487. }
  488. }
  489. $this->success('success',$result);
  490. }
  491. //视频匹配
  492. public function getvideouser(){
  493. //判断资格
  494. /*$start = strtotime(date('Y-m-d'));
  495. $end = $start + 86399;
  496. $map = [
  497. 'user_id' => $this->auth->id,
  498. 'createtime' => ['between',[$start,$end]],
  499. 'price' => 0,
  500. ];
  501. $check = Db::name('user_match_video_log')->where($map)->find();*/
  502. $check = true;
  503. //已经用掉免费的了,判断金额
  504. if($check){
  505. $price = config('site.video_min_price');
  506. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  507. if($gold < $price){
  508. $this->error('您的金币已经不足,请充值');
  509. }
  510. }
  511. //找到互关的人,排除
  512. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  513. //dump($follow_me);
  514. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  515. //dump($my_follow);exit;
  516. //给出备选用户
  517. $map = [
  518. 'status' =>1, //未封禁用户
  519. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  520. 'is_online' => 0, //不在语聊间的
  521. 'is_livebc' => 0, //不在直播的
  522. 'is_active' => 1, //在线的
  523. //'real_status' => 1, //真人认证
  524. //'idcard_status' => 1, //实名认证
  525. 'open_match_video' => 1, //打开视频开关的
  526. // 'id' => ['NOT IN',$my_follow] //不是好友的
  527. ];
  528. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  529. $lists = $this->fliter_user($lists,10);
  530. $result = [];
  531. if(!empty($lists)){
  532. foreach($lists as $key => $val){
  533. $result[] = ['id'=>$val];
  534. }
  535. }
  536. //tag任务赠送金币
  537. //视频匹配奖励 +5金币
  538. if(!empty($result)){
  539. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  540. if($task_rs === false){
  541. $this->error('完成任务赠送奖励失败');
  542. }
  543. }
  544. $this->success('success',$result);
  545. }
  546. //聊天匹配
  547. public function gettypinguser(){
  548. //找到互关的人,排除
  549. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  550. //dump($follow_me);
  551. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  552. //dump($my_follow);exit;
  553. //给出备选用户
  554. $map = [
  555. 'status' =>1, //未封禁用户
  556. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  557. //'real_status' => 1, //真人认证
  558. //'idcard_status' => 1, //实名认证
  559. //'is_active' => 1, //在线的
  560. //打开聊天开关的
  561. 'open_match_typing' => 1, //打开文字聊天开关的
  562. //'id' => ['NOT IN',$my_follow] //不是好友的
  563. ];
  564. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  565. //$lists = $this->fliter_user($lists,100);
  566. $lists = array_column($lists,'id');
  567. $result = [];
  568. if(!empty($lists)){
  569. /*foreach($lists as $key => $val){
  570. $result[] = ['id'=>$val];
  571. }*/
  572. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  573. $result = list_domain_image($result,['avatar,audio_bio']);
  574. }
  575. //tag任务赠送金币
  576. //缘分匹配奖励 +5金币
  577. if(!empty($result)){
  578. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  579. if($task_rs === false){
  580. $this->error('完成任务赠送奖励失败');
  581. }
  582. }
  583. $this->success('success',$result);
  584. }
  585. //过滤规则
  586. private function fliter_user($lists,$number = 1){
  587. if(empty($lists)){
  588. return $lists;
  589. }
  590. //dump($lists);
  591. //过滤掉通话中的
  592. foreach($lists as $key => $val){
  593. if(redis_matching_get($val['id']) == 1){
  594. unset($lists[$key]);
  595. }
  596. }
  597. //预留全部
  598. $all_result = array_column($lists,'id');
  599. //dump($all_result);
  600. //提取同城的
  601. $citydata = [];
  602. foreach($lists as $key => $val){
  603. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  604. $citydata[] = $val['id'];
  605. }
  606. }
  607. //dump($citydata);
  608. //有标签交集的
  609. $tagdata = [];
  610. foreach($lists as $key => $val){
  611. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  612. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  613. $val_tag_ids = explode(',',$val['tag_ids']);
  614. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  615. $tagdata[] = $val['id'];
  616. }
  617. }
  618. }
  619. //dump($tagdata);
  620. //双条件都满足
  621. $double_data = [];
  622. if(!empty($citydata) && !empty($tagdata)){
  623. $double_data = array_intersect($citydata,$tagdata);
  624. }
  625. //dump($double_data);
  626. if(count($double_data) >= $number){
  627. return $double_data;
  628. }
  629. //两种条件合并,去重。空数组合并没影响
  630. $merge_data = array_merge($citydata,$tagdata);
  631. $merge_data = array_flip(array_flip($merge_data));
  632. //dump($merge_data);
  633. if(count($merge_data) >= $number){
  634. return $merge_data;
  635. }
  636. return $all_result;
  637. }
  638. /**
  639. * 是否关注
  640. */
  641. public function isFollows() {
  642. $user_id = $this->request->request("user_id",0,"intval");
  643. if (!$user_id || $user_id<=0) {
  644. $this->error(__('Invalid parameters'));
  645. }
  646. $map = [
  647. 'uid' => $this->auth->id,
  648. 'follow_uid' => $user_id,
  649. ];
  650. $check = Db::name('user_follow')->where($map)->find();
  651. $data = [];
  652. if($check){
  653. $data["is_show_follow"] = 0;
  654. }else{
  655. $data["is_show_follow"] = 1;
  656. }
  657. $this->success("获取成功!",$data);
  658. }
  659. /**
  660. * 获取当前用户信息
  661. */
  662. public function getMyUserInfo() {
  663. $userInfo = $this->auth->getUserinfo();
  664. //当月消费金额
  665. $redis = new Redis();
  666. $redisconfig = config("redis");
  667. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  668. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  669. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  670. $this->success("获取成功!",$userInfo);
  671. }
  672. /**
  673. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  674. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  675. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  676. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  677. * @return float | false | string
  678. */
  679. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  680. if( empty( $point_1 ) || empty( $point_2 ) ){
  681. return false;
  682. }
  683. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  684. $p1_x = $point_1[0];
  685. $p1_y = $point_1[1];
  686. $p2_x = $point_2[0];
  687. $p2_y = $point_2[1];
  688. if(
  689. $p1_x < -180 || $p1_x > 180
  690. || $p2_x < -180 || $p2_x > 180
  691. || $p1_y < -90 || $p1_y > 90
  692. || $p2_y < -90 || $p2_y > 90
  693. ){
  694. return '0公里';
  695. }
  696. // 根据2点各自的坐标,计算2点之间直线距离的公式
  697. $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);
  698. // 是否计算为字符串公里距离
  699. if( !$calc_as_string ){
  700. return (string)round( $distance / 1000 , 1 ) . '公里';
  701. }
  702. // 如果计算为字符串公里距离
  703. if( $distance / 1000 > 1 ){
  704. $k = (string)round( $distance / 1000 , 1 );
  705. $m = (string)$distance % 1000 ;
  706. $distance = "{$k}公里{$m}米";
  707. }
  708. else{
  709. $distance = "{$distance}米";
  710. }
  711. return $distance;
  712. }
  713. //地图api,根据两地坐标,获得两地距离,打卡用的
  714. //type=0直线,type=1开车
  715. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  716. $result = 0;
  717. $apiurl = 'https://restapi.amap.com/v3/distance?';
  718. $param = [
  719. 'key' => '398c424811d1a59beac2f915323d334e',
  720. 'origins' => $start_lon.','.$start_lat,
  721. 'destination' => $end_lon.','.$end_lat,
  722. 'type' => $type,
  723. 'output' => 'json',
  724. ];
  725. $apiurl .= http_build_query($param);
  726. $request_rs = json_decode(curl_get($apiurl),true);
  727. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  728. if(isset($request_rs['results'][0]['distance']))
  729. {
  730. $result = $request_rs['results'][0]['distance'];
  731. }
  732. }
  733. //dump($result);
  734. return $result;
  735. }
  736. public function distance()
  737. {
  738. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  739. dump($a);
  740. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  741. dump($a);
  742. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  743. dump($b);
  744. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  745. dump($b);
  746. }
  747. //开通守护
  748. public function addguard() {
  749. // 接口防并发
  750. if (!$this->apiLimit(1, 1000)) {
  751. $this->error(__('Operation frequently'));
  752. }
  753. $user_id = input('user_id', 0, 'intval');// 守护对象
  754. if (!$user_id) {
  755. $this->error();
  756. }
  757. // 不可以守护给自己
  758. if($this->auth->id == $user_id) {
  759. $this->error("不可以守护自己");
  760. }
  761. //查询是否开通守护
  762. $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  763. if ($count) {
  764. $this->error('已经开通守护了');
  765. }
  766. $giftvalue = config('site.guard_price');
  767. if ($giftvalue <= 0) {
  768. $this->error('守护金额异常~');
  769. }
  770. //被守护人信息
  771. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  772. if (!$touserinfo) {
  773. $this->error("不存在的用户");
  774. }
  775. // 判断当前用户余额
  776. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  777. if($user_gold < $giftvalue) {
  778. $this->error("您的金币余额不足");
  779. }
  780. Db::startTrans();
  781. // 添加礼物守护记录表
  782. $data = [
  783. 'user_id' => $this->auth->id,
  784. 'user_to_id' => $user_id,
  785. 'price' => $giftvalue,
  786. 'createtime' => time(),
  787. ];
  788. $log_id = Db::name('user_guard')->insertGetId($data);
  789. if(!$log_id){
  790. Db::rollback();
  791. $this->error('守护失败');
  792. }
  793. if($giftvalue > 0){
  794. // 扣除当前用户余额
  795. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
  796. if($wallet_rs['status'] === false){
  797. Db::rollback();
  798. $this->error($wallet_rs['msg']);
  799. }
  800. // 添加守护用户余额
  801. $money_to_gold = config('site.money_to_gold');
  802. $gift_plat_scale = config('site.gift_plat_scale');
  803. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  804. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  805. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
  806. if($wallet_rs['status'] === false){
  807. Db::rollback();
  808. $this->error($wallet_rs['msg']);
  809. }
  810. //增加赠送用户上级余额
  811. if ($touserinfo['intro_uid']) {
  812. //获取返利比率
  813. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  814. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  815. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  816. //上级获得金额
  817. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  818. if ($intro_uid_money > 0) {
  819. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
  820. if($intro_result['status']===false)
  821. {
  822. Db::rollback();
  823. $this->error($intro_result['msg']);
  824. }
  825. }
  826. }
  827. }
  828. }
  829. //tag任务守护金币
  830. //搭讪奖励
  831. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  832. // if($task_rs === false){
  833. // Db::rollback();
  834. // $this->error('完成任务守护奖励失败');
  835. // }
  836. Db::commit();
  837. $this->success('守护成功');
  838. }
  839. //守护列表
  840. public function guardlist(){
  841. $user_id = input('user_id', 0, 'intval');
  842. if (!$user_id) {
  843. $this->error('您的网络开小差啦~');
  844. }
  845. $list = Db::name('user_guard')
  846. ->alias('a')
  847. ->join('user','a.user_id = user.id','LEFT')
  848. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  849. ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
  850. if (!$list) {
  851. $this->success('success', $list);
  852. }
  853. $list = list_domain_image($list,['avatar']);
  854. $time = time();
  855. foreach ($list as &$v) {
  856. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  857. }
  858. $this->success('success',$list);
  859. }
  860. //我的守护
  861. public function myguardlist(){
  862. $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
  863. if (!in_array($type, [1, 2])) {
  864. $this->error('您的网络开小差了');
  865. }
  866. $where = [];
  867. if ($type == 1) {
  868. $join = 'a.user_to_id = user.id';
  869. $where['a.user_id'] = $this->auth->id;
  870. } else {
  871. $join = 'a.user_id = user.id';
  872. $where['a.user_to_id'] = $this->auth->id;
  873. }
  874. $list = Db::name('user_guard')
  875. ->alias('a')
  876. ->join('user',$join,'LEFT')
  877. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  878. ->where($where)->order('a.id desc')->autopage()->select();
  879. if (!$list) {
  880. $this->success('success', $list);
  881. }
  882. $list = list_domain_image($list,['avatar']);
  883. $time = time();
  884. foreach ($list as &$v) {
  885. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  886. }
  887. $this->success('success',$list);
  888. }
  889. //打字聊天每句话调用一次
  890. public function chat_once(){
  891. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  892. $this->success('success',array('money'=>''));
  893. }
  894. if ($this->auth->gender == 0) { //女生不花钱
  895. $this->error('您的网络开小差啦~');
  896. }
  897. //检测用户
  898. $to_user_id = input_post('to_user_id');
  899. $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();
  900. if(!$to_user_info){
  901. $this->error('不存在的用户');
  902. }
  903. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  904. $this->success('success',array('money'=>''));
  905. }
  906. if ($to_user_info['gender'] != 0) {
  907. $this->error('同性不能聊天~');
  908. }
  909. //验证金额
  910. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  911. if ($wallet_info['vip_endtime'] >= time()) { //会员
  912. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  913. //获取折扣
  914. $vip_chat_discount = config('site.vip_chat_discount');
  915. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  916. $price = ceil($price * $vip_chat_discount / 10);
  917. }
  918. } else {
  919. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  920. }
  921. //正常价格
  922. $bili = config('site.money_to_gold'); //兑换比例
  923. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  924. $money = bcdiv($price,$bili,2); //对应人民币
  925. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  926. $resArray['money'] = $money; //返回给前端的计算结果
  927. Db::startTrans();
  928. //记录日志
  929. $data = [
  930. 'user_id' => $this->auth->id,
  931. 'price' => $price,
  932. 'createtime' => time(),
  933. 'to_user_id' => $to_user_id,
  934. 'money' => $money,
  935. ];
  936. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  937. if(!$log_id){
  938. Db::rollback();
  939. $this->error('扣费失败');
  940. }
  941. //有性别差,扣费
  942. if($price > 0){
  943. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
  944. if($rs['status'] === false){
  945. Db::rollback();
  946. $this->error($rs['msg']);
  947. }
  948. }
  949. //另一方加钱,0收费
  950. if($money > 0){
  951. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
  952. if($rs['status'] === false){
  953. Db::rollback();
  954. $this->error($rs['msg']);
  955. }
  956. $touserinfo = $to_user_info;
  957. //增加赠送用户上级余额
  958. if ($touserinfo['intro_uid']) {
  959. //获取返利比率
  960. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  961. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  962. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  963. //上级获得金额
  964. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  965. if ($intro_uid_money > 0) {
  966. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
  967. if($intro_result['status']===false)
  968. {
  969. Db::rollback();
  970. $this->error($intro_result['msg']);
  971. }
  972. }
  973. }
  974. }
  975. }
  976. //增加亲密度
  977. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  978. if (!$user_intimacy_rs['status']) {
  979. Db::rollback();
  980. $this->error('您的网络开小差啦~');
  981. }
  982. //tag任务赠送金币
  983. //私信5名异性奖励
  984. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  985. if($task_rs === false){
  986. Db::rollback();
  987. $this->error('完成任务赠送奖励失败');
  988. }
  989. /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
  990. if($task_rs === false){
  991. Db::rollback();
  992. $this->error('完成任务赠送奖励失败');
  993. }*/
  994. Db::commit();
  995. //发送消息
  996. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  997. $tenim = new \app\api\controller\Tenim;
  998. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  999. }
  1000. $this->success('success',$resArray);
  1001. }
  1002. //语音通话每分钟调用一次
  1003. public function voice_onemin(){
  1004. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1005. $this->success('success');
  1006. }
  1007. if ($this->auth->gender == 0) { //女生不花钱
  1008. $this->error('您的网络开小差啦~');
  1009. }
  1010. //检测用户
  1011. $to_user_id = input_post('to_user_id');
  1012. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1013. $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();
  1014. if(!$to_user_info){
  1015. $this->error('不存在的用户');
  1016. }
  1017. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1018. $this->success('success');
  1019. }
  1020. if ($to_user_info['gender'] != 0) {
  1021. $this->error('同性不能聊天~');
  1022. }
  1023. //验证金额
  1024. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1025. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1026. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1027. //获取折扣
  1028. $vip_video_discount = config('site.vip_video_discount');
  1029. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1030. $price = ceil($price * $vip_video_discount / 10);
  1031. }
  1032. } else {
  1033. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1034. }
  1035. //正常价格
  1036. $bili = config('site.money_to_gold'); //兑换比例
  1037. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1038. $money = bcdiv($price,$bili,2); //对应人民币
  1039. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1040. Db::startTrans();
  1041. //查询是否有匹配记录
  1042. $user_match_audio_log_info = [];
  1043. if ($request_id) {
  1044. $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();
  1045. }
  1046. if ($user_match_audio_log_info) {
  1047. //修改记录日志
  1048. $data = [
  1049. 'price' => $user_match_audio_log_info['price'] + $price,
  1050. 'createtime' => time(),
  1051. 'money' => $user_match_audio_log_info['money'] + $money,
  1052. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  1053. ];
  1054. $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id'], 'createtime' => $user_match_audio_log_info['createtime']])->setField($data);
  1055. if (!$log_id) {
  1056. Db::rollback();
  1057. $this->error('扣费失败');
  1058. }
  1059. } else {
  1060. //添加记录日志
  1061. $data = [
  1062. 'user_id' => $this->auth->id,
  1063. 'price' => $price,
  1064. 'createtime' => time(),
  1065. 'to_user_id' => $to_user_id,
  1066. 'money' => $money,
  1067. 'request_id' => $request_id,
  1068. 'call_minutes' => 1
  1069. ];
  1070. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  1071. if (!$log_id) {
  1072. Db::rollback();
  1073. $this->error('扣费失败');
  1074. }
  1075. }
  1076. //有性别差,扣费
  1077. if($price > 0){
  1078. $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);
  1079. if($rs['status'] === false){
  1080. Db::rollback();
  1081. $this->error($rs['msg']);
  1082. }
  1083. }
  1084. //另一方加钱,0收费
  1085. if($money > 0){
  1086. $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);
  1087. if($rs['status'] === false){
  1088. Db::rollback();
  1089. $this->error($rs['msg']);
  1090. }
  1091. $touserinfo = $to_user_info;
  1092. //增加赠送用户上级余额
  1093. if ($touserinfo['intro_uid']) {
  1094. //获取返利比率
  1095. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1096. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1097. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1098. //上级获得金额
  1099. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1100. if ($intro_uid_money > 0) {
  1101. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人语音聊天获赠奖励' . $data['call_minutes'] . '分钟','gift_user_typing',$log_id, 0, $request_id);
  1102. if($intro_result['status']===false)
  1103. {
  1104. Db::rollback();
  1105. $this->error($intro_result['msg']);
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. //增加亲密度
  1112. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1113. if (!$user_intimacy_rs['status']) {
  1114. Db::rollback();
  1115. $this->error('您的网络开小差啦~');
  1116. }
  1117. //tag任务赠送金币
  1118. //与1名异性语音通话奖励
  1119. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
  1120. if($task_rs === false){
  1121. Db::rollback();
  1122. $this->error('完成任务赠送奖励失败');
  1123. }
  1124. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
  1125. if($task_rs === false){
  1126. Db::rollback();
  1127. $this->error('完成任务赠送奖励失败');
  1128. }
  1129. //发送消息
  1130. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1131. $tenim = new \app\api\controller\Tenim;
  1132. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1133. }
  1134. Db::commit();
  1135. $this->success('success');
  1136. }
  1137. //视频通话每分钟调用一次
  1138. public function videochat_onemin(){
  1139. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1140. $this->success('success');
  1141. }
  1142. if ($this->auth->gender == 0) { //女生不花钱
  1143. $this->error('您的网络开小差啦~');
  1144. }
  1145. //检测用户
  1146. $to_user_id = input_post('to_user_id');
  1147. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1148. $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();
  1149. if(!$to_user_info){
  1150. $this->error('不存在的用户');
  1151. }
  1152. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1153. $this->success('success');
  1154. }
  1155. if ($to_user_info['gender'] != 0) {
  1156. $this->error('同性不能聊天~');
  1157. }
  1158. /* //检查是否免费过
  1159. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1160. if (!$count) {
  1161. //记录日志
  1162. $data = [
  1163. 'user_id' => $this->auth->id,
  1164. 'price' => 0,
  1165. 'createtime' => time(),
  1166. 'to_user_id' => $to_user_id,
  1167. 'money' => 0,
  1168. ];
  1169. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1170. if(!$log_id){
  1171. $this->error('扣费失败');
  1172. }
  1173. $this->success('success');
  1174. }*/
  1175. //验证金额
  1176. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1177. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1178. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1179. //获取折扣
  1180. $vip_video_discount = config('site.vip_video_discount');
  1181. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1182. $price = ceil($price * $vip_video_discount / 10);
  1183. }
  1184. } else {
  1185. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1186. }
  1187. //正常价格
  1188. $bili = config('site.money_to_gold'); //兑换比例
  1189. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1190. $money = bcdiv($price,$bili,2); //对应人民币
  1191. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1192. Db::startTrans();
  1193. //查询是否有匹配记录
  1194. $user_match_video_log_info = [];
  1195. if ($request_id) {
  1196. $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();
  1197. }
  1198. if ($user_match_video_log_info) {
  1199. //修改记录日志
  1200. $data = [
  1201. 'price' => $user_match_video_log_info['price'] + $price,
  1202. 'createtime' => time(),
  1203. 'money' => $user_match_video_log_info['money'] + $money,
  1204. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  1205. ];
  1206. $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id'], 'createtime' => $user_match_video_log_info['createtime']])->setField($data);
  1207. if (!$log_id) {
  1208. Db::rollback();
  1209. $this->error('扣费失败');
  1210. }
  1211. } else {
  1212. //添加记录日志
  1213. $data = [
  1214. 'user_id' => $this->auth->id,
  1215. 'price' => $price,
  1216. 'createtime' => time(),
  1217. 'to_user_id' => $to_user_id,
  1218. 'money' => $money,
  1219. 'request_id' => $request_id,
  1220. 'call_minutes' => 1
  1221. ];
  1222. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  1223. if (!$log_id) {
  1224. Db::rollback();
  1225. $this->error('扣费失败');
  1226. }
  1227. }
  1228. //有性别差,扣费
  1229. if($price > 0){
  1230. $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);
  1231. if($rs['status'] === false){
  1232. Db::rollback();
  1233. $this->error($rs['msg']);
  1234. }
  1235. }
  1236. //另一方加钱,0收费
  1237. if($money > 0){
  1238. $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);
  1239. if($rs['status'] === false){
  1240. Db::rollback();
  1241. $this->error($rs['msg']);
  1242. }
  1243. $touserinfo = $to_user_info;
  1244. //增加赠送用户上级余额
  1245. if ($touserinfo['intro_uid']) {
  1246. //获取返利比率
  1247. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1248. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1249. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1250. //上级获得金额
  1251. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1252. if ($intro_uid_money > 0) {
  1253. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人视频聊天获赠奖励' . $data['call_minutes'] . '分钟','gift_user_typing',$log_id, 0, $request_id);
  1254. if($intro_result['status']===false)
  1255. {
  1256. Db::rollback();
  1257. $this->error($intro_result['msg']);
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. //增加亲密度
  1264. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1265. if (!$user_intimacy_rs['status']) {
  1266. Db::rollback();
  1267. $this->error('您的网络开小差啦~');
  1268. }
  1269. //tag任务赠送金币
  1270. //与1名异性视频通话奖励
  1271. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
  1272. if($task_rs === false){
  1273. Db::rollback();
  1274. $this->error('完成任务赠送奖励失败');
  1275. }
  1276. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
  1277. if($task_rs === false){
  1278. Db::rollback();
  1279. $this->error('完成任务赠送奖励失败');
  1280. }
  1281. Db::commit();
  1282. //发送消息
  1283. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1284. $tenim = new \app\api\controller\Tenim;
  1285. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1286. }
  1287. $this->success('success');
  1288. }
  1289. //消息列表好友/密友
  1290. public function intimacyfriends() {
  1291. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  1292. $where = [];
  1293. /*if ($type == 0) {
  1294. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  1295. $mt_user = Db::name('user');
  1296. // $mt_user_follow = Db::name('user_follow');
  1297. $mt_user_intimacy = Db::name('user_intimacy');
  1298. foreach ($list as &$v) {
  1299. //查询亲密度
  1300. if ($this->auth->gender == 1) {
  1301. $where['uid'] = $this->auth->id;
  1302. $where['other_uid'] = $v['user_id'];
  1303. } else {
  1304. $where['other_uid'] = $this->auth->id;
  1305. $where['uid'] = $v['user_id'];
  1306. }
  1307. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  1308. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  1309. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  1310. //查询对方信息
  1311. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  1312. $v['nickname'] = $user_info['nickname'];
  1313. $v['avatar'] = one_domain_image($user_info['avatar']);
  1314. $v['updatetime'] = get_last_time($v['updatetime']);
  1315. $v['age'] = birthtime_to_age($user_info['birthday']);
  1316. $v['gender'] = $user_info['gender'];
  1317. $v['real_status'] = $user_info['real_status'];
  1318. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1319. $v['status'] = 1;
  1320. }
  1321. } else {*/
  1322. if ($this->auth->gender == 1) {
  1323. $where['uid'] = $this->auth->id;
  1324. $field = 'other_uid user_id, value, updatetime';
  1325. } else {
  1326. $where['other_uid'] = $this->auth->id;
  1327. $field = 'uid user_id, value, updatetime';
  1328. }
  1329. if ($type == 1) { //密友
  1330. $where['value'] = ['egt', 1000];
  1331. } elseif ($type == 2) { //好友
  1332. $where['value'] = ['egt', 100];
  1333. } else { //消息列表好友
  1334. $where['value'] = ['egt', 10];
  1335. }
  1336. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  1337. $mt_user = Db::name('user');
  1338. $mt_user_follow = Db::name('user_follow');
  1339. foreach ($list as &$v) {
  1340. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  1341. $v['nickname'] = $user_info['nickname'];
  1342. $v['avatar'] = one_domain_image($user_info['avatar']);
  1343. $v['updatetime'] = get_last_time($v['updatetime']);
  1344. $v['age'] = birthtime_to_age($user_info['birthday']);
  1345. $v['gender'] = $user_info['gender'];
  1346. $v['real_status'] = $user_info['real_status'];
  1347. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1348. $v['is_active'] = $user_info['is_active'];
  1349. }
  1350. // }
  1351. $this->success('success',$list);
  1352. }
  1353. //消息列表通话
  1354. public function calllist() {
  1355. if ($this->auth->gender == 1) {
  1356. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
  1357. } elseif ($this->auth->gender == 0) {
  1358. $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
  1359. } else {
  1360. $this->success('success', []);
  1361. }
  1362. if (!$list) {
  1363. $this->success('success', $list);
  1364. }
  1365. $arr = [];
  1366. $mt_user_match_audio_log = Db::name('user_match_audio_log');
  1367. $mt_user_match_video_log = Db::name('user_match_video_log');
  1368. $mt_user = Db::name('user');
  1369. foreach ($list as &$v) {
  1370. $data = [];
  1371. if ($this->auth->gender == 1) {
  1372. if ($v['log_type'] == 11) { //视频通话
  1373. $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1374. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1375. } else { //语音通话
  1376. $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1377. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1378. }
  1379. } else {
  1380. if ($v['log_type'] == 21) { //视频通话
  1381. $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1382. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1383. } else { //语音通话
  1384. $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1385. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1386. }
  1387. }
  1388. $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
  1389. $data['user_id'] = $log_info['user_id'];
  1390. $data['nickname'] = $user_info['nickname'];
  1391. $data['avatar'] = one_domain_image($user_info['avatar']);
  1392. $data['createtime'] = get_last_time($log_info['createtime']);
  1393. $data['is_active'] = $user_info['is_active'];
  1394. $arr[] = $data;
  1395. }
  1396. $this->success('success', $arr);
  1397. }
  1398. //查询对方用户收费价格和我的余额
  1399. public function otheruserinfo(){
  1400. $user_id = input('user_id', 0, 'intval');
  1401. if (!$user_id) {
  1402. $this->error('您的网络开小差啦~');
  1403. }
  1404. $field = [
  1405. 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
  1406. ];
  1407. $info = Db::name('user')->field($field)->where('id',$user_id)->find();
  1408. if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
  1409. if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
  1410. $this->error('性别存在问题');
  1411. }
  1412. }
  1413. if ($this->auth->gender == 0) { //收费价格按照女号
  1414. $info['chat_price'] = $this->auth->chat_price;
  1415. $info['voice_price'] = $this->auth->voice_price;
  1416. $info['video_price'] = $this->auth->video_price;
  1417. $info['open_match_audio'] = $this->auth->open_match_audio;
  1418. $info['open_match_video'] = $this->auth->open_match_video;
  1419. }
  1420. $info['chat_price_vip'] = $info['chat_price']; //vip价格
  1421. $info['voice_price_vip'] = $info['voice_price'];
  1422. $info['video_price_vip'] = $info['video_price'];
  1423. $info['is_vip'] = 0; //是否vip: 0否 1是
  1424. //获取聊天折扣
  1425. $vip_chat_discount = config('site.vip_chat_discount');
  1426. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1427. $info['vip_chat_discount'] = $vip_chat_discount;
  1428. } else {
  1429. $info['vip_chat_discount'] = 10;
  1430. }
  1431. //获取语音视频折扣
  1432. $vip_video_discount = config('site.vip_video_discount');
  1433. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1434. $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
  1435. $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
  1436. } else {
  1437. $info['vip_voice_discount'] = 10;
  1438. $info['vip_video_discount'] = 10;
  1439. }
  1440. //获取聊天折扣
  1441. $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
  1442. //获取语音折扣
  1443. $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
  1444. //获取视频折扣
  1445. $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
  1446. if ($this->auth->gender == 0) { //查询男号余额和vip
  1447. $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
  1448. } else {
  1449. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1450. }
  1451. if ($wallet_info['vip_endtime'] >= time()) {
  1452. $info['is_vip'] = 1;
  1453. }
  1454. $info['gold'] = $wallet_info['gold'];
  1455. $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
  1456. $info['money_to_gold'] = config('site.money_to_gold'); //一元人民币兑换金币数量
  1457. $this->success('success',$info);
  1458. }
  1459. //亲密度等级信息
  1460. public function intimacylevel() {
  1461. $user_id = input('user_id', 0, 'intval'); //对方id
  1462. if (!$user_id) {
  1463. $this->error('参数缺失');
  1464. }
  1465. if ($this->auth->gender == 0) { //女用户
  1466. $where['uid'] = $user_id;
  1467. $where['other_uid'] = $this->auth->id;
  1468. } else { //男用户
  1469. $where['uid'] = $this->auth->id;
  1470. $where['other_uid'] = $user_id;
  1471. }
  1472. $level = 0; //当前等级
  1473. $level_name = ''; //当前等级名称
  1474. $qinmi_sum = 0; //当前亲密度
  1475. $next_level_diff = 0; //距下一等级亲密度差值
  1476. //亲密度等级列表
  1477. $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
  1478. //当前亲密度信息
  1479. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  1480. if ($user_intimacy_info) {
  1481. //当前亲密度
  1482. $qinmi_sum = $user_intimacy_info['value'];
  1483. if ($list) {
  1484. //当前等级信息
  1485. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
  1486. if ($level_info) {
  1487. $level = $level_info['level'];
  1488. $level_name = $level_info['name'];
  1489. }
  1490. //下一等级信息
  1491. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  1492. if ($next_level_info) {
  1493. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  1494. }
  1495. }
  1496. } else {
  1497. $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
  1498. }
  1499. if ($list) {
  1500. foreach ($list as &$v) {
  1501. if ($v['level'] < $level) {
  1502. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  1503. } elseif ($v['level'] == $level) {
  1504. $v['is_unlock'] = 2;
  1505. } else {
  1506. $v['is_unlock'] = 3;
  1507. }
  1508. }
  1509. }
  1510. $data['level'] = $level; //当前等级
  1511. $data['level_name'] = $level_name; //当前等级名称
  1512. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  1513. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  1514. $data['level_list'] = $list; //等级列表
  1515. $this->success('亲密度等级信息', $data);
  1516. }
  1517. //语音视频随聊
  1518. public function getrandomuser() {
  1519. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1520. if (!in_array($type, [1, 2, 3])) {
  1521. $this->error('您的网络开小差了');
  1522. }
  1523. $size = input('size',0,'intval');// 是否查 10 条
  1524. $size = $size > 0 ? 1 : 0;
  1525. //给出备选用户
  1526. $map = [
  1527. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1528. 'is_active' => 1, //在线的
  1529. 'status' =>1, //未封禁用户
  1530. 'is_kefu' => 0, //不是客服
  1531. ];
  1532. if ($this->auth->gender == 1) {
  1533. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1534. }
  1535. if ($type == 1) {
  1536. $map['open_match_audio'] = 1;
  1537. } elseif ($type == 2) {
  1538. $map['open_match_video'] = 1;
  1539. }
  1540. $key = md5(json_encode($map));// 根据搜索条件做Key
  1541. $lists = Cache::remember("getrandomuser_{$key}_{$size}",function () use ($map,$size){
  1542. $query = Db::name('user')
  1543. ->field('id,nickname,username,avatar')
  1544. ->where($map)
  1545. ->order('is_active desc, active_time desc');
  1546. if ($size == 1){
  1547. $query->limit(10);
  1548. }else{
  1549. $query->page($this->page,100);
  1550. }
  1551. $lists = $query->select();
  1552. //$lists = $this->fliter_user($lists,100);
  1553. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1554. $mt_user_greet_content = Db::name('user_greet_content');
  1555. foreach ($lists as &$v) {
  1556. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1557. if ($info) {
  1558. if ($info['type'] == 0) {
  1559. $v['greet_content'] = $info['content'];
  1560. } elseif ($info['type'] == 1) {
  1561. $v['greet_content'] = '[语音]';
  1562. } elseif ($info['type'] == 2) {
  1563. $v['greet_content'] = '[图片]';
  1564. }
  1565. } else {
  1566. $v['greet_content'] = '';
  1567. }
  1568. }
  1569. return $lists;
  1570. },2);
  1571. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1572. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1573. $return_data['list'] = $lists;
  1574. $this->success('success',$return_data);
  1575. }
  1576. //语音视频随聊
  1577. //作废
  1578. public function getrandomuserbak() {
  1579. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1580. if (!in_array($type, [1, 2, 3])) {
  1581. $this->error('您的网络开小差了');
  1582. }
  1583. //找到互关的人,排除
  1584. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  1585. //dump($follow_me);
  1586. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  1587. //dump($my_follow);exit;
  1588. //给出备选用户
  1589. $map = [
  1590. 'status' =>1, //未封禁用户
  1591. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1592. // 'is_online' => 0, //不在语聊间的
  1593. 'is_livebc' => 0, //不在直播的
  1594. 'is_active' => 1, //在线的
  1595. // 'real_status' => 1, //真人认证
  1596. // 'idcard_status' => 1, //实名认证
  1597. // 'id' => ['NOT IN',$my_follow] //不是好友的
  1598. 'is_kefu' => 0, //不是客服
  1599. ];
  1600. if ($this->auth->gender == 1) {
  1601. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1602. }
  1603. if ($type == 1) {
  1604. $map['open_match_audio'] = 1;
  1605. } elseif ($type == 2) {
  1606. $map['open_match_video'] = 1;
  1607. }
  1608. $lists = Db::name('user')
  1609. ->field('id,nickname,username,avatar')
  1610. ->where($map)
  1611. ->order('is_active desc, active_time desc')
  1612. ->page($this->page,100)
  1613. ->select();
  1614. //$lists = $this->fliter_user($lists,100);
  1615. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1616. $mt_user_greet_content = Db::name('user_greet_content');
  1617. foreach ($lists as &$v) {
  1618. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1619. if ($info) {
  1620. if ($info['type'] == 0) {
  1621. $v['greet_content'] = $info['content'];
  1622. } elseif ($info['type'] == 1) {
  1623. $v['greet_content'] = '[语音]';
  1624. } elseif ($info['type'] == 2) {
  1625. $v['greet_content'] = '[图片]';
  1626. }
  1627. } else {
  1628. $v['greet_content'] = '';
  1629. }
  1630. }
  1631. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1632. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1633. $return_data['list'] = $lists;
  1634. $this->success('success',$return_data);
  1635. }
  1636. //查询免费体验视频通话用户信息
  1637. public function getfreevideouserinfo() {
  1638. $to_user_id = input('to_user_id', 0, 'intval');
  1639. $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
  1640. if(!$to_user_info){
  1641. $this->error('不存在的用户');
  1642. }
  1643. if ($to_user_info['gender'] == $this->auth->gender) {
  1644. $this->error('同性不能聊天~');
  1645. }
  1646. $to_user_info['desc'] = '';
  1647. $age = birthtime_to_age($to_user_info['birthday']);
  1648. if ($age > 0) {
  1649. $to_user_info['desc'] = $age . '岁';
  1650. } else {
  1651. $to_user_info['desc'] = '18岁';
  1652. }
  1653. if ($to_user_info['height']) {
  1654. $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
  1655. }
  1656. //查询是否免费过
  1657. $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1658. $this->success('信息', $to_user_info);
  1659. }
  1660. //免费体验视频通话1分钟
  1661. public function videochat_onemin_free(){
  1662. $this->success('success');
  1663. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1664. $this->success('success');
  1665. }
  1666. //检查是否免费过
  1667. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1668. if ($count) {
  1669. $this->error('已经免费体验过');
  1670. }
  1671. //检测用户
  1672. $to_user_id = input_post('to_user_id');
  1673. $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();
  1674. if(!$to_user_info){
  1675. $this->error('不存在的用户');
  1676. }
  1677. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1678. $this->success('success');
  1679. }
  1680. if ($to_user_info['gender'] == $this->auth->gender) {
  1681. $this->error('同性不能聊天~');
  1682. }
  1683. //记录日志
  1684. $data = [
  1685. 'user_id' => $this->auth->id,
  1686. 'price' => 0,
  1687. 'createtime' => time(),
  1688. 'to_user_id' => $to_user_id,
  1689. 'money' => 0,
  1690. ];
  1691. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1692. if(!$log_id){
  1693. $this->error('扣费失败');
  1694. }
  1695. $this->success('success');
  1696. }
  1697. //男性非会员解锁聊天
  1698. public function unlockchat() {
  1699. // 接口防并发
  1700. if (!$this->apiLimit(1, 1000)) {
  1701. $this->error(__('Operation frequently'));
  1702. }
  1703. //男性非会员是否已开通聊天
  1704. if ($this->auth->gender == 0) {
  1705. $this->error('不需要解锁');
  1706. }
  1707. $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  1708. if ($vip_endtime > time()) {
  1709. $this->error('不需要解锁');
  1710. }
  1711. $user_id = input('user_id', 0, 'intval');//对方id
  1712. if (!$user_id) {
  1713. $this->error();
  1714. }
  1715. // 不可以守护给自己
  1716. if($this->auth->id == $user_id) {
  1717. $this->error("不可以解锁自己");
  1718. }
  1719. //查询是否解锁过
  1720. $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  1721. if ($user_chat_unlock) {
  1722. $this->error('已经解锁过了');
  1723. }
  1724. $giftvalue = config('site.unlock_chat_gold');
  1725. if ($giftvalue <= 0) {
  1726. $this->error('解锁金额异常~');
  1727. }
  1728. //被解锁人信息
  1729. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  1730. if (!$touserinfo) {
  1731. $this->error("不存在的用户");
  1732. }
  1733. // 判断当前用户余额
  1734. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  1735. if($user_gold < $giftvalue) {
  1736. $this->error("您的金币余额不足");
  1737. }
  1738. Db::startTrans();
  1739. //添加解锁记录表
  1740. $data = [
  1741. 'user_id' => $this->auth->id,
  1742. 'user_to_id' => $user_id,
  1743. 'price' => $giftvalue,
  1744. 'createtime' => time(),
  1745. ];
  1746. $log_id = Db::name('user_chat_unlock')->insertGetId($data);
  1747. if(!$log_id){
  1748. Db::rollback();
  1749. $this->error('解锁失败');
  1750. }
  1751. if($giftvalue > 0){
  1752. // 扣除当前用户余额
  1753. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_chat_unlock',$log_id);
  1754. if($wallet_rs['status'] === false){
  1755. Db::rollback();
  1756. $this->error($wallet_rs['msg']);
  1757. }
  1758. // 添加守护用户余额
  1759. $money_to_gold = config('site.money_to_gold');
  1760. $gift_plat_scale = config('site.gift_plat_scale');
  1761. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  1762. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  1763. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_chat_unlock',$log_id,2);
  1764. if($wallet_rs['status'] === false){
  1765. Db::rollback();
  1766. $this->error($wallet_rs['msg']);
  1767. }
  1768. //增加赠送用户上级余额
  1769. if ($touserinfo['intro_uid']) {
  1770. //获取返利比率
  1771. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1772. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1773. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1774. //上级获得金额
  1775. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1776. if ($intro_uid_money > 0) {
  1777. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人解锁聊天获赠奖励','gift_user_typing',$log_id);
  1778. if($intro_result['status']===false)
  1779. {
  1780. Db::rollback();
  1781. $this->error($intro_result['msg']);
  1782. }
  1783. }
  1784. }
  1785. }
  1786. }
  1787. //tag任务守护金币
  1788. //搭讪奖励
  1789. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  1790. // if($task_rs === false){
  1791. // Db::rollback();
  1792. // $this->error('完成任务守护奖励失败');
  1793. // }
  1794. Db::commit();
  1795. $this->success('解锁成功');
  1796. }
  1797. }