dlh_test_server/app/common/model/goods/GoodsSubsidy.php
2024-12-10 16:29:34 +08:00

43 lines
1.3 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, store_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']);
$v['store_subsidy'] = self::formatStr($v['store_subsidy']);
}
return ['count' => $lists->total(), 'lists' => $lists->getCollection()];
}
public function getSubsidyById($id)
{
$result = $this->where(['id' => $id, 'is_delete' => 0])->field('id, profit, subsidy, store_subsidy')->find();
$result['profit'] = self::formatStr($result['profit']);
$result['subsidy'] = self::formatStr($result['subsidy']);
$result['store_subsidy'] = self::formatStr($result['store_subsidy']);
return $result;
}
public static function formatStr($str)
{
$s = explode('.', strval($str));
if (count($s) > 1 && $s[1] > 0) {
return $str . '%';
}
return intval($s[0]) . '%';
}
}