AwardIntegralPriceRepository.php 2.5 KB

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