BalanceRechargeRecords.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/4/19
  6. * Time: 下午3:56
  7. */
  8. namespace app\backend\modules\finance\models;
  9. use app\common\models\finance\BalanceRecharge;
  10. use app\common\services\PayFactory;
  11. class BalanceRechargeRecords extends BalanceRecharge
  12. {
  13. /**
  14. * Payment translation set.
  15. *
  16. * @var array
  17. */
  18. public static $typeComment = [
  19. self::PAY_TYPE_SHOP => "后台充值",
  20. PayFactory::PAY_WEACHAT => "微信支付",
  21. PayFactory::WECHAT_MIN_PAY => "微信小程序",
  22. // PayFactory::WECHAT_NATIVE => '微信扫码支付',
  23. PayFactory::PAY_ALIPAY => "支付宝",
  24. PayFactory::PAY_APP_WEACHAT => "APP-微信",
  25. PayFactory::PAY_APP_ALIPAY => "APP-支付宝",
  26. PayFactory::PAY_WECHAT_HJ => '汇聚微信支付',
  27. PayFactory::PAY_ALIPAY_HJ => '汇聚支付宝支付',
  28. // 搜索时 使用默认名称
  29. PayFactory::LSP_PAY => '通证支付',
  30. ];
  31. protected $appends = ['type_name'];
  32. /**
  33. * Gets the value of the additional field type_name.
  34. *
  35. * @return string
  36. */
  37. public function getTypeNameAttribute()
  38. {
  39. return static::getTypeNameComment($this->attributes['type']);
  40. }
  41. /**
  42. * Gets the value of the additional field type_name.
  43. *
  44. * @param $attributes
  45. * @return string
  46. */
  47. public function getTypeNameComment($attributes)
  48. {
  49. // 通证支付 自定义名称
  50. if ($attributes == PayFactory::LSP_PAY) {
  51. if (app('plugins')->isEnabled('love-speed-pool')) {
  52. return \Setting::get('plugin.love_speed_pool.diy_pay_name') ?: "通证支付";
  53. }
  54. }
  55. return isset(static::$typeComment[$attributes]) ? static::$typeComment[$attributes] : "其他支付";
  56. }
  57. //todo 以下代码未检查
  58. public function scopeRecords($query)
  59. {
  60. $query->withMember();
  61. }
  62. /**
  63. * @param static $query
  64. * @param array $search
  65. */
  66. public function scopeSearch($query, $search)
  67. {
  68. if (Is_numeric($search['status'])) $query->where('status', $search['status']);
  69. if (Is_numeric($search['pay_type'])) $query->where('type', $search['pay_type']);
  70. if ($search['ordersn']) $query->where('ordersn', 'like', $search['ordersn'] . '%');
  71. if ($search['realname'] || $search['level_id'] || $search['group_id']) {
  72. $query->whereHas('member', function ($member) use ($search) {
  73. if ($search['realname']) {
  74. $member->select('uid', 'nickname', 'realname', 'mobile', 'avatar')
  75. ->where('realname', 'like', '%' . $search['realname'] . '%')
  76. ->orWhere('mobile', 'like', '%' . $search['realname'] . '%')
  77. ->orWhere('nickname', 'like', '%' . $search['realname'] . '%')
  78. ->orWhere('uid', $search['realname']);
  79. }
  80. if ($search['level_id']) {
  81. $member->whereHas('yzMember', function ($level) use ($search) {
  82. $level->where('level_id', $search['level_id']);
  83. });
  84. }
  85. if ($search['group_id']) {
  86. $member->whereHas('yzMember', function ($group) use ($search) {
  87. $group->where('group_id', $search['group_id']);
  88. });
  89. }
  90. });
  91. }
  92. if (Is_numeric($search['time']['start']) && Is_numeric($search['time']['end'])) {
  93. $query->whereBetween('created_at', [$search['time']['start']/1000, $search['time']['end']/1000]);
  94. }
  95. }
  96. }