dlh_test_server/app/admin/logic/goods/SubsidyLogic.php
2024-11-12 15:37:05 +08:00

91 lines
2.3 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 think\facade\Db;
/**
* 商品品牌
* Class GoodsBrandLogic
* @package app\admin\logic
*/
class SubsidyLogic extends Logic
{
// 列表
public static function lists($get)
{
$lists = GoodsSubsidy::where('is_delete', 0)
->withAttr('discount', function ($value) {
$arr = explode('.', $value);
if ($arr[1] > 0) {
return $value . '%';
}
return intval($value) . '%';
})
->withAttr('subsidy', function ($value) {
$arr = explode('.', $value);
if ($arr[1] > 0) {
return $value . '%';
}
return intval($value) . '%';
})
->paginate([
'list_rows'=> $get['limit'],
'page'=> $get['page'],
]);
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
}
// 添加返补比例设置
public static function add($post)
{
try {
Db::startTrans();
GoodsSubsidy::create([
'discount' => str_replace('%', '', $post['discount']),
'subsidy' => str_replace('%', '', $post['subsidy']),
]);
Db::commit();
return true;
} catch (\Exception $e) {
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([
'discount' => str_replace('%', '', $post['discount']),
'subsidy' => str_replace('%', '', $post['subsidy']),
], ['id' => $post['id']]);
Db::commit();
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
// 删除
public static function del($id)
{
return GoodsSubsidy::update(['is_delete' => 1, 'delete_time' => time()], ['id' => $id]);
}
}