LifePackageOrder.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 LifePackageOrder extends Model
  11. {
  12. /**
  13. *
  14. * The table associated with the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'life_package_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/10/19
  28. */
  29. public static function getOrderList(int $page, int $limit,$keywords,$order_package_type)
  30. {
  31. $list = static::select('*')
  32. ->with(['Shop','User','Package','PackageGoods'])
  33. ->when($keywords != '', function ($query) use ($keywords){
  34. $query->where('order_dno', 'like', '%' . $keywords . '%');
  35. })
  36. ->when($order_package_type != '', function ($query) use ($order_package_type){
  37. $query->where('order_package_type',$order_package_type);
  38. })
  39. ->orderBy('order_create_time','DESC')
  40. ->forPage($page, $limit)
  41. ->get();
  42. $count = static::when($keywords != '', function ($query) use ($keywords){
  43. $query->where('order_dno', 'like', '%' . $keywords . '%');
  44. })
  45. ->when($order_package_type != '', function ($query) use ($order_package_type){
  46. $query->where('order_package_type',$order_package_type);
  47. })
  48. ->count();
  49. return [$list, $count];
  50. }
  51. //关联店铺
  52. public function Shop(){
  53. return $this->belongsTo(MerchantShop::class,'order_shop_id','shop_id');
  54. }
  55. //关联用户
  56. public function User(){
  57. return $this->belongsTo(User::class,'order_user_id','user_id');
  58. }
  59. //关联套餐
  60. public function Package(){
  61. return $this->belongsTo(LifePackage::class,'order_package_id','package_id');
  62. }
  63. //关联套餐内项目
  64. public function PackageGoods(){
  65. return $this->hasMany(LifePackageGoods::class,'package_id','order_package_id')->where(['goods_is_del'=>0]);
  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. return date('Y-m-d H:i:s', $value);
  75. }
  76. }