122 lines
4.9 KiB
PHP
122 lines
4.9 KiB
PHP
<?php
|
||
/**
|
||
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
||
* =========================================================
|
||
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
||
* ----------------------------------------------
|
||
* 官方网址: https://www.gobuysaas.com
|
||
* =========================================================
|
||
*/
|
||
|
||
namespace addon\team\model;
|
||
|
||
use app\model\BaseModel;
|
||
class Level extends BaseModel{
|
||
/**
|
||
* Common: 获取等级列表
|
||
* Author: wu-hui
|
||
* Time: 2024/08/07 11:43
|
||
* @param $params
|
||
* @param $siteId
|
||
* @return array
|
||
*/
|
||
public function getPageList($params, $siteId){
|
||
$page = $params['page'] ?? 1;
|
||
$pageLimit = $params['limit'] ?? PAGE_LIST_ROWS;
|
||
// 生成查询条件
|
||
$where = [
|
||
'site_id' => $siteId
|
||
];
|
||
if(isset($params['title']) && $params['title'] !== '') $where[] = ['title','like',"%{$params['title']}%"];
|
||
if(isset($params['weight']) && $params['weight'] !== '') $where[] = ['weight','=',$params['weight']];
|
||
|
||
$result = model('team_level')->pageList($where,'*','weight DESC,id DESC',$page,$pageLimit);
|
||
foreach($result['list'] as &$levelInfo){
|
||
$levelInfo['upgrade_conditions'] = unserialize($levelInfo['upgrade_conditions']);
|
||
}
|
||
|
||
return $this->success($result);
|
||
}
|
||
/**
|
||
* Common: 编辑信息
|
||
* Author: wu-hui
|
||
* Time: 2024/08/07 16:58
|
||
* @param $info
|
||
* @return array
|
||
*/
|
||
public function editInfo($info){
|
||
$id = $info['id'] ?? 0;
|
||
$upgradeConditions = $info['upgrade_conditions'] ?? [];
|
||
$data = [
|
||
'title' => $info['title'] ?? '',
|
||
'weight' => $info['weight'] ?? 0,
|
||
'commission_rate' => $info['commission_rate'] ?? 0,
|
||
'commission_tier' => $info['commission_tier'] ?? 0,
|
||
'same_level_rate' => $info['same_level_rate'] ?? 0,
|
||
'same_level_tier' => $info['same_level_tier'] ?? 0,
|
||
'upgrade_type' => $info['upgrade_type'] ?? 1,
|
||
'upgrade_conditions' => serialize($upgradeConditions)
|
||
];
|
||
// 判断参数是否有效
|
||
if(empty($data['title'])) return $this->error('','请输入等级名称!');
|
||
if((int)$data['weight'] <= 0 || (int)$data['weight'] > 100) return $this->error('','权重值只能在1~100');
|
||
if($data['upgrade_type'] != 0){
|
||
if(count($upgradeConditions['where'] ?? []) <= 0) return $this->error('','请选择升级条件!');
|
||
if(in_array('one_people',$upgradeConditions['where']) && (int)$upgradeConditions['one_people'] <= 0) return $this->error('','请输入直推人数要求!');
|
||
if(in_array('team_people',$upgradeConditions['where']) && (int)$upgradeConditions['team_people'] <= 0) return $this->error('','请输入团队人数要求!');
|
||
if(in_array('one_money',$upgradeConditions['where']) && (float)$upgradeConditions['one_money'] <= 0) return $this->error('','请输入直推业绩金额要求!');
|
||
if(in_array('team_money',$upgradeConditions['where']) && (float)$upgradeConditions['team_money'] <= 0) return $this->error('','请输入团队业绩金额要求!');
|
||
if(in_array('buy_goods',$upgradeConditions['where']) && count($upgradeConditions['buy_goods']) <= 0) return $this->error('','请至少选择一个商品!');
|
||
}
|
||
// 判断:等级名称是否已经存在
|
||
$titleIsHasWhere = [
|
||
['site_id', '=', $info['site_id']],
|
||
['title', '=', $info['title']],
|
||
];
|
||
if($id > 0) $titleIsHasWhere[] = ['id', '<>', $id];
|
||
$titleIsHas = (int)model('team_level')->getValue($titleIsHasWhere, 'id');
|
||
if($titleIsHas > 0) return $this->error('','等级名称已存在!');
|
||
// 判断:等级权重是否已经存在
|
||
$weightIsHasWhere = [
|
||
['site_id', '=', $info['site_id']],
|
||
['weight', '=', $info['weight']],
|
||
];
|
||
if($id > 0) $weightIsHasWhere[] = ['id', '<>', $id];
|
||
$weightIsHas = (int)model('team_level')->getValue($weightIsHasWhere, 'id');
|
||
if($weightIsHas > 0) return $this->error('','等级权重不能重复!');
|
||
// 判断:根据是否存在id 进行对应的操作
|
||
if($id > 0){
|
||
// 编辑
|
||
model('team_level')->update($data, [
|
||
['id', '=', $id]
|
||
]);
|
||
}else{
|
||
// 添加
|
||
$data['site_id'] = $info['site_id'];
|
||
|
||
model('team_level')->add($data);
|
||
}
|
||
|
||
return $this->success('操作成功');
|
||
}
|
||
/**
|
||
* Common: 删除等级信息
|
||
* Author: wu-hui
|
||
* Time: 2024/08/08 9:07
|
||
* @param $id
|
||
* @return array
|
||
*/
|
||
public function deleteInfo($id){
|
||
model('team_level')->delete([
|
||
['id', '=', $id]
|
||
]);
|
||
|
||
return $this->success('删除成功');
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|