HomeOrder.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 HomeOrder extends Model
  11. {
  12. /**
  13. *
  14. * The table associated with the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'home_order';
  19. public $timestamps = false;
  20. /**
  21. * Notes:获取订单列表
  22. * @param string $keywords
  23. * @param int $page
  24. * @param int $limit
  25. * @return array
  26. * User: YCP
  27. * Date: 2022/11/2
  28. */
  29. public static function getOrderList(int $page, int $limit,$keywords)
  30. {
  31. $list = static::select('*')
  32. ->with(['User','HomeGoods'])
  33. ->when($keywords != '', function ($query) use ($keywords){
  34. $query->where('order_dno', 'like', '%' . $keywords . '%');
  35. })
  36. ->orderBy('order_create_time','DESC')
  37. ->forPage($page, $limit)
  38. ->get();
  39. $count = static::when($keywords != '', function ($query) use ($keywords){
  40. $query->where('order_dno', 'like', '%' . $keywords . '%');
  41. })
  42. ->count();
  43. return [$list, $count];
  44. }
  45. //关联用户
  46. public function User(){
  47. return $this->belongsTo(User::class,'order_user_id','user_id');
  48. }
  49. //关联项目
  50. public function HomeGoods(){
  51. return $this->belongsTo(HomeGoods::class,'order_goods_id','goods_id');
  52. }
  53. //时间格式
  54. public function getOrderCreateTimeAttribute($value)
  55. {
  56. return date('Y-m-d H:i:s', $value);
  57. }
  58. }