PostTrait.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Illuminate\Support\Facades\Redis;
  10. trait PostTrait
  11. {
  12. //预计可获得U米数
  13. public function availableBean()
  14. {
  15. $bean = Redis::get('yesterday_post_create_bean');
  16. $count = Redis::get('yesterday_post_count');
  17. $num = 1000;
  18. if($bean && $count){
  19. $num = $bean / $count;
  20. }
  21. $h = date('h');
  22. $H = date('H');
  23. $t = $h * 60 / 720 + 2;
  24. if(in_array(intval($H), [9,10,11,12,17.18,19,20,21])){
  25. $t += 0.5;
  26. }
  27. return intval($num * $t);
  28. }
  29. //获取内容话题
  30. public function getTopic($topic_ids)
  31. {
  32. $ids = explode(',', $topic_ids);
  33. $topic = [];
  34. foreach($ids as $id){
  35. $name = Redis::ZRANGEBYSCORE('topic.name', $id, $id);
  36. if($name && isset($name[0])){
  37. $topic[] = $name[0];
  38. }
  39. }
  40. return $topic;
  41. }
  42. }