sifangpay/app/Models/Merchant.php

121 lines
3.0 KiB
PHP

<?php
namespace App\Models;
use App\Classc\SearchScopeTrait;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Merchant extends Authenticatable
{
//
use SearchScopeTrait, Notifiable, SoftDeletes;
//主动显示属性
protected $appends = ['check_status_name'];
protected $hidden = ['password'];
protected $guarded = [];
protected $casts = [
'created_at' => 'date:Y-m-d',
'joined_at' => 'datetime:Y-m-d H:00',
];
public function banks()
{
return $this->morphMany('App\Models\BankRel', 'model');
}
public function getDefaultBank()
{
return $this->hasOne('App\Models\BankRel', 'model_id', 'id')->where('model_type', 'merchant');
}
//钱包信息
public function wallets()
{
return $this->hasOne('App\Models\MerchantWallet', 'merchant_id', 'id')->withDefault([
'money' => '0',
'total_money' => 0,
'draw_money' => 0,
'other_money' => 0,
'trans_money' => 0
]);
}
//提款类型
public function getDrawTypeNameAttribute()
{
$draw_type = config('adconfig.draw_type');
return $draw_type[$this->draw_type];
}
public function mySubMerchant()
{
return $this->hasMany('App\Models\Merchant', 'from_id', 'id')->pluck('id')->toArray();
}
//上级。旧的字段,保留
public function froms()
{
return $this->hasOne('App\Models\Merchant', 'id', 'from_id')->withDefault([
'name' => '',
]);
}
public function setPasswordAttribute($password)
{
if ($password) {
$this->attributes['password'] = bcrypt($password);
}
}
//支付状态
public function getCheckStatusNameAttribute()
{
$staus = [
1 => '审核通过',
0 => '审核失败',
2 => '等待审核'
];
return isset($staus[$this->check_status]) ? $staus[$this->check_status] : '';
}
//身份
public function getLevelNameAttribute()
{
$arr = config('adconfig.merchant_level');
return array_key_exists($this->level, $arr) ? $arr[$this->level] : '';
}
//取得当前身份的下级
public static function subAllMerchant($id)
{
$id_arr = MerchantRatio::where('parent_id', $id)->pluck('merchant_id')->toArray();
return $id_arr;
}
//每天押款比例
public static function getDayDrawRatio($id)
{
$obj = self::find($id);
$draw_day_money_ratio = $obj->draw_day_money_ratio;
if ($draw_day_money_ratio == -1) {
$draw_day_money_ratio = config_cache('draw_config.draw_day_money_ratio');
} else {
if ($draw_day_money_ratio <= 0) {
$draw_day_money_ratio = 0;
}
}
return $draw_day_money_ratio;
}
}