| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\common\repositories\user;
- use app\common\dao\user\AwardIntegralPriceDao;
- use app\common\model\user\AwardIntegralPrice;
- use app\common\repositories\BaseRepository;
- class AwardIntegralPriceRepository extends BaseRepository
- {
- /**
- * @var AwardIntegralPriceDao
- */
- protected $dao;
- /**
- * UserSignRepository constructor.
- * @param AwardIntegralPriceDao $dao
- */
- public function __construct(AwardIntegralPriceDao $dao)
- {
- $this->dao = $dao;
- }
- public function awardIntegralPrice($day = '')
- {
- if (!$day) {
- $day = date('Y-m-d');
- }
- if ($info = $this->dao->search(['day' => $day])->find()) {
- return $info->toArray();
- }
- @file_put_contents('yesterday.txt', AwardIntegralPrice::getLastSql() . PHP_EOL, FILE_APPEND);
- $yesterday_price = $this->dao->search(['day' => date('Y-m-d', strtotime('-1 day', strtotime($day)))])->find();
- if ($yesterday_price) {
- $basePrice = $yesterday_price->price;
- } else {
- $basePrice = systemConfig('award_integral_price', 0.1);
- }
- //todo 业绩
- $achievement = 0;
- /** @var UserExtractRepository $extractRepositories */
- $extractRepositories = app()->make(UserExtractRepository::class);
- $commission = $extractRepositories->search(['status' => 1])->whereTime('check_time', $day)->sum('commission');
- $userService = app()->make(UserRepository::class);
- $num = $userService->search(['status' => 1])->sum('award_integral');
- $sum_achievement = $commission + $achievement;
- $rise = $num > 0 ? bcdiv($sum_achievement, $num, 3) : 0;
- $price = bcadd($rise, $basePrice, 3);
- return compact('basePrice', 'price', 'rise', 'achievement', 'commission', 'num');
- }
- public function setPrice($day, $price, $commission, $achievement, $num)
- {
- $add_time = time();
- return $this->dao->create(compact('day', 'price', 'commission', 'achievement', 'num', 'add_time'));
- }
- }
|