Usercenter.php 96 KB

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