UserPoint.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. namespace app\controller\admin\v1\marketing\integral;
  12. use app\controller\admin\AuthController;
  13. use app\services\user\UserBillServices;
  14. use app\services\activity\integral\UserPointServices;
  15. use think\facade\App;
  16. /**
  17. * 积分控制器
  18. * Class UserPoint
  19. * @package app\controller\admin\v1\markging\integral
  20. */
  21. class UserPoint extends AuthController
  22. {
  23. /**
  24. * Finance constructor.
  25. * @param App $app
  26. * @param UserBillServices $services
  27. */
  28. public function __construct(App $app, UserBillServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * @return mixed
  35. */
  36. public function index()
  37. {
  38. $where = $this->request->getMore([
  39. ['start_time', ''],
  40. ['end_time', ''],
  41. ['nickname', ''],
  42. ['page', 1],
  43. ['limit', 10],
  44. ]);
  45. return $this->success($this->services->getPointList($where));
  46. }
  47. /**
  48. * 获取积分日志头部信息
  49. * @return mixed
  50. */
  51. public function integral_statistics()
  52. {
  53. $where = $this->request->getMore([
  54. ['start_time', ''],
  55. ['end_time', ''],
  56. ['nickname', ''],
  57. ]);
  58. return $this->success(['res' => $this->services->getUserPointBadgelist($where)]);
  59. }
  60. /**
  61. * 积分记录
  62. * @return mixed
  63. */
  64. public function pointRecord(UserPointServices $pointServices)
  65. {
  66. $where = $this->request->getMore([
  67. ['time', ''],
  68. ['trading_type', 0]
  69. ]);
  70. $date = $pointServices->pointRecord($where);
  71. return app('json')->success($date);
  72. }
  73. /**
  74. * 积分记录备注
  75. * @return mixed
  76. */
  77. public function pointRecordRemark(UserPointServices $pointServices, $id = 0)
  78. {
  79. [$mark] = $this->request->postMore([
  80. ['mark', '']
  81. ], true);
  82. $pointServices->recordRemark($id, $mark);
  83. return app('json')->success('备注成功');
  84. }
  85. /**
  86. * 积分统计基础信息
  87. * @return mixed
  88. */
  89. public function getBasic(UserPointServices $pointServices)
  90. {
  91. $where = $this->request->getMore([
  92. ['time', '']
  93. ]);
  94. $where['time'] = $this->getDay($where['time']);
  95. return app('json')->success($pointServices->getBasic($where));
  96. }
  97. /**
  98. * 积分统计趋势图
  99. * @return mixed
  100. */
  101. public function getTrend(UserPointServices $pointServices)
  102. {
  103. $where = $this->request->getMore([
  104. ['time', '']
  105. ]);
  106. $where['time'] = $this->getDay($where['time']);
  107. return app('json')->success($pointServices->getTrend($where));
  108. }
  109. /**
  110. * 积分来源
  111. * @return mixed
  112. */
  113. public function getChannel(UserPointServices $pointServices)
  114. {
  115. $where = $this->request->getMore([
  116. ['time', '']
  117. ]);
  118. $where['time'] = $this->getDay($where['time']);
  119. return app('json')->success($pointServices->getChannel($where));
  120. }
  121. /**
  122. * 积分消耗
  123. * @return mixed
  124. */
  125. public function getType(UserPointServices $pointServices)
  126. {
  127. $where = $this->request->getMore([
  128. ['time', '']
  129. ]);
  130. $where['time'] = $this->getDay($where['time']);
  131. return app('json')->success($pointServices->getType($where));
  132. }
  133. /**
  134. * 格式化时间
  135. * @param $time
  136. * @return string
  137. */
  138. public function getDay($time)
  139. {
  140. if (strstr($time, '-') !== false) {
  141. [$startTime, $endTime] = explode('-', $time);
  142. if (!$startTime && !$endTime) {
  143. return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
  144. } else {
  145. return $startTime . '-' . $endTime;
  146. }
  147. } else {
  148. return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
  149. }
  150. }
  151. }