| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /**
- * Created by PhpStorm.
- * User: king
- * Date: 2018/10/22
- * Time: 下午12:00
- */
- namespace app\backend\modules\point\models;
- use app\common\scopes\UniacidScope;
- class RechargeModel extends \app\common\models\point\RechargeModel
- {
- protected $appends = ['type_name'];
- /**
- * Payment translation set.
- *
- * @var array
- */
- private static $typeComment = [
- 0 => "后台充值",
- ];
- public static function boot()
- {
- parent::boot();
- self::addGlobalScope(new UniacidScope);
- }
- /**
- * Gets the value of the additional field type_name.
- *
- * @return string
- */
- public function getTypeNameAttribute()
- {
- return static::getTypeNameComment($this->attributes['type']);
- }
- /**
- * Gets the value of the additional field type_name.
- *
- * @param $attributes
- * @return string
- */
- public function getTypeNameComment($attributes)
- {
- return isset(static::$typeComment[$attributes]) ? static::$typeComment[$attributes] : "其他支付";
- }
- /**
- * @param static $query
- * @param array $search
- */
- public function scopeSearch($query, $search)
- {
- $query->searchMember($search);
- if ($search['order_sn']) $query->where('order_sn', 'like', $search['order_sn'] . '%');
- if ($search['search_time']) {
- $query->whereBetween('created_at', [strtotime($search['time']['start']), strtotime($search['time']['end'])]);
- }
- }
- /**
- * @param static $query
- * @param array $search
- */
- public function scopeSearchMember($query, $search)
- {
- if ($search['member']) {
- $query->whereHas('member', function ($query) use ($search) {
- $query->search($search);
- });
- }
- }
- public function scopeWithMember($query)
- {
- return $query->with(['member' => function ($query) {
- return $query->select('uid', 'nickname', 'realname', 'mobile', 'avatar');
- }]);
- }
- /**
- * 字段规则
- *
- * @return array
- */
- public function rules()
- {
- return [
- 'uniacid' => "required",
- 'member_id' => "required",
- 'money' => 'numeric|regex:/^[\-\+]?\d+(?:\.\d{1,2})?$/|max:9999999999',
- 'type' => 'required',
- 'order_sn' => 'required',
- 'status' => 'required',
- 'remark' => 'max:50'
- ];
- }
- }
|