UserIntegral.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\controller\admin\user;
  3. use app\common\repositories\store\ExcelRepository;
  4. use app\common\repositories\system\CacheRepository;
  5. use app\common\repositories\system\config\ConfigClassifyRepository;
  6. use app\common\repositories\system\config\ConfigValueRepository;
  7. use app\common\repositories\user\UserBillRepository;
  8. use app\validate\admin\IntegralConfigValidate;
  9. use ln\basic\BaseController;
  10. use think\App;
  11. class UserIntegral extends BaseController
  12. {
  13. protected $repository;
  14. public function __construct(App $app, UserBillRepository $repository)
  15. {
  16. parent::__construct($app);
  17. $this->repository = $repository;
  18. }
  19. /**
  20. * TODO 积分日志
  21. * @return \think\response\Json
  22. * @author Qinii
  23. * @day 6/9/21
  24. */
  25. public function getList()
  26. {
  27. [$page, $limit] = $this->getPage();
  28. $where = $this->request->params(['keyword', 'date']);
  29. $where['category'] = 'integral';
  30. return app('json')->success($this->repository->getList($where, $page, $limit));
  31. }
  32. /**
  33. * TODO
  34. * @return \think\response\Json
  35. * @author Qinii
  36. * @day 6/9/21
  37. */
  38. public function getTitle()
  39. {
  40. return app('json')->success($this->repository->getStat());
  41. }
  42. public function excel()
  43. {
  44. $where = $this->request->params(['keyword', 'date']);
  45. $where['category'] = 'integral';
  46. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'integralLog', $this->request->merId());
  47. return app('json')->success('开始导出数据');
  48. }
  49. public function getConfig()
  50. {
  51. $config = systemConfig(['integral_status', 'integral_clear_time', 'integral_order_rate', 'integral_freeze', 'integral_user_give', 'integral_money']);
  52. $config = array_filter($config, function ($v) {
  53. return $v !== '';
  54. }) + ['integral_status' => 0, 'integral_clear_time' => 0, 'integral_order_rate' => 0, 'integral_freeze' => 0, 'integral_user_give' => 0, 'integral_money' => 0];
  55. $config['rule'] = app()->make(CacheRepository::class)->getResult('sys_integral_rule');
  56. return app('json')->success($config);
  57. }
  58. public function saveConfig(IntegralConfigValidate $validate)
  59. {
  60. $config = $this->request->params(['integral_status', 'integral_clear_time', 'integral_order_rate', 'integral_freeze', 'integral_user_give', 'integral_money', 'rule']);
  61. $validate->check($config);
  62. app()->make(CacheRepository::class)->save('sys_integral_rule', $config['rule']);
  63. unset($config['rule']);
  64. if (!($cid = app()->make(ConfigClassifyRepository::class)->keyById('integral'))) return app('json')->fail('保存失败');
  65. app()->make(ConfigValueRepository::class)->save($cid, $config, 0);
  66. return app('json')->success('保存成功');
  67. }
  68. }