Topicdongtai.php 32 KB

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