BookCourse.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 书院订单模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class BookCourse extends Model
  11. {
  12. /**
  13. * The table associated with the model.
  14. *
  15. * @var string
  16. */
  17. protected $table = 'life_book_course_order';
  18. public $timestamps = false;
  19. /**
  20. * Notes:书院订单列表
  21. * @param string $keywords
  22. * @param int $page
  23. * @param int $limit
  24. * @return array
  25. * User: ZQ-QJF
  26. * Date: 2022/10/14
  27. */
  28. public static function getOrderList(int $page, int $limit, string $keywords)
  29. {
  30. $list = static::select('*')
  31. ->where(['order_is_del'=>0])
  32. ->when($keywords != '', function ($query) use ($keywords){
  33. $query->where('order_dno', $keywords);
  34. })
  35. ->with(['User'])
  36. ->orderBy('order_create_time','DESC')
  37. ->forPage($page, $limit)
  38. ->get();
  39. $count = static::where(['order_is_del'=>0])
  40. ->when($keywords != '', function ($query) use ($keywords){
  41. $query->where('order_dno', $keywords);
  42. })
  43. ->count();
  44. return [$list, $count];
  45. }
  46. public function User(){
  47. return $this->belongsTo(User::class,'order_user_id','user_id');
  48. }
  49. public function getOrderPayTimeAttribute($value)
  50. {
  51. return date('Y-m-d H:i:s', $value);
  52. }
  53. public function Detail(){
  54. return $this->hasMany(BookCourseLog::class,'log_order_id','order_id');
  55. }
  56. }