YqZsyTestService.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: z-yang
  5. * Date: 2019/1/11
  6. * Time: 9:50
  7. */
  8. namespace App\Modules\YunQi\Services;
  9. use App\Modules\OfficialAccount\Services\ForceSubscribeService;
  10. use App\Modules\YunQi\Models\YqZsyTest;
  11. class YqZsyTestService
  12. {
  13. public static function getRandomBooks($uid,$num=1):array{
  14. $sex = ForceSubscribeService::getSimpleSexByUid($uid);
  15. if($sex == 1){
  16. $channel_name = '男频';
  17. }else{
  18. $channel_name = '女频';
  19. }
  20. $books = YqZsyTest::join('books','books.id','=','yq_zsy_test.bid')
  21. ->join('book_categories','book_categories.id','=','books.category_id')
  22. ->where('book_categories.channel_name',$channel_name)
  23. ->select('yq_zsy_test.bid')->where('type','yunqi')->get();
  24. if($books->count()<=0){
  25. return [];
  26. }
  27. $num = $books->count()>$num ?$num:$books->count();
  28. return $books->random($num)->pluck('bid')->all();
  29. }
  30. public static function getByBid($bid){
  31. return YqZsyTest::where('bid',$bid)->select('id','bid','type')->first();
  32. }
  33. }