Usercenter.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Cache;
  5. use think\Db;
  6. /**
  7. * 会员中心,不是个人中心
  8. */
  9. class Usercenter extends Api
  10. {
  11. protected $noNeedLogin = ['test','testredis'];
  12. protected $noNeedRight = '*';
  13. protected $allowFields = [
  14. 'id',
  15. 'username',
  16. 'nickname',
  17. //'truename',//
  18. 'email',
  19. 'mobile',
  20. 'avatar',
  21. 'real_status',
  22. 'gender',
  23. 'height',
  24. 'weight',
  25. 'birthday',
  26. 'bio',
  27. 'audio_bio',
  28. 'idcard_status',
  29. 'is_active',
  30. 'longitude',
  31. 'latitude',
  32. 'cityname',
  33. 'photo_images',
  34. 'education_id',
  35. 'hobby_ids',
  36. 'job_id',
  37. 'marital_id',
  38. 'tag_ids',
  39. 'wages_id',
  40. 'hometown_cityid',
  41. 'wechat_account',
  42. 'secretvideo_status',
  43. 'character_id',
  44. 'constellation_id',
  45. 'stature_id',
  46. 'is_appointment',
  47. 'chat_price',
  48. 'voice_price',
  49. 'video_price',
  50. 'greet_voice',
  51. 'greet_chat',
  52. 'is_kefu',
  53. 'is_hideaddress', 'is_recommend','is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'
  54. ];
  55. //获取他人用户信息,留下足迹
  56. public function getuserinfo(){
  57. $uid = input_post('uid',0);
  58. $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
  59. if(!$userinfo){
  60. $this->error('不存在的用户');
  61. }
  62. //用户数据
  63. $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
  64. $new_data = [
  65. 'age' => birthtime_to_age($userinfo['birthday']),
  66. ];
  67. if ($this->auth->gender == 1) {
  68. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $this->auth->id, 'other_uid' => $uid])->value('value');
  69. } elseif ($this->auth->gender == 0) {
  70. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $this->auth->id])->value('value');
  71. } else {
  72. $qinmi_sum = 0;
  73. }
  74. $new_data['qinmi_sum'] = $qinmi_sum ? :0;
  75. //合并
  76. $userinfo = array_merge($userinfo,$new_data);
  77. //枚举
  78. $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
  79. $userinfo['education'] = $userinfo['education'] ? : '';
  80. $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
  81. $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
  82. $userinfo['job'] = $userinfo['job'] ? : '';
  83. $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
  84. $userinfo['marital'] = $userinfo['marital'] ? : '';
  85. $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
  86. $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
  87. $userinfo['wages'] = $userinfo['wages'] ? : '';
  88. $userinfo['character'] = Db::name('enum_character')->where('id',$userinfo['character_id'])->value('name');
  89. $userinfo['character'] = $userinfo['character'] ? : '';
  90. $userinfo['constellation'] = Db::name('enum_constellation')->where('id',$userinfo['constellation_id'])->value('name');
  91. $userinfo['constellation'] = $userinfo['constellation'] ? : '';
  92. $userinfo['stature'] = Db::name('enum_stature')->where('id',$userinfo['stature_id'])->value('name');
  93. $userinfo['stature'] = $userinfo['stature'] ? : '';
  94. $userinfo['live'] = Db::name('enum_live')->where('id',$userinfo['live_id'])->value('name');
  95. $userinfo['live'] = $userinfo['live'] ? : '';
  96. $userinfo['car'] = Db::name('enum_car')->where('id',$userinfo['car_id'])->value('name');
  97. $userinfo['car'] = $userinfo['car'] ? : '';
  98. $userinfo['chest'] = Db::name('enum_chest')->where('id',$userinfo['chest_id'])->value('name');
  99. $userinfo['chest'] = $userinfo['chest'] ? : '';
  100. //家乡
  101. $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
  102. $userinfo['hometown_city'] = ($userinfo['hometown_city'] && $userinfo['is_hideaddress'] == 0) ? $userinfo['hometown_city'] : '';
  103. //vip
  104. $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
  105. $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
  106. //是否喜欢和关注
  107. $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
  108. $userinfo['is_follow'] = $is_follow ? 1 : 0;
  109. $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
  110. $userinfo['is_like'] = $is_like ? 1 : 0;
  111. //是否拉黑
  112. $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
  113. $userinfo['is_black'] = $is_black ? 1 : 0;
  114. //关注人数,粉丝人数
  115. $follow_num = Db::name('user_follow')->where(['uid'=>$uid])->count('id');
  116. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$uid])->count('id');
  117. $userinfo['follow_num'] = $follow_num;
  118. $userinfo['fans_num'] = $fans_num;
  119. //访客数
  120. $visit_num = Db::name('user_visit')->where(['to_uid'=>$uid])->count('id');
  121. $userinfo['visit_num'] = $visit_num;
  122. //查询是否打过招呼
  123. $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  124. if ($count) {
  125. $userinfo['is_chat'] = 1; //是否打过招呼: 1是 0否
  126. } else {
  127. $userinfo['is_chat'] = 0; //是否打过招呼: 1是 0否
  128. }
  129. //守护数量和是否已经守护
  130. $userinfo['guard_num'] = Db::name('user_guard')->where(['user_to_id' => $uid])->count('id');
  131. $userinfo['is_guard'] = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  132. //查询财富等级和魅力等级
  133. $wallet_info = Db::name('user_wallet')->where(['user_id' => $uid])->find();
  134. $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  135. if ($wealth_level) {
  136. $userinfo['wealth_level'] = localpath_to_netpath($wealth_level['image']);
  137. } else {
  138. $userinfo['wealth_level'] = '';
  139. }
  140. $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  141. if ($charm_level) {
  142. $userinfo['charm_level'] = localpath_to_netpath($charm_level['image']);
  143. } else {
  144. $userinfo['charm_level'] = '';
  145. }
  146. //开通守护消耗金币数量
  147. $userinfo['guard_price'] = config('site.guard_price') ? : 0;
  148. //男性非会员是否已开通聊天
  149. // $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  150. // $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  151. // if ($this->auth->gender == 0 || $vip_endtime > time() || $user_chat_unlock) {
  152. $userinfo['is_chat_unlock'] = 1; //已解锁
  153. // } else {
  154. // $userinfo['is_chat_unlock'] = 0;
  155. // }
  156. //男性非会员解锁聊天所需金币数量
  157. $userinfo['unlock_chat_gold'] = config('site.unlock_chat_gold') > 0 ? config('site.unlock_chat_gold') : 10;
  158. //动态信息
  159. $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();
  160. if ($dongtai) {
  161. $dongtai_image = [];
  162. foreach ($dongtai as &$v) {
  163. $arr['type'] = $v['type'];
  164. if ($v['type'] == 1) {
  165. //图片
  166. $images_url = explode(',', $v['images']);
  167. foreach ($images_url as &$value) {
  168. $arr['images'] = one_domain_image($value);
  169. array_push($dongtai_image, $arr);
  170. if (count($dongtai_image) == 3) {
  171. break 2;
  172. }
  173. }
  174. } else {
  175. //视频
  176. $images_url = explode('.', $v['images']);
  177. unset($images_url[count($images_url) - 1]);
  178. $arr['images'] = join('.', $images_url) . '_0.jpg';
  179. $arr['images'] = one_domain_image($arr['images']);
  180. array_push($dongtai_image, $arr);
  181. if (count($dongtai_image) == 3) {
  182. break;
  183. }
  184. }
  185. }
  186. $userinfo['dongtai_image'] = $dongtai_image;
  187. // $dongtai = join(',', $dongtai);
  188. // $dongtai = explode(',', $dongtai);
  189. // $dongtai = array_slice($dongtai, 0, 3);
  190. // $dongtai = join(',', $dongtai);
  191. // $userinfo['dongtai_image'] = one_domain_image($dongtai);
  192. // $userinfo['dongtai_image'] = explode(',', $userinfo['dongtai_image']);
  193. } else {
  194. $userinfo['dongtai_image'] = [];
  195. }
  196. if ($this->auth->id != $uid) {
  197. //查看别人信息,就要留下痕迹
  198. $data = [
  199. 'uid' => $this->auth->id,
  200. 'to_uid' => $uid,
  201. ];
  202. $check = Db::name('user_visit')->where($data)->find();
  203. if ($check) {
  204. Db::name('user_visit')->where($data)->update(['number' => $check['number'] + 1, 'updatetime' => time()]);
  205. } else {
  206. $data['number'] = 1;
  207. $data['updatetime'] = time();
  208. Db::name('user_visit')->insertGetId($data);
  209. }
  210. }
  211. //礼物墙
  212. $userinfo['gift_wall'] = $this->giftwall($uid);
  213. $this->success('success',$userinfo);
  214. }
  215. //某用户的礼物墙
  216. private function giftwall($uid){
  217. //$uid = $this->auth->id;
  218. //聊天礼物
  219. $gift_user_typing = Db::name('gift_user_typing')->alias('log')
  220. ->join('gift', 'gift.id = log.gift_id', 'LEFT')
  221. ->field('log.gift_id,log.gift_name,sum(log.number) as number,gift.image')
  222. ->where(['log.user_to_id' => $uid])
  223. ->group('log.gift_id')
  224. ->order('gift.price desc')
  225. ->column('log.gift_id,log.gift_name,sum(log.number) as number,gift.image');
  226. $gift_user_typing = list_domain_image($gift_user_typing,['image']);
  227. //dump($gift_user_typing);
  228. //动态礼物
  229. $gift_user_dongtai = Db::name('gift_user_dongtai')->alias('log')
  230. ->join('gift', 'gift.id = log.gift_id', 'LEFT')
  231. ->field('log.gift_id,log.gift_name,sum(log.number) as number,gift.image')
  232. ->where(['log.user_to_id' => $uid])
  233. ->group('log.gift_id')
  234. ->order('gift.price desc')
  235. ->column('log.gift_id,log.gift_name,sum(log.number) as number,gift.image');
  236. $gift_user_dongtai = list_domain_image($gift_user_dongtai,['image']);
  237. //dump($gift_user_dongtai);
  238. //为空
  239. if(empty($gift_user_typing) && empty($gift_user_dongtai)){
  240. return [];
  241. }
  242. if(empty($gift_user_typing) && !empty($gift_user_dongtai)){
  243. foreach($gift_user_dongtai as $key => $val){
  244. $result[] = $val;
  245. }
  246. return $result;
  247. }
  248. if(!empty($gift_user_typing) && empty($gift_user_dongtai)){
  249. foreach($gift_user_typing as $key => $val){
  250. $result[] = $val;
  251. }
  252. return $result;
  253. }
  254. //合并
  255. foreach($gift_user_typing as $key => $val){
  256. foreach($gift_user_dongtai as $k => $v){
  257. if($key == $k){
  258. $gift_user_typing[$key]['number'] += $v['number'];
  259. }
  260. if(!isset($gift_user_typing[$k])){
  261. $gift_user_typing[$k] = $v;
  262. }
  263. }
  264. }
  265. //dump($gift_user_typing);
  266. //结果
  267. $result = [];
  268. foreach($gift_user_typing as $key => $val){
  269. $result[] = $val;
  270. }
  271. return $result;
  272. }
  273. /**
  274. * 是否关注
  275. */
  276. public function isFollows() {
  277. $user_id = $this->request->request("user_id",0,"intval");
  278. if (!$user_id || $user_id<=0) {
  279. $this->error(__('Invalid parameters'));
  280. }
  281. $map = [
  282. 'uid' => $this->auth->id,
  283. 'follow_uid' => $user_id,
  284. ];
  285. $check = Db::name('user_follow')->where($map)->find();
  286. $data = [];
  287. if($check){
  288. $data["is_show_follow"] = 0;
  289. }else{
  290. $data["is_show_follow"] = 1;
  291. }
  292. $this->success("获取成功!",$data);
  293. }
  294. /**
  295. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  296. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  297. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  298. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  299. * @return float | false | string
  300. */
  301. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  302. if( empty( $point_1 ) || empty( $point_2 ) ){
  303. return false;
  304. }
  305. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  306. $p1_x = $point_1[0];
  307. $p1_y = $point_1[1];
  308. $p2_x = $point_2[0];
  309. $p2_y = $point_2[1];
  310. if(
  311. $p1_x < -180 || $p1_x > 180
  312. || $p2_x < -180 || $p2_x > 180
  313. || $p1_y < -90 || $p1_y > 90
  314. || $p2_y < -90 || $p2_y > 90
  315. ){
  316. return '0公里';
  317. }
  318. // 根据2点各自的坐标,计算2点之间直线距离的公式
  319. $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);
  320. // 是否计算为字符串公里距离
  321. if( !$calc_as_string ){
  322. return (string)round( $distance / 1000 , 1 ) . '公里';
  323. }
  324. // 如果计算为字符串公里距离
  325. if( $distance / 1000 > 1 ){
  326. $k = (string)round( $distance / 1000 , 1 );
  327. $m = (string)$distance % 1000 ;
  328. $distance = "{$k}公里{$m}米";
  329. }
  330. else{
  331. $distance = "{$distance}米";
  332. }
  333. return $distance;
  334. }
  335. //地图api,根据两地坐标,获得两地距离,打卡用的
  336. //type=0直线,type=1开车
  337. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  338. $result = 0;
  339. $apiurl = 'https://restapi.amap.com/v3/distance?';
  340. $param = [
  341. 'key' => '398c424811d1a59beac2f915323d334e',
  342. 'origins' => $start_lon.','.$start_lat,
  343. 'destination' => $end_lon.','.$end_lat,
  344. 'type' => $type,
  345. 'output' => 'json',
  346. ];
  347. $apiurl .= http_build_query($param);
  348. $request_rs = json_decode(curl_get($apiurl),true);
  349. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  350. if(isset($request_rs['results'][0]['distance']))
  351. {
  352. $result = $request_rs['results'][0]['distance'];
  353. }
  354. }
  355. //dump($result);
  356. return $result;
  357. }
  358. public function distance()
  359. {
  360. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  361. dump($a);
  362. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  363. dump($a);
  364. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  365. dump($b);
  366. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  367. dump($b);
  368. }
  369. //开通守护
  370. public function addguard() {
  371. // 接口防并发
  372. if (!$this->apiLimit(1, 1)) {
  373. $this->error(__('Operation frequently'));
  374. }
  375. $user_id = input('user_id', 0, 'intval');// 守护对象
  376. if (!$user_id) {
  377. $this->error();
  378. }
  379. // 不可以守护给自己
  380. if($this->auth->id == $user_id) {
  381. $this->error("不可以守护自己");
  382. }
  383. //查询是否开通守护
  384. $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  385. if ($count) {
  386. $this->error('已经开通守护了');
  387. }
  388. $giftvalue = config('site.guard_price');
  389. if ($giftvalue <= 0) {
  390. $this->error('守护金额异常~');
  391. }
  392. //被守护人信息
  393. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  394. if (!$touserinfo) {
  395. $this->error("不存在的用户");
  396. }
  397. // 判断当前用户余额
  398. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  399. if($user_gold < $giftvalue) {
  400. $this->error("您的金币余额不足");
  401. }
  402. Db::startTrans();
  403. // 添加礼物守护记录表
  404. $data = [
  405. 'user_id' => $this->auth->id,
  406. 'user_to_id' => $user_id,
  407. 'price' => $giftvalue,
  408. 'createtime' => time(),
  409. ];
  410. $log_id = Db::name('user_guard')->insertGetId($data);
  411. if(!$log_id){
  412. Db::rollback();
  413. $this->error('守护失败');
  414. }
  415. if($giftvalue > 0){
  416. // 扣除当前用户余额
  417. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
  418. if($wallet_rs['status'] === false){
  419. Db::rollback();
  420. $this->error($wallet_rs['msg']);
  421. }
  422. // 添加守护用户余额
  423. $money_to_gold = config('site.money_to_gold');
  424. $gift_plat_scale = config('site.gift_plat_scale');
  425. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  426. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  427. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
  428. if($wallet_rs['status'] === false){
  429. Db::rollback();
  430. $this->error($wallet_rs['msg']);
  431. }
  432. //增加赠送用户上级余额
  433. if ($touserinfo['intro_uid']) {
  434. //获取返利比率
  435. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  436. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  437. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  438. //上级获得金额
  439. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  440. if ($intro_uid_money > 0) {
  441. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
  442. if($intro_result['status']===false)
  443. {
  444. Db::rollback();
  445. $this->error($intro_result['msg']);
  446. }
  447. }
  448. }
  449. }
  450. }
  451. //tag任务守护金币
  452. //搭讪奖励
  453. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  454. // if($task_rs === false){
  455. // Db::rollback();
  456. // $this->error('完成任务守护奖励失败');
  457. // }
  458. Db::commit();
  459. $this->success('守护成功');
  460. }
  461. //守护列表
  462. public function guardlist(){
  463. $user_id = input('user_id', 0, 'intval');
  464. if (!$user_id) {
  465. $this->error('您的网络开小差啦~');
  466. }
  467. $list = Db::name('user_guard')
  468. ->alias('a')
  469. ->join('user','a.user_id = user.id','LEFT')
  470. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  471. ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
  472. if (!$list) {
  473. $this->success('success', $list);
  474. }
  475. $list = list_domain_image($list,['avatar']);
  476. $time = time();
  477. foreach ($list as &$v) {
  478. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  479. }
  480. $this->success('success',$list);
  481. }
  482. //我的守护
  483. public function myguardlist(){
  484. $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
  485. if (!in_array($type, [1, 2])) {
  486. $this->error('您的网络开小差了');
  487. }
  488. $where = [];
  489. if ($type == 1) {
  490. $join = 'a.user_to_id = user.id';
  491. $where['a.user_id'] = $this->auth->id;
  492. } else {
  493. $join = 'a.user_id = user.id';
  494. $where['a.user_to_id'] = $this->auth->id;
  495. }
  496. $list = Db::name('user_guard')
  497. ->alias('a')
  498. ->join('user',$join,'LEFT')
  499. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  500. ->where($where)->order('a.id desc')->autopage()->select();
  501. if (!$list) {
  502. $this->success('success', $list);
  503. }
  504. $list = list_domain_image($list,['avatar']);
  505. $time = time();
  506. foreach ($list as &$v) {
  507. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  508. }
  509. $this->success('success',$list);
  510. }
  511. //打字聊天每句话调用一次
  512. public function chat_once(){
  513. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  514. $this->success('success',array('money'=>''));
  515. }
  516. if ($this->auth->gender == 0) { //女生不花钱
  517. $this->error('您的网络开小差啦~');
  518. }
  519. //检测用户
  520. $to_user_id = input_post('to_user_id');
  521. $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();
  522. if(!$to_user_info){
  523. $this->error('不存在的用户');
  524. }
  525. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  526. $this->success('success',array('money'=>''));
  527. }
  528. if ($to_user_info['gender'] != 0) {
  529. $this->error('同性不能聊天~');
  530. }
  531. //验证金额
  532. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  533. if ($wallet_info['vip_endtime'] >= time()) { //会员
  534. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  535. //获取折扣
  536. $vip_chat_discount = config('site.vip_chat_discount');
  537. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  538. $price = ceil($price * $vip_chat_discount / 10);
  539. }
  540. } else {
  541. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  542. }
  543. //正常价格
  544. $bili = config('site.money_to_gold'); //兑换比例
  545. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  546. $money = bcdiv($price,$bili,2); //对应人民币
  547. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  548. $resArray['money'] = $money; //返回给前端的计算结果
  549. Db::startTrans();
  550. //记录日志
  551. $data = [
  552. 'user_id' => $this->auth->id,
  553. 'price' => $price,
  554. 'createtime' => time(),
  555. 'to_user_id' => $to_user_id,
  556. 'money' => $money,
  557. ];
  558. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  559. if(!$log_id){
  560. Db::rollback();
  561. $this->error('扣费失败');
  562. }
  563. //有性别差,扣费
  564. if($price > 0){
  565. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
  566. if($rs['status'] === false){
  567. Db::rollback();
  568. $this->error($rs['msg']);
  569. }
  570. }
  571. //另一方加钱,0收费
  572. if($money > 0){
  573. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
  574. if($rs['status'] === false){
  575. Db::rollback();
  576. $this->error($rs['msg']);
  577. }
  578. $touserinfo = $to_user_info;
  579. //增加赠送用户上级余额
  580. if ($touserinfo['intro_uid']) {
  581. //获取返利比率
  582. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  583. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  584. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  585. //上级获得金额
  586. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  587. if ($intro_uid_money > 0) {
  588. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
  589. if($intro_result['status']===false)
  590. {
  591. Db::rollback();
  592. $this->error($intro_result['msg']);
  593. }
  594. }
  595. }
  596. }
  597. }
  598. //增加亲密度
  599. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  600. if (!$user_intimacy_rs['status']) {
  601. Db::rollback();
  602. $this->error('您的网络开小差啦~');
  603. }
  604. //tag任务赠送金币
  605. //私信5名异性奖励
  606. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  607. if($task_rs === false){
  608. Db::rollback();
  609. $this->error('完成任务赠送奖励失败');
  610. }
  611. /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
  612. if($task_rs === false){
  613. Db::rollback();
  614. $this->error('完成任务赠送奖励失败');
  615. }*/
  616. Db::commit();
  617. //发送消息
  618. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  619. $tenim = new \app\api\controller\Tenim;
  620. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  621. }
  622. $this->success('success',$resArray);
  623. }
  624. //语音通话每分钟调用一次
  625. public function voice_onemin(){
  626. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  627. $this->success('success');
  628. }
  629. if ($this->auth->gender == 0) { //女生不花钱
  630. $this->error('您的网络开小差啦~');
  631. }
  632. //检测用户
  633. $to_user_id = input_post('to_user_id');
  634. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  635. $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();
  636. if(!$to_user_info){
  637. $this->error('不存在的用户');
  638. }
  639. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  640. $this->success('success');
  641. }
  642. if ($to_user_info['gender'] != 0) {
  643. $this->error('同性不能聊天~');
  644. }
  645. //验证金额
  646. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  647. if ($wallet_info['vip_endtime'] >= time()) { //会员
  648. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  649. //获取折扣
  650. $vip_video_discount = config('site.vip_video_discount');
  651. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  652. $price = ceil($price * $vip_video_discount / 10);
  653. }
  654. } else {
  655. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  656. }
  657. //正常价格
  658. $bili = config('site.money_to_gold'); //兑换比例
  659. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  660. $money = bcdiv($price,$bili,2); //对应人民币
  661. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  662. Db::startTrans();
  663. //查询是否有匹配记录
  664. $user_match_audio_log_info = [];
  665. if ($request_id) {
  666. $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();
  667. }
  668. if ($user_match_audio_log_info) {
  669. //修改记录日志
  670. $data = [
  671. 'price' => $user_match_audio_log_info['price'] + $price,
  672. 'createtime' => time(),
  673. 'money' => $user_match_audio_log_info['money'] + $money,
  674. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  675. ];
  676. $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);
  677. if (!$log_id) {
  678. Db::rollback();
  679. $this->error('扣费失败');
  680. }
  681. } else {
  682. //添加记录日志
  683. $data = [
  684. 'user_id' => $this->auth->id,
  685. 'price' => $price,
  686. 'createtime' => time(),
  687. 'to_user_id' => $to_user_id,
  688. 'money' => $money,
  689. 'request_id' => $request_id,
  690. 'call_minutes' => 1
  691. ];
  692. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  693. if (!$log_id) {
  694. Db::rollback();
  695. $this->error('扣费失败');
  696. }
  697. }
  698. //有性别差,扣费
  699. if($price > 0){
  700. $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);
  701. if($rs['status'] === false){
  702. Db::rollback();
  703. $this->error($rs['msg']);
  704. }
  705. }
  706. //另一方加钱,0收费
  707. if($money > 0){
  708. $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);
  709. if($rs['status'] === false){
  710. Db::rollback();
  711. $this->error($rs['msg']);
  712. }
  713. $touserinfo = $to_user_info;
  714. //增加赠送用户上级余额
  715. if ($touserinfo['intro_uid']) {
  716. //获取返利比率
  717. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  718. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  719. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  720. //上级获得金额
  721. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  722. if ($intro_uid_money > 0) {
  723. $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);
  724. if($intro_result['status']===false)
  725. {
  726. Db::rollback();
  727. $this->error($intro_result['msg']);
  728. }
  729. }
  730. }
  731. }
  732. }
  733. //增加亲密度
  734. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  735. if (!$user_intimacy_rs['status']) {
  736. Db::rollback();
  737. $this->error('您的网络开小差啦~');
  738. }
  739. //tag任务赠送金币
  740. //与1名异性语音通话奖励
  741. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
  742. if($task_rs === false){
  743. Db::rollback();
  744. $this->error('完成任务赠送奖励失败');
  745. }
  746. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
  747. if($task_rs === false){
  748. Db::rollback();
  749. $this->error('完成任务赠送奖励失败');
  750. }
  751. //发送消息
  752. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  753. $tenim = new \app\api\controller\Tenim;
  754. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  755. }
  756. Db::commit();
  757. $this->success('success');
  758. }
  759. //视频通话每分钟调用一次
  760. public function videochat_onemin(){
  761. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  762. $this->success('success');
  763. }
  764. if ($this->auth->gender == 0) { //女生不花钱
  765. $this->error('您的网络开小差啦~');
  766. }
  767. //检测用户
  768. $to_user_id = input_post('to_user_id');
  769. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  770. $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();
  771. if(!$to_user_info){
  772. $this->error('不存在的用户');
  773. }
  774. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  775. $this->success('success');
  776. }
  777. if ($to_user_info['gender'] != 0) {
  778. $this->error('同性不能聊天~');
  779. }
  780. /* //检查是否免费过
  781. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  782. if (!$count) {
  783. //记录日志
  784. $data = [
  785. 'user_id' => $this->auth->id,
  786. 'price' => 0,
  787. 'createtime' => time(),
  788. 'to_user_id' => $to_user_id,
  789. 'money' => 0,
  790. ];
  791. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  792. if(!$log_id){
  793. $this->error('扣费失败');
  794. }
  795. $this->success('success');
  796. }*/
  797. //验证金额
  798. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  799. if ($wallet_info['vip_endtime'] >= time()) { //会员
  800. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  801. //获取折扣
  802. $vip_video_discount = config('site.vip_video_discount');
  803. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  804. $price = ceil($price * $vip_video_discount / 10);
  805. }
  806. } else {
  807. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  808. }
  809. //正常价格
  810. $bili = config('site.money_to_gold'); //兑换比例
  811. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  812. $money = bcdiv($price,$bili,2); //对应人民币
  813. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  814. Db::startTrans();
  815. //查询是否有匹配记录
  816. $user_match_video_log_info = [];
  817. if ($request_id) {
  818. $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();
  819. }
  820. if ($user_match_video_log_info) {
  821. //修改记录日志
  822. $data = [
  823. 'price' => $user_match_video_log_info['price'] + $price,
  824. 'createtime' => time(),
  825. 'money' => $user_match_video_log_info['money'] + $money,
  826. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  827. ];
  828. $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);
  829. if (!$log_id) {
  830. Db::rollback();
  831. $this->error('扣费失败');
  832. }
  833. } else {
  834. //添加记录日志
  835. $data = [
  836. 'user_id' => $this->auth->id,
  837. 'price' => $price,
  838. 'createtime' => time(),
  839. 'to_user_id' => $to_user_id,
  840. 'money' => $money,
  841. 'request_id' => $request_id,
  842. 'call_minutes' => 1
  843. ];
  844. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  845. if (!$log_id) {
  846. Db::rollback();
  847. $this->error('扣费失败');
  848. }
  849. }
  850. //有性别差,扣费
  851. if($price > 0){
  852. $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);
  853. if($rs['status'] === false){
  854. Db::rollback();
  855. $this->error($rs['msg']);
  856. }
  857. }
  858. //另一方加钱,0收费
  859. if($money > 0){
  860. $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);
  861. if($rs['status'] === false){
  862. Db::rollback();
  863. $this->error($rs['msg']);
  864. }
  865. $touserinfo = $to_user_info;
  866. //增加赠送用户上级余额
  867. if ($touserinfo['intro_uid']) {
  868. //获取返利比率
  869. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  870. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  871. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  872. //上级获得金额
  873. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  874. if ($intro_uid_money > 0) {
  875. $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);
  876. if($intro_result['status']===false)
  877. {
  878. Db::rollback();
  879. $this->error($intro_result['msg']);
  880. }
  881. }
  882. }
  883. }
  884. }
  885. //增加亲密度
  886. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  887. if (!$user_intimacy_rs['status']) {
  888. Db::rollback();
  889. $this->error('您的网络开小差啦~');
  890. }
  891. //tag任务赠送金币
  892. //与1名异性视频通话奖励
  893. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
  894. if($task_rs === false){
  895. Db::rollback();
  896. $this->error('完成任务赠送奖励失败');
  897. }
  898. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
  899. if($task_rs === false){
  900. Db::rollback();
  901. $this->error('完成任务赠送奖励失败');
  902. }
  903. Db::commit();
  904. //发送消息
  905. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  906. $tenim = new \app\api\controller\Tenim;
  907. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  908. }
  909. $this->success('success');
  910. }
  911. //消息列表好友/密友
  912. public function intimacyfriends() {
  913. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  914. $where = [];
  915. /*if ($type == 0) {
  916. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  917. $mt_user = Db::name('user');
  918. // $mt_user_follow = Db::name('user_follow');
  919. $mt_user_intimacy = Db::name('user_intimacy');
  920. foreach ($list as &$v) {
  921. //查询亲密度
  922. if ($this->auth->gender == 1) {
  923. $where['uid'] = $this->auth->id;
  924. $where['other_uid'] = $v['user_id'];
  925. } else {
  926. $where['other_uid'] = $this->auth->id;
  927. $where['uid'] = $v['user_id'];
  928. }
  929. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  930. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  931. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  932. //查询对方信息
  933. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  934. $v['nickname'] = $user_info['nickname'];
  935. $v['avatar'] = one_domain_image($user_info['avatar']);
  936. $v['updatetime'] = get_last_time($v['updatetime']);
  937. $v['age'] = birthtime_to_age($user_info['birthday']);
  938. $v['gender'] = $user_info['gender'];
  939. $v['real_status'] = $user_info['real_status'];
  940. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  941. $v['status'] = 1;
  942. }
  943. } else {*/
  944. if ($this->auth->gender == 1) {
  945. $where['uid'] = $this->auth->id;
  946. $field = 'other_uid user_id, value, updatetime';
  947. } else {
  948. $where['other_uid'] = $this->auth->id;
  949. $field = 'uid user_id, value, updatetime';
  950. }
  951. if ($type == 1) { //密友
  952. $where['value'] = ['egt', 1000];
  953. } elseif ($type == 2) { //好友
  954. $where['value'] = ['egt', 100];
  955. } else { //消息列表好友
  956. $where['value'] = ['egt', 10];
  957. }
  958. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  959. $mt_user = Db::name('user');
  960. $mt_user_follow = Db::name('user_follow');
  961. foreach ($list as &$v) {
  962. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  963. $v['nickname'] = $user_info['nickname'];
  964. $v['avatar'] = one_domain_image($user_info['avatar']);
  965. $v['updatetime'] = get_last_time($v['updatetime']);
  966. $v['age'] = birthtime_to_age($user_info['birthday']);
  967. $v['gender'] = $user_info['gender'];
  968. $v['real_status'] = $user_info['real_status'];
  969. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  970. $v['is_active'] = $user_info['is_active'];
  971. }
  972. // }
  973. $this->success('success',$list);
  974. }
  975. //消息列表通话
  976. public function calllist() {
  977. if ($this->auth->gender == 1) {
  978. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
  979. } elseif ($this->auth->gender == 0) {
  980. $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
  981. } else {
  982. $this->success('success', []);
  983. }
  984. if (!$list) {
  985. $this->success('success', $list);
  986. }
  987. $arr = [];
  988. $mt_user_match_audio_log = Db::name('user_match_audio_log');
  989. $mt_user_match_video_log = Db::name('user_match_video_log');
  990. $mt_user = Db::name('user');
  991. foreach ($list as &$v) {
  992. $data = [];
  993. if ($this->auth->gender == 1) {
  994. if ($v['log_type'] == 11) { //视频通话
  995. $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  996. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  997. } else { //语音通话
  998. $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  999. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1000. }
  1001. } else {
  1002. if ($v['log_type'] == 21) { //视频通话
  1003. $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1004. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1005. } else { //语音通话
  1006. $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1007. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1008. }
  1009. }
  1010. $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
  1011. $data['user_id'] = $log_info['user_id'];
  1012. $data['nickname'] = $user_info['nickname'];
  1013. $data['avatar'] = one_domain_image($user_info['avatar']);
  1014. $data['createtime'] = get_last_time($log_info['createtime']);
  1015. $data['is_active'] = $user_info['is_active'];
  1016. $arr[] = $data;
  1017. }
  1018. $this->success('success', $arr);
  1019. }
  1020. //查询对方用户收费价格和我的余额
  1021. public function otheruserinfo(){
  1022. $user_id = input('user_id', 0, 'intval');
  1023. if (!$user_id) {
  1024. $this->error('您的网络开小差啦~');
  1025. }
  1026. $field = [
  1027. 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
  1028. ];
  1029. $info = Db::name('user')->field($field)->where('id',$user_id)->find();
  1030. if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
  1031. if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
  1032. $this->error('性别存在问题');
  1033. }
  1034. }
  1035. if ($this->auth->gender == 0) { //收费价格按照女号
  1036. $info['chat_price'] = $this->auth->chat_price;
  1037. $info['voice_price'] = $this->auth->voice_price;
  1038. $info['video_price'] = $this->auth->video_price;
  1039. $info['open_match_audio'] = $this->auth->open_match_audio;
  1040. $info['open_match_video'] = $this->auth->open_match_video;
  1041. }
  1042. $info['chat_price_vip'] = $info['chat_price']; //vip价格
  1043. $info['voice_price_vip'] = $info['voice_price'];
  1044. $info['video_price_vip'] = $info['video_price'];
  1045. $info['is_vip'] = 0; //是否vip: 0否 1是
  1046. //获取聊天折扣
  1047. $vip_chat_discount = config('site.vip_chat_discount');
  1048. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1049. $info['vip_chat_discount'] = $vip_chat_discount;
  1050. } else {
  1051. $info['vip_chat_discount'] = 10;
  1052. }
  1053. //获取语音视频折扣
  1054. $vip_video_discount = config('site.vip_video_discount');
  1055. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1056. $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
  1057. $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
  1058. } else {
  1059. $info['vip_voice_discount'] = 10;
  1060. $info['vip_video_discount'] = 10;
  1061. }
  1062. //获取聊天折扣
  1063. $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
  1064. //获取语音折扣
  1065. $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
  1066. //获取视频折扣
  1067. $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
  1068. if ($this->auth->gender == 0) { //查询男号余额和vip
  1069. $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
  1070. } else {
  1071. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1072. }
  1073. if ($wallet_info['vip_endtime'] >= time()) {
  1074. $info['is_vip'] = 1;
  1075. }
  1076. $info['gold'] = $wallet_info['gold'];
  1077. $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
  1078. $info['money_to_gold'] = config('site.money_to_gold'); //一元人民币兑换金币数量
  1079. $this->success('success',$info);
  1080. }
  1081. //亲密度等级信息
  1082. public function intimacylevel() {
  1083. $user_id = input('user_id', 0, 'intval'); //对方id
  1084. if (!$user_id) {
  1085. $this->error('参数缺失');
  1086. }
  1087. if ($this->auth->gender == 0) { //女用户
  1088. $where['uid'] = $user_id;
  1089. $where['other_uid'] = $this->auth->id;
  1090. } else { //男用户
  1091. $where['uid'] = $this->auth->id;
  1092. $where['other_uid'] = $user_id;
  1093. }
  1094. $level = 0; //当前等级
  1095. $level_name = ''; //当前等级名称
  1096. $qinmi_sum = 0; //当前亲密度
  1097. $next_level_diff = 0; //距下一等级亲密度差值
  1098. //亲密度等级列表
  1099. $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
  1100. //当前亲密度信息
  1101. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  1102. if ($user_intimacy_info) {
  1103. //当前亲密度
  1104. $qinmi_sum = $user_intimacy_info['value'];
  1105. if ($list) {
  1106. //当前等级信息
  1107. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
  1108. if ($level_info) {
  1109. $level = $level_info['level'];
  1110. $level_name = $level_info['name'];
  1111. }
  1112. //下一等级信息
  1113. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  1114. if ($next_level_info) {
  1115. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  1116. }
  1117. }
  1118. } else {
  1119. $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
  1120. }
  1121. if ($list) {
  1122. foreach ($list as &$v) {
  1123. if ($v['level'] < $level) {
  1124. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  1125. } elseif ($v['level'] == $level) {
  1126. $v['is_unlock'] = 2;
  1127. } else {
  1128. $v['is_unlock'] = 3;
  1129. }
  1130. }
  1131. }
  1132. $data['level'] = $level; //当前等级
  1133. $data['level_name'] = $level_name; //当前等级名称
  1134. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  1135. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  1136. $data['level_list'] = $list; //等级列表
  1137. $this->success('亲密度等级信息', $data);
  1138. }
  1139. //语音视频随聊
  1140. public function getrandomuser() {
  1141. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1142. if (!in_array($type, [1, 2, 3])) {
  1143. $this->error('您的网络开小差了');
  1144. }
  1145. $size = input('size',0,'intval');// 是否查 10 条
  1146. $size = $size > 0 ? 1 : 0;
  1147. //给出备选用户
  1148. $map = [
  1149. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1150. 'is_active' => 1, //在线的
  1151. 'status' =>1, //未封禁用户
  1152. 'is_kefu' => 0, //不是客服
  1153. ];
  1154. if ($this->auth->gender == 1) {
  1155. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1156. }
  1157. if ($type == 1) {
  1158. $map['open_match_audio'] = 1;
  1159. } elseif ($type == 2) {
  1160. $map['open_match_video'] = 1;
  1161. }
  1162. $key = md5(json_encode($map));// 根据搜索条件做Key
  1163. $lists = Cache::remember("getrandomuser_{$key}_{$size}",function () use ($map,$size){
  1164. $query = Db::name('user')
  1165. ->field('id,nickname,username,avatar')
  1166. ->where($map)
  1167. ->order('is_active desc, logintime desc');
  1168. if ($size == 1){
  1169. $query->limit(10);
  1170. }else{
  1171. $query->page($this->page,100);
  1172. }
  1173. $lists = $query->select();
  1174. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1175. $mt_user_greet_content = Db::name('user_greet_content');
  1176. foreach ($lists as &$v) {
  1177. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1178. if ($info) {
  1179. if ($info['type'] == 0) {
  1180. $v['greet_content'] = $info['content'];
  1181. } elseif ($info['type'] == 1) {
  1182. $v['greet_content'] = '[语音]';
  1183. } elseif ($info['type'] == 2) {
  1184. $v['greet_content'] = '[图片]';
  1185. }
  1186. } else {
  1187. $v['greet_content'] = '';
  1188. }
  1189. }
  1190. return $lists;
  1191. },2);
  1192. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1193. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1194. $return_data['list'] = $lists;
  1195. $this->success('success',$return_data);
  1196. }
  1197. //查询免费体验视频通话用户信息
  1198. public function getfreevideouserinfo() {
  1199. $to_user_id = input('to_user_id', 0, 'intval');
  1200. $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
  1201. if(!$to_user_info){
  1202. $this->error('不存在的用户');
  1203. }
  1204. if ($to_user_info['gender'] == $this->auth->gender) {
  1205. $this->error('同性不能聊天~');
  1206. }
  1207. $to_user_info['desc'] = '';
  1208. $age = birthtime_to_age($to_user_info['birthday']);
  1209. if ($age > 0) {
  1210. $to_user_info['desc'] = $age . '岁';
  1211. } else {
  1212. $to_user_info['desc'] = '18岁';
  1213. }
  1214. if ($to_user_info['height']) {
  1215. $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
  1216. }
  1217. //查询是否免费过
  1218. $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1219. $this->success('信息', $to_user_info);
  1220. }
  1221. //免费体验视频通话1分钟
  1222. public function videochat_onemin_free(){
  1223. $this->success('success');
  1224. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1225. $this->success('success');
  1226. }
  1227. //检查是否免费过
  1228. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1229. if ($count) {
  1230. $this->error('已经免费体验过');
  1231. }
  1232. //检测用户
  1233. $to_user_id = input_post('to_user_id');
  1234. $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();
  1235. if(!$to_user_info){
  1236. $this->error('不存在的用户');
  1237. }
  1238. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1239. $this->success('success');
  1240. }
  1241. if ($to_user_info['gender'] == $this->auth->gender) {
  1242. $this->error('同性不能聊天~');
  1243. }
  1244. //记录日志
  1245. $data = [
  1246. 'user_id' => $this->auth->id,
  1247. 'price' => 0,
  1248. 'createtime' => time(),
  1249. 'to_user_id' => $to_user_id,
  1250. 'money' => 0,
  1251. ];
  1252. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1253. if(!$log_id){
  1254. $this->error('扣费失败');
  1255. }
  1256. $this->success('success');
  1257. }
  1258. //男性非会员解锁聊天
  1259. public function unlockchat() {
  1260. // 接口防并发
  1261. if (!$this->apiLimit(1, 1)) {
  1262. $this->error(__('Operation frequently'));
  1263. }
  1264. //男性非会员是否已开通聊天
  1265. if ($this->auth->gender == 0) {
  1266. $this->error('不需要解锁');
  1267. }
  1268. $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  1269. if ($vip_endtime > time()) {
  1270. $this->error('不需要解锁');
  1271. }
  1272. $user_id = input('user_id', 0, 'intval');//对方id
  1273. if (!$user_id) {
  1274. $this->error();
  1275. }
  1276. // 不可以守护给自己
  1277. if($this->auth->id == $user_id) {
  1278. $this->error("不可以解锁自己");
  1279. }
  1280. //查询是否解锁过
  1281. $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  1282. if ($user_chat_unlock) {
  1283. $this->error('已经解锁过了');
  1284. }
  1285. $giftvalue = config('site.unlock_chat_gold');
  1286. if ($giftvalue <= 0) {
  1287. $this->error('解锁金额异常~');
  1288. }
  1289. //被解锁人信息
  1290. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  1291. if (!$touserinfo) {
  1292. $this->error("不存在的用户");
  1293. }
  1294. // 判断当前用户余额
  1295. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  1296. if($user_gold < $giftvalue) {
  1297. $this->error("您的金币余额不足");
  1298. }
  1299. Db::startTrans();
  1300. //添加解锁记录表
  1301. $data = [
  1302. 'user_id' => $this->auth->id,
  1303. 'user_to_id' => $user_id,
  1304. 'price' => $giftvalue,
  1305. 'createtime' => time(),
  1306. ];
  1307. $log_id = Db::name('user_chat_unlock')->insertGetId($data);
  1308. if(!$log_id){
  1309. Db::rollback();
  1310. $this->error('解锁失败');
  1311. }
  1312. if($giftvalue > 0){
  1313. // 扣除当前用户余额
  1314. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_chat_unlock',$log_id);
  1315. if($wallet_rs['status'] === false){
  1316. Db::rollback();
  1317. $this->error($wallet_rs['msg']);
  1318. }
  1319. // 添加守护用户余额
  1320. $money_to_gold = config('site.money_to_gold');
  1321. $gift_plat_scale = config('site.gift_plat_scale');
  1322. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  1323. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  1324. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_chat_unlock',$log_id,2);
  1325. if($wallet_rs['status'] === false){
  1326. Db::rollback();
  1327. $this->error($wallet_rs['msg']);
  1328. }
  1329. //增加赠送用户上级余额
  1330. if ($touserinfo['intro_uid']) {
  1331. //获取返利比率
  1332. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1333. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1334. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1335. //上级获得金额
  1336. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1337. if ($intro_uid_money > 0) {
  1338. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人解锁聊天获赠奖励','gift_user_typing',$log_id);
  1339. if($intro_result['status']===false)
  1340. {
  1341. Db::rollback();
  1342. $this->error($intro_result['msg']);
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. //tag任务守护金币
  1349. //搭讪奖励
  1350. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  1351. // if($task_rs === false){
  1352. // Db::rollback();
  1353. // $this->error('完成任务守护奖励失败');
  1354. // }
  1355. Db::commit();
  1356. $this->success('解锁成功');
  1357. }
  1358. }