LifeFarmOrder.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 绿色蔬菜
  7. * Class Order
  8. * @package app\admin\model
  9. */
  10. class LifeFarmOrder extends Model
  11. {
  12. /**
  13. *
  14. * The table associated with the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'life_farm_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: ZQ
  27. * Date: 2022/10/13
  28. */
  29. public static function getOrderList(int $page, int $limit,string $keywords)
  30. {
  31. $list = static::select('*')
  32. ->when($keywords != '', function ($query) use ($keywords){
  33. $query->where('order_sn', 'like', '%' . $keywords . '%');
  34. })
  35. ->with(['User','Shop'])
  36. ->orderBy('order_create_time','DESC')
  37. ->forPage($page, $limit)
  38. ->get()->toArray();
  39. $count = static::when($keywords != '', function ($query) use ($keywords){
  40. $query->where('order_sn', 'like', '%' . $keywords . '%');
  41. })->count();
  42. return [$list, $count];
  43. }
  44. //关联店铺
  45. public function Shop(){
  46. return $this->belongsTo(MerchantShop::class,'order_shop_id','shop_id');
  47. }
  48. //获取用户信息
  49. public function User(){
  50. return $this->belongsTo(User::class,'order_user_id','user_id');
  51. }
  52. public function getOrderCreateTimeAttribute($value)
  53. {
  54. return date('Y-m-d H:i:s', $value);
  55. }
  56. public function getOrderDeliverTimeAttribute($value)
  57. {
  58. return date('Y-m-d H:i:s', $value);
  59. }
  60. public function getOrderPayTimeAttribute($value)
  61. {
  62. return date('Y-m-d H:i:s', $value);
  63. }
  64. }