<?php
|
|
namespace app\operations\model\plus\team;
|
|
use app\common\model\plus\team\Grade as GradeModel;
|
use app\operations\model\plus\team\User as UserModel;
|
|
/**
|
* 用户会员等级模型
|
*/
|
class Grade extends GradeModel
|
{
|
/**
|
* 获取列表记录
|
*/
|
public function getList($data)
|
{
|
$list = $this->selectList();
|
// 如果为空,则插入默认等级
|
if(count($list) == 0){
|
$this->save([
|
'name' => '默认等级',
|
'is_default' => 1,
|
'weight' => 1,
|
'grade_id' => Grade::getDefaultGradeId(),
|
'app_id' => self::$app_id
|
]);
|
// 更新之前的默认为0的id为此等级id
|
(new UserModel())->where('grade_id', '=', 0)->update([
|
'grade_id' => $this['grade_id']
|
]);
|
$list = $this->selectList();
|
}
|
return $list;
|
}
|
|
private function selectList(){
|
return $this->where('is_delete', '=', 0)
|
->order(['weight' => 'asc', 'create_time' => 'asc'])
|
->select();
|
}
|
|
/**
|
* 获取可用的分红等级列表
|
*/
|
public static function getUsableList($appId = null)
|
{
|
$model = new static;
|
$appId = $appId ? $appId : $model::$app_id;
|
return $model->where('is_delete', '=', '0')
|
->where('app_id', '=', $appId)
|
->order(['weight' => 'asc', 'create_time' => 'asc'])
|
->select();
|
}
|
|
/**
|
* 新增记录
|
*/
|
public function add($data)
|
{
|
$data['app_id'] = self::$app_id;
|
$data['is_default'] = 0;
|
$data['remark'] = $this->setRemark($data);
|
return $this->save($data);
|
}
|
|
/**
|
* 编辑记录
|
*/
|
public function edit($data)
|
{
|
if($this['is_default'] == 0){
|
|
$data['remark'] = $this->setRemark($data);
|
}
|
return $this->save($data);
|
}
|
|
private function setRemark($data){
|
$remark = '';
|
$condition_type_str = $data['condition_type'] == 'and' ? '并且' : '或者';
|
if($data['open_agent_money'] == 1){
|
$money = sprintf('%.2f',$data['agent_money']);
|
$remark .= "累计推广佣金满{$money}元";
|
}
|
if($data['open_agent_user'] == 1){
|
if(!empty($remark)){
|
$remark .= '\r\n' . $condition_type_str;
|
}
|
$remark .= "直推分销商满{$data['agent_user']}人";
|
}
|
if($data['open_team_user'] == 1){
|
if(!empty($remark)){
|
$remark .= '\r\n' . $condition_type_str;
|
}
|
$remark .= "团队人数满{$data['team_user']}人";
|
}
|
if($data['open_team_money'] == 1){
|
if(!empty($remark)){
|
$remark .= '\r\n' . $condition_type_str;
|
}
|
$money = sprintf('%.2f',$data['team_money']);
|
$remark .= "团队业绩满{$money}元";
|
}
|
return $remark;
|
}
|
|
/**
|
* 软删除
|
*/
|
public function setDelete()
|
{
|
// 判断该等级下是否存在会员
|
if (UserModel::checkExistByGradeId($this['grade_id'])) {
|
return false;
|
}
|
return $this->save(['is_delete' => 1]);
|
}
|
|
}
|