UserAwardIntegralServices.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\user;
  13. use app\dao\system\AwardLakeDao;
  14. use app\dao\user\UserIntegralDao;
  15. use app\services\BaseServices;
  16. use crmeb\traits\ServicesTrait;
  17. use app\webscoket\SocketPush;
  18. use think\db\exception\DataNotFoundException;
  19. use think\db\exception\DbException;
  20. use think\db\exception\ModelNotFoundException;
  21. /**
  22. *
  23. * Class UserRechargeServices
  24. * @package app\services\user
  25. * @mixin UserIntegralDao
  26. */
  27. class UserAwardIntegralServices extends BaseServices
  28. {
  29. use ServicesTrait;
  30. private $lake_dao;
  31. /**
  32. * UserRechargeServices constructor.
  33. * @param UserIntegralDao $dao
  34. */
  35. public function __construct(UserIntegralDao $dao, AwardLakeDao $awardLakeDao)
  36. {
  37. $this->dao = $dao;
  38. $this->lake_dao = $awardLakeDao;
  39. }
  40. /**
  41. * 获取单条数据
  42. * @param int $id
  43. * @param array $field
  44. */
  45. public function getIntegral(int $id, array $field = [])
  46. {
  47. return $this->dao->get($id, $field);
  48. }
  49. /**
  50. * 获取单条数据
  51. * @return float
  52. */
  53. public function getIntegralSum($where)
  54. {
  55. return $this->dao->sum($where, 'num', true);
  56. }
  57. /**
  58. * 获取单条数据
  59. * @return float
  60. */
  61. public function getLake()
  62. {
  63. return $this->lake_dao->sum([], 'num');
  64. }
  65. /**
  66. * 获取单条数据
  67. * @param int $link_id
  68. * @return string|null
  69. * @throws DataNotFoundException
  70. * @throws DbException
  71. * @throws ModelNotFoundException
  72. */
  73. public function getPrice(int $link_id = 0)
  74. {
  75. if ($link_id > 0) {
  76. $info = $this->dao->getOne(['link_id' => $link_id]);
  77. if ($info) return (string)($info['price'] ?: 0);
  78. }
  79. $lake_sum = $this->getLake();
  80. $sum_integral = $this->getIntegralSum(['status' => 0]);
  81. return (string)($sum_integral > 0 ? bcdiv((string)$lake_sum, (string)$sum_integral, 8) : 1);
  82. }
  83. }