197 lines
7.2 KiB
PHP
197 lines
7.2 KiB
PHP
<?php
|
||
/**
|
||
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
||
* =========================================================
|
||
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
||
* ----------------------------------------------
|
||
* 官方网址: https://www.gobuysaas.com
|
||
* =========================================================
|
||
*/
|
||
|
||
namespace addon\commission\model;
|
||
|
||
use app\model\system\Config;
|
||
use app\model\BaseModel;
|
||
|
||
|
||
class Setting extends BaseModel{
|
||
|
||
public array $defaultConfig = [
|
||
'switch' => '0',// 是否开启平台抽成
|
||
'is_alone' => '0',// 是否独立设置 总平台无该设置项
|
||
'integral_rate' => '0',// 积分抽成比例
|
||
'operations_rate' => '0',// 运营抽成比例
|
||
'partner_rate' => '0',// 合伙人分佣比例
|
||
'partner_cycle' => '0',// 合伙人分佣周期 0=每天,1=每周,2=每月
|
||
'merchants_rate' => '0',// 招商员分佣比例
|
||
'promoter_rate' => '0',// 推广员分佣比例
|
||
];
|
||
|
||
|
||
/**
|
||
* Common: 编辑配置 - 总平台、店铺
|
||
* Author: wu-hui
|
||
* Time: 2024/04/29 14:51
|
||
* @param int $siteId
|
||
* @param array $data
|
||
* @param int $is_use
|
||
* @return array
|
||
*/
|
||
public function setConfig(int $siteId = 0,array $data = [],int $is_use = 1){
|
||
$setWhere = [
|
||
['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','commission_setting']
|
||
];
|
||
|
||
return (new Config())->setConfig($data, '平台抽成设置', $is_use, $setWhere);
|
||
}
|
||
/**
|
||
* Common: 获取配置 - 总平台、店铺
|
||
* Author: wu-hui
|
||
* Time: 2024/04/29 14:51
|
||
* @param int $siteId
|
||
* @return array|string[]
|
||
*/
|
||
public function getConfig(int $siteId = 0){
|
||
$setWhere = [
|
||
['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','commission_setting']
|
||
];
|
||
$res = (new Config())->getConfig($setWhere);
|
||
$value = $res['data'] ? $res['data']['value'] : [];
|
||
$config = array_merge($this->defaultConfig, $value);
|
||
// 判断:当前获取设置 是否为总平台设置
|
||
$config['is_admin'] = $siteId == $this->adminSiteId;
|
||
|
||
return $config;
|
||
}
|
||
|
||
|
||
/**
|
||
* Common: 编辑配置 - 商品
|
||
* Author: wu-hui
|
||
* Time: 2024/05/02 10:15
|
||
* @param int $goodsId
|
||
* @param array $data
|
||
*/
|
||
public function setGoodConfig(int $goodsId,array $data){
|
||
// 判断:当前商品是否已经存在设置
|
||
$set = model('goods_commission')->getInfo(['goods_id'=>$goodsId]);
|
||
$set = $set ?? [];
|
||
$updateData = [
|
||
'switch' => $data['switch'] ?? 0,
|
||
'is_alone' => $data['is_alone'] ?? 0,
|
||
'commission_type' => $data['commission_type'] ?? 0,
|
||
'integral_rate' => $data['integral_rate'] ?? 0,
|
||
'operations_rate' => $data['operations_rate'] ?? 0,
|
||
'partner_rate' => $data['partner_rate'] ?? 0,
|
||
'merchants_rate' => $data['merchants_rate'] ?? 0,
|
||
'promoter_rate' => $data['promoter_rate'] ?? 0,
|
||
];
|
||
if($set){
|
||
model('goods_commission')->update($updateData,['goods_id'=>$goodsId]);
|
||
}else{
|
||
$updateData['goods_id'] = $goodsId;
|
||
$updateData['site_id'] = $data['site_id'];
|
||
model('goods_commission')->add($updateData);
|
||
}
|
||
}
|
||
/**
|
||
* Common: 获取配置 - 商品
|
||
* Author: wu-hui
|
||
* Time: 2024/04/30 17:49
|
||
* @param int $goodsId
|
||
* @return array|string[]
|
||
*/
|
||
public function getGoodConfig(int $goodsId){
|
||
$set = model('goods_commission')->getInfo(['goods_id'=>$goodsId]);
|
||
$set = $set ?? [];
|
||
$defaultConfig = $this->defaultConfig;
|
||
$defaultConfig['switch'] = $set['switch'] ?? 1;//商品默认开启
|
||
$defaultConfig['commission_type'] = $set['commission_type'] ?? 0;//抽成类型:0=比例,1=固定金额
|
||
|
||
return array_merge($defaultConfig, $set);
|
||
}
|
||
/**
|
||
* Common: 获取最终设置
|
||
* Author: wu-hui
|
||
* Time: 2024/05/03 11:49
|
||
* @param int $siteId
|
||
* @param int $goodsId
|
||
* @return array|string[]
|
||
*/
|
||
public function getFinalSet(int $siteId,int $goodsId = 0){
|
||
// ---获取总平台设置
|
||
$adminSet = $this->getConfig();
|
||
if($siteId == $this->adminSiteId) return $adminSet;
|
||
// ---获取子平台(店铺)设置
|
||
$shopSet = $this->getConfig((int)$siteId);
|
||
// 店铺关闭抽成 || (店铺开启抽成,但是为独立设置)=使用店铺设置;店铺开启抽成 并且不为独立设置=总平台统一设置
|
||
if($shopSet['switch'] == 0 || ($shopSet['switch'] == 1 && $shopSet['is_alone'] == 1)) $shopFinal = $shopSet;
|
||
else $shopFinal = $adminSet;
|
||
// 处理店铺不可修改项
|
||
$shopFinal['partner_cycle'] = $adminSet['partner_cycle'];
|
||
$goodFinal['operations_rate'] = $adminSet['operations_rate'];
|
||
$shopFinal['is_alone'] = $shopSet['is_alone'];
|
||
// 判断:是否仅获取店铺级 最终设置;是则返回店铺级最终设置;否则继续判断商品级
|
||
if($goodsId <= 0) return $shopFinal;
|
||
// ---获取商品设置
|
||
$goodSet = (array)$this->getGoodConfig($goodsId);
|
||
if(empty($goodSet)) return $shopFinal;
|
||
// 商品关闭抽成 || (商品开启抽成,但是为独立设置)=使用商品设置;商品开启抽成 并且不为独立设置=店铺最终设置
|
||
if($goodSet['switch'] == 0 || ($goodSet['switch'] == 1 && $goodSet['is_alone'] == 1)) $goodFinal = $goodSet;
|
||
else $goodFinal = $shopFinal;
|
||
// 设置补齐
|
||
$goodFinal['partner_cycle'] = $adminSet['partner_cycle'];
|
||
$goodFinal['operations_rate'] = $shopFinal['operations_rate'];// todo 运营抽成目前商品不可独立设置
|
||
$goodFinal['is_alone'] = $goodSet['is_alone'];
|
||
|
||
return $goodFinal;
|
||
}
|
||
|
||
|
||
/**
|
||
* Common: 豆豆价格 - 设置
|
||
* Author: wu-hui
|
||
* Time: 2024/05/08 17:39
|
||
* @param int $siteId
|
||
* @param float $legumesPrice
|
||
* @return array
|
||
*/
|
||
public function setLegumesPrice(int $siteId = 0,float $legumesPrice = 0.5){
|
||
$setWhere = [
|
||
['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','legumes_price']
|
||
];
|
||
|
||
return (new Config())->setConfig(['legumes_price' => $legumesPrice], '豆豆价格', 1, $setWhere);
|
||
}
|
||
/**
|
||
* Common: 豆豆价格 - 获取
|
||
* Author: wu-hui
|
||
* Time: 2024/05/08 17:37
|
||
* @param int $siteId
|
||
* @return float|mixed
|
||
*/
|
||
public function getLegumesPrice(int $siteId = 0){
|
||
$setWhere = [
|
||
['site_id','=', $siteId > 0 ? $siteId : $this->adminSiteId],
|
||
['app_module','=','shop'],
|
||
['config_key','=','legumes_price']
|
||
];
|
||
$res = (new Config())->getConfig($setWhere);
|
||
$value = $res['data'] ? $res['data']['value'] : [];
|
||
|
||
return $value['legumes_price'] ?? 0.5;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|