AwardIntegralPriceRepository.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\model\user\AwardIntegralPrice;
  14. use app\common\repositories\BaseRepository;
  15. class AwardIntegralPriceRepository extends BaseRepository
  16. {
  17. /**
  18. * @var AwardIntegralPriceDao
  19. */
  20. protected $dao;
  21. /**
  22. * UserSignRepository constructor.
  23. * @param AwardIntegralPriceDao $dao
  24. */
  25. public function __construct(AwardIntegralPriceDao $dao)
  26. {
  27. $this->dao = $dao;
  28. }
  29. public function awardIntegralPrice($day = '')
  30. {
  31. if (!$day) {
  32. $day = date('Y-m-d');
  33. }
  34. if ($info = $this->dao->search(['day' => date('Y-m-d')])->find()) {
  35. return $info->toArray();
  36. }
  37. @file_put_contents('yesterday.txt', AwardIntegralPrice::getLastSql() . PHP_EOL, FILE_APPEND);
  38. $yesterday_price = $this->dao->search(['day' => date('Y-m-d', strtotime('-1 day', strtotime($day)))])->find();
  39. if ($yesterday_price) {
  40. $basePrice = $yesterday_price->price;
  41. } else {
  42. $basePrice = systemConfig('award_integral_price', 0.1);
  43. }
  44. //todo 业绩
  45. $achievement = 0;
  46. /** @var UserExtractRepository $extractRepositories */
  47. $extractRepositories = app()->make(UserExtractRepository::class);
  48. $commission = $extractRepositories->search(['status' => 1])->whereTime('check_time', $day)->sum('commission');
  49. $userService = app()->make(UserRepository::class);
  50. $num = $userService->search(['status' => 1])->sum('award_integral');
  51. $sum_achievement = $commission + $achievement;
  52. $rise = $num > 0 ? bcdiv($sum_achievement, $num, 3) : 0;
  53. $price = bcadd($rise, $basePrice, 3);
  54. return compact('basePrice', 'price', 'rise', 'achievement', 'commission', 'num');
  55. }
  56. public function setPrice($day, $price, $commission, $achievement, $num)
  57. {
  58. $add_time = time();
  59. return $this->dao->create(compact('day', 'price', 'commission', 'achievement', 'num', 'add_time'));
  60. }
  61. }