Pay.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\common\ChannelDict;
  13. use app\dict\pay\PayDict;
  14. use app\model\member\Member;
  15. use core\base\BaseModel;
  16. /**
  17. * 订单模型
  18. * Class Order
  19. * @package app\model\order
  20. */
  21. class Pay extends BaseModel
  22. {
  23. // 关闭自动写入update_time字段
  24. protected $updateTime = false;
  25. /**
  26. * 数据表主键
  27. * @var string
  28. */
  29. protected $pk = 'id';
  30. /**
  31. * 模型名称
  32. * @var string
  33. */
  34. protected $name = 'pay';
  35. //类型
  36. protected $type = [
  37. 'pay_time' => 'timestamp',
  38. 'close_time' => 'timestamp',
  39. ];
  40. protected $json = ['allow_type'];
  41. protected $jsonAssoc = true;
  42. public function member()
  43. {
  44. return $this->hasOne(Member::class, 'member_id', 'main_id');
  45. }
  46. /**
  47. * 状态字段转化
  48. * @param $value
  49. * @param $data
  50. * @return mixed
  51. */
  52. public function getStatusNameAttr($value, $data)
  53. {
  54. if (empty($data['status']))
  55. return '';
  56. return PayDict::getStatus()[$data['status']] ?? '';
  57. }
  58. /**
  59. * 支付方式字段转化
  60. * @param $value
  61. * @param $data
  62. * @return mixed
  63. */
  64. public function getTypeNameAttr($value, $data)
  65. {
  66. if (empty($data['type']))
  67. return '';
  68. $temp = PayDict::getPayType()[$data['type']] ?? [];
  69. return $temp['name'] ?? '';
  70. }
  71. /**
  72. * 支付渠道
  73. * @param $value
  74. * @param $data
  75. * @return array|mixed|string|void
  76. */
  77. public function getChannelNameAttr($value, $data){
  78. if (isset($data['channel'])) {
  79. if(!empty($data['channel']))
  80. {
  81. return ChannelDict::getType($data['channel']) ?? '';
  82. }else{
  83. return '';
  84. }
  85. }
  86. }
  87. /**
  88. * 创建时间搜索器
  89. * @param $query
  90. * @param $value
  91. * @param $data
  92. */
  93. public function searchCreateTimeAttr($query, $value, $data)
  94. {
  95. $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
  96. $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
  97. if ($start_time > 0 && $end_time > 0) {
  98. $query->whereBetweenTime('create_time', $start_time, $end_time);
  99. } else if ($start_time > 0 && $end_time == 0) {
  100. $query->where([['create_time', '>=', $start_time]]);
  101. } else if ($start_time == 0 && $end_time > 0) {
  102. $query->where([['create_time', '<=', $end_time]]);
  103. }
  104. }
  105. /**
  106. * 查询交易流水号
  107. * @param $query
  108. * @param $value
  109. * @return void
  110. */
  111. public function searchOutTradeNoAttr($query, $value) {
  112. if (!empty($value)) {
  113. $query->where([['out_trade_no', '=', $value]]);
  114. }
  115. }
  116. /**
  117. * 查询支付方式
  118. * @param $query
  119. * @param $value
  120. * @return void
  121. */
  122. public function searchTypeAttr($query, $value) {
  123. if (!empty($value)) {
  124. $query->where([['type', '=', $value]]);
  125. }
  126. }
  127. /**
  128. * 查询支付渠道
  129. * @param $query
  130. * @param $value
  131. * @return void
  132. */
  133. public function searchChannelAttr($query, $value) {
  134. if (!empty($value)) {
  135. $query->where([['channel', '=', $value]]);
  136. }
  137. }
  138. /**
  139. * 查询交易状态
  140. * @param $query
  141. * @param $value
  142. * @return void
  143. */
  144. public function searchStatusAttr($query, $value) {
  145. if ($value != '') {
  146. $query->where([['status', '=', $value]]);
  147. }
  148. }
  149. }