UserIntegral.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\controller\admin\user;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\system\CacheRepository;
  14. use app\common\repositories\system\config\ConfigClassifyRepository;
  15. use app\common\repositories\system\config\ConfigValueRepository;
  16. use app\common\repositories\user\UserBillRepository;
  17. use app\validate\admin\IntegralConfigValidate;
  18. use crmeb\basic\BaseController;
  19. use crmeb\services\ExcelService;
  20. use think\App;
  21. /**
  22. * Class UserIntegral
  23. * app\controller\admin\user
  24. * 用户积分
  25. */
  26. class UserIntegral extends BaseController
  27. {
  28. protected $repository;
  29. public function __construct(App $app, UserBillRepository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * 积分日志
  36. * @return \think\response\Json
  37. * @author Qinii
  38. * @day 6/9/21
  39. */
  40. public function getList()
  41. {
  42. [$page, $limit] = $this->getPage();
  43. $where = $this->request->params(['keyword', 'date']);
  44. $where['category'] = 'integral';
  45. return app('json')->success($this->repository->getList($where, $page, $limit));
  46. }
  47. /**
  48. * 头部统计
  49. * @return \think\response\Json
  50. * @author Qinii
  51. * @day 6/9/21
  52. */
  53. public function getTitle()
  54. {
  55. return app('json')->success($this->repository->getStat());
  56. }
  57. /**
  58. * 导出
  59. * @return \think\response\Json
  60. * @author Qinii
  61. * @day 6/9/21
  62. */
  63. public function excel()
  64. {
  65. $where = $this->request->params(['keyword', 'date']);
  66. $where['category'] = 'integral';
  67. [$page, $limit] = $this->getPage();
  68. $data = app()->make(ExcelService::class)->integralLog($where, $page, $limit);
  69. return app('json')->success($data);
  70. }
  71. /**
  72. * 配置
  73. * @return \think\response\Json
  74. * @author Qinii
  75. */
  76. public function getConfig()
  77. {
  78. $config = systemConfig(
  79. [
  80. 'integral_status',
  81. 'integral_clear_time',
  82. 'integral_order_rate',
  83. 'integral_freeze',
  84. 'integral_user_give',
  85. 'integral_money',
  86. 'integral_community_give',
  87. 'integral_community_give_limit'
  88. ]
  89. );
  90. $config = array_filter($config, function ($v) {
  91. return $v !== '';
  92. }) + ['integral_status' => 0, 'integral_clear_time' => 0, 'integral_order_rate' => 0, 'integral_freeze' => 0, 'integral_user_give' => 0, 'integral_money' => 0, 'integral_community_give' => 0, 'integral_community_give_limit' => 1];
  93. $config['rule'] = app()->make(CacheRepository::class)->getResultByKey(CacheRepository::INTEGRAL_RULE);
  94. return app('json')->success($config);
  95. }
  96. /**
  97. * 保存配置
  98. * @param IntegralConfigValidate $validate
  99. * @return \think\response\Json
  100. * @author Qinii
  101. */
  102. public function saveConfig(IntegralConfigValidate $validate)
  103. {
  104. $config = $this->request->params(['integral_status', 'integral_clear_time', 'integral_order_rate', 'integral_freeze', 'integral_user_give', 'integral_money', 'integral_community_give', 'integral_community_give_limit', 'rule']);
  105. $validate->check($config);
  106. app()->make(CacheRepository::class)->save('sys_integral_rule', $config['rule']);
  107. unset($config['rule']);
  108. if (!($cid = app()->make(ConfigClassifyRepository::class)->keyById('integral'))) return app('json')->fail('保存失败');
  109. app()->make(ConfigValueRepository::class)->save($cid, $config, 0);
  110. return app('json')->success('保存成功');
  111. }
  112. }