Piaoliuping.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 漂流瓶
  7. */
  8. class Piaoliuping extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //捡一个
  13. public function getone(){
  14. //判断vip身份,限制每日捡的个数
  15. $vip_endtime = model('wallet')->getWallet($this->auth->id,'vip_endtime');
  16. if($vip_endtime < time()){
  17. $plp_unvip_daysnum = intval(config('site.plp_unvip_daysnum'));
  18. if($plp_unvip_daysnum > -1){
  19. $starttime = strtotime(date('Y-m-d'));
  20. $endtime = $starttime + 86399;
  21. $where = [
  22. 'user_id' => $this->auth->id,
  23. 'createtime' => ['BETWEEN',[$starttime,$endtime]],
  24. ];
  25. $count = Db::name('piaoliuping_log')->where($where)->count('id');
  26. if($count >= $plp_unvip_daysnum){
  27. $this->error('非vip每天只能捡'.$plp_unvip_daysnum.'个');
  28. }
  29. }
  30. }
  31. //不能是自己发的
  32. $map = [
  33. 'plp.user_id' => ['NEQ',$this->auth->id],
  34. ];
  35. //不能重复
  36. $log_list = Db::name('piaoliuping_log')->where('user_id',$this->auth->id)->column('plp_id');
  37. if(!empty($log_list)){
  38. $map['plp.id'] = ['NOTIN',$log_list];
  39. }
  40. $rs = Db::name('piaoliuping')->alias('plp')
  41. ->field('plp.*,user.nickname,user.avatar')
  42. ->join('user','plp.user_id = user.id','LEFT')
  43. ->where($map)->orderRaw('rand()')->find();
  44. //记录查看记录
  45. if(!empty($rs)){
  46. $log_data = [
  47. 'user_id' => $this->auth->id,
  48. 'plp_id' => $rs['id'],
  49. 'createtime' => time(),
  50. ];
  51. Db::name('piaoliuping_log')->insertGetId($log_data);
  52. }
  53. $this->success('success',$rs);
  54. }
  55. //扔一个
  56. public function addone(){
  57. $content = input('content','','trim,strip_tags,htmlspecialchars');
  58. // $cityname = input('cityname','','trim');
  59. if(empty($content)){
  60. $this->error('写点什么吧...');
  61. }
  62. $data = [
  63. 'user_id' => $this->auth->id,
  64. 'content' => $content,
  65. 'createtime' => time(),
  66. 'cityname' => $this->auth->cityname,
  67. ];
  68. Db::name('piaoliuping')->insertGetId($data);
  69. $this->success('成功');
  70. }
  71. }