Topicdongtai.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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. $dt_id = input('dt_id', 0, 'intval'); //动态id
  485. $gift_id = input('gift_id');// 礼物ID
  486. $number = input('number',1,'intval');//数量
  487. if (!$dt_id || !$gift_id || $number < 1) {
  488. $this->error();
  489. }
  490. //查询动态
  491. $dongtai_info = Db::name('topic_dongtai')->find($dt_id);
  492. if (!$dongtai_info) {
  493. $this->error('您的网络开小差啦~');
  494. }
  495. if ($dongtai_info['status'] != 0) {
  496. $this->error('您的网络开小差啦~');
  497. }
  498. $user_id = $dongtai_info['user_id'];
  499. // 不可以赠送给自己
  500. if($this->auth->id == $user_id) {
  501. $this->error("不可以赠送给自己");
  502. }
  503. // 获取礼物信息
  504. $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
  505. if (!$giftinfo)
  506. {
  507. $this->error("请选择礼物");
  508. }
  509. $giftvalue = bcmul($giftinfo['value'],$number,2);
  510. //被赠送人信息
  511. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  512. if (!$touserinfo) {
  513. $this->error("不存在的用户");
  514. }
  515. // 判断当前用户余额
  516. if($giftinfo['wallettype'] == 1){
  517. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  518. if($user_gold < $giftvalue) {
  519. $this->error("您的金币不足");
  520. }
  521. }else{
  522. $user_jewel = model('wallet')->getWallet($this->auth->id,'jewel');
  523. if($user_jewel < $giftvalue) {
  524. $this->error("您的钻石不足");
  525. }
  526. }
  527. $money = 0.00;
  528. Db::startTrans();
  529. // 添加礼物赠送记录表
  530. $data = [
  531. 'user_id' => $this->auth->id,
  532. 'user_to_id' => $user_id,
  533. 'dt_id' => $dt_id,
  534. 'gift_id' => $giftinfo['id'],
  535. 'gift_name' => $giftinfo['name'],
  536. 'number' => $number,
  537. 'createtime' => time(),
  538. 'wallettype' => $giftinfo['wallettype'],
  539. ];
  540. if($giftinfo['wallettype'] == 1){
  541. $data['price'] = $giftvalue;
  542. }else{
  543. $data['jewel'] = $giftvalue;
  544. }
  545. $log_id = Db::name('gift_user_dongtai')->insertGetId($data);
  546. if(!$log_id){
  547. Db::rollback();
  548. $this->error('赠送失败');
  549. }
  550. if($giftvalue > 0){
  551. // 扣除当前用户余额
  552. if($giftinfo['wallettype'] == 1){
  553. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,59,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id);
  554. if($wallet_rs['status'] === false){
  555. Db::rollback();
  556. $this->error($wallet_rs['msg']);
  557. }
  558. // 添加赠送用户余额
  559. $money_to_gold = config('site.money_to_gold');//送金币礼物得积分
  560. $gift_plat_scale = config('site.gift_plat_scale');
  561. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  562. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  563. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,60,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id,2);
  564. if($wallet_rs['status'] === false){
  565. Db::rollback();
  566. $this->error($wallet_rs['msg']);
  567. }
  568. //增加赠送用户上级余额
  569. if ($touserinfo['intro_uid']) {
  570. //获取返利比率
  571. $agent_info = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->field('is_agent,h_intro_income_rebate_rate')->find();
  572. $intro_income_rebate_rate = ($agent_info['is_agent'] == 1) ? $agent_info['h_intro_income_rebate_rate'] : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  573. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  574. //上级获得金额
  575. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  576. if ($intro_uid_money > 0) {
  577. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人动态礼物获赠奖励','gift_user_dongtai',$log_id);
  578. if($intro_result['status']===false)
  579. {
  580. Db::rollback();
  581. $this->error($intro_result['msg']);
  582. }
  583. }
  584. }
  585. }
  586. if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
  587. //增加亲密度
  588. /*$user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
  589. if (!$user_intimacy_rs['status']) {
  590. Db::rollback();
  591. $this->error('您的网络开小差啦~');
  592. }*/
  593. }
  594. }else{
  595. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'jewel',-$giftvalue,39,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id);
  596. if($wallet_rs['status'] === false){
  597. Db::rollback();
  598. $this->error($wallet_rs['msg']);
  599. }
  600. }
  601. }
  602. Db::commit();
  603. //发送消息
  604. /*if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  605. $tenim = new \app\api\controller\Tenim;
  606. $tenim->sendMessageToUser($this->auth->id, $user_id, $user_intimacy_rs['level_remark'], 1);
  607. }*/
  608. $return_data['money'] = $money; //获得金额
  609. // $return_data['level_remark'] = isset($user_intimacy_rs) ? $user_intimacy_rs['level_remark'] : ''; //亲密度等级提示语
  610. $return_data['level_remark'] = ''; //亲密度等级提示语
  611. $this->success('赠送成功', $return_data);
  612. }
  613. //动态收到礼物列表
  614. public function dongtaigiftlist() {
  615. $id = input('id', 0, 'intval');
  616. if (!$id) {
  617. $this->error('您的网络开小差啦~');
  618. }
  619. //点赞只能查看异性
  620. $dongtaiWhere['td.id'] = $id;
  621. $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
  622. ->join('user u','u.id = td.user_id','LEFT')
  623. ->where($dongtaiWhere)->find();
  624. $where['a.dt_id'] = $id;
  625. $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
  626. if ($gender == 1) {
  627. $where['user.gender'] = 0;
  628. } elseif ($gender == 0) {
  629. $where['user.gender'] = 1;
  630. }
  631. $list = Db::name('gift_user_dongtai')->alias('a')->field('a.user_id, count(a.id) count')
  632. ->join('user', 'a.user_id = user.id', 'left')
  633. ->where($where)->group('a.user_id')->order('a.id desc')->autopage()->select();
  634. if (!$list) {
  635. $this->success('success', $list);
  636. }
  637. $mt_user = Db::name('user');
  638. foreach ($list as &$v) {
  639. $user_info = $mt_user->field('nickname, avatar, gender, birthday')->where(['id' => $v['user_id']])->find();
  640. $v['nickname'] = $user_info['nickname'];
  641. $v['avatar'] = one_domain_image($user_info['avatar']);
  642. $v['birthday'] = birthtime_to_age($user_info['birthday']);
  643. }
  644. $this->success('success', $list);
  645. }
  646. //用户动态列表
  647. public function mydongtailist() {
  648. $user_id = input('user_id', $this->auth->id);
  649. if (!$user_id) {
  650. $this->error('您的网络开小差啦~');
  651. }
  652. $where['dt.user_id'] = $user_id;
  653. $where['dt.status'] = 0;
  654. $where['dt.auit_status'] = 1;
  655. $orderby = 'dt.id desc';
  656. $list = Db::name('topic_dongtai')->alias('dt')
  657. ->join('user','dt.user_id = user.id','LEFT')
  658. ->join('topic_hub th','dt.topic_id = th.id','LEFT')
  659. ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.cityname,user.is_hideaddress,th.name,user.real_status')
  660. ->where($where)
  661. ->order($orderby)->autopage()->select();
  662. $list = list_domain_image($list,['images','avatar']);
  663. //追加是否点赞
  664. if(!empty($list)){
  665. $ids = array_column($list,'id');
  666. $map = [
  667. 'dt_id' => ['IN',$ids],
  668. 'user_id' => $this->auth->id,
  669. ];
  670. $good_list = Db::name('topic_dongtai_good')->where($map)->select();
  671. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  672. $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
  673. $mt_user_wallet = Db::name('user_wallet'); //钱包
  674. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  675. $mt_charm_level = Db::name('charm_level'); //魅力等级
  676. foreach ($list as &$val) {
  677. $val['birthday'] = birthtime_to_age($val['birthday']);
  678. $val['createtime'] = get_last_time($val['createtime']);
  679. $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'];
  680. //是否点过赞:0否 1是
  681. $val['isgood'] = 0;
  682. foreach($good_list as $k => $v){
  683. if($val['id'] == $v['dt_id']){
  684. $val['isgood'] = 1;
  685. }
  686. }
  687. //礼物数量
  688. $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
  689. //查询是否打过招呼
  690. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
  691. if ($count) {
  692. $val['is_chat'] = 1; //是否打过招呼: 1是 0否
  693. } else {
  694. $val['is_chat'] = 0; //是否打过招呼: 1是 0否
  695. }
  696. //查询财富等级和魅力等级
  697. $wallet_info = $mt_user_wallet->where(['user_id' => $val['user_id']])->find();
  698. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  699. if ($wealth_level) {
  700. $val['wealth_level'] = localpath_to_netpath($wealth_level['image']);
  701. } else {
  702. $val['wealth_level'] = '';
  703. }
  704. $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  705. if ($charm_level) {
  706. $val['charm_level'] = localpath_to_netpath($charm_level['image']);
  707. } else {
  708. $val['charm_level'] = '';
  709. }
  710. //创建视频缩略图
  711. $val['images_thumb'] = '';
  712. if ($val['type'] == 2) {
  713. $images_url = explode('.', $val['images']);
  714. unset($images_url[count($images_url) - 1]);
  715. $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
  716. }
  717. }
  718. }
  719. $this->success('success',$list);
  720. }
  721. //删除动态
  722. public function deldongtai() {
  723. $id = input('id', 0, 'intval');
  724. if (!$id) {
  725. $this->error('您的网络开小差啦~');
  726. }
  727. $info = Db::name('topic_dongtai')->find($id);
  728. if (!$info) {
  729. $this->error('您的网络开小差啦~');
  730. }
  731. if ($info['user_id'] != $this->auth->id) {
  732. $this->error('您的网络开小差啦~');
  733. }
  734. $rs = Db::name('topic_dongtai')->where(['id' => $id])->setField('status', 1);
  735. if (!$rs) {
  736. $this->error('您的网络开小差啦~');
  737. }
  738. $this->success('删除成功');
  739. }
  740. }