<?php
namespace app\common\model\user;
use think\Hook;
use app\common\model\BaseModel;
class Grade extends BaseModel
{
protected $name = 'user_grade';
public static function init()
{
parent::init();
$static = new static;
Hook::listen('user_grade', $static);
}
public function getUpgradeAttr($json)
{
return json_decode($json, true);
}
public function getEquityAttr($json)
{
return json_decode($json, true);
}
public function setUpgradeAttr($data)
{
return json_encode($data);
}
public function setEquityAttr($data)
{
return json_encode($data);
}
public static function detail($grade_id, $with = [])
{
return static::get($grade_id, $with);
}
public static function getUsableList($wxappId = null, $order = ['weight' => 'asc'])
{
$model = new static;
$wxappId = $wxappId ? $wxappId : $model::$wxapp_id;
return $model->where('status', '=', '1')
->where('is_delete', '=', '0')
->where('wxapp_id', '=', $wxappId)
->order($order)
->select();
}
public static function checkExistByWeight($weight, $gradeId = 0)
{
$model = new static;
$gradeId > 0 && $model->where('grade_id', '<>', (int)$gradeId);
return $model->where('weight', '=', (int)$weight)
->value('grade_id');
}
}