PackageOrder.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 PackageOrder extends Model
  11. {
  12. const PAY_STATUS_NO = 1;
  13. const PAY_STATUS_YES = 2;
  14. const PAY_STATUS = [
  15. self::PAY_STATUS_NO => '待支付',
  16. self::PAY_STATUS_YES => '已支付'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'package_order';
  24. public $timestamps = false;
  25. /**
  26. * Notes:获取产品列表
  27. * @param string $keywords
  28. * @param int $page
  29. * @param int $limit
  30. * @return array
  31. * User: QJF
  32. * Date: 2022/9/20
  33. */
  34. public static function getPackageOrderList(int $page, int $limit ,$keywords)
  35. {
  36. $list = static::select('package_order.*','user.user_nickname','user.user_headimgurl')
  37. ->when($keywords != '', function ($query) use ($keywords){
  38. $query->where('order_dno', 'like', '%' . $keywords . '%');
  39. })
  40. ->with('package')
  41. ->join('user','package_order.order_user_id','=','user.user_id')
  42. ->orderBy('package_order.order_create_time','DESC')
  43. ->forPage($page, $limit)
  44. ->get();
  45. $count = static::when($keywords != '', function ($query) use ($keywords){
  46. $query->where('order_dno', 'like', '%' . $keywords . '%');
  47. })->count();
  48. return [$list, $count];
  49. }
  50. //关联套餐表
  51. public function Package(){
  52. return $this->belongsTo(Package::class,'order_package_id','package_id');
  53. }
  54. public function getOrderPlaceTimeAttribute($value)
  55. {
  56. return date('Y-m-d H:i:s', $value);
  57. }
  58. public function getOrderEndTimeAttribute($value)
  59. {
  60. return date('Y-m-d H:i:s', $value);
  61. }
  62. public function getOrderPayTimeAttribute($value)
  63. {
  64. return date('Y-m-d H:i:s', $value);
  65. }
  66. public function getOrderCreateTimeAttribute($value)
  67. {
  68. return date('Y-m-d H:i:s', $value);
  69. }
  70. public function getOrderUpdateTimeAttribute($value)
  71. {
  72. return date('Y-m-d H:i:s', $value);
  73. }
  74. /**
  75. * Notes:插入主订单数据
  76. * @param array $data
  77. * @return false|int
  78. * User: yym
  79. * Date: 2022/9/27
  80. */
  81. public static function insertData(array $data)
  82. {
  83. if(empty($data))
  84. {
  85. return false;
  86. }
  87. return static::insertGetId($data);
  88. }
  89. }