Topicdongtai.php 35 KB

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