dlh_test_server/app/common/model/goods/GoodsSubsidy.php

41 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace app\common\model\goods;
use app\common\basics\Models;
class GoodsSubsidy extends Models
{
2024-11-16 15:05:43 +08:00
public function getSubsidy($get)
{
$lists = $this->where('is_delete', 0)
->order('id desc')
2024-11-18 10:17:40 +08:00
->field('id, profit, subsidy')
2024-11-16 15:05:43 +08:00
->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)
{
2024-11-18 10:17:40 +08:00
$result = $this->where(['id' => $id, 'is_delete' => 0])->field('id, profit, subsidy')->find();
2024-11-16 15:05:43 +08:00
$result['profit'] = self::formatStr($result['profit']);
$result['subsidy'] = self::formatStr($result['subsidy']);
return $result;
}
2024-11-17 14:08:29 +08:00
public static function formatStr($str)
2024-11-16 15:05:43 +08:00
{
2024-11-18 14:46:55 +08:00
$s = explode('.', strval($str));
if (count($s) > 1 && $s[1] > 0) {
return $str . '%';
}
return intval($s[0]) . '%';
2024-11-16 15:05:43 +08:00
}
}