PostTrait.php 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/6
  6. * Time: 18:05
  7. */
  8. namespace App\Traits;
  9. use App\Models\Post;
  10. use Illuminate\Support\Facades\Redis;
  11. trait PostTrait
  12. {
  13. // public function __construct(Post $post) {
  14. // $this->post = $post;
  15. // }
  16. //预计可获得U米数
  17. public function availableBean()
  18. {
  19. $bean = Redis::get('yesterday_post_create_bean');
  20. $count = Redis::get('yesterday_post_count');
  21. $num = 1000;
  22. if($bean && $count){
  23. $num = $bean / $count;
  24. }
  25. $h = date('h');
  26. $H = date('H');
  27. $t = $h * 60 / 720 + 2;
  28. if(in_array(intval($H), [9,10,11,12,17.18,19,20,21])){
  29. $t += 0.5;
  30. }
  31. return intval($num * $t);
  32. }
  33. //详情
  34. public function detail($id)
  35. {
  36. return Post::join('post_data', 'post_data.post_id', '=', 'post.id')
  37. ->select('post.*')
  38. ->find($id);
  39. }
  40. }