Files
huangjingfen/pro_v3.5.1/app/services/order/StoreOrderEconomizeServices.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

77 lines
2.1 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\services\order;
use app\dao\order\StoreOrderEconomizeDao;
use app\services\BaseServices;
use think\annotation\Inject;
use think\exception\ValidateException;
/**
* 计算节省金额
* Class StoreOrderEconomizeServices
* @package app\services\order
* @mixin StoreOrderEconomizeDao
*/
class StoreOrderEconomizeServices extends BaseServices
{
/**
* @var StoreOrderEconomizeDao
*/
#[Inject]
protected StoreOrderEconomizeDao $dao;
/**
* 添加节省金额数据
* @param array $add
* @return \crmeb\basic\BaseModel|\think\Model
*/
public function addEconomize(array $add)
{
if (!$add) throw new ValidateException('数据不存在');
return $this->dao->save($add);
}
/**
* @param array $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOne(array $where)
{
if (!$where) throw new ValidateException('条件缺失');
return $this->dao->getOne($where);
}
/**
* 汇总付费会员节省金额
* @param $uid
* @return float
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function sumEconomizeMoney($uid)
{
$economizeMoney = 0.00;
if (!$uid) return $economizeMoney;
$list = $this->dao->getList(['uid' => $uid]);
if ($list) {
foreach ($list as $k => $v) {
$economizeMoney += $v['postage_price'];
$economizeMoney += $v['member_price'];
$economizeMoney += $v['offline_price'];
$economizeMoney += $v['coupon_price'];
}
}
return (float)sprintf("%.2f", $economizeMoney);
}
}