AwardIntegralPriceRepository.php 9.9 KB

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