RechargeModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: king
  5. * Date: 2018/10/22
  6. * Time: 下午12:00
  7. */
  8. namespace app\backend\modules\point\models;
  9. use app\common\scopes\UniacidScope;
  10. class RechargeModel extends \app\common\models\point\RechargeModel
  11. {
  12. protected $appends = ['type_name'];
  13. /**
  14. * Payment translation set.
  15. *
  16. * @var array
  17. */
  18. private static $typeComment = [
  19. 0 => "后台充值",
  20. ];
  21. public static function boot()
  22. {
  23. parent::boot();
  24. self::addGlobalScope(new UniacidScope);
  25. }
  26. /**
  27. * Gets the value of the additional field type_name.
  28. *
  29. * @return string
  30. */
  31. public function getTypeNameAttribute()
  32. {
  33. return static::getTypeNameComment($this->attributes['type']);
  34. }
  35. /**
  36. * Gets the value of the additional field type_name.
  37. *
  38. * @param $attributes
  39. * @return string
  40. */
  41. public function getTypeNameComment($attributes)
  42. {
  43. return isset(static::$typeComment[$attributes]) ? static::$typeComment[$attributes] : "其他支付";
  44. }
  45. /**
  46. * @param static $query
  47. * @param array $search
  48. */
  49. public function scopeSearch($query, $search)
  50. {
  51. $query->searchMember($search);
  52. if ($search['order_sn']) $query->where('order_sn', 'like', $search['order_sn'] . '%');
  53. if ($search['search_time']) {
  54. $query->whereBetween('created_at', [strtotime($search['time']['start']), strtotime($search['time']['end'])]);
  55. }
  56. }
  57. /**
  58. * @param static $query
  59. * @param array $search
  60. */
  61. public function scopeSearchMember($query, $search)
  62. {
  63. if ($search['member']) {
  64. $query->whereHas('member', function ($query) use ($search) {
  65. $query->search($search);
  66. });
  67. }
  68. }
  69. public function scopeWithMember($query)
  70. {
  71. return $query->with(['member' => function ($query) {
  72. return $query->select('uid', 'nickname', 'realname', 'mobile', 'avatar');
  73. }]);
  74. }
  75. /**
  76. * 字段规则
  77. *
  78. * @return array
  79. */
  80. public function rules()
  81. {
  82. return [
  83. 'uniacid' => "required",
  84. 'member_id' => "required",
  85. 'money' => 'numeric|regex:/^[\-\+]?\d+(?:\.\d{1,2})?$/|max:9999999999',
  86. 'type' => 'required',
  87. 'order_sn' => 'required',
  88. 'status' => 'required',
  89. 'remark' => 'max:50'
  90. ];
  91. }
  92. }