BalanceOrder.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\common\model\user;
  3. use app\common\model\BaseModel;
  4. use app\common\enum\order\OrderPayStatusEnum;
  5. use app\common\enum\order\OrderPayTypeEnum;
  6. use app\common\service\order\OrderService;
  7. /**
  8. * 充值订单模型
  9. */
  10. class BalanceOrder extends BaseModel
  11. {
  12. protected $name = 'balance_order';
  13. protected $pk = 'order_id';
  14. /**
  15. * 关联用户表
  16. */
  17. public function user()
  18. {
  19. return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id');
  20. }
  21. /**
  22. * 付款状态
  23. */
  24. public function getPayTypeAttr($value)
  25. {
  26. return ['text' => OrderPayTypeEnum::data()[$value]['name'], 'value' => $value];
  27. }
  28. /**
  29. * 付款状态
  30. */
  31. public function getPayStatusAttr($value)
  32. {
  33. return ['text' => OrderPayStatusEnum::data()[$value]['name'], 'value' => $value];
  34. }
  35. /**
  36. * 订单详情
  37. */
  38. public static function detail($where, $with = ['user'])
  39. {
  40. is_array($where) ? $filter = $where : $filter['order_id'] = (int)$where;
  41. return (new static())->with($with)->find($where);
  42. }
  43. /**
  44. * 生成订单号
  45. */
  46. public function orderNo()
  47. {
  48. return OrderService::createOrderNo();
  49. }
  50. }