| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?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\dao\user\AwardIntegralPriceDayDao;
- use app\common\dao\user\AwardLakeDao;
- use app\common\dao\user\AwardLakeLogDao;
- use app\common\model\store\order\StoreOrder;
- use app\common\model\user\AwardIntegralPrice;
- use app\common\model\user\AwardLakeLog;
- use app\common\model\user\UserExtract;
- 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 = '')
- {
- try {
- if (!$day) {
- $day = date('Y-m-d', strtotime('-1 day'));
- }
- 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);
- }
- $time_start = strtotime($day);
- $time_end = strtotime($day) + 86400;
- //todo 业绩
- $achievement = StoreOrder::where('paid', 1)
- ->whereBetween('create_time', [$day . ' 00:00:00', $day . ' 23:59:59'])
- ->where('is_del', 0)->where('is_system_del', 0)
- ->where('status', '>=', 0)
- ->sum('total_price');
- @file_put_contents('yesterday.txt', StoreOrder::getLastSql() . PHP_EOL, FILE_APPEND);
- $achievement = bcmul((string)$achievement, '0.1', 8); //从总业绩的5%上涨到10%
- /** @var UserExtractRepository $extractRepositories */
- $extractRepositories = app()->make(UserExtractRepository::class);
- $commission = $extractRepositories->search(['status' => 1])->whereBetween('check_time', [$time_start, $time_end])->sum('commission');
- @file_put_contents('yesterday.txt', UserExtract::getLastSql() . PHP_EOL, FILE_APPEND);
- $userService = app()->make(UserRepository::class);
- $num = $userService->search(['status' => 1])->sum('award_integral');
- $sum_achievement = bcadd((string)$commission, (string)$achievement, 8);
- $rise = $num > 0 ? bcdiv($sum_achievement, $num, 8) : 0;
- $add_price = 0;
- if ($rise > 0) {
- @file_put_contents('quanju4.txt', $rise . "-123\r\n", 8);
- // 增长值分成25份
- $day_25_rise = bcdiv($rise, 25, 8);
- @file_put_contents('quanju4.txt', $day_25_rise . "-456\r\n", 8);
- /** @var AwardIntegralPriceDayDao $AwardIntegralPriceDayDao */
- $AwardIntegralPriceDayDao = app()->make(AwardIntegralPriceDayDao::class);
- $AwardIntegralPriceDayDao->create(['day' => strtotime('-25 day'), 'all_add_price' => $rise, 'day_add_price' => $day_25_rise]); //保存今天增长的总价格和每日增长价格
- $day_25 = strtotime('-25 day');
- $add_price = $AwardIntegralPriceDayDao->search(['day' => $day_25])->sum('day_add_price');
- @file_put_contents('quanju4.txt', sprintf("%.8f", $add_price) . "-789\r\n", 8);
- }
- @file_put_contents('quanju4.txt', $basePrice . "-之前的总价总价\r\n", 8);
- @file_put_contents('quanju4.txt', $add_price . "-963\r\n", 8);
- $price = bcadd(sprintf("%.8f", $add_price), (string)$basePrice, 8);
- @file_put_contents('quanju4.txt', time() . "-正常获取走的到这里吗\r\n", 8);
- @file_put_contents('quanju4.txt', $price . "-总价\r\n", 8);
- } catch (\Exception $e) {
- @file_put_contents('quanju4.txt', $e->getMessage() . "-积分价格报错内容\r\n", 8);
- @file_put_contents('quanju4.txt', $e->getFile() . "-文件\r\n", 8);
- @file_put_contents('quanju4.txt', $e->getLine() . "-位置\r\n", 8);
- }
- return compact('basePrice', 'price', 'rise', 'achievement', 'commission', 'num', 'add_price');
- }
- public function setPrice($day, $price, $commission, $achievement, $num, $add_price)
- {
- $add_time = time();
- @file_put_contents('quanju4.txt', $add_price . "-我add_price呢\r\n", 8);
- return $this->dao->create(compact('day', 'price', 'commission', 'achievement', 'num', 'add_time', 'add_price'));
- }
- /**
- * 列表搜索
- * @param int $merId
- * @param array $where
- * @param $page
- * @param $limit
- * @return array
- * @author Qinii
- */
- public function search(int $merId, array $where, $page, $limit)
- {
- $query = $this->dao->search($merId, $where)->order('add_time DESC');
- $count = $query->count($this->dao->getPk());
- $list = $query->page($page, $limit)->hidden(['update_time'])->select();
- return compact('count', 'list');
- }
- /**
- * 根据条件获取列表数据
- *
- * 每日分红价格列表
- * @param array $where 查询条件数组,用于指定数据库查询的条件。
- * @param int $page 当前页码,用于指定要返回的页码。
- * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
- * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
- */
- public function getList(array $where, $page, $limit)
- {
- // 根据条件查询数据,$where 为查询条件数组
- $query = $this->dao->search($where);
- // 统计满足条件的数据总数
- $count = $query->count();
- // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
- // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
- $list = $query->page($page, $limit)->order('day DESC')->select()->toArray();
- // 返回包含数据总数和数据列表的数组
- return compact('count', 'list');
- }
- /**
- * 根据条件获取列表数据
- *
- * 每日奖池列表
- * @param array $where 查询条件数组,用于指定数据库查询的条件。
- * @param int $page 当前页码,用于指定要返回的页码。
- * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
- * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
- */
- public function getLakeList(array $where, $page, $limit)
- {
- // 根据条件查询数据,$where 为查询条件数组
- $mark = app()->make(AwardLakeDao::class);
- $query = $mark->search($where);
- // 统计满足条件的数据总数
- $count = $query->count();
- // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
- // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
- $list = $query->page($page, $limit)->order('level asc')->select()->toArray();
- // 返回包含数据总数和数据列表的数组
- return compact('count', 'list');
- }
- /**
- * 根据条件获取列表数据
- *
- * 每日奖池列表
- * @param array $where 查询条件数组,用于指定数据库查询的条件。
- * @param int $page 当前页码,用于指定要返回的页码。
- * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
- * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
- */
- public function getLakeLogList(array $where, $page, $limit)
- {
- // 根据条件查询数据,$where 为查询条件数组
- $mark = app()->make(AwardLakeLogDao::class);
- $query = $mark->search($where);
- // 统计满足条件的数据总数
- $count = $query->count();
- // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
- // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
- $list = $query->page($page, $limit)->order('add_time DESC')->select()->toArray();
- // 返回包含数据总数和数据列表的数组
- return compact('count', 'list');
- }
- public function getPrice()
- {
- $mark = app()->make(AwardIntegralPriceDao::class);
- $price = $mark->search([])->order('add_time DESC')->value('price');
- return $price;
- }
- }
|