分销功能提交
This commit is contained in:
@@ -69,6 +69,10 @@ class PostCreateAddFriendPlanV1Controller extends BaseController
|
||||
return ResponseHelper::error('请选择设备', 400);
|
||||
}
|
||||
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
|
||||
// 处理分销配置
|
||||
$distributionConfig = $this->processDistributionConfig($params, $companyId);
|
||||
|
||||
// 归类参数
|
||||
$msgConf = isset($params['messagePlans']) ? $params['messagePlans'] : [];
|
||||
@@ -106,9 +110,16 @@ class PostCreateAddFriendPlanV1Controller extends BaseController
|
||||
$sceneConf['addFriendInterval'],
|
||||
$sceneConf['startTime'],
|
||||
$sceneConf['orderTableFile'],
|
||||
$sceneConf['endTime']
|
||||
$sceneConf['endTime'],
|
||||
$sceneConf['distributionEnabled'],
|
||||
$sceneConf['distributionChannels'],
|
||||
$sceneConf['customerRewardAmount'],
|
||||
$sceneConf['addFriendRewardAmount']
|
||||
);
|
||||
|
||||
// 将分销配置添加到sceneConf中
|
||||
$sceneConf['distribution'] = $distributionConfig;
|
||||
|
||||
// 构建数据
|
||||
$data = [
|
||||
'name' => $params['name'],
|
||||
@@ -327,4 +338,75 @@ class PostCreateAddFriendPlanV1Controller extends BaseController
|
||||
json_decode($string);
|
||||
return (json_last_error() == JSON_ERROR_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理分销配置
|
||||
*
|
||||
* @param array $params 请求参数
|
||||
* @param int $companyId 公司ID
|
||||
* @return array 分销配置
|
||||
*/
|
||||
private function processDistributionConfig($params, $companyId)
|
||||
{
|
||||
$distributionEnabled = !empty($params['distributionEnabled']) ? true : false;
|
||||
|
||||
$config = [
|
||||
'enabled' => $distributionEnabled,
|
||||
'channels' => [],
|
||||
'customerRewardAmount' => 0, // 获客奖励金额(分)
|
||||
'addFriendRewardAmount' => 0, // 添加奖励金额(分)
|
||||
];
|
||||
|
||||
// 如果未开启分销,直接返回默认配置
|
||||
if (!$distributionEnabled) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
// 验证渠道ID
|
||||
$channelIds = $params['distributionChannels'] ?? [];
|
||||
if (empty($channelIds) || !is_array($channelIds)) {
|
||||
throw new \Exception('请选择至少一个分销渠道');
|
||||
}
|
||||
|
||||
// 查询有效的渠道(只保留存在且已启用的渠道)
|
||||
$channels = Db::name('distribution_channel')
|
||||
->where([
|
||||
['id', 'in', $channelIds],
|
||||
['companyId', '=', $companyId],
|
||||
['status', '=', 'enabled'],
|
||||
['deleteTime', '=', 0]
|
||||
])
|
||||
->field('id,code,name')
|
||||
->select();
|
||||
|
||||
// 如果没有有效渠道,才报错
|
||||
if (empty($channels)) {
|
||||
throw new \Exception('所选的分销渠道均不存在或已被禁用,请重新选择');
|
||||
}
|
||||
|
||||
// 只保留有效的渠道ID
|
||||
$config['channels'] = array_column($channels, 'id');
|
||||
|
||||
// 验证获客奖励金额(元转分)
|
||||
$customerRewardAmount = isset($params['customerRewardAmount']) ? floatval($params['customerRewardAmount']) : 0;
|
||||
if ($customerRewardAmount < 0) {
|
||||
throw new \Exception('获客奖励金额不能为负数');
|
||||
}
|
||||
if ($customerRewardAmount > 0 && !preg_match('/^\d+(\.\d{1,2})?$/', (string)$customerRewardAmount)) {
|
||||
throw new \Exception('获客奖励金额格式不正确,最多保留2位小数');
|
||||
}
|
||||
$config['customerRewardAmount'] = intval(round($customerRewardAmount * 100)); // 元转分
|
||||
|
||||
// 验证添加奖励金额(元转分)
|
||||
$addFriendRewardAmount = isset($params['addFriendRewardAmount']) ? floatval($params['addFriendRewardAmount']) : 0;
|
||||
if ($addFriendRewardAmount < 0) {
|
||||
throw new \Exception('添加奖励金额不能为负数');
|
||||
}
|
||||
if ($addFriendRewardAmount > 0 && !preg_match('/^\d+(\.\d{1,2})?$/', (string)$addFriendRewardAmount)) {
|
||||
throw new \Exception('添加奖励金额格式不正确,最多保留2位小数');
|
||||
}
|
||||
$config['addFriendRewardAmount'] = intval(round($addFriendRewardAmount * 100)); // 元转分
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user