AwardIntegralPriceRepository.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\user;
  12. use app\common\dao\user\AwardIntegralPriceDao;
  13. use app\common\dao\user\AwardLakeDao;
  14. use app\common\dao\user\AwardLakeLogDao;
  15. use app\common\model\store\order\StoreOrder;
  16. use app\common\model\user\AwardIntegralPrice;
  17. use app\common\model\user\AwardLakeLog;
  18. use app\common\model\user\UserExtract;
  19. use app\common\repositories\BaseRepository;
  20. class AwardIntegralPriceRepository extends BaseRepository
  21. {
  22. /**
  23. * @var AwardIntegralPriceDao
  24. */
  25. protected $dao;
  26. /**
  27. * UserSignRepository constructor.
  28. * @param AwardIntegralPriceDao $dao
  29. */
  30. public function __construct(AwardIntegralPriceDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. public function awardIntegralPrice($day = '')
  35. {
  36. if (!$day) {
  37. $day = date('Y-m-d');
  38. }
  39. if ($info = $this->dao->search(['day' => $day])->find()) {
  40. return $info->toArray();
  41. }
  42. // @file_put_contents('yesterday.txt', AwardIntegralPrice::getLastSql() . PHP_EOL, FILE_APPEND);
  43. $yesterday_price = $this->dao->search(['day' => date('Y-m-d', strtotime('-1 day', strtotime($day)))])->find();
  44. if ($yesterday_price) {
  45. $basePrice = $yesterday_price->price;
  46. } else {
  47. $basePrice = systemConfig('award_integral_price', 0.1);
  48. }
  49. $time_start = strtotime($day);
  50. $time_end = strtotime($day) + 86400;
  51. //todo 业绩
  52. $achievement = StoreOrder::where('paid', 1)
  53. ->whereBetween('create_time', [$day . ' 00:00:00', $day . ' 23:59:59'])
  54. ->where('is_del', 0)->where('is_system_del', 0)
  55. ->where('status', '>=', 0)
  56. ->sum('total_price');
  57. @file_put_contents('yesterday.txt', StoreOrder::getLastSql() . PHP_EOL, FILE_APPEND);
  58. $achievement = bcmul((string)$achievement, '0.05', 2);
  59. /** @var UserExtractRepository $extractRepositories */
  60. $extractRepositories = app()->make(UserExtractRepository::class);
  61. $commission = $extractRepositories->search(['status' => 1])->whereBetween('check_time', [$time_start, $time_end])->sum('commission');
  62. @file_put_contents('yesterday.txt', UserExtract::getLastSql() . PHP_EOL, FILE_APPEND);
  63. $userService = app()->make(UserRepository::class);
  64. $num = $userService->search(['status' => 1])->sum('award_integral');
  65. $sum_achievement = bcadd((string)$commission, (string)$achievement, 2);
  66. $rise = $num > 0 ? bcdiv($sum_achievement, $num, 3) : 0;
  67. $price = bcadd($rise, $basePrice, 3);
  68. return compact('basePrice', 'price', 'rise', 'achievement', 'commission', 'num');
  69. }
  70. public function setPrice($day, $price, $commission, $achievement, $num)
  71. {
  72. $add_time = time();
  73. return $this->dao->create(compact('day', 'price', 'commission', 'achievement', 'num', 'add_time'));
  74. }
  75. /**
  76. * 列表搜索
  77. * @param int $merId
  78. * @param array $where
  79. * @param $page
  80. * @param $limit
  81. * @return array
  82. * @author Qinii
  83. */
  84. public function search(int $merId, array $where, $page, $limit)
  85. {
  86. $query = $this->dao->search($merId, $where)->order('add_time DESC');
  87. $count = $query->count($this->dao->getPk());
  88. $list = $query->page($page, $limit)->hidden(['update_time'])->select();
  89. return compact('count', 'list');
  90. }
  91. /**
  92. * 根据条件获取列表数据
  93. *
  94. * 每日分红价格列表
  95. * @param array $where 查询条件数组,用于指定数据库查询的条件。
  96. * @param int $page 当前页码,用于指定要返回的页码。
  97. * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
  98. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
  99. */
  100. public function getList(array $where, $page, $limit)
  101. {
  102. // 根据条件查询数据,$where 为查询条件数组
  103. $query = $this->dao->search($where);
  104. // 统计满足条件的数据总数
  105. $count = $query->count();
  106. // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
  107. // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
  108. $list = $query->page($page, $limit)->select()->toArray();
  109. // 返回包含数据总数和数据列表的数组
  110. return compact('count', 'list');
  111. }
  112. /**
  113. * 根据条件获取列表数据
  114. *
  115. * 每日奖池列表
  116. * @param array $where 查询条件数组,用于指定数据库查询的条件。
  117. * @param int $page 当前页码,用于指定要返回的页码。
  118. * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
  119. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
  120. */
  121. public function getLakeList(array $where, $page, $limit)
  122. {
  123. // 根据条件查询数据,$where 为查询条件数组
  124. $mark = app()->make(AwardLakeLogDao::class);
  125. $query = $mark->search($where);
  126. // 统计满足条件的数据总数
  127. $count = $query->count();
  128. // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
  129. // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
  130. $list = $query->page($page, $limit)->select()->toArray();
  131. // 返回包含数据总数和数据列表的数组
  132. return compact('count', 'list');
  133. }
  134. /**
  135. * 根据条件获取列表数据
  136. *
  137. * 每日奖池列表
  138. * @param array $where 查询条件数组,用于指定数据库查询的条件。
  139. * @param int $page 当前页码,用于指定要返回的页码。
  140. * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
  141. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
  142. */
  143. public function getLakeLogList(array $where, $page, $limit)
  144. {
  145. // 根据条件查询数据,$where 为查询条件数组
  146. $mark = app()->make(AwardLakeLogDao::class);
  147. $query = $mark->search($where);
  148. // 统计满足条件的数据总数
  149. $count = $query->count();
  150. // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
  151. // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
  152. $list = $query->page($page, $limit)->select()->toArray();
  153. // 返回包含数据总数和数据列表的数组
  154. return compact('count', 'list');
  155. }
  156. public function getPrice(){
  157. $mark = app()->make(AwardIntegralPriceDao::class);
  158. $price = $mark->search([])->order('add_time DESC')->value('price');
  159. return $price;
  160. }
  161. }