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