124 lines
4.9 KiB
PHP
Executable File
124 lines
4.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\logic\goods;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\goods\GoodsBrand;
|
|
use app\common\model\goods\GoodsSubsidy;
|
|
use app\common\server\ConfigServer;
|
|
use think\Exception;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 商品品牌
|
|
* Class GoodsBrandLogic
|
|
* @package app\admin\logic
|
|
*/
|
|
class SubsidyLogic extends Logic
|
|
{
|
|
// 添加返补比例设置
|
|
public static function add($post)
|
|
{
|
|
try {
|
|
Db::startTrans();
|
|
GoodsSubsidy::create([
|
|
'profit' => str_replace('%', '', $post['profit']),
|
|
// 'discount' => str_replace('%', '', $post['discount']),
|
|
'subsidy' => str_replace('%', '', $post['subsidy']),
|
|
]);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Notes: 编辑
|
|
* @param $post
|
|
* @return bool
|
|
*@author 段誉(2021/4/15 10:54)
|
|
*/
|
|
public static function edit($post)
|
|
{
|
|
try {
|
|
Db::startTrans();
|
|
GoodsSubsidy::update([
|
|
'profit' => str_replace('%', '', $post['profit']),
|
|
// 'discount' => str_replace('%', '', $post['discount']),
|
|
'subsidy' => str_replace('%', '', $post['subsidy']),
|
|
], ['id' => $post['id']]);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// 删除
|
|
public static function del($id)
|
|
{
|
|
return GoodsSubsidy::update(['is_delete' => 1, 'delete_time' => time()], ['id' => $id]);
|
|
}
|
|
|
|
// 获取全局返补比例
|
|
public static function getSubsidyConfig()
|
|
{
|
|
return [
|
|
'promote_user' => ConfigServer::get('subsidy', 'promote_user'),
|
|
'promote_store' => ConfigServer::get('subsidy', 'promote_store'),
|
|
'platform_services' => ConfigServer::get('subsidy', 'platform_services'),
|
|
'no_level' => ConfigServer::get('subsidy', 'no_level'),
|
|
'distribution_promote_store' => ConfigServer::get('subsidy', 'distribution_promote_store'),
|
|
'distribution_user' => ConfigServer::get('subsidy', 'distribution_user'),
|
|
'distribution_electrodeless' => ConfigServer::get('subsidy', 'distribution_electrodeless'),
|
|
'up_front' => ConfigServer::get('subsidy', 'up_front'),
|
|
'up_front_proportion' => ConfigServer::get('subsidy', 'up_front_proportion'),
|
|
'promoter_queue_ratio' => ConfigServer::get('subsidy', 'promoter_queue_ratio'),
|
|
'self_queue_ratio' => ConfigServer::get('subsidy', 'self_queue_ratio'),
|
|
'all_queue_ratio' => ConfigServer::get('subsidy', 'all_queue_ratio'),
|
|
];
|
|
}
|
|
|
|
// 设置全局返补比例
|
|
public static function setSubsidyConfig($post)
|
|
{
|
|
try {
|
|
if (empty($post['promote_user']) && empty($post['promote_store']) && empty($post['platform_services']) && empty($post['no_level'])) {
|
|
self::$error = '所提交的字段内容不能为空';
|
|
return false;
|
|
}
|
|
|
|
Db::startTrans();
|
|
ConfigServer::set('subsidy', 'promote_user', str_replace('%', '', $post['promote_user']));
|
|
ConfigServer::set('subsidy', 'promote_store', str_replace('%', '', $post['promote_store']));
|
|
ConfigServer::set('subsidy', 'platform_services', str_replace('%', '', $post['platform_services']));
|
|
ConfigServer::set('subsidy', 'no_level', str_replace('%', '', $post['no_level']));
|
|
ConfigServer::set('subsidy', 'distribution_promote_store', str_replace('%', '', $post['distribution_promote_store']));
|
|
ConfigServer::set('subsidy', 'distribution_user', str_replace('%', '', $post['distribution_user']));
|
|
ConfigServer::set('subsidy', 'distribution_electrodeless', str_replace('%', '', $post['distribution_electrodeless']));
|
|
ConfigServer::set('subsidy', 'up_front', str_replace('%', '', $post['up_front']));
|
|
ConfigServer::set('subsidy', 'up_front_proportion', str_replace('%', '', $post['up_front_proportion']));
|
|
ConfigServer::set('subsidy', 'promoter_queue_ratio', str_replace('%', '', $post['promoter_queue_ratio']));
|
|
ConfigServer::set('subsidy', 'self_queue_ratio', str_replace('%', '', $post['self_queue_ratio']));
|
|
ConfigServer::set('subsidy', 'all_queue_ratio', str_replace('%', '', $post['all_queue_ratio']));
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static function formatStr($str)
|
|
{
|
|
$s = explode('.', $str);
|
|
return $s[1] > 0 ? $s . '%' : intval($str) . '%';
|
|
}
|
|
} |