Usercenter.php 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443
  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. public 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 video_onemin(){
  438. //检测用户
  439. $to_user_id = input_post('to_user_id');
  440. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  441. if(!$to_user_info){
  442. $this->error('不存在的用户');
  443. }
  444. //正常价格
  445. $price = config('site.video_min_price'); //扣费金币
  446. $bili = config('site.money_to_gold'); //兑换比例
  447. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  448. $money = bcdiv($price,$bili,2); //对应人民币
  449. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  450. //发起用户的分数,被发起用户的分数。按性别给分
  451. $auth_level = 0;
  452. $tous_level = 0;
  453. //打分
  454. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  455. $auth_level = 30;//实名女最高
  456. }
  457. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  458. $auth_level = 20;//未实名女次之
  459. }
  460. if($this->auth->gender == 1){
  461. $auth_level = 10;//男性最低
  462. }
  463. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  464. $tous_level = 30;
  465. }
  466. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  467. $tous_level = 20;
  468. }
  469. if($to_user_info['gender'] == 1){
  470. $tous_level = 10;
  471. }
  472. //同性不收钱
  473. //都是男的,不扣钱
  474. //都是实名认证的女性,不扣钱
  475. //都是未实名认证的女性,不扣钱
  476. if($auth_level == $tous_level){
  477. $price = 0;$money = 0;
  478. }
  479. Db::startTrans();
  480. //记录日志
  481. $data = [
  482. 'user_id' => $this->auth->id,
  483. 'price' => $price,
  484. 'createtime' => time(),
  485. 'to_user_id' => $to_user_id,
  486. 'money' => $money,
  487. ];
  488. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  489. if(!$log_id){
  490. Db::rollback();
  491. $this->error('扣费失败');
  492. }
  493. //同性别,提前结束
  494. if($auth_level == $tous_level){
  495. Db::commit();
  496. $this->success('success');
  497. }
  498. //扣钱uid,收钱uid,收钱free_video
  499. //分数少扣钱,分数多收益
  500. if($auth_level < $tous_level){
  501. $kou_user = $this->auth->id;
  502. $get_user = $to_user_info['id'];
  503. $get_user_free = $to_user_info['free_video'];
  504. }else{
  505. $kou_user = $to_user_info['id'];
  506. $get_user = $this->auth->id;
  507. $get_user_free = $this->auth->free_video;
  508. }
  509. //需要扣别人的钱,判断钱是否购
  510. if($price > 0 && $kou_user != $this->auth->id){
  511. $gold = model('wallet')->getWallet($kou_user,'gold');
  512. if(bccomp($price,$gold) == 1){
  513. Db::rollback();
  514. $this->error('对方金币不足');
  515. }
  516. }
  517. //有性别差,扣费
  518. if($price > 0){
  519. $rs = model('wallet')->lockChangeAccountRemain($kou_user, $get_user,'gold',-$price,11,'','user_match_video_log',$log_id);
  520. if($rs['status'] === false){
  521. Db::rollback();
  522. $this->error($rs['msg']);
  523. }
  524. }
  525. //另一方加钱,0收费
  526. if($money > 0 && $get_user_free == 0){
  527. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,21,'','user_match_video_log',$log_id);
  528. if($rs['status'] === false){
  529. Db::rollback();
  530. $this->error($rs['msg']);
  531. }
  532. }
  533. Db::commit();
  534. $this->success('success');
  535. }
  536. //语音通话每分钟调用一次
  537. public function audio_onemin(){
  538. //检测用户
  539. $to_user_id = input_post('to_user_id');
  540. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  541. if(!$to_user_info){
  542. $this->error('不存在的用户');
  543. }
  544. //正常价格
  545. $price = config('site.audio_min_price'); //扣费金币
  546. $bili = config('site.money_to_gold'); //兑换比例
  547. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  548. $money = bcdiv($price,$bili,2); //对应人民币
  549. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  550. //发起用户的分数,被发起用户的分数。按性别给分
  551. $auth_level = 0;
  552. $tous_level = 0;
  553. //打分
  554. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  555. $auth_level = 30;//实名女最高
  556. }
  557. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  558. $auth_level = 20;//未实名女次之
  559. }
  560. if($this->auth->gender == 1){
  561. $auth_level = 10;//男性最低
  562. }
  563. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  564. $tous_level = 30;
  565. }
  566. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  567. $tous_level = 20;
  568. }
  569. if($to_user_info['gender'] == 1){
  570. $tous_level = 10;
  571. }
  572. //同性不收钱
  573. //都是男的,不扣钱
  574. //都是实名认证的女性,不扣钱
  575. //都是未实名认证的女性,不扣钱
  576. if($auth_level == $tous_level){
  577. $price = 0;$money = 0;
  578. }
  579. Db::startTrans();
  580. //记录日志
  581. $data = [
  582. 'user_id' => $this->auth->id,
  583. 'price' => $price,
  584. 'createtime' => time(),
  585. 'to_user_id' => $to_user_id,
  586. 'money' => $money,
  587. ];
  588. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  589. if(!$log_id){
  590. Db::rollback();
  591. $this->error('扣费失败');
  592. }
  593. //同性别,提前结束
  594. if($auth_level == $tous_level){
  595. Db::commit();
  596. $this->success('success');
  597. }
  598. //扣钱uid,收钱uid,收钱free_video
  599. //分数少扣钱,分数多收益
  600. if($auth_level < $tous_level){
  601. $kou_user = $this->auth->id;
  602. $get_user = $to_user_info['id'];
  603. $get_user_free = $to_user_info['free_audio'];
  604. }else{
  605. $kou_user = $to_user_info['id'];
  606. $get_user = $this->auth->id;
  607. $get_user_free = $this->auth->free_audio;
  608. }
  609. //需要扣别人的钱,判断钱是否购
  610. if($price > 0 && $kou_user != $this->auth->id){
  611. $gold = model('wallet')->getWallet($kou_user,'gold');
  612. if(bccomp($price,$gold) == 1){
  613. Db::rollback();
  614. $this->error('对方金币不足');
  615. }
  616. }
  617. //有性别差,扣费
  618. if($price > 0){
  619. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
  620. if($rs['status'] === false){
  621. Db::rollback();
  622. $this->error($rs['msg']);
  623. }
  624. }
  625. //另一方加钱,0收费
  626. if($money > 0 && $get_user_free == 0){
  627. $rs = model('wallet')->lockChangeAccountRemain($get_user, $kou_user,'money',$money,22,'','user_match_audio_log',$log_id);
  628. if($rs['status'] === false){
  629. Db::rollback();
  630. $this->error($rs['msg']);
  631. }
  632. }
  633. Db::commit();
  634. $this->success('success');
  635. }
  636. //打字聊天每句话调用一次
  637. public function typing_once(){
  638. //检测用户
  639. $to_user_id = input_post('to_user_id');
  640. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  641. if(!$to_user_info){
  642. $this->error('不存在的用户');
  643. }
  644. //正常价格
  645. $price = config('site.typing_min_price'); //扣费金币
  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. //发起用户的分数,被发起用户的分数。按性别给分
  651. $auth_level = 0;
  652. $tous_level = 0;
  653. //打分
  654. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  655. $auth_level = 30;//实名女最高
  656. }
  657. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  658. $auth_level = 20;//未实名女次之
  659. }
  660. if($this->auth->gender == 1){
  661. $auth_level = 10;//男性最低
  662. }
  663. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  664. $tous_level = 30;
  665. }
  666. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  667. $tous_level = 20;
  668. }
  669. if($to_user_info['gender'] == 1){
  670. $tous_level = 10;
  671. }
  672. //同性不收钱
  673. //都是男的,不扣钱
  674. //都是实名认证的女性,不扣钱
  675. //都是未实名认证的女性,不扣钱
  676. if($auth_level == $tous_level){
  677. $price = 0;$money = 0;
  678. }
  679. //性别优势的人发起,免费
  680. if($auth_level > $tous_level){
  681. $price = 0;$money = 0;
  682. }
  683. Db::startTrans();
  684. //记录日志
  685. $data = [
  686. 'user_id' => $this->auth->id,
  687. 'price' => $price,
  688. 'createtime' => time(),
  689. 'to_user_id' => $to_user_id,
  690. 'money' => $money,
  691. ];
  692. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  693. if(!$log_id){
  694. Db::rollback();
  695. $this->error('扣费失败');
  696. }
  697. //同性别,提前结束
  698. if($auth_level == $tous_level){
  699. Db::commit();
  700. $this->success('success');
  701. }
  702. //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
  703. if($price == 0 && $money == 0){
  704. Db::commit();
  705. $this->success('success');
  706. }
  707. //扣钱uid,收钱uid,收钱free_video
  708. //分数少扣钱,分数多收益
  709. if($auth_level < $tous_level){
  710. $kou_user = $this->auth->id;
  711. $get_user = $to_user_info['id'];
  712. $get_user_free = $to_user_info['free_typing'];
  713. }else{
  714. //这种已经没有了
  715. $kou_user = $to_user_info['id'];
  716. $get_user = $this->auth->id;
  717. $get_user_free = $this->auth->free_typing;
  718. }
  719. //有性别差,扣费
  720. if($price > 0){
  721. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
  722. if($rs['status'] === false){
  723. Db::rollback();
  724. $this->error($rs['msg']);
  725. }
  726. }
  727. //另一方加钱,0收费
  728. if($money > 0 && $get_user_free == 0){
  729. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,23,'','user_match_typing_log',$log_id);
  730. if($rs['status'] === false){
  731. Db::rollback();
  732. $this->error($rs['msg']);
  733. }
  734. }
  735. //tag任务赠送金币
  736. //搭讪奖励
  737. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  738. if($task_rs === false){
  739. Db::rollback();
  740. $this->error('完成任务赠送奖励失败');
  741. }
  742. Db::commit();
  743. $this->success('success');
  744. }
  745. //语音匹配
  746. public function getaudiouser(){
  747. //判断资格
  748. /*$start = strtotime(date('Y-m-d'));
  749. $end = $start + 86399;
  750. $map = [
  751. 'user_id' => $this->auth->id,
  752. 'createtime' => ['between',[$start,$end]],
  753. 'price' => 0,
  754. ];
  755. $check = Db::name('user_match_audio_log')->where($map)->find();*/
  756. $check = true;
  757. //已经用掉免费的了,判断金额
  758. if($check){
  759. $price = config('site.audio_min_price');
  760. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  761. if($gold < $price){
  762. $this->error('您的金币已经不足,请充值');
  763. }
  764. }
  765. //找到互关的人,排除
  766. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  767. //dump($follow_me);
  768. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  769. //dump($my_follow);exit;
  770. //给出备选用户
  771. $map = [
  772. 'status' =>1, //未封禁用户
  773. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  774. 'is_online' => 0, //不在语聊间的
  775. 'is_livebc' => 0, //不在直播的
  776. 'is_active' => 1, //在线的
  777. //'real_status' => 1, //真人认证
  778. //'idcard_status' => 1, //实名认证
  779. 'open_match_audio' => 1, //打开语聊开关
  780. //'id' => ['NOT IN',$my_follow] //不是好友的
  781. ];
  782. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  783. $lists = $this->fliter_user($lists,10);
  784. $result = [];
  785. if(!empty($lists)){
  786. foreach($lists as $key => $val){
  787. $result[] = ['id'=>$val];
  788. }
  789. }
  790. //tag任务赠送金币
  791. //语音匹配奖励 +5金币
  792. if(!empty($result)){
  793. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  794. if($task_rs === false){
  795. $this->error('完成任务赠送奖励失败');
  796. }
  797. }
  798. $this->success('success',$result);
  799. }
  800. //视频匹配
  801. public function getvideouser(){
  802. //判断资格
  803. /*$start = strtotime(date('Y-m-d'));
  804. $end = $start + 86399;
  805. $map = [
  806. 'user_id' => $this->auth->id,
  807. 'createtime' => ['between',[$start,$end]],
  808. 'price' => 0,
  809. ];
  810. $check = Db::name('user_match_video_log')->where($map)->find();*/
  811. $check = true;
  812. //已经用掉免费的了,判断金额
  813. if($check){
  814. $price = config('site.video_min_price');
  815. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  816. if($gold < $price){
  817. $this->error('您的金币已经不足,请充值');
  818. }
  819. }
  820. //找到互关的人,排除
  821. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  822. //dump($follow_me);
  823. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  824. //dump($my_follow);exit;
  825. //给出备选用户
  826. $map = [
  827. 'status' =>1, //未封禁用户
  828. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  829. 'is_online' => 0, //不在语聊间的
  830. 'is_livebc' => 0, //不在直播的
  831. 'is_active' => 1, //在线的
  832. //'real_status' => 1, //真人认证
  833. //'idcard_status' => 1, //实名认证
  834. 'open_match_video' => 1, //打开视频开关的
  835. // 'id' => ['NOT IN',$my_follow] //不是好友的
  836. ];
  837. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  838. $lists = $this->fliter_user($lists,10);
  839. $result = [];
  840. if(!empty($lists)){
  841. foreach($lists as $key => $val){
  842. $result[] = ['id'=>$val];
  843. }
  844. }
  845. //tag任务赠送金币
  846. //视频匹配奖励 +5金币
  847. if(!empty($result)){
  848. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  849. if($task_rs === false){
  850. $this->error('完成任务赠送奖励失败');
  851. }
  852. }
  853. $this->success('success',$result);
  854. }
  855. //聊天匹配
  856. public function gettypinguser(){
  857. //找到互关的人,排除
  858. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  859. //dump($follow_me);
  860. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  861. //dump($my_follow);exit;
  862. //给出备选用户
  863. $map = [
  864. 'status' =>1, //未封禁用户
  865. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  866. //'real_status' => 1, //真人认证
  867. //'idcard_status' => 1, //实名认证
  868. //'is_active' => 1, //在线的
  869. //打开聊天开关的
  870. 'open_match_typing' => 1, //打开文字聊天开关的
  871. //'id' => ['NOT IN',$my_follow] //不是好友的
  872. ];
  873. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  874. //$lists = $this->fliter_user($lists,100);
  875. $lists = array_column($lists,'id');
  876. $result = [];
  877. if(!empty($lists)){
  878. /*foreach($lists as $key => $val){
  879. $result[] = ['id'=>$val];
  880. }*/
  881. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  882. $result = list_domain_image($result,['avatar,audio_bio']);
  883. }
  884. //tag任务赠送金币
  885. //缘分匹配奖励 +5金币
  886. if(!empty($result)){
  887. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  888. if($task_rs === false){
  889. $this->error('完成任务赠送奖励失败');
  890. }
  891. }
  892. $this->success('success',$result);
  893. }
  894. //过滤规则
  895. private function fliter_user($lists,$number = 1){
  896. if(empty($lists)){
  897. return $lists;
  898. }
  899. //dump($lists);
  900. //过滤掉通话中的
  901. foreach($lists as $key => $val){
  902. if(redis_matching_get($val['id']) == 1){
  903. unset($lists[$key]);
  904. }
  905. }
  906. //预留全部
  907. $all_result = array_column($lists,'id');
  908. //dump($all_result);
  909. //提取同城的
  910. $citydata = [];
  911. foreach($lists as $key => $val){
  912. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  913. $citydata[] = $val['id'];
  914. }
  915. }
  916. //dump($citydata);
  917. //有标签交集的
  918. $tagdata = [];
  919. foreach($lists as $key => $val){
  920. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  921. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  922. $val_tag_ids = explode(',',$val['tag_ids']);
  923. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  924. $tagdata[] = $val['id'];
  925. }
  926. }
  927. }
  928. //dump($tagdata);
  929. //双条件都满足
  930. $double_data = [];
  931. if(!empty($citydata) && !empty($tagdata)){
  932. $double_data = array_intersect($citydata,$tagdata);
  933. }
  934. //dump($double_data);
  935. if(count($double_data) >= $number){
  936. return $double_data;
  937. }
  938. //两种条件合并,去重。空数组合并没影响
  939. $merge_data = array_merge($citydata,$tagdata);
  940. $merge_data = array_flip(array_flip($merge_data));
  941. //dump($merge_data);
  942. if(count($merge_data) >= $number){
  943. return $merge_data;
  944. }
  945. return $all_result;
  946. }
  947. /**
  948. * 是否关注
  949. */
  950. public function isFollows() {
  951. $user_id = $this->request->request("user_id",0,"intval");
  952. if (!$user_id || $user_id<=0) {
  953. $this->error(__('Invalid parameters'));
  954. }
  955. $map = [
  956. 'uid' => $this->auth->id,
  957. 'follow_uid' => $user_id,
  958. ];
  959. $check = Db::name('user_follow')->where($map)->find();
  960. $data = [];
  961. if($check){
  962. $data["is_show_follow"] = 0;
  963. }else{
  964. $data["is_show_follow"] = 1;
  965. }
  966. $this->success("获取成功!",$data);
  967. }
  968. /**
  969. * 获取主播技能分类
  970. */
  971. public function getAnchorType() {
  972. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  973. }
  974. /**
  975. * 主播申请
  976. */
  977. public function anchorApply() {
  978. $this->error('不需要申请');
  979. /*$type_id = $this->request->request('type_id'); // 技能分类ID
  980. $desc = $this->request->request('desc'); // 申请备注
  981. if (!$type_id && !$desc) {
  982. $this->error(__('Invalid parameters'));
  983. }
  984. $useranchorModel = new \app\common\model\UserAnchor();
  985. $data = [];
  986. $data["user_id"] = $this->auth->id;
  987. $data["type_id"] = $type_id;
  988. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  989. $data["desc"] = $desc;
  990. $data["createtime"] = time();
  991. $res = $useranchorModel->insertGetId($data);
  992. if($res) {
  993. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  994. $this->success("申请发送成功!");
  995. } else {
  996. $this->error("网络错误,请稍后重试");
  997. }*/
  998. }
  999. /**
  1000. * 获取当前用户信息
  1001. */
  1002. public function getMyUserInfo() {
  1003. $userInfo = $this->auth->getUserinfo();
  1004. //当月消费金额
  1005. $redis = new Redis();
  1006. $redisconfig = config("redis");
  1007. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  1008. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  1009. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  1010. $this->success("获取成功!",$userInfo);
  1011. }
  1012. /**
  1013. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  1014. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  1015. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  1016. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  1017. * @return float | false | string
  1018. */
  1019. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  1020. if( empty( $point_1 ) || empty( $point_2 ) ){
  1021. return false;
  1022. }
  1023. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  1024. $p1_x = $point_1[0];
  1025. $p1_y = $point_1[1];
  1026. $p2_x = $point_2[0];
  1027. $p2_y = $point_2[1];
  1028. if(
  1029. $p1_x < -180 || $p1_x > 180
  1030. || $p2_x < -180 || $p2_x > 180
  1031. || $p1_y < -90 || $p1_y > 90
  1032. || $p2_y < -90 || $p2_y > 90
  1033. ){
  1034. return '0公里';
  1035. }
  1036. // 根据2点各自的坐标,计算2点之间直线距离的公式
  1037. $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);
  1038. // 是否计算为字符串公里距离
  1039. if( !$calc_as_string ){
  1040. return (string)round( $distance / 1000 , 1 ) . '公里';
  1041. }
  1042. // 如果计算为字符串公里距离
  1043. if( $distance / 1000 > 1 ){
  1044. $k = (string)round( $distance / 1000 , 1 );
  1045. $m = (string)$distance % 1000 ;
  1046. $distance = "{$k}公里{$m}米";
  1047. }
  1048. else{
  1049. $distance = "{$distance}米";
  1050. }
  1051. return $distance;
  1052. }
  1053. //地图api,根据两地坐标,获得两地距离,打卡用的
  1054. //type=0直线,type=1开车
  1055. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  1056. $result = 0;
  1057. $apiurl = 'https://restapi.amap.com/v3/distance?';
  1058. $param = [
  1059. 'key' => '398c424811d1a59beac2f915323d334e',
  1060. 'origins' => $start_lon.','.$start_lat,
  1061. 'destination' => $end_lon.','.$end_lat,
  1062. 'type' => $type,
  1063. 'output' => 'json',
  1064. ];
  1065. $apiurl .= http_build_query($param);
  1066. $request_rs = json_decode(curl_get($apiurl),true);
  1067. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  1068. if(isset($request_rs['results'][0]['distance']))
  1069. {
  1070. $result = $request_rs['results'][0]['distance'];
  1071. }
  1072. }
  1073. //dump($result);
  1074. return $result;
  1075. }
  1076. public function distance()
  1077. {
  1078. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  1079. dump($a);
  1080. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  1081. dump($a);
  1082. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  1083. dump($b);
  1084. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  1085. dump($b);
  1086. }
  1087. //开通守护
  1088. public function addguard() {
  1089. // 接口防并发
  1090. if (!$this->apiLimit(1, 1000)) {
  1091. $this->error(__('Operation frequently'));
  1092. }
  1093. $user_id = input('user_id', 0, 'intval');// 守护对象
  1094. if (!$user_id) {
  1095. $this->error();
  1096. }
  1097. // 不可以守护给自己
  1098. if($this->auth->id == $user_id) {
  1099. $this->error("不可以守护自己");
  1100. }
  1101. //查询是否开通守护
  1102. $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  1103. if ($count) {
  1104. $this->error('已经开通守护了');
  1105. }
  1106. $giftvalue = config('site.guard_price');
  1107. if ($giftvalue <= 0) {
  1108. $this->error('守护金额异常~');
  1109. }
  1110. //被守护人信息
  1111. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  1112. if (!$touserinfo) {
  1113. $this->error("不存在的用户");
  1114. }
  1115. // 判断当前用户余额
  1116. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  1117. if($user_gold < $giftvalue) {
  1118. $this->error("您的金币余额不足");
  1119. }
  1120. Db::startTrans();
  1121. // 添加礼物守护记录表
  1122. $data = [
  1123. 'user_id' => $this->auth->id,
  1124. 'user_to_id' => $user_id,
  1125. 'price' => $giftvalue,
  1126. 'createtime' => time(),
  1127. ];
  1128. $log_id = Db::name('user_guard')->insertGetId($data);
  1129. if(!$log_id){
  1130. Db::rollback();
  1131. $this->error('守护失败');
  1132. }
  1133. if($giftvalue > 0){
  1134. // 扣除当前用户余额
  1135. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
  1136. if($wallet_rs['status'] === false){
  1137. Db::rollback();
  1138. $this->error($wallet_rs['msg']);
  1139. }
  1140. // 添加守护用户余额
  1141. $money_to_gold = config('site.money_to_gold');
  1142. $gift_plat_scale = config('site.gift_plat_scale');
  1143. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  1144. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  1145. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
  1146. if($wallet_rs['status'] === false){
  1147. Db::rollback();
  1148. $this->error($wallet_rs['msg']);
  1149. }
  1150. //增加赠送用户上级余额
  1151. if ($touserinfo['intro_uid']) {
  1152. //获取返利比率
  1153. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1154. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1155. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1156. //上级获得金额
  1157. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1158. if ($intro_uid_money > 0) {
  1159. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
  1160. if($intro_result['status']===false)
  1161. {
  1162. Db::rollback();
  1163. $this->error($intro_result['msg']);
  1164. }
  1165. }
  1166. }
  1167. }
  1168. }
  1169. //tag任务守护金币
  1170. //搭讪奖励
  1171. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  1172. // if($task_rs === false){
  1173. // Db::rollback();
  1174. // $this->error('完成任务守护奖励失败');
  1175. // }
  1176. Db::commit();
  1177. $this->success('守护成功');
  1178. }
  1179. //守护列表
  1180. public function guardlist(){
  1181. $user_id = input('user_id', 0, 'intval');
  1182. if (!$user_id) {
  1183. $this->error('您的网络开小差啦~');
  1184. }
  1185. $list = Db::name('user_guard')
  1186. ->alias('a')
  1187. ->join('user','a.user_id = user.id','LEFT')
  1188. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  1189. ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
  1190. if (!$list) {
  1191. $this->success('success', $list);
  1192. }
  1193. $list = list_domain_image($list,['avatar']);
  1194. $time = time();
  1195. foreach ($list as &$v) {
  1196. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  1197. }
  1198. $this->success('success',$list);
  1199. }
  1200. //我的守护
  1201. public function myguardlist(){
  1202. $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
  1203. if (!in_array($type, [1, 2])) {
  1204. $this->error('您的网络开小差了');
  1205. }
  1206. $where = [];
  1207. if ($type == 1) {
  1208. $join = 'a.user_to_id = user.id';
  1209. $where['a.user_id'] = $this->auth->id;
  1210. } else {
  1211. $join = 'a.user_id = user.id';
  1212. $where['a.user_to_id'] = $this->auth->id;
  1213. }
  1214. $list = Db::name('user_guard')
  1215. ->alias('a')
  1216. ->join('user',$join,'LEFT')
  1217. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  1218. ->where($where)->order('a.id desc')->autopage()->select();
  1219. if (!$list) {
  1220. $this->success('success', $list);
  1221. }
  1222. $list = list_domain_image($list,['avatar']);
  1223. $time = time();
  1224. foreach ($list as &$v) {
  1225. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  1226. }
  1227. $this->success('success',$list);
  1228. }
  1229. //打字聊天每句话调用一次
  1230. public function chat_once(){
  1231. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1232. $this->success('success',array('money'=>''));
  1233. }
  1234. if ($this->auth->gender == 0) { //女生不花钱
  1235. $this->error('您的网络开小差啦~');
  1236. }
  1237. //检测用户
  1238. $to_user_id = input_post('to_user_id');
  1239. $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();
  1240. if(!$to_user_info){
  1241. $this->error('不存在的用户');
  1242. }
  1243. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1244. $this->success('success',array('money'=>''));
  1245. }
  1246. if ($to_user_info['gender'] != 0) {
  1247. $this->error('同性不能聊天~');
  1248. }
  1249. //验证金额
  1250. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1251. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1252. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  1253. //获取折扣
  1254. $vip_chat_discount = config('site.vip_chat_discount');
  1255. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1256. $price = ceil($price * $vip_chat_discount / 10);
  1257. }
  1258. } else {
  1259. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  1260. }
  1261. //正常价格
  1262. $bili = config('site.money_to_gold'); //兑换比例
  1263. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1264. $money = bcdiv($price,$bili,2); //对应人民币
  1265. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1266. $resArray['money'] = $money; //返回给前端的计算结果
  1267. Db::startTrans();
  1268. //记录日志
  1269. $data = [
  1270. 'user_id' => $this->auth->id,
  1271. 'price' => $price,
  1272. 'createtime' => time(),
  1273. 'to_user_id' => $to_user_id,
  1274. 'money' => $money,
  1275. ];
  1276. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  1277. if(!$log_id){
  1278. Db::rollback();
  1279. $this->error('扣费失败');
  1280. }
  1281. //有性别差,扣费
  1282. if($price > 0){
  1283. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
  1284. if($rs['status'] === false){
  1285. Db::rollback();
  1286. $this->error($rs['msg']);
  1287. }
  1288. }
  1289. //另一方加钱,0收费
  1290. if($money > 0){
  1291. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
  1292. if($rs['status'] === false){
  1293. Db::rollback();
  1294. $this->error($rs['msg']);
  1295. }
  1296. $touserinfo = $to_user_info;
  1297. //增加赠送用户上级余额
  1298. if ($touserinfo['intro_uid']) {
  1299. //获取返利比率
  1300. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1301. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1302. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1303. //上级获得金额
  1304. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1305. if ($intro_uid_money > 0) {
  1306. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
  1307. if($intro_result['status']===false)
  1308. {
  1309. Db::rollback();
  1310. $this->error($intro_result['msg']);
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. //增加亲密度
  1317. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1318. if (!$user_intimacy_rs['status']) {
  1319. Db::rollback();
  1320. $this->error('您的网络开小差啦~');
  1321. }
  1322. //tag任务赠送金币
  1323. //私信5名异性奖励
  1324. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  1325. if($task_rs === false){
  1326. Db::rollback();
  1327. $this->error('完成任务赠送奖励失败');
  1328. }
  1329. /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
  1330. if($task_rs === false){
  1331. Db::rollback();
  1332. $this->error('完成任务赠送奖励失败');
  1333. }*/
  1334. Db::commit();
  1335. //发送消息
  1336. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1337. $tenim = new \app\api\controller\Tenim;
  1338. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1339. }
  1340. $this->success('success',$resArray);
  1341. }
  1342. //语音通话每分钟调用一次
  1343. public function voice_onemin(){
  1344. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1345. $this->success('success');
  1346. }
  1347. if ($this->auth->gender == 0) { //女生不花钱
  1348. $this->error('您的网络开小差啦~');
  1349. }
  1350. //检测用户
  1351. $to_user_id = input_post('to_user_id');
  1352. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1353. $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();
  1354. if(!$to_user_info){
  1355. $this->error('不存在的用户');
  1356. }
  1357. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1358. $this->success('success');
  1359. }
  1360. if ($to_user_info['gender'] != 0) {
  1361. $this->error('同性不能聊天~');
  1362. }
  1363. //验证金额
  1364. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1365. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1366. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1367. //获取折扣
  1368. $vip_video_discount = config('site.vip_video_discount');
  1369. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1370. $price = ceil($price * $vip_video_discount / 10);
  1371. }
  1372. } else {
  1373. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1374. }
  1375. //正常价格
  1376. $bili = config('site.money_to_gold'); //兑换比例
  1377. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1378. $money = bcdiv($price,$bili,2); //对应人民币
  1379. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1380. Db::startTrans();
  1381. //查询是否有匹配记录
  1382. $user_match_audio_log_info = [];
  1383. if ($request_id) {
  1384. $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();
  1385. }
  1386. if ($user_match_audio_log_info) {
  1387. //修改记录日志
  1388. $data = [
  1389. 'price' => $user_match_audio_log_info['price'] + $price,
  1390. 'createtime' => time(),
  1391. 'money' => $user_match_audio_log_info['money'] + $money,
  1392. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  1393. ];
  1394. $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);
  1395. if (!$log_id) {
  1396. Db::rollback();
  1397. $this->error('扣费失败');
  1398. }
  1399. } else {
  1400. //添加记录日志
  1401. $data = [
  1402. 'user_id' => $this->auth->id,
  1403. 'price' => $price,
  1404. 'createtime' => time(),
  1405. 'to_user_id' => $to_user_id,
  1406. 'money' => $money,
  1407. 'request_id' => $request_id,
  1408. 'call_minutes' => 1
  1409. ];
  1410. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  1411. if (!$log_id) {
  1412. Db::rollback();
  1413. $this->error('扣费失败');
  1414. }
  1415. }
  1416. //有性别差,扣费
  1417. if($price > 0){
  1418. $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);
  1419. if($rs['status'] === false){
  1420. Db::rollback();
  1421. $this->error($rs['msg']);
  1422. }
  1423. }
  1424. //另一方加钱,0收费
  1425. if($money > 0){
  1426. $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);
  1427. if($rs['status'] === false){
  1428. Db::rollback();
  1429. $this->error($rs['msg']);
  1430. }
  1431. $touserinfo = $to_user_info;
  1432. //增加赠送用户上级余额
  1433. if ($touserinfo['intro_uid']) {
  1434. //获取返利比率
  1435. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1436. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1437. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1438. //上级获得金额
  1439. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1440. if ($intro_uid_money > 0) {
  1441. $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);
  1442. if($intro_result['status']===false)
  1443. {
  1444. Db::rollback();
  1445. $this->error($intro_result['msg']);
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. //增加亲密度
  1452. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1453. if (!$user_intimacy_rs['status']) {
  1454. Db::rollback();
  1455. $this->error('您的网络开小差啦~');
  1456. }
  1457. //tag任务赠送金币
  1458. //与1名异性语音通话奖励
  1459. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
  1460. if($task_rs === false){
  1461. Db::rollback();
  1462. $this->error('完成任务赠送奖励失败');
  1463. }
  1464. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
  1465. if($task_rs === false){
  1466. Db::rollback();
  1467. $this->error('完成任务赠送奖励失败');
  1468. }
  1469. //发送消息
  1470. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1471. $tenim = new \app\api\controller\Tenim;
  1472. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1473. }
  1474. Db::commit();
  1475. $this->success('success');
  1476. }
  1477. //视频通话每分钟调用一次
  1478. public function videochat_onemin(){
  1479. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1480. $this->success('success');
  1481. }
  1482. if ($this->auth->gender == 0) { //女生不花钱
  1483. $this->error('您的网络开小差啦~');
  1484. }
  1485. //检测用户
  1486. $to_user_id = input_post('to_user_id');
  1487. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1488. $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();
  1489. if(!$to_user_info){
  1490. $this->error('不存在的用户');
  1491. }
  1492. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1493. $this->success('success');
  1494. }
  1495. if ($to_user_info['gender'] != 0) {
  1496. $this->error('同性不能聊天~');
  1497. }
  1498. /* //检查是否免费过
  1499. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1500. if (!$count) {
  1501. //记录日志
  1502. $data = [
  1503. 'user_id' => $this->auth->id,
  1504. 'price' => 0,
  1505. 'createtime' => time(),
  1506. 'to_user_id' => $to_user_id,
  1507. 'money' => 0,
  1508. ];
  1509. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1510. if(!$log_id){
  1511. $this->error('扣费失败');
  1512. }
  1513. $this->success('success');
  1514. }*/
  1515. //验证金额
  1516. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1517. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1518. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1519. //获取折扣
  1520. $vip_video_discount = config('site.vip_video_discount');
  1521. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1522. $price = ceil($price * $vip_video_discount / 10);
  1523. }
  1524. } else {
  1525. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1526. }
  1527. //正常价格
  1528. $bili = config('site.money_to_gold'); //兑换比例
  1529. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1530. $money = bcdiv($price,$bili,2); //对应人民币
  1531. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1532. Db::startTrans();
  1533. //查询是否有匹配记录
  1534. $user_match_video_log_info = [];
  1535. if ($request_id) {
  1536. $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();
  1537. }
  1538. if ($user_match_video_log_info) {
  1539. //修改记录日志
  1540. $data = [
  1541. 'price' => $user_match_video_log_info['price'] + $price,
  1542. 'createtime' => time(),
  1543. 'money' => $user_match_video_log_info['money'] + $money,
  1544. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  1545. ];
  1546. $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);
  1547. if (!$log_id) {
  1548. Db::rollback();
  1549. $this->error('扣费失败');
  1550. }
  1551. } else {
  1552. //添加记录日志
  1553. $data = [
  1554. 'user_id' => $this->auth->id,
  1555. 'price' => $price,
  1556. 'createtime' => time(),
  1557. 'to_user_id' => $to_user_id,
  1558. 'money' => $money,
  1559. 'request_id' => $request_id,
  1560. 'call_minutes' => 1
  1561. ];
  1562. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  1563. if (!$log_id) {
  1564. Db::rollback();
  1565. $this->error('扣费失败');
  1566. }
  1567. }
  1568. //有性别差,扣费
  1569. if($price > 0){
  1570. $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);
  1571. if($rs['status'] === false){
  1572. Db::rollback();
  1573. $this->error($rs['msg']);
  1574. }
  1575. }
  1576. //另一方加钱,0收费
  1577. if($money > 0){
  1578. $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);
  1579. if($rs['status'] === false){
  1580. Db::rollback();
  1581. $this->error($rs['msg']);
  1582. }
  1583. $touserinfo = $to_user_info;
  1584. //增加赠送用户上级余额
  1585. if ($touserinfo['intro_uid']) {
  1586. //获取返利比率
  1587. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1588. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1589. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1590. //上级获得金额
  1591. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1592. if ($intro_uid_money > 0) {
  1593. $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);
  1594. if($intro_result['status']===false)
  1595. {
  1596. Db::rollback();
  1597. $this->error($intro_result['msg']);
  1598. }
  1599. }
  1600. }
  1601. }
  1602. }
  1603. //增加亲密度
  1604. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1605. if (!$user_intimacy_rs['status']) {
  1606. Db::rollback();
  1607. $this->error('您的网络开小差啦~');
  1608. }
  1609. //tag任务赠送金币
  1610. //与1名异性视频通话奖励
  1611. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
  1612. if($task_rs === false){
  1613. Db::rollback();
  1614. $this->error('完成任务赠送奖励失败');
  1615. }
  1616. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
  1617. if($task_rs === false){
  1618. Db::rollback();
  1619. $this->error('完成任务赠送奖励失败');
  1620. }
  1621. Db::commit();
  1622. //发送消息
  1623. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1624. $tenim = new \app\api\controller\Tenim;
  1625. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1626. }
  1627. $this->success('success');
  1628. }
  1629. //消息列表好友/密友
  1630. public function intimacyfriends() {
  1631. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  1632. $where = [];
  1633. /*if ($type == 0) {
  1634. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  1635. $mt_user = Db::name('user');
  1636. // $mt_user_follow = Db::name('user_follow');
  1637. $mt_user_intimacy = Db::name('user_intimacy');
  1638. foreach ($list as &$v) {
  1639. //查询亲密度
  1640. if ($this->auth->gender == 1) {
  1641. $where['uid'] = $this->auth->id;
  1642. $where['other_uid'] = $v['user_id'];
  1643. } else {
  1644. $where['other_uid'] = $this->auth->id;
  1645. $where['uid'] = $v['user_id'];
  1646. }
  1647. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  1648. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  1649. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  1650. //查询对方信息
  1651. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  1652. $v['nickname'] = $user_info['nickname'];
  1653. $v['avatar'] = one_domain_image($user_info['avatar']);
  1654. $v['updatetime'] = get_last_time($v['updatetime']);
  1655. $v['age'] = birthtime_to_age($user_info['birthday']);
  1656. $v['gender'] = $user_info['gender'];
  1657. $v['real_status'] = $user_info['real_status'];
  1658. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1659. $v['status'] = 1;
  1660. }
  1661. } else {*/
  1662. if ($this->auth->gender == 1) {
  1663. $where['uid'] = $this->auth->id;
  1664. $field = 'other_uid user_id, value, updatetime';
  1665. } else {
  1666. $where['other_uid'] = $this->auth->id;
  1667. $field = 'uid user_id, value, updatetime';
  1668. }
  1669. if ($type == 1) { //密友
  1670. $where['value'] = ['egt', 1000];
  1671. } elseif ($type == 2) { //好友
  1672. $where['value'] = ['egt', 100];
  1673. } else { //消息列表好友
  1674. $where['value'] = ['egt', 10];
  1675. }
  1676. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  1677. $mt_user = Db::name('user');
  1678. $mt_user_follow = Db::name('user_follow');
  1679. foreach ($list as &$v) {
  1680. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  1681. $v['nickname'] = $user_info['nickname'];
  1682. $v['avatar'] = one_domain_image($user_info['avatar']);
  1683. $v['updatetime'] = get_last_time($v['updatetime']);
  1684. $v['age'] = birthtime_to_age($user_info['birthday']);
  1685. $v['gender'] = $user_info['gender'];
  1686. $v['real_status'] = $user_info['real_status'];
  1687. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1688. $v['is_active'] = $user_info['is_active'];
  1689. }
  1690. // }
  1691. $this->success('success',$list);
  1692. }
  1693. //消息列表通话
  1694. public function calllist() {
  1695. if ($this->auth->gender == 1) {
  1696. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
  1697. } elseif ($this->auth->gender == 0) {
  1698. $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
  1699. } else {
  1700. $this->success('success', []);
  1701. }
  1702. if (!$list) {
  1703. $this->success('success', $list);
  1704. }
  1705. $arr = [];
  1706. $mt_user_match_audio_log = Db::name('user_match_audio_log');
  1707. $mt_user_match_video_log = Db::name('user_match_video_log');
  1708. $mt_user = Db::name('user');
  1709. foreach ($list as &$v) {
  1710. $data = [];
  1711. if ($this->auth->gender == 1) {
  1712. if ($v['log_type'] == 11) { //视频通话
  1713. $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1714. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1715. } else { //语音通话
  1716. $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1717. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1718. }
  1719. } else {
  1720. if ($v['log_type'] == 21) { //视频通话
  1721. $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1722. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1723. } else { //语音通话
  1724. $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1725. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1726. }
  1727. }
  1728. $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
  1729. $data['user_id'] = $log_info['user_id'];
  1730. $data['nickname'] = $user_info['nickname'];
  1731. $data['avatar'] = one_domain_image($user_info['avatar']);
  1732. $data['createtime'] = get_last_time($log_info['createtime']);
  1733. $data['is_active'] = $user_info['is_active'];
  1734. $arr[] = $data;
  1735. }
  1736. $this->success('success', $arr);
  1737. }
  1738. //查询对方用户收费价格和我的余额
  1739. public function otheruserinfo(){
  1740. $user_id = input('user_id', 0, 'intval');
  1741. if (!$user_id) {
  1742. $this->error('您的网络开小差啦~');
  1743. }
  1744. $field = [
  1745. 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
  1746. ];
  1747. $info = Db::name('user')->field($field)->where('id',$user_id)->find();
  1748. if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
  1749. if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
  1750. $this->error('性别存在问题');
  1751. }
  1752. }
  1753. if ($this->auth->gender == 0) { //收费价格按照女号
  1754. $info['chat_price'] = $this->auth->chat_price;
  1755. $info['voice_price'] = $this->auth->voice_price;
  1756. $info['video_price'] = $this->auth->video_price;
  1757. $info['open_match_audio'] = $this->auth->open_match_audio;
  1758. $info['open_match_video'] = $this->auth->open_match_video;
  1759. }
  1760. $info['chat_price_vip'] = $info['chat_price']; //vip价格
  1761. $info['voice_price_vip'] = $info['voice_price'];
  1762. $info['video_price_vip'] = $info['video_price'];
  1763. $info['is_vip'] = 0; //是否vip: 0否 1是
  1764. //获取聊天折扣
  1765. $vip_chat_discount = config('site.vip_chat_discount');
  1766. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1767. $info['vip_chat_discount'] = $vip_chat_discount;
  1768. } else {
  1769. $info['vip_chat_discount'] = 10;
  1770. }
  1771. //获取语音视频折扣
  1772. $vip_video_discount = config('site.vip_video_discount');
  1773. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1774. $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
  1775. $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
  1776. } else {
  1777. $info['vip_voice_discount'] = 10;
  1778. $info['vip_video_discount'] = 10;
  1779. }
  1780. //获取聊天折扣
  1781. $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
  1782. //获取语音折扣
  1783. $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
  1784. //获取视频折扣
  1785. $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
  1786. if ($this->auth->gender == 0) { //查询男号余额和vip
  1787. $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
  1788. } else {
  1789. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1790. }
  1791. if ($wallet_info['vip_endtime'] >= time()) {
  1792. $info['is_vip'] = 1;
  1793. }
  1794. $info['gold'] = $wallet_info['gold'];
  1795. $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
  1796. $info['money_to_gold'] = config('site.money_to_gold'); //一元人民币兑换金币数量
  1797. $this->success('success',$info);
  1798. }
  1799. //亲密度等级信息
  1800. public function intimacylevel() {
  1801. $user_id = input('user_id', 0, 'intval'); //对方id
  1802. if (!$user_id) {
  1803. $this->error('参数缺失');
  1804. }
  1805. if ($this->auth->gender == 0) { //女用户
  1806. $where['uid'] = $user_id;
  1807. $where['other_uid'] = $this->auth->id;
  1808. } else { //男用户
  1809. $where['uid'] = $this->auth->id;
  1810. $where['other_uid'] = $user_id;
  1811. }
  1812. $level = 0; //当前等级
  1813. $level_name = ''; //当前等级名称
  1814. $qinmi_sum = 0; //当前亲密度
  1815. $next_level_diff = 0; //距下一等级亲密度差值
  1816. //亲密度等级列表
  1817. $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
  1818. //当前亲密度信息
  1819. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  1820. if ($user_intimacy_info) {
  1821. //当前亲密度
  1822. $qinmi_sum = $user_intimacy_info['value'];
  1823. if ($list) {
  1824. //当前等级信息
  1825. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
  1826. if ($level_info) {
  1827. $level = $level_info['level'];
  1828. $level_name = $level_info['name'];
  1829. }
  1830. //下一等级信息
  1831. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  1832. if ($next_level_info) {
  1833. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  1834. }
  1835. }
  1836. } else {
  1837. $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
  1838. }
  1839. if ($list) {
  1840. foreach ($list as &$v) {
  1841. if ($v['level'] < $level) {
  1842. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  1843. } elseif ($v['level'] == $level) {
  1844. $v['is_unlock'] = 2;
  1845. } else {
  1846. $v['is_unlock'] = 3;
  1847. }
  1848. }
  1849. }
  1850. $data['level'] = $level; //当前等级
  1851. $data['level_name'] = $level_name; //当前等级名称
  1852. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  1853. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  1854. $data['level_list'] = $list; //等级列表
  1855. $this->success('亲密度等级信息', $data);
  1856. }
  1857. //语音视频随聊
  1858. public function getrandomuser() {
  1859. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1860. if (!in_array($type, [1, 2, 3])) {
  1861. $this->error('您的网络开小差了');
  1862. }
  1863. $size = input('size',0,'intval');// 是否查 10 条
  1864. $size = $size > 0 ? 1 : 0;
  1865. //给出备选用户
  1866. $map = [
  1867. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1868. 'is_active' => 1, //在线的
  1869. 'status' =>1, //未封禁用户
  1870. // 'is_online' => 0, //不在语聊间的
  1871. 'is_livebc' => 0, //不在直播的
  1872. // 'real_status' => 1, //真人认证
  1873. // 'idcard_status' => 1, //实名认证
  1874. // 'id' => ['NOT IN',$my_follow] //不是好友的
  1875. 'is_kefu' => 0, //不是客服
  1876. ];
  1877. if ($this->auth->gender == 1) {
  1878. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1879. }
  1880. if ($type == 1) {
  1881. $map['open_match_audio'] = 1;
  1882. } elseif ($type == 2) {
  1883. $map['open_match_video'] = 1;
  1884. }
  1885. $key = md5(json_encode($map));// 根据搜索条件做Key
  1886. $lists = Cache::remember("getrandomuser_{$key}_{$size}",function () use ($map,$size){
  1887. $query = Db::name('user')
  1888. ->field('id,nickname,username,avatar')
  1889. ->where($map)
  1890. ->order('is_active desc, active_time desc');
  1891. if ($size == 1){
  1892. $query->limit(10);
  1893. }else{
  1894. $query->page($this->page,100);
  1895. }
  1896. $lists = $query->select();
  1897. //$lists = $this->fliter_user($lists,100);
  1898. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1899. $mt_user_greet_content = Db::name('user_greet_content');
  1900. foreach ($lists as &$v) {
  1901. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1902. if ($info) {
  1903. if ($info['type'] == 0) {
  1904. $v['greet_content'] = $info['content'];
  1905. } elseif ($info['type'] == 1) {
  1906. $v['greet_content'] = '[语音]';
  1907. } elseif ($info['type'] == 2) {
  1908. $v['greet_content'] = '[图片]';
  1909. }
  1910. } else {
  1911. $v['greet_content'] = '';
  1912. }
  1913. }
  1914. return $lists;
  1915. },2);
  1916. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1917. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1918. $return_data['list'] = $lists;
  1919. $this->success('success',$return_data);
  1920. }
  1921. //语音视频随聊
  1922. public function getrandomuserbak() {
  1923. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1924. if (!in_array($type, [1, 2, 3])) {
  1925. $this->error('您的网络开小差了');
  1926. }
  1927. //找到互关的人,排除
  1928. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  1929. //dump($follow_me);
  1930. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  1931. //dump($my_follow);exit;
  1932. //给出备选用户
  1933. $map = [
  1934. 'status' =>1, //未封禁用户
  1935. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1936. // 'is_online' => 0, //不在语聊间的
  1937. 'is_livebc' => 0, //不在直播的
  1938. 'is_active' => 1, //在线的
  1939. // 'real_status' => 1, //真人认证
  1940. // 'idcard_status' => 1, //实名认证
  1941. // 'id' => ['NOT IN',$my_follow] //不是好友的
  1942. 'is_kefu' => 0, //不是客服
  1943. ];
  1944. if ($this->auth->gender == 1) {
  1945. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1946. }
  1947. if ($type == 1) {
  1948. $map['open_match_audio'] = 1;
  1949. } elseif ($type == 2) {
  1950. $map['open_match_video'] = 1;
  1951. }
  1952. $lists = Db::name('user')
  1953. ->field('id,nickname,username,avatar')
  1954. ->where($map)
  1955. ->order('is_active desc, active_time desc')
  1956. ->page($this->page,100)
  1957. ->select();
  1958. //$lists = $this->fliter_user($lists,100);
  1959. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1960. $mt_user_greet_content = Db::name('user_greet_content');
  1961. foreach ($lists as &$v) {
  1962. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1963. if ($info) {
  1964. if ($info['type'] == 0) {
  1965. $v['greet_content'] = $info['content'];
  1966. } elseif ($info['type'] == 1) {
  1967. $v['greet_content'] = '[语音]';
  1968. } elseif ($info['type'] == 2) {
  1969. $v['greet_content'] = '[图片]';
  1970. }
  1971. } else {
  1972. $v['greet_content'] = '';
  1973. }
  1974. }
  1975. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1976. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1977. $return_data['list'] = $lists;
  1978. $this->success('success',$return_data);
  1979. }
  1980. //查询免费体验视频通话用户信息
  1981. public function getfreevideouserinfo() {
  1982. $to_user_id = input('to_user_id', 0, 'intval');
  1983. $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
  1984. if(!$to_user_info){
  1985. $this->error('不存在的用户');
  1986. }
  1987. if ($to_user_info['gender'] == $this->auth->gender) {
  1988. $this->error('同性不能聊天~');
  1989. }
  1990. $to_user_info['desc'] = '';
  1991. $age = birthtime_to_age($to_user_info['birthday']);
  1992. if ($age > 0) {
  1993. $to_user_info['desc'] = $age . '岁';
  1994. } else {
  1995. $to_user_info['desc'] = '18岁';
  1996. }
  1997. if ($to_user_info['height']) {
  1998. $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
  1999. }
  2000. //查询是否免费过
  2001. $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  2002. $this->success('信息', $to_user_info);
  2003. }
  2004. //免费体验视频通话1分钟
  2005. public function videochat_onemin_free(){
  2006. $this->success('success');
  2007. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  2008. $this->success('success');
  2009. }
  2010. //检查是否免费过
  2011. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  2012. if ($count) {
  2013. $this->error('已经免费体验过');
  2014. }
  2015. //检测用户
  2016. $to_user_id = input_post('to_user_id');
  2017. $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();
  2018. if(!$to_user_info){
  2019. $this->error('不存在的用户');
  2020. }
  2021. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  2022. $this->success('success');
  2023. }
  2024. if ($to_user_info['gender'] == $this->auth->gender) {
  2025. $this->error('同性不能聊天~');
  2026. }
  2027. //记录日志
  2028. $data = [
  2029. 'user_id' => $this->auth->id,
  2030. 'price' => 0,
  2031. 'createtime' => time(),
  2032. 'to_user_id' => $to_user_id,
  2033. 'money' => 0,
  2034. ];
  2035. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  2036. if(!$log_id){
  2037. $this->error('扣费失败');
  2038. }
  2039. $this->success('success');
  2040. }
  2041. //男性非会员解锁聊天
  2042. public function unlockchat() {
  2043. // 接口防并发
  2044. if (!$this->apiLimit(1, 1000)) {
  2045. $this->error(__('Operation frequently'));
  2046. }
  2047. //男性非会员是否已开通聊天
  2048. if ($this->auth->gender == 0) {
  2049. $this->error('不需要解锁');
  2050. }
  2051. $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  2052. if ($vip_endtime > time()) {
  2053. $this->error('不需要解锁');
  2054. }
  2055. $user_id = input('user_id', 0, 'intval');//对方id
  2056. if (!$user_id) {
  2057. $this->error();
  2058. }
  2059. // 不可以守护给自己
  2060. if($this->auth->id == $user_id) {
  2061. $this->error("不可以解锁自己");
  2062. }
  2063. //查询是否解锁过
  2064. $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  2065. if ($user_chat_unlock) {
  2066. $this->error('已经解锁过了');
  2067. }
  2068. $giftvalue = config('site.unlock_chat_gold');
  2069. if ($giftvalue <= 0) {
  2070. $this->error('解锁金额异常~');
  2071. }
  2072. //被解锁人信息
  2073. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  2074. if (!$touserinfo) {
  2075. $this->error("不存在的用户");
  2076. }
  2077. // 判断当前用户余额
  2078. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  2079. if($user_gold < $giftvalue) {
  2080. $this->error("您的金币余额不足");
  2081. }
  2082. Db::startTrans();
  2083. //添加解锁记录表
  2084. $data = [
  2085. 'user_id' => $this->auth->id,
  2086. 'user_to_id' => $user_id,
  2087. 'price' => $giftvalue,
  2088. 'createtime' => time(),
  2089. ];
  2090. $log_id = Db::name('user_chat_unlock')->insertGetId($data);
  2091. if(!$log_id){
  2092. Db::rollback();
  2093. $this->error('解锁失败');
  2094. }
  2095. if($giftvalue > 0){
  2096. // 扣除当前用户余额
  2097. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_chat_unlock',$log_id);
  2098. if($wallet_rs['status'] === false){
  2099. Db::rollback();
  2100. $this->error($wallet_rs['msg']);
  2101. }
  2102. // 添加守护用户余额
  2103. $money_to_gold = config('site.money_to_gold');
  2104. $gift_plat_scale = config('site.gift_plat_scale');
  2105. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  2106. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  2107. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_chat_unlock',$log_id,2);
  2108. if($wallet_rs['status'] === false){
  2109. Db::rollback();
  2110. $this->error($wallet_rs['msg']);
  2111. }
  2112. //增加赠送用户上级余额
  2113. if ($touserinfo['intro_uid']) {
  2114. //获取返利比率
  2115. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  2116. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  2117. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  2118. //上级获得金额
  2119. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  2120. if ($intro_uid_money > 0) {
  2121. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人解锁聊天获赠奖励','gift_user_typing',$log_id);
  2122. if($intro_result['status']===false)
  2123. {
  2124. Db::rollback();
  2125. $this->error($intro_result['msg']);
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. //tag任务守护金币
  2132. //搭讪奖励
  2133. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  2134. // if($task_rs === false){
  2135. // Db::rollback();
  2136. // $this->error('完成任务守护奖励失败');
  2137. // }
  2138. Db::commit();
  2139. $this->success('解锁成功');
  2140. }
  2141. }