Topicdongtai.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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. $address = $address['provincename'].$address['cityname'];
  227. $data = [
  228. 'topic_id' => $topic_id,
  229. 'user_id' => $this->auth->id,
  230. 'content' => $content,
  231. 'images' => $images,
  232. // 'longitude' => input('longitude',''),
  233. // 'latitude' => input('latitude',''),
  234. 'createtime' => time(),
  235. 'updatetime' => time(),
  236. 'is_show_real' => $show_real,
  237. 'address' => $address,
  238. 'type' => $type
  239. ];
  240. Db::startTrans();
  241. $id = Db::name('topic_dongtai')->insertGetId($data);
  242. if (!$id) {
  243. Db::rollback();
  244. $this->error('您的网络开小差啦~');
  245. }
  246. //圈子新增一个贴
  247. if ($topic_id) {
  248. $rs = Db::name('topic_hub')->where('id', $topic_id)->setInc('t_number');
  249. if (!$rs) {
  250. Db::rollback();
  251. $this->error('您的网络开小差啦~');
  252. }
  253. }
  254. Db::commit();
  255. $this->success('发布成功',$id);
  256. }
  257. //动态列表
  258. public function dongtailist() {
  259. $type = input('type', 0, 'intval'); //类型:0热门 1最新
  260. $topic_id = input('topic_id', 0); //热门话题id
  261. if (!in_array($type, [0, 1])) {
  262. $this->error('您的网络开小差啦~');
  263. }
  264. if ($type == 0) {
  265. // $orderby = 'dt.goodnum desc';
  266. $orderby = 'dt.id desc';
  267. } else {
  268. $orderby = 'dt.id desc';
  269. }
  270. $where['dt.status'] = 0;
  271. $where['dt.auit_status'] = 1;
  272. $where['user.is_kefu'] = 0;
  273. if ($this->auth->gender == 1) {
  274. $where['user.gender'] = 0;
  275. } elseif ($this->auth->gender == 0) {
  276. $where['user.gender'] = 1;
  277. } else {
  278. $this->success('success',[]);
  279. }
  280. if ($topic_id) {
  281. $where['dt.topic_id'] = $topic_id;
  282. $orderby = 'dt.id desc';
  283. }
  284. $list = Db::name('topic_dongtai')->alias('dt')
  285. ->join('user','dt.user_id = user.id','LEFT')
  286. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  287. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  288. ->where($where)
  289. ->order($orderby)->autopage()->select();
  290. $list = list_domain_image($list,['images','avatar']);
  291. //追加是否点赞
  292. if(!empty($list)){
  293. $ids = array_column($list,'id');
  294. $map = [
  295. 'dt_id' => ['IN',$ids],
  296. 'user_id' => $this->auth->id,
  297. ];
  298. $good_list = Db::name('topic_dongtai_good')->where($map)->select();
  299. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  300. $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
  301. $mt_user_wallet = Db::name('user_wallet'); //钱包
  302. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  303. $mt_charm_level = Db::name('charm_level'); //魅力等级
  304. foreach ($list as &$val) {
  305. $val['name'] = $val['name'] ? : '';
  306. $val['birthday'] = birthtime_to_age($val['birthday']);
  307. $val['createtime'] = get_last_time($val['createtime']);
  308. $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'] ;
  309. //是否点过赞:0否 1是
  310. $val['isgood'] = 0;
  311. foreach($good_list as $k => $v){
  312. if($val['id'] == $v['dt_id']){
  313. $val['isgood'] = 1;
  314. }
  315. }
  316. //礼物数量
  317. $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
  318. //查询是否打过招呼
  319. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
  320. if ($count) {
  321. $val['is_chat'] = 1; //是否打过招呼: 1是 0否
  322. } else {
  323. $val['is_chat'] = 0; //是否打过招呼: 1是 0否
  324. }
  325. //查询财富等级和魅力等级
  326. $wallet_info = $mt_user_wallet->where(['user_id' => $val['user_id']])->find();
  327. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  328. if ($wealth_level) {
  329. $val['wealth_level'] = localpath_to_netpath($wealth_level['image']);
  330. } else {
  331. $val['wealth_level'] = '';
  332. }
  333. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  334. if ($charm_level) {
  335. $val['charm_level'] = localpath_to_netpath($charm_level['image']);
  336. } else {
  337. $val['charm_level'] = '';
  338. }
  339. //创建视频缩略图
  340. $val['images_thumb'] = '';
  341. if ($val['type'] == 2) {
  342. $images_url = explode('.', $val['images']);
  343. unset($images_url[count($images_url) - 1]);
  344. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  345. }
  346. }
  347. }
  348. $this->success('success',$list);
  349. }
  350. //动态详情
  351. public function dongtaiinfo(){
  352. $id = input('id', 0, 'intval');
  353. if (!$id) {
  354. $this->error('您的网络开小差啦~');
  355. }
  356. $info = Db::name('topic_dongtai')->alias('dt')
  357. ->join('user','dt.user_id = user.id','LEFT')
  358. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  359. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  360. ->where('dt.id',$id)->find();
  361. if (!$info) {
  362. $this->error('您的网络开小差啦~');
  363. }
  364. if ($info['status'] != 0) {
  365. $this->error('您的网络开小差啦~');
  366. }
  367. $info = info_domain_image($info,['images','avatar']);
  368. $info['birthday'] = birthtime_to_age($info['birthday']);
  369. $info['createtime'] = get_last_time($info['createtime']);
  370. $info['cityname'] = $info['is_hideaddress'] ? '' : $info['address'];
  371. //是否点赞过
  372. $info['isgood'] = $this->is_good($id,$this->auth->id);
  373. //礼物数量
  374. $info['gift_count'] = Db::name('gift_user_dongtai')->where(['dt_id' => $info['id']])->count('id');
  375. //查询是否打过招呼
  376. $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $info['user_id']])->count('id');
  377. if ($count) {
  378. $info['is_chat'] = 1; //是否打过招呼: 1是 0否
  379. } else {
  380. $info['is_chat'] = 0; //是否打过招呼: 1是 0否
  381. }
  382. //查询财富等级和魅力等级
  383. $wallet_info = Db::name('user_wallet')->where(['user_id' => $info['user_id']])->find();
  384. $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  385. if ($wealth_level) {
  386. $info['wealth_level'] = localpath_to_netpath($wealth_level['image']);
  387. } else {
  388. $info['wealth_level'] = '';
  389. }
  390. $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  391. if ($charm_level) {
  392. $info['charm_level'] = localpath_to_netpath($charm_level['image']);
  393. } else {
  394. $info['charm_level'] = '';
  395. }
  396. //创建视频缩略图
  397. $info['images_thumb'] = '';
  398. if ($info['type'] == 2) {
  399. $images_url = explode('.', $info['images']);
  400. unset($images_url[count($images_url) - 1]);
  401. $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
  402. }
  403. $this->success('success',$info);
  404. }
  405. //点赞
  406. public function dongtaigood(){
  407. $id = input('id', 0, 'intval');
  408. if (!$id) {
  409. $this->error('您的网络开小差啦~');
  410. }
  411. $info = Db::name('topic_dongtai')->find($id);
  412. if (!$info) {
  413. $this->error('您的网络开小差啦~');
  414. }
  415. if ($info['status'] != 0) {
  416. $this->error('您的网络开小差啦~');
  417. }
  418. $where = [
  419. 'dt_id' => $id,
  420. 'user_id' => $this->auth->id,
  421. ];
  422. $check = Db::name('topic_dongtai_good')->where($where)->find();
  423. if($check){
  424. $this->error('已经赞过了');
  425. }
  426. $where['createtime'] = time();
  427. Db::startTrans();
  428. $rs = Db::name('topic_dongtai_good')->insertGetId($where);
  429. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
  430. //tag任务赠送金币
  431. //点赞奖励
  432. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,14);
  433. // if($task_rs === false){
  434. // Db::rollback();
  435. // $this->error('完成任务赠送奖励失败');
  436. // }
  437. if($rs && $up !== false){
  438. Db::commit();
  439. $this->success('点赞成功');
  440. }
  441. Db::rollback();
  442. $this->error('点赞失败');
  443. }
  444. //点赞列表
  445. public function dongtaigoodlist() {
  446. $id = input('id', 0, 'intval');
  447. if (!$id) {
  448. $this->error('您的网络开小差啦~');
  449. }
  450. //点赞只能查看异性
  451. $dongtaiWhere['td.id'] = $id;
  452. $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
  453. ->join('user u','u.id = td.user_id','LEFT')
  454. ->where($dongtaiWhere)->find();
  455. $where['a.dt_id'] = $id;
  456. $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
  457. if ($gender == 1) {
  458. $where['user.gender'] = 0;
  459. } elseif ($gender == 0) {
  460. $where['user.gender'] = 1;
  461. }
  462. $list = Db::name('topic_dongtai_good')->alias('a')
  463. ->join('user', 'a.user_id = user.id', 'left')
  464. ->field('a.*, user.nickname,user.avatar,user.gender,user.birthday')
  465. ->where($where)
  466. ->order('a.id desc')
  467. ->autopage()->select();
  468. if (!$list) {
  469. $this->success('success', $list);
  470. }
  471. $list = list_domain_image($list,['avatar']);
  472. foreach ($list as &$v) {
  473. $v['birthday'] = birthtime_to_age($v['birthday']);
  474. $v['createtime'] = get_last_time($v['createtime']);
  475. }
  476. $this->success('success', $list);
  477. }
  478. //动态赠送礼物
  479. public function givegiftdongtai() {
  480. // 接口防并发
  481. if (!$this->apiLimit(1, 1)) {
  482. $this->error(__('Operation frequently'));
  483. }
  484. // $user_id = input('user_id');// 赠送对象
  485. $dt_id = input('dt_id', 0, 'intval'); //动态id
  486. $gift_id = input('gift_id');// 礼物ID
  487. $number = input('number',1,'intval');//数量
  488. if (!$dt_id || !$gift_id || $number < 1) {
  489. $this->error();
  490. }
  491. //查询动态
  492. $dongtai_info = Db::name('topic_dongtai')->find($dt_id);
  493. if (!$dongtai_info) {
  494. $this->error('您的网络开小差啦~');
  495. }
  496. if ($dongtai_info['status'] != 0) {
  497. $this->error('您的网络开小差啦~');
  498. }
  499. $user_id = $dongtai_info['user_id'];
  500. // 不可以赠送给自己
  501. if($this->auth->id == $user_id) {
  502. $this->error("不可以赠送给自己");
  503. }
  504. // 获取礼物信息
  505. $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
  506. if (!$giftinfo)
  507. {
  508. $this->error("请选择礼物");
  509. }
  510. $giftvalue = bcmul($giftinfo['value'],$number);
  511. //被赠送人信息
  512. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  513. if (!$touserinfo) {
  514. $this->error("不存在的用户");
  515. }
  516. // 判断当前用户余额
  517. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  518. if($user_gold < $giftvalue) {
  519. $this->error("您的金币余额不足");
  520. }
  521. Db::startTrans();
  522. // 添加礼物赠送记录表
  523. $data = [
  524. 'user_id' => $this->auth->id,
  525. 'user_to_id' => $user_id,
  526. 'dt_id' => $dt_id,
  527. 'gift_id' => $giftinfo['id'],
  528. 'gift_name' => $giftinfo['name'],
  529. 'number' => $number,
  530. 'price' => $giftvalue,
  531. 'createtime' => time(),
  532. ];
  533. $log_id = Db::name('gift_user_dongtai')->insertGetId($data);
  534. if(!$log_id){
  535. Db::rollback();
  536. $this->error('赠送失败');
  537. }
  538. if($giftvalue > 0){
  539. // 扣除当前用户余额
  540. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,59,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id);
  541. if($wallet_rs['status'] === false){
  542. Db::rollback();
  543. $this->error($wallet_rs['msg']);
  544. }
  545. // 添加赠送用户余额
  546. $money_to_gold = config('site.money_to_gold');
  547. $gift_plat_scale = config('site.gift_plat_scale');
  548. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  549. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  550. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,60,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id,2);
  551. if($wallet_rs['status'] === false){
  552. Db::rollback();
  553. $this->error($wallet_rs['msg']);
  554. }
  555. //增加赠送用户上级余额
  556. if ($touserinfo['intro_uid']) {
  557. //获取返利比率
  558. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  559. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  560. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  561. //上级获得金额
  562. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  563. if ($intro_uid_money > 0) {
  564. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人动态礼物获赠奖励','gift_user_dongtai',$log_id);
  565. if($intro_result['status']===false)
  566. {
  567. Db::rollback();
  568. $this->error($intro_result['msg']);
  569. }
  570. }
  571. }
  572. }
  573. if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
  574. //增加亲密度
  575. $user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
  576. if (!$user_intimacy_rs['status']) {
  577. Db::rollback();
  578. $this->error('您的网络开小差啦~');
  579. }
  580. }
  581. }
  582. //tag任务赠送金币
  583. //搭讪奖励
  584. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  585. // if($task_rs === false){
  586. // Db::rollback();
  587. // $this->error('完成任务赠送奖励失败');
  588. // }
  589. Db::commit();
  590. //发送消息
  591. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  592. $tenim = new \app\api\controller\Tenim;
  593. $tenim->sendMessageToUser($this->auth->id, $user_id, $user_intimacy_rs['level_remark'], 1);
  594. }
  595. $return_data['money'] = $money; //获得金额
  596. $return_data['level_remark'] = isset($user_intimacy_rs) ? $user_intimacy_rs['level_remark'] : ''; //亲密度等级提示语
  597. $this->success('赠送成功', $return_data);
  598. }
  599. //动态收到礼物列表
  600. public function dongtaigiftlist() {
  601. $id = input('id', 0, 'intval');
  602. if (!$id) {
  603. $this->error('您的网络开小差啦~');
  604. }
  605. //点赞只能查看异性
  606. $dongtaiWhere['td.id'] = $id;
  607. $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
  608. ->join('user u','u.id = td.user_id','LEFT')
  609. ->where($dongtaiWhere)->find();
  610. $where['a.dt_id'] = $id;
  611. $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
  612. if ($gender == 1) {
  613. $where['user.gender'] = 0;
  614. } elseif ($gender == 0) {
  615. $where['user.gender'] = 1;
  616. }
  617. $list = Db::name('gift_user_dongtai')->alias('a')->field('a.user_id, count(a.id) count')
  618. ->join('user', 'a.user_id = user.id', 'left')
  619. ->where($where)->group('a.user_id')->order('a.id desc')->autopage()->select();
  620. if (!$list) {
  621. $this->success('success', $list);
  622. }
  623. $mt_user = Db::name('user');
  624. foreach ($list as &$v) {
  625. $user_info = $mt_user->field('nickname, avatar, gender, birthday')->where(['id' => $v['user_id']])->find();
  626. $v['nickname'] = $user_info['nickname'];
  627. $v['avatar'] = one_domain_image($user_info['avatar']);
  628. $v['birthday'] = birthtime_to_age($user_info['birthday']);
  629. }
  630. $this->success('success', $list);
  631. }
  632. //用户动态列表
  633. public function mydongtailist() {
  634. $user_id = input('user_id', $this->auth->id);
  635. if (!$user_id) {
  636. $this->error('您的网络开小差啦~');
  637. }
  638. $where['dt.user_id'] = $user_id;
  639. $where['dt.status'] = 0;
  640. $where['dt.auit_status'] = 1;
  641. $orderby = 'dt.id desc';
  642. $list = Db::name('topic_dongtai')->alias('dt')
  643. ->join('user','dt.user_id = user.id','LEFT')
  644. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  645. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  646. ->where($where)
  647. ->order($orderby)->autopage()->select();
  648. $list = list_domain_image($list,['images','avatar']);
  649. //追加是否点赞
  650. if(!empty($list)){
  651. $ids = array_column($list,'id');
  652. $map = [
  653. 'dt_id' => ['IN',$ids],
  654. 'user_id' => $this->auth->id,
  655. ];
  656. $good_list = Db::name('topic_dongtai_good')->where($map)->select();
  657. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  658. $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
  659. $mt_user_wallet = Db::name('user_wallet'); //钱包
  660. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  661. $mt_charm_level = Db::name('charm_level'); //魅力等级
  662. foreach ($list as &$val) {
  663. $val['birthday'] = birthtime_to_age($val['birthday']);
  664. $val['createtime'] = get_last_time($val['createtime']);
  665. $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'];
  666. //是否点过赞:0否 1是
  667. $val['isgood'] = 0;
  668. foreach($good_list as $k => $v){
  669. if($val['id'] == $v['dt_id']){
  670. $val['isgood'] = 1;
  671. }
  672. }
  673. //礼物数量
  674. $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
  675. //查询是否打过招呼
  676. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
  677. if ($count) {
  678. $val['is_chat'] = 1; //是否打过招呼: 1是 0否
  679. } else {
  680. $val['is_chat'] = 0; //是否打过招呼: 1是 0否
  681. }
  682. //查询财富等级和魅力等级
  683. $wallet_info = $mt_user_wallet->where(['user_id' => $val['user_id']])->find();
  684. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  685. if ($wealth_level) {
  686. $val['wealth_level'] = localpath_to_netpath($wealth_level['image']);
  687. } else {
  688. $val['wealth_level'] = '';
  689. }
  690. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  691. if ($charm_level) {
  692. $val['charm_level'] = localpath_to_netpath($charm_level['image']);
  693. } else {
  694. $val['charm_level'] = '';
  695. }
  696. //创建视频缩略图
  697. $val['images_thumb'] = '';
  698. if ($val['type'] == 2) {
  699. $images_url = explode('.', $val['images']);
  700. unset($images_url[count($images_url) - 1]);
  701. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  702. }
  703. }
  704. }
  705. $this->success('success',$list);
  706. }
  707. //删除动态
  708. public function deldongtai() {
  709. $id = input('id', 0, 'intval');
  710. if (!$id) {
  711. $this->error('您的网络开小差啦~');
  712. }
  713. $info = Db::name('topic_dongtai')->find($id);
  714. if (!$info) {
  715. $this->error('您的网络开小差啦~');
  716. }
  717. if ($info['user_id'] != $this->auth->id) {
  718. $this->error('您的网络开小差啦~');
  719. }
  720. $rs = Db::name('topic_dongtai')->where(['id' => $id])->setField('status', 1);
  721. if (!$rs) {
  722. $this->error('您的网络开小差啦~');
  723. }
  724. $this->success('删除成功');
  725. }
  726. }