Topicdongtai.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\library\Keyworld;
  6. /**
  7. * 圈子动态
  8. */
  9. class Topicdongtai extends Api
  10. {
  11. protected $noNeedLogin = ['info','floor_info','topic_list'];
  12. protected $noNeedRight = ['*'];
  13. //自己看列表
  14. //某用户的帖子列表
  15. public function my_lists(){
  16. $uid = input('uid',$this->auth->id);
  17. $list = Db::name('topic_dongtai')->alias('dt')
  18. ->join('user','dt.user_id = user.id','LEFT')
  19. ->field('dt.*,user.nickname,user.avatar')
  20. ->where('dt.user_id',$uid)
  21. ->order('dt.id desc')->autopage()->select();
  22. $list = list_domain_image($list,['images','avatar']);
  23. if(!empty($list)){
  24. foreach($list as $key => $val){
  25. $list[$key]['isgood'] = $this->is_good($val['id'],$this->auth->id);
  26. }
  27. }
  28. $this->success('success',$list);
  29. }
  30. //我回复的帖子列表
  31. public function answer_dt_lists(){
  32. $map = [
  33. 'answer.user_id' => $this->auth->id,
  34. 'answer.level' => 1,
  35. ];
  36. $lists = Db::name('topic_dongtai_answer')->alias('answer')
  37. ->field('answer.id,answer.content as answer_content,answer.createtime,user.nickname,user.avatar,dt.id as dt_id,dt.content as dt_content')
  38. ->join('user','answer.user_id = user.id','LEFT')
  39. ->join('topic_dongtai dt','answer.dt_id = dt.id','LEFT')
  40. ->where($map)->autopage()->select();
  41. $this->success('success',$lists);
  42. }
  43. //是否点赞
  44. private function is_good($dt_id,$uid){
  45. $where = [
  46. 'dt_id' => $dt_id,
  47. 'user_id' => $uid,
  48. ];
  49. $check = Db::name('topic_dongtai_good')->where($where)->find();
  50. if($check){
  51. return 1;
  52. }else{
  53. return 0;
  54. }
  55. }
  56. //详情
  57. public function info(){
  58. $id = input('id');
  59. $info = Db::name('topic_dongtai')->alias('dt')
  60. ->join('user','dt.user_id = user.id','LEFT')
  61. ->field('dt.*,user.nickname,user.avatar')
  62. ->where('dt.id',$id)->find();
  63. $info = info_domain_image($info,['images','avatar']);
  64. //是否点赞过
  65. if($info){
  66. $info['isgood'] = $this->is_good($id,$this->auth->id);
  67. }
  68. //评论
  69. if($info){
  70. $info['answer'] = $this->answer_list($id);
  71. }
  72. $this->success('success',$info);
  73. }
  74. //评论
  75. public function answer(){
  76. $id = input('id',0);
  77. $content = input('content','');
  78. $to_user_id = input('to_user_id',0);
  79. $level = input('level',1); //回复类型:1=层主回复楼主,2=层中回复
  80. $floor = input('floor',0);
  81. if(empty($content) || empty($id)){
  82. $this->error();
  83. }
  84. //关键字替换
  85. $content = Keyworld::sensitive($content);
  86. //判断
  87. if($level == 2 && $floor == 0){
  88. $this->error('楼层错误');
  89. }
  90. //回复楼主,最新楼层
  91. if($level == 1 || $floor == 0){
  92. $to_user_id = 0;
  93. $floor = 1; //默认一楼
  94. $last_floor = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->order('floor desc')->value('floor');
  95. if($last_floor){
  96. $floor = $last_floor + 1;
  97. }
  98. }
  99. //判断user_id
  100. if($to_user_id){
  101. $to_user = Db::name('user')->where('id',$to_user_id)->value('id');
  102. if(empty($to_user)){
  103. $this->error('被回复的用户不存在');
  104. }
  105. }
  106. //data
  107. $data = [
  108. 'dt_id' => $id,
  109. 'floor' => $floor,
  110. 'user_id' => $this->auth->id,
  111. 'content' => $content,
  112. 'to_user_id' => $to_user_id,
  113. 'level' => $level,
  114. 'createtime' => time(),
  115. 'updatetime' => time(),
  116. ];
  117. Db::startTrans();
  118. $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
  119. //tag任务赠送金币
  120. //评论奖励
  121. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,13);
  122. if($task_rs === false){
  123. Db::rollback();
  124. $this->error('完成任务赠送奖励失败');
  125. }
  126. Db::commit();
  127. $this->success('评价成功');
  128. }
  129. //评论列表
  130. private function answer_list($dt_id){
  131. //楼
  132. $floor_list = Db::name('topic_dongtai_answer')
  133. ->alias('a')
  134. ->field('a.*,user.nickname,user.avatar')
  135. ->join('user','a.user_id = user.id','LEFT')
  136. ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('id asc')->autopage()->select();
  137. $floor_list = list_domain_image($floor_list,['avatar']);
  138. if(empty($floor_list)){
  139. return [];
  140. }
  141. //层
  142. $floors = array_column($floor_list,'floor');
  143. $child_lists = Db::name('topic_dongtai_answer')->alias('a')
  144. ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
  145. ->join('user','a.user_id = user.id','LEFT')
  146. ->join('user tuser','a.to_user_id = tuser.id','LEFT')
  147. ->where(['a.dt_id'=>$dt_id,'a.floor'=>['IN',$floors],'a.level'=>2])->order('id asc')->select();
  148. $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
  149. /*if(empty($child_lists)){
  150. return $floor_list;
  151. }*/
  152. //合并
  153. foreach($floor_list as $key => $val){
  154. $child = [];
  155. foreach($child_lists as $k => $v){
  156. if($val['floor'] == $v['floor']){
  157. $child[] = $v;
  158. }
  159. }
  160. //追加到外循环
  161. $floor_list[$key]['childcount'] = 0;
  162. if(count($child) > 4){
  163. $floor_list[$key]['childcount'] = count($child) - 4;
  164. }
  165. $floor_list[$key]['child'] = array_slice($child,0,4);
  166. }
  167. return $floor_list;
  168. }
  169. //单独某一层的详细
  170. public function floor_info(){
  171. $floor_id = input('floor_id');
  172. //楼
  173. $floor_info = Db::name('topic_dongtai_answer')
  174. ->alias('a')
  175. ->field('a.*,user.nickname,user.avatar')
  176. ->join('user','a.user_id = user.id','LEFT')
  177. ->where(['a.id'=>$floor_id])->find();
  178. $floor_info = info_domain_image($floor_info,['avatar']);
  179. //层
  180. $floors = $floor_info['floor'];
  181. $child_lists = Db::name('topic_dongtai_answer')->alias('a')
  182. ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
  183. ->join('user','a.user_id = user.id','LEFT')
  184. ->join('user tuser','a.to_user_id = tuser.id','LEFT')
  185. ->where(['a.floor'=>$floors,'a.level'=>2])->order('id asc')->autopage()->select();
  186. $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
  187. //合并
  188. $floor_info['child'] = $child_lists;
  189. $this->success('success',$floor_info);
  190. }
  191. //发布动态
  192. public function adddongtai(){
  193. $content = input('content','', 'trim');
  194. $images = input('images','', 'trim');
  195. $show_real = input('show_real', 0, 'intval'); //是否标记真人:0=否,1=是
  196. //$address = input('address', '', 'trim'); //位置
  197. $topic_id = input('topic_id', 0, 'intval'); //热门话题id
  198. $type = input('type', 0, 'intval'); //类型:0=文字,1=图片,2=视频
  199. if(!$content && !$images){
  200. $this->error(__('Invalid parameters'));
  201. }
  202. if (!in_array($show_real, [0, 1])) {
  203. $this->error(__('Invalid parameters'));
  204. }
  205. if ($show_real == 1 && $this->auth->real_status != 1) { //验证是否已经通过真人认证
  206. $this->error('您尚未通过真人认证,暂不能标记真人');
  207. }
  208. /*if (iconv_strlen($address, 'utf-8') > 255) {
  209. $this->error('请选择正确位置');
  210. }*/
  211. if ($topic_id) {
  212. $topic_info = Db::name('topic_hub')->where(['id' => $topic_id])->find();
  213. if (!$topic_info) {
  214. $this->error('话题已过时,请重新选择');
  215. }
  216. if ($topic_info['status'] != 1) {
  217. $this->error('话题已过时,请重新选择');
  218. }
  219. }
  220. if (!in_array($type, [0, 1, 2])) {
  221. $this->error('您的网络开小差啦~');
  222. }
  223. //关键字替换
  224. $content = Keyworld::sensitive($content);
  225. $address = $this->ip_to_address();
  226. $data = [
  227. 'topic_id' => $topic_id,
  228. 'user_id' => $this->auth->id,
  229. 'content' => $content,
  230. 'images' => $images,
  231. // 'longitude' => input('longitude',''),
  232. // 'latitude' => input('latitude',''),
  233. 'createtime' => time(),
  234. 'updatetime' => time(),
  235. 'is_show_real' => $show_real,
  236. 'address' => $address,
  237. 'type' => $type
  238. ];
  239. Db::startTrans();
  240. $id = Db::name('topic_dongtai')->insertGetId($data);
  241. if (!$id) {
  242. Db::rollback();
  243. $this->error('您的网络开小差啦~');
  244. }
  245. //圈子新增一个贴
  246. if ($topic_id) {
  247. $rs = Db::name('topic_hub')->where('id', $topic_id)->setInc('t_number');
  248. if (!$rs) {
  249. Db::rollback();
  250. $this->error('您的网络开小差啦~');
  251. }
  252. }
  253. Db::commit();
  254. $this->success('发布成功',$id);
  255. }
  256. //动态列表
  257. public function dongtailist() {
  258. $type = input('type', 0, 'intval'); //类型:0热门 1最新
  259. $topic_id = input('topic_id', 0); //热门话题id
  260. if (!in_array($type, [0, 1])) {
  261. $this->error('您的网络开小差啦~');
  262. }
  263. if ($type == 0) {
  264. // $orderby = 'dt.goodnum desc';
  265. $orderby = 'dt.id desc';
  266. } else {
  267. $orderby = 'dt.id desc';
  268. }
  269. $where['dt.status'] = 0;
  270. $where['dt.auit_status'] = 1;
  271. $where['user.is_kefu'] = 0;
  272. if ($this->auth->gender == 1) {
  273. $where['user.gender'] = 0;
  274. } elseif ($this->auth->gender == 0) {
  275. $where['user.gender'] = 1;
  276. } else {
  277. $this->success('success',[]);
  278. }
  279. if ($topic_id) {
  280. $where['dt.topic_id'] = $topic_id;
  281. $orderby = 'dt.id desc';
  282. }
  283. $list = Db::name('topic_dongtai')->alias('dt')
  284. ->join('user','dt.user_id = user.id','LEFT')
  285. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  286. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  287. ->where($where)
  288. ->order($orderby)->autopage()->select();
  289. $list = list_domain_image($list,['images','avatar']);
  290. //追加是否点赞
  291. if(!empty($list)){
  292. $ids = array_column($list,'id');
  293. $map = [
  294. 'dt_id' => ['IN',$ids],
  295. 'user_id' => $this->auth->id,
  296. ];
  297. $good_list = Db::name('topic_dongtai_good')->where($map)->select();
  298. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  299. $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
  300. $mt_user_wallet = Db::name('user_wallet'); //钱包
  301. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  302. $mt_charm_level = Db::name('charm_level'); //魅力等级
  303. foreach ($list as &$val) {
  304. $val['name'] = $val['name'] ? : '';
  305. $val['birthday'] = birthtime_to_age($val['birthday']);
  306. $val['createtime'] = get_last_time($val['createtime']);
  307. $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'] ;
  308. //是否点过赞:0否 1是
  309. $val['isgood'] = 0;
  310. foreach($good_list as $k => $v){
  311. if($val['id'] == $v['dt_id']){
  312. $val['isgood'] = 1;
  313. }
  314. }
  315. //礼物数量
  316. $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
  317. //查询是否打过招呼
  318. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
  319. if ($count) {
  320. $val['is_chat'] = 1; //是否打过招呼: 1是 0否
  321. } else {
  322. $val['is_chat'] = 0; //是否打过招呼: 1是 0否
  323. }
  324. //查询财富等级和魅力等级
  325. $wallet_info = $mt_user_wallet->where(['user_id' => $val['user_id']])->find();
  326. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  327. if ($wealth_level) {
  328. $val['wealth_level'] = $wealth_level['image'];
  329. } else {
  330. $val['wealth_level'] = '';
  331. }
  332. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  333. if ($charm_level) {
  334. $val['charm_level'] = $charm_level['image'];
  335. } else {
  336. $val['charm_level'] = '';
  337. }
  338. //创建视频缩略图
  339. $val['images_thumb'] = '';
  340. if ($val['type'] == 2) {
  341. $images_url = explode('.', $val['images']);
  342. unset($images_url[count($images_url) - 1]);
  343. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  344. }
  345. }
  346. }
  347. $this->success('success',$list);
  348. }
  349. //动态详情
  350. public function dongtaiinfo(){
  351. $id = input('id', 0, 'intval');
  352. if (!$id) {
  353. $this->error('您的网络开小差啦~');
  354. }
  355. $info = Db::name('topic_dongtai')->alias('dt')
  356. ->join('user','dt.user_id = user.id','LEFT')
  357. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  358. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  359. ->where('dt.id',$id)->find();
  360. if (!$info) {
  361. $this->error('您的网络开小差啦~');
  362. }
  363. if ($info['status'] != 0) {
  364. $this->error('您的网络开小差啦~');
  365. }
  366. $info = info_domain_image($info,['images','avatar']);
  367. $info['birthday'] = birthtime_to_age($info['birthday']);
  368. $info['createtime'] = get_last_time($info['createtime']);
  369. $info['cityname'] = $info['is_hideaddress'] ? '' : $info['address'];
  370. //是否点赞过
  371. $info['isgood'] = $this->is_good($id,$this->auth->id);
  372. //礼物数量
  373. $info['gift_count'] = Db::name('gift_user_dongtai')->where(['dt_id' => $info['id']])->count('id');
  374. //查询是否打过招呼
  375. $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $info['user_id']])->count('id');
  376. if ($count) {
  377. $info['is_chat'] = 1; //是否打过招呼: 1是 0否
  378. } else {
  379. $info['is_chat'] = 0; //是否打过招呼: 1是 0否
  380. }
  381. //查询财富等级和魅力等级
  382. $wallet_info = Db::name('user_wallet')->where(['user_id' => $info['user_id']])->find();
  383. $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  384. if ($wealth_level) {
  385. $info['wealth_level'] = $wealth_level['image'];
  386. } else {
  387. $info['wealth_level'] = '';
  388. }
  389. $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  390. if ($charm_level) {
  391. $info['charm_level'] = $charm_level['image'];
  392. } else {
  393. $info['charm_level'] = '';
  394. }
  395. //创建视频缩略图
  396. $info['images_thumb'] = '';
  397. if ($info['type'] == 2) {
  398. $images_url = explode('.', $info['images']);
  399. unset($images_url[count($images_url) - 1]);
  400. $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
  401. }
  402. $this->success('success',$info);
  403. }
  404. //点赞
  405. public function dongtaigood(){
  406. $id = input('id', 0, 'intval');
  407. if (!$id) {
  408. $this->error('您的网络开小差啦~');
  409. }
  410. $info = Db::name('topic_dongtai')->find($id);
  411. if (!$info) {
  412. $this->error('您的网络开小差啦~');
  413. }
  414. if ($info['status'] != 0) {
  415. $this->error('您的网络开小差啦~');
  416. }
  417. $where = [
  418. 'dt_id' => $id,
  419. 'user_id' => $this->auth->id,
  420. ];
  421. $check = Db::name('topic_dongtai_good')->where($where)->find();
  422. if($check){
  423. $this->error('已经赞过了');
  424. }
  425. $where['createtime'] = time();
  426. Db::startTrans();
  427. $rs = Db::name('topic_dongtai_good')->insertGetId($where);
  428. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
  429. //tag任务赠送金币
  430. //点赞奖励
  431. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,14);
  432. // if($task_rs === false){
  433. // Db::rollback();
  434. // $this->error('完成任务赠送奖励失败');
  435. // }
  436. if($rs && $up !== false){
  437. Db::commit();
  438. $this->success('点赞成功');
  439. }
  440. Db::rollback();
  441. $this->error('点赞失败');
  442. }
  443. //点赞列表
  444. public function dongtaigoodlist() {
  445. $id = input('id', 0, 'intval');
  446. if (!$id) {
  447. $this->error('您的网络开小差啦~');
  448. }
  449. //点赞只能查看异性
  450. $dongtaiWhere['td.id'] = $id;
  451. $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
  452. ->join('user u','u.id = td.user_id','LEFT')
  453. ->where($dongtaiWhere)->find();
  454. $where['a.dt_id'] = $id;
  455. $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
  456. if ($gender == 1) {
  457. $where['user.gender'] = 0;
  458. } elseif ($gender == 0) {
  459. $where['user.gender'] = 1;
  460. }
  461. $list = Db::name('topic_dongtai_good')->alias('a')
  462. ->join('user', 'a.user_id = user.id', 'left')
  463. ->field('a.*, user.nickname,user.avatar,user.gender,user.birthday')
  464. ->where($where)
  465. ->order('a.id desc')
  466. ->autopage()->select();
  467. if (!$list) {
  468. $this->success('success', $list);
  469. }
  470. $list = list_domain_image($list,['avatar']);
  471. foreach ($list as &$v) {
  472. $v['birthday'] = birthtime_to_age($v['birthday']);
  473. $v['createtime'] = get_last_time($v['createtime']);
  474. }
  475. $this->success('success', $list);
  476. }
  477. //动态赠送礼物
  478. public function givegiftdongtai() {
  479. // 接口防并发
  480. if (!$this->apiLimit(1, 1000)) {
  481. $this->error(__('Operation frequently'));
  482. }
  483. // $user_id = input('user_id');// 赠送对象
  484. $dt_id = input('dt_id', 0, 'intval'); //动态id
  485. $gift_id = input('gift_id');// 礼物ID
  486. $number = input('number',1,'intval');//数量
  487. if (!$dt_id || !$gift_id || $number < 1) {
  488. $this->error();
  489. }
  490. //查询动态
  491. $dongtai_info = Db::name('topic_dongtai')->find($dt_id);
  492. if (!$dongtai_info) {
  493. $this->error('您的网络开小差啦~');
  494. }
  495. if ($dongtai_info['status'] != 0) {
  496. $this->error('您的网络开小差啦~');
  497. }
  498. $user_id = $dongtai_info['user_id'];
  499. // 不可以赠送给自己
  500. if($this->auth->id == $user_id) {
  501. $this->error("不可以赠送给自己");
  502. }
  503. // 获取礼物信息
  504. $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
  505. if (!$giftinfo)
  506. {
  507. $this->error("请选择礼物");
  508. }
  509. $giftvalue = bcmul($giftinfo['value'],$number);
  510. //被赠送人信息
  511. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  512. if (!$touserinfo) {
  513. $this->error("不存在的用户");
  514. }
  515. // 判断当前用户余额
  516. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  517. if($user_gold < $giftvalue) {
  518. $this->error("您的金币余额不足");
  519. }
  520. Db::startTrans();
  521. // 添加礼物赠送记录表
  522. $data = [
  523. 'user_id' => $this->auth->id,
  524. 'user_to_id' => $user_id,
  525. 'dt_id' => $dt_id,
  526. 'gift_id' => $giftinfo['id'],
  527. 'gift_name' => $giftinfo['name'],
  528. 'number' => $number,
  529. 'price' => $giftvalue,
  530. 'createtime' => time(),
  531. ];
  532. $log_id = Db::name('gift_user_dongtai')->insertGetId($data);
  533. if(!$log_id){
  534. Db::rollback();
  535. $this->error('赠送失败');
  536. }
  537. if($giftvalue > 0){
  538. // 扣除当前用户余额
  539. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,59,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id);
  540. if($wallet_rs['status'] === false){
  541. Db::rollback();
  542. $this->error($wallet_rs['msg']);
  543. }
  544. // 添加赠送用户余额
  545. $money_to_gold = config('site.money_to_gold');
  546. $gift_plat_scale = config('site.gift_plat_scale');
  547. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  548. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  549. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,60,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id,2);
  550. if($wallet_rs['status'] === false){
  551. Db::rollback();
  552. $this->error($wallet_rs['msg']);
  553. }
  554. /*//增加赠送用户上级金币
  555. if ($touserinfo['intro_uid']) {
  556. //获取返利比率
  557. $intro_gift_rebate_rate = (int)config('site.intro_gift_rebate_rate'); //邀请人收礼物返利比率
  558. if ($intro_gift_rebate_rate > 0 && $intro_gift_rebate_rate <= 100) {
  559. //上级获得金币数量
  560. $intro_uid_gold = floor($giftvalue * $intro_gift_rebate_rate / 100);
  561. if ($intro_uid_gold > 0) {
  562. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'gold',$intro_uid_gold,66, '动态礼物获赠奖励','gift_user_dongtai',$log_id);
  563. if($intro_result['status']===false)
  564. {
  565. Db::rollback();
  566. $this->error($intro_result['msg']);
  567. }
  568. }
  569. }
  570. }*/
  571. //增加赠送用户上级余额
  572. if ($touserinfo['intro_uid']) {
  573. //获取返利比率
  574. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  575. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  576. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  577. //上级获得金额
  578. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  579. if ($intro_uid_money > 0) {
  580. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人动态礼物获赠奖励','gift_user_dongtai',$log_id);
  581. if($intro_result['status']===false)
  582. {
  583. Db::rollback();
  584. $this->error($intro_result['msg']);
  585. }
  586. }
  587. }
  588. }
  589. if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
  590. //增加亲密度
  591. $user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
  592. if (!$user_intimacy_rs['status']) {
  593. Db::rollback();
  594. $this->error('您的网络开小差啦~');
  595. }
  596. }
  597. }
  598. //tag任务赠送金币
  599. //搭讪奖励
  600. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  601. // if($task_rs === false){
  602. // Db::rollback();
  603. // $this->error('完成任务赠送奖励失败');
  604. // }
  605. Db::commit();
  606. //发送消息
  607. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  608. $tenim = new \app\api\controller\Tenim;
  609. $tenim->sendMessageToUser($this->auth->id, $user_id, $user_intimacy_rs['level_remark'], 1);
  610. }
  611. $return_data['money'] = $money; //获得金额
  612. $return_data['level_remark'] = isset($user_intimacy_rs) ? $user_intimacy_rs['level_remark'] : ''; //亲密度等级提示语
  613. $this->success('赠送成功', $return_data);
  614. }
  615. //动态收到礼物列表
  616. public function dongtaigiftlist() {
  617. $id = input('id', 0, 'intval');
  618. if (!$id) {
  619. $this->error('您的网络开小差啦~');
  620. }
  621. //点赞只能查看异性
  622. $dongtaiWhere['td.id'] = $id;
  623. $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
  624. ->join('user u','u.id = td.user_id','LEFT')
  625. ->where($dongtaiWhere)->find();
  626. $where['a.dt_id'] = $id;
  627. $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
  628. if ($gender == 1) {
  629. $where['user.gender'] = 0;
  630. } elseif ($gender == 0) {
  631. $where['user.gender'] = 1;
  632. }
  633. $list = Db::name('gift_user_dongtai')->alias('a')->field('a.user_id, count(a.id) count')
  634. ->join('user', 'a.user_id = user.id', 'left')
  635. ->where($where)->group('a.user_id')->order('a.id desc')->autopage()->select();
  636. if (!$list) {
  637. $this->success('success', $list);
  638. }
  639. $mt_user = Db::name('user');
  640. foreach ($list as &$v) {
  641. $user_info = $mt_user->field('nickname, avatar, gender, birthday')->where(['id' => $v['user_id']])->find();
  642. $v['nickname'] = $user_info['nickname'];
  643. $v['avatar'] = one_domain_image($user_info['avatar']);
  644. $v['birthday'] = birthtime_to_age($user_info['birthday']);
  645. }
  646. $this->success('success', $list);
  647. }
  648. //用户动态列表
  649. public function mydongtailist() {
  650. $user_id = input('user_id', $this->auth->id);
  651. if (!$user_id) {
  652. $this->error('您的网络开小差啦~');
  653. }
  654. $where['dt.user_id'] = $user_id;
  655. $where['dt.status'] = 0;
  656. $where['dt.auit_status'] = 1;
  657. $orderby = 'dt.id desc';
  658. $list = Db::name('topic_dongtai')->alias('dt')
  659. ->join('user','dt.user_id = user.id','LEFT')
  660. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  661. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  662. ->where($where)
  663. ->order($orderby)->autopage()->select();
  664. $list = list_domain_image($list,['images','avatar']);
  665. //追加是否点赞
  666. if(!empty($list)){
  667. $ids = array_column($list,'id');
  668. $map = [
  669. 'dt_id' => ['IN',$ids],
  670. 'user_id' => $this->auth->id,
  671. ];
  672. $good_list = Db::name('topic_dongtai_good')->where($map)->select();
  673. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  674. $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
  675. $mt_user_wallet = Db::name('user_wallet'); //钱包
  676. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  677. $mt_charm_level = Db::name('charm_level'); //魅力等级
  678. foreach ($list as &$val) {
  679. $val['birthday'] = birthtime_to_age($val['birthday']);
  680. $val['createtime'] = get_last_time($val['createtime']);
  681. $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'];
  682. //是否点过赞:0否 1是
  683. $val['isgood'] = 0;
  684. foreach($good_list as $k => $v){
  685. if($val['id'] == $v['dt_id']){
  686. $val['isgood'] = 1;
  687. }
  688. }
  689. //礼物数量
  690. $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
  691. //查询是否打过招呼
  692. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
  693. if ($count) {
  694. $val['is_chat'] = 1; //是否打过招呼: 1是 0否
  695. } else {
  696. $val['is_chat'] = 0; //是否打过招呼: 1是 0否
  697. }
  698. //查询财富等级和魅力等级
  699. $wallet_info = $mt_user_wallet->where(['user_id' => $val['user_id']])->find();
  700. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  701. if ($wealth_level) {
  702. $val['wealth_level'] = $wealth_level['image'];
  703. } else {
  704. $val['wealth_level'] = '';
  705. }
  706. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  707. if ($charm_level) {
  708. $val['charm_level'] = $charm_level['image'];
  709. } else {
  710. $val['charm_level'] = '';
  711. }
  712. //创建视频缩略图
  713. $val['images_thumb'] = '';
  714. if ($val['type'] == 2) {
  715. $images_url = explode('.', $val['images']);
  716. unset($images_url[count($images_url) - 1]);
  717. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  718. }
  719. }
  720. }
  721. $this->success('success',$list);
  722. }
  723. //删除动态
  724. public function deldongtai() {
  725. $id = input('id', 0, 'intval');
  726. if (!$id) {
  727. $this->error('您的网络开小差啦~');
  728. }
  729. $info = Db::name('topic_dongtai')->find($id);
  730. if (!$info) {
  731. $this->error('您的网络开小差啦~');
  732. }
  733. if ($info['user_id'] != $this->auth->id) {
  734. $this->error('您的网络开小差啦~');
  735. }
  736. $rs = Db::name('topic_dongtai')->where(['id' => $id])->setField('status', 1);
  737. if (!$rs) {
  738. $this->error('您的网络开小差啦~');
  739. }
  740. $this->success('删除成功');
  741. }
  742. }