Piaoliuping.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = 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每天只能捡3个');
  28. }
  29. }
  30. }
  31. //不能是自己发的
  32. $map = [
  33. '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['id'] = ['NOTIN',$log_list];
  39. }
  40. $rs = Db::name('piaoliuping')->where($map)->orderRaw('rand()')->find();
  41. //记录查看记录
  42. if(!empty($rs)){
  43. $log_data = [
  44. 'user_id' => $this->auth->id,
  45. 'plp_id' => $rs['id'],
  46. 'createtime' => time(),
  47. ];
  48. Db::name('piaoliuping_log')->insertGetId($log_data);
  49. }
  50. $this->success('success',$rs);
  51. }
  52. //扔一个
  53. public function addone(){
  54. $content = input('content','','trim,strip_tags,htmlspecialchars');
  55. $cityname = input('cityname','','trim');
  56. if(empty($content)){
  57. $this->error('写点什么吧...');
  58. }
  59. $data = [
  60. 'user_id' => $this->auth->id,
  61. 'content' => $content,
  62. 'createtime' => time(),
  63. 'cityname' => $cityname,
  64. ];
  65. Db::name('piaoliuping')->insertGetId($data);
  66. $this->success('成功');
  67. }
  68. }