Usercenter.php 93 KB

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