Topicdongtai.php 35 KB

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