GoodsOrder.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 GoodsOrder extends Model
  11. {
  12. /**
  13. *
  14. * The table associated with the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'life_market_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,$keywords,$order_type_model)
  30. {
  31. $list = static::select(['life_market_order.*','merchant_shop.shop_name'])
  32. ->leftJoin('merchant_shop','shop_id','=','life_market_order.order_shop_id')
  33. ->when($keywords != '', function ($query) use ($keywords){
  34. $query->where('order_dno', 'like', '%' . $keywords . '%');
  35. })
  36. ->where('order_type_model',$order_type_model)
  37. ->with(['user','Detail'])
  38. ->orderBy('order_create_time','DESC')
  39. ->forPage($page, $limit)
  40. ->get()->toArray();
  41. $count = static::when($keywords != '', function ($query) use ($keywords){
  42. $query->where('order_dno', 'like', '%' . $keywords . '%');
  43. })->count();
  44. return [$list, $count];
  45. }
  46. //关联店铺
  47. public function Shop(){
  48. return $this->belongsTo(MerchantShop::class,'order_shop_id','shop_id');
  49. }
  50. //获取用户信息
  51. public function User(){
  52. return $this->belongsTo(User::class,'order_user_id','user_id');
  53. }
  54. //获取订单详情
  55. public function Detail(){
  56. return $this->hasMany(GoodsOrderDetail::class,'detail_order_id','order_id')
  57. ->leftJoin('life_market_goods','goods_id','=','life_market_order_detail.detail_goods_id')
  58. ->leftJoin('category','category_id','=','life_market_goods.goods_category_id')
  59. ->select(['life_market_order_detail.*','life_market_goods.goods_name','life_market_goods.goods_category_id','category.category_name']);
  60. }
  61. //关联购物车
  62. public function Cart(){
  63. return $this->hasMany(GoodsOrderCart::class,'cart_id','order_cart_id')
  64. ->leftJoin('life_market_goods','goods_id','=','life_market_cart.cart_goods_id')
  65. ->select(['life_market_cart.*','life_market_goods.goods_name']);
  66. }
  67. //时间格式
  68. public function getOrderCreateTimeAttribute($value)
  69. {
  70. return date('Y-m-d H:i:s', $value);
  71. }
  72. public function getOrderPayTimeAttribute($value)
  73. {
  74. if($value == 0 || $value == ''){
  75. return 0;
  76. }else{
  77. return date('Y-m-d H:i:s', $value);
  78. }
  79. }
  80. }