Refund.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\model\pay;
  12. use app\dict\pay\PayDict;
  13. use app\dict\pay\RefundDict;
  14. use core\base\BaseModel;
  15. /**
  16. * 订单退款模型
  17. * Class Refund
  18. * @package app\model\pay
  19. */
  20. class Refund extends BaseModel
  21. {
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'pay_refund';
  32. //类型
  33. protected $type = [
  34. 'refund_time' => 'timestamp',
  35. 'close_time' => 'timestamp',
  36. ];
  37. /**
  38. * 支付状态字段转化
  39. * @param $value
  40. * @param $data
  41. * @return mixed
  42. */
  43. public function getStatusNameAttr($value, $data)
  44. {
  45. if (empty($data['status'])) return '';
  46. return RefundDict::getStatus()[$data['status']] ?? '';
  47. }
  48. /**
  49. * 支付方式字段转化
  50. * @param $value
  51. * @param $data
  52. * @return mixed
  53. */
  54. public function getTypeNameAttr($value, $data)
  55. {
  56. if (empty($data['type'])) return '';
  57. return PayDict::getPayType()[$data['type']]['name'] ?? '';
  58. }
  59. /**
  60. * 退款方式
  61. * @param $value
  62. * @param $data
  63. * @return mixed|string
  64. *
  65. */
  66. public function getRefundTypeNameAttr($value, $data)
  67. {
  68. if (empty($data['refund_type'])) return '';
  69. return RefundDict::getType()[$data['refund_type']] ?? '';
  70. }
  71. /**
  72. * 创建时间搜索器
  73. * @param $query
  74. * @param $value
  75. * @param $data
  76. */
  77. public function searchCreateTimeAttr($query, $value, $data)
  78. {
  79. $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
  80. $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
  81. if ($start_time > 0 && $end_time > 0) {
  82. $query->whereBetweenTime('create_time', $start_time, $end_time);
  83. } else if ($start_time > 0 && $end_time == 0) {
  84. $query->where([['create_time', '>=', $start_time]]);
  85. } else if ($start_time == 0 && $end_time > 0) {
  86. $query->where([['create_time', '<=', $end_time]]);
  87. }
  88. }
  89. /**
  90. * 状态
  91. * @param $query
  92. * @param $value
  93. * @param $data
  94. */
  95. public function searchStatusAttr($query, $value, $data)
  96. {
  97. if ($value != '') {
  98. $query->where('status', '=', $value);
  99. }
  100. }
  101. /**
  102. * 状态
  103. * @param $query
  104. * @param $value
  105. * @param $data
  106. */
  107. public function searchOutTradeNoAttr($query, $value, $data)
  108. {
  109. if ($value != '') {
  110. $query->where('out_trade_no', 'like', "%$value%");
  111. }
  112. }
  113. /**
  114. * 状态
  115. * @param $query
  116. * @param $value
  117. * @param $data
  118. */
  119. public function searchRefundNoAttr($query, $value, $data)
  120. {
  121. if ($value != '') {
  122. $query->where('refund_no', 'like', "%$value%");
  123. }
  124. }
  125. }