杨总惠通宝
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
htb_backend/app/common/repositories/system/HuitongRepository.php

99 lines
2.8 KiB

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system;
use app\common\dao\store\order\StoreOrderDao;
use app\common\dao\system\HuitongDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderBaseRepository;
use app\common\repositories\user\UserAssetsRepository;
9 months ago
use think\facade\Log;
/**
* Class StoreOrderRepository
* @package app\common\repositories\store\order
* @author xaboy
* @day 2020/6/9
* @mixin StoreOrderDao
*/
class HuitongRepository extends BaseRepository
{
/**
* StoreOrderRepository constructor.
* @param HuitongDao $dao
*/
public function __construct(HuitongDao $dao)
{
$this->dao = $dao;
}
public function dayStatistics()
{
/**
* @var UserAssetsRepository $userAssets
*/
$userAssets = app()->make(UserAssetsRepository::class);
$config = $userAssets->getConfig();
/**
* @var StoreOrderBaseRepository $orderBase
*/
$orderBase = app()->make(StoreOrderBaseRepository::class);
9 months ago
$count = $orderBase->getTotalBase(date('Y-m-d', strtotime('-1day')));
if (empty($count)) {
return;
}
9 months ago
Log::info("+++++++");
$base = round($config['huitong_add'] * $count / 100, 2);
if ($base < 0.01) {
$base = 0.01;
}
$last = $this->dao->getLastHuitong();
if (empty($last)) {
$huitong = 1;
} else {
$huitong = $last['current'];
}
$totalHuitong = $userAssets->getTotalHuitong();
$add = round($base / $totalHuitong, 2);
if ($add < 0.01) {
$add = 0.01;
}
$this->dao->create([
'date' => date('Y-m-d'),
'current' => $huitong + $add,
'ext' => json_encode(array(
'base' => $base,
'huitong' => $huitong,
'total' => $totalHuitong,
)),
]);
}
public function getCurrent(){
$last = $this->dao->getLastHuitong();
if (empty($last)) {
$huitong = 1;
} else {
$huitong = $last['current'];
}
return $huitong;
}
}