Order.php 2.2 KB

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