Order.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\common\model\recharge;
  3. use app\common\model\BaseModel;
  4. use app\common\enum\recharge\order\RechargeType as RechargeTypeEnum;
  5. use app\common\enum\recharge\order\PayStatus as PayStatusTypeEnum;
  6. /**
  7. * 用户充值订单模型
  8. * Class Order
  9. * @package app\common\model\recharge
  10. */
  11. class Order extends BaseModel
  12. {
  13. protected $name = 'recharge_order';
  14. /**
  15. * 获取当前模型属性
  16. * @return array
  17. */
  18. public static function getAttributes()
  19. {
  20. return [
  21. // 充值方式
  22. 'rechargeType' => RechargeTypeEnum::data(),
  23. // 支付状态
  24. 'pay_status' => PayStatusTypeEnum::data(),
  25. ];
  26. }
  27. /**
  28. * 关联会员记录表
  29. * @return \think\model\relation\BelongsTo
  30. */
  31. public function user()
  32. {
  33. return $this->belongsTo('app\common\model\User');
  34. }
  35. /**
  36. * 关联订单套餐快照表
  37. * @return \think\model\relation\HasOne
  38. */
  39. public function orderPlan()
  40. {
  41. return $this->hasOne('OrderPlan', 'order_id');
  42. }
  43. /**
  44. * 付款状态
  45. * @param $value
  46. * @return array
  47. */
  48. public function getRechargeTypeAttr($value)
  49. {
  50. return ['text' => RechargeTypeEnum::data()[$value]['name'], 'value' => $value];
  51. }
  52. /**
  53. * 付款状态
  54. * @param $value
  55. * @return array
  56. */
  57. public function getPayStatusAttr($value)
  58. {
  59. return ['text' => PayStatusTypeEnum::data()[$value]['name'], 'value' => $value];
  60. }
  61. /**
  62. * 付款时间
  63. * @param $value
  64. * @return array
  65. */
  66. public function getPayTimeAttr($value)
  67. {
  68. return [
  69. 'text' => $value > 0 ? date('Y-m-d H:i:s', $value) : '',
  70. 'value' => $value
  71. ];
  72. }
  73. /**
  74. * 获取订单详情
  75. * @param $where
  76. * @return static|null
  77. * @throws \think\exception\DbException
  78. */
  79. public static function detail($where)
  80. {
  81. return static::get($where);
  82. }
  83. }