UserIntegral.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. class UserIntegral extends BaseController
  22. {
  23. protected $repository;
  24. public function __construct(App $app, UserBillRepository $repository)
  25. {
  26. parent::__construct($app);
  27. $this->repository = $repository;
  28. }
  29. /**
  30. * TODO 积分日志
  31. * @return \think\response\Json
  32. * @author Qinii
  33. * @day 6/9/21
  34. */
  35. public function getList()
  36. {
  37. [$page, $limit] = $this->getPage();
  38. $where = $this->request->params(['keyword', 'date']);
  39. $where['category'] = 'integral';
  40. return app('json')->success($this->repository->getList($where, $page, $limit));
  41. }
  42. /**
  43. * TODO
  44. * @return \think\response\Json
  45. * @author Qinii
  46. * @day 6/9/21
  47. */
  48. public function getTitle()
  49. {
  50. return app('json')->success($this->repository->getStat());
  51. }
  52. public function excel()
  53. {
  54. $where = $this->request->params(['keyword', 'date']);
  55. $where['category'] = 'integral';
  56. [$page, $limit] = $this->getPage();
  57. $data = app()->make(ExcelService::class)->integralLog($where,$page,$limit);
  58. return app('json')->success($data);
  59. }
  60. public function getConfig()
  61. {
  62. $config = systemConfig(['integral_status', 'integral_clear_time', 'integral_order_rate', 'integral_freeze', 'integral_user_give', 'integral_money']);
  63. $config = array_filter($config, function ($v) {
  64. return $v !== '';
  65. }) + ['integral_status' => 0, 'integral_clear_time' => 0, 'integral_order_rate' => 0, 'integral_freeze' => 0, 'integral_user_give' => 0, 'integral_money' => 0];
  66. $config['rule'] = app()->make(CacheRepository::class)->getResultByKey(CacheRepository::INTEGRAL_RULE);
  67. return app('json')->success($config);
  68. }
  69. public function saveConfig(IntegralConfigValidate $validate)
  70. {
  71. $config = $this->request->params(['integral_status', 'integral_clear_time', 'integral_order_rate', 'integral_freeze', 'integral_user_give', 'integral_money', 'rule']);
  72. $validate->check($config);
  73. app()->make(CacheRepository::class)->save('sys_integral_rule', $config['rule']);
  74. unset($config['rule']);
  75. if (!($cid = app()->make(ConfigClassifyRepository::class)->keyById('integral'))) return app('json')->fail('保存失败');
  76. app()->make(ConfigValueRepository::class)->save($cid, $config, 0);
  77. return app('json')->success('保存成功');
  78. }
  79. }