Course.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Course extends Model
  5. {
  6. protected $table = 'course_base';
  7. protected $primaryKey = 'id';
  8. const CREATED_AT = 'creation_date';
  9. public static function getList(int $page,int $limit)
  10. {
  11. $offset = ($page - 1) * $limit;
  12. $query = self::query()->where(['status'=>0])->orderBy('created_at','desc')->offset($offset)->limit($limit)->get();
  13. if ($query){
  14. return $query->toArray();
  15. }else{
  16. return [];
  17. }
  18. }
  19. public static function isPay(array $list,int $id){
  20. if (empty($list)){
  21. return [];
  22. }
  23. if (empty($id)){
  24. $payList = [];
  25. }else{
  26. $payList = UserCourse::getListByUserId($id);
  27. $payList = array_column($payList,'course_id');
  28. }
  29. foreach ($list as &$v){
  30. if (in_array($v['id'],$payList)){
  31. $v['is_pay'] = 1;
  32. }else{
  33. $v['is_pay'] = 0;
  34. }
  35. }
  36. return $list;
  37. }
  38. public static function getOne($where)
  39. {
  40. $query = self::query()->where($where)->first();
  41. if ($query){
  42. return $query->toArray();
  43. }else{
  44. return [];
  45. }
  46. }
  47. public static function getCourse(int $page,int $limit,array $where)
  48. {
  49. $offset = ($page - 1) * $limit;
  50. $where['status'] = 0;
  51. $query = self::query()->where($where)->orderBy('created_at','desc')->offset($offset)->limit($limit)->get();
  52. if ($query){
  53. return $query->toArray();
  54. }else{
  55. return [];
  56. }
  57. }
  58. public static function getPayCountList(int $page,int $limit)
  59. {
  60. $offset = ($page - 1) * $limit;
  61. $query = self::query()->where(['status'=>0])->orderBy('pay_count','desc')->offset($offset)->limit($limit)->get();
  62. if ($query){
  63. return $query->toArray();
  64. }else{
  65. return [];
  66. }
  67. }
  68. public static function getListByLabel(int $page,int $limit,array $label)
  69. {
  70. $offset = ($page - 1) * $limit;
  71. $query = self::query()
  72. ->where(['status'=>0])
  73. ->whereIn('one_level_label',$label)
  74. ->orderBy('pay_count','desc')
  75. ->offset($offset)
  76. ->limit($limit)
  77. ->get();
  78. if ($query){
  79. return $query->toArray();
  80. }else{
  81. return [];
  82. }
  83. }
  84. public static function insertData(array $data)
  85. {
  86. return self::query()->insert($data);
  87. }
  88. public static function del(int $id)
  89. {
  90. return self::query()->where('id', $id)->delete();
  91. }
  92. public static function countIncrement(int $id,string $column)
  93. {
  94. return self::query()->where('id', $id)->increment($column);
  95. }
  96. }