dlh_test_server/app/admin/logic/goods/SubsidyLogic.php
2024-11-16 10:10:03 +08:00

134 lines
4.5 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 lists($get)
{
$lists = GoodsSubsidy::where('is_delete', 0)
->order('id desc')
->paginate([
'list_rows'=> $get['limit'],
'page'=> $get['page'],
]);
foreach ($lists as &$v) {
$v['profit'] = self::formatStr($v['profit']);
$v['discount'] = self::formatStr($v['discount']);
$v['subsidy'] = self::formatStr($v['subsidy']);
}
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
}
// 添加返补比例设置
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'),
];
}
// 设置全局返补比例
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']));
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) . '%';
}
}