dlh_test_server/app/common/model/goods/GoodsSubsidy.php
2024-11-18 10:17:40 +08:00

40 lines
1.1 KiB
PHP

<?php
namespace app\common\model\goods;
use app\common\basics\Models;
class GoodsSubsidy extends Models
{
public function getSubsidy($get)
{
$lists = $this->where('is_delete', 0)
->order('id desc')
->field('id, profit, subsidy')
->paginate([
'list_rows'=> $get['limit'],
'page'=> $get['page'],
]);
foreach ($lists as &$v) {
$v['profit'] = self::formatStr($v['profit']);
$v['subsidy'] = self::formatStr($v['subsidy']);
}
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
}
public function getSubsidyById($id)
{
$result = $this->where(['id' => $id, 'is_delete' => 0])->field('id, profit, subsidy')->find();
$result['profit'] = self::formatStr($result['profit']);
$result['subsidy'] = self::formatStr($result['subsidy']);
return $result;
}
public static function formatStr($str)
{
$s = explode('.', $str);
return $s[1] > 0 ? $s . '%' : intval($str) . '%';
}
}