123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\services\user;
- use app\dao\system\AwardLakeDao;
- use app\dao\user\UserIntegralDao;
- use app\services\BaseServices;
- use crmeb\traits\ServicesTrait;
- use app\webscoket\SocketPush;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- /**
- *
- * Class UserRechargeServices
- * @package app\services\user
- * @mixin UserIntegralDao
- */
- class UserAwardIntegralServices extends BaseServices
- {
- use ServicesTrait;
- private $lake_dao;
- /**
- * UserRechargeServices constructor.
- * @param UserIntegralDao $dao
- */
- public function __construct(UserIntegralDao $dao, AwardLakeDao $awardLakeDao)
- {
- $this->dao = $dao;
- $this->lake_dao = $awardLakeDao;
- }
- /**
- * 获取单条数据
- * @param int $id
- * @param array $field
- */
- public function getIntegral(int $id, array $field = [])
- {
- return $this->dao->get($id, $field);
- }
- /**
- * 获取单条数据
- * @return float
- */
- public function getIntegralSum($where)
- {
- return $this->dao->sum($where, 'num', true);
- }
- /**
- * 获取单条数据
- * @return float
- */
- public function getLake()
- {
- return $this->lake_dao->sum([], 'num');
- }
- /**
- * 获取单条数据
- * @param int $link_id
- * @return string|null
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getPrice(int $link_id = 0)
- {
- if ($link_id > 0) {
- $info = $this->dao->getOne(['link_id' => $link_id]);
- if ($info) return (string)($info['price'] ?: 0);
- }
- $lake_sum = $this->getLake();
- $sum_integral = $this->getIntegralSum(['status' => 0]);
- return (string)($sum_integral > 0 ? bcdiv((string)$lake_sum, (string)$sum_integral, 8) : 1);
- }
- }
|