PostTrait.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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, $type = 0)
  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. if($type){
  38. $topic[] = [
  39. 'id' => intval($id),
  40. 'name' => $name[0],
  41. ];
  42. }else{
  43. $topic[] = $name[0];
  44. }
  45. }
  46. }
  47. return $topic;
  48. }
  49. }