AwardIntegralPriceRepository.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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\AwardIntegralPriceDayDao;
  14. use app\common\dao\user\AwardLakeDao;
  15. use app\common\dao\user\AwardLakeLogDao;
  16. use app\common\model\store\order\StoreOrder;
  17. use app\common\model\user\AwardIntegralPrice;
  18. use app\common\model\user\AwardLakeLog;
  19. use app\common\model\user\UserExtract;
  20. use app\common\repositories\BaseRepository;
  21. class AwardIntegralPriceRepository extends BaseRepository
  22. {
  23. /**
  24. * @var AwardIntegralPriceDao
  25. */
  26. protected $dao;
  27. /**
  28. * UserSignRepository constructor.
  29. * @param AwardIntegralPriceDao $dao
  30. */
  31. public function __construct(AwardIntegralPriceDao $dao)
  32. {
  33. $this->dao = $dao;
  34. }
  35. public function awardIntegralPrice($day = '')
  36. {
  37. if (!$day) {
  38. $day = date('Y-m-d', strtotime('-1 day'));
  39. }
  40. if ($info = $this->dao->search(['day' => $day])->find()) {
  41. return $info->toArray();
  42. }
  43. // @file_put_contents('yesterday.txt', AwardIntegralPrice::getLastSql() . PHP_EOL, FILE_APPEND);
  44. $yesterday_price = $this->dao->search(['day' => date('Y-m-d', strtotime('-1 day', strtotime($day)))])->find();
  45. if ($yesterday_price) {
  46. $basePrice = $yesterday_price->price;
  47. } else {
  48. $basePrice = systemConfig('award_integral_price', 0.1);
  49. }
  50. $time_start = strtotime($day);
  51. $time_end = strtotime($day) + 86400;
  52. //todo 业绩
  53. $achievement = StoreOrder::where('paid', 1)
  54. ->whereBetween('create_time', [$day . ' 00:00:00', $day . ' 23:59:59'])
  55. ->where('is_del', 0)->where('is_system_del', 0)
  56. ->where('status', '>=', 0)
  57. ->sum('total_price');
  58. @file_put_contents('yesterday.txt', StoreOrder::getLastSql() . PHP_EOL, FILE_APPEND);
  59. $achievement = bcmul((string)$achievement, '0.1', 6); //从总业绩的5%上涨到10%
  60. /** @var UserExtractRepository $extractRepositories */
  61. $extractRepositories = app()->make(UserExtractRepository::class);
  62. $commission = $extractRepositories->search(['status' => 1])->whereBetween('check_time', [$time_start, $time_end])->sum('commission');
  63. @file_put_contents('yesterday.txt', UserExtract::getLastSql() . PHP_EOL, FILE_APPEND);
  64. $userService = app()->make(UserRepository::class);
  65. $num = $userService->search(['status' => 1])->sum('award_integral');
  66. $sum_achievement = bcadd((string)$commission, (string)$achievement, 6);
  67. $rise = $num > 0 ? bcdiv($sum_achievement, $num, 6) : 0;
  68. $add_price = 0;
  69. if ($rise > 0) {
  70. try {
  71. // 增长值分成25份
  72. $day_25_rise = bcdiv($rise, 25, 6);
  73. /** @var AwardIntegralPriceDayDao $AwardIntegralPriceDayDao */
  74. $AwardIntegralPriceDayDao = app()->make(AwardIntegralPriceDayDao::class);
  75. $AwardIntegralPriceDayDao->create(['day' => strtotime('-25 day'), 'price' => $rise, 'add_price' => $day_25_rise]); //保存今天增长的总价格和每日增长价格
  76. $day_25 = strtotime('-25 day');
  77. $add_price = $AwardIntegralPriceDayDao->search(['day' => $day_25])->sum('price');
  78. } catch (\Exception $e) {
  79. @file_put_contents('quanju4.txt', $e->getMessage() . "-积分价格报错内容\r\n", 8);
  80. @file_put_contents('quanju4.txt', $e->getFile() . "-文件\r\n", 8);
  81. @file_put_contents('quanju4.txt', $e->getLine() . "-位置\r\n", 8);
  82. }
  83. }
  84. $price = bcadd($add_price, $basePrice, 6);
  85. @file_put_contents('quanju4.txt', time() . "-正常获取走的到这里吗\r\n", 8);
  86. return compact('basePrice', 'price', 'rise', 'achievement', 'commission', 'num', 'add_price');
  87. }
  88. public function setPrice($day, $price, $commission, $achievement, $num, $add_price)
  89. {
  90. $add_time = time();
  91. @file_put_contents('quanju4.txt', $add_price . "-我add_price呢\r\n", 8);
  92. return $this->dao->create(compact('day', 'price', 'commission', 'achievement', 'num', 'add_time', 'add_price'));
  93. }
  94. /**
  95. * 列表搜索
  96. * @param int $merId
  97. * @param array $where
  98. * @param $page
  99. * @param $limit
  100. * @return array
  101. * @author Qinii
  102. */
  103. public function search(int $merId, array $where, $page, $limit)
  104. {
  105. $query = $this->dao->search($merId, $where)->order('add_time DESC');
  106. $count = $query->count($this->dao->getPk());
  107. $list = $query->page($page, $limit)->hidden(['update_time'])->select();
  108. return compact('count', 'list');
  109. }
  110. /**
  111. * 根据条件获取列表数据
  112. *
  113. * 每日分红价格列表
  114. * @param array $where 查询条件数组,用于指定数据库查询的条件。
  115. * @param int $page 当前页码,用于指定要返回的页码。
  116. * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
  117. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
  118. */
  119. public function getList(array $where, $page, $limit)
  120. {
  121. // 根据条件查询数据,$where 为查询条件数组
  122. $query = $this->dao->search($where);
  123. // 统计满足条件的数据总数
  124. $count = $query->count();
  125. // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
  126. // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
  127. $list = $query->page($page, $limit)->order('day DESC')->select()->toArray();
  128. // 返回包含数据总数和数据列表的数组
  129. return compact('count', 'list');
  130. }
  131. /**
  132. * 根据条件获取列表数据
  133. *
  134. * 每日奖池列表
  135. * @param array $where 查询条件数组,用于指定数据库查询的条件。
  136. * @param int $page 当前页码,用于指定要返回的页码。
  137. * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
  138. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
  139. */
  140. public function getLakeList(array $where, $page, $limit)
  141. {
  142. // 根据条件查询数据,$where 为查询条件数组
  143. $mark = app()->make(AwardLakeDao::class);
  144. $query = $mark->search($where);
  145. // 统计满足条件的数据总数
  146. $count = $query->count();
  147. // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
  148. // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
  149. $list = $query->page($page, $limit)->order('level asc')->select()->toArray();
  150. // 返回包含数据总数和数据列表的数组
  151. return compact('count', 'list');
  152. }
  153. /**
  154. * 根据条件获取列表数据
  155. *
  156. * 每日奖池列表
  157. * @param array $where 查询条件数组,用于指定数据库查询的条件。
  158. * @param int $page 当前页码,用于指定要返回的页码。
  159. * @param int $limit 每页的数据数量,用于指定每页返回的数据条数。
  160. * @return array 返回包含 'count' 和 'list' 两个元素的数组,'count' 为数据总数,'list' 为数据列表。
  161. */
  162. public function getLakeLogList(array $where, $page, $limit)
  163. {
  164. // 根据条件查询数据,$where 为查询条件数组
  165. $mark = app()->make(AwardLakeLogDao::class);
  166. $query = $mark->search($where);
  167. // 统计满足条件的数据总数
  168. $count = $query->count();
  169. // 查询满足条件的数据列表,带有 'label' 关联数据,按 'label_rule_id' 倒序排列
  170. // 分页查询,返回当前页码的 $limit 条数据,并将结果转换为数组形式
  171. $list = $query->page($page, $limit)->order('add_time DESC')->select()->toArray();
  172. // 返回包含数据总数和数据列表的数组
  173. return compact('count', 'list');
  174. }
  175. public function getPrice()
  176. {
  177. $mark = app()->make(AwardIntegralPriceDao::class);
  178. $price = $mark->search([])->order('add_time DESC')->value('price');
  179. return $price;
  180. }
  181. }