Rebate.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\data\controller\api\auth;
  3. use app\data\controller\api\Auth;
  4. use app\data\service\RebateService;
  5. /**
  6. * 用户返利管理
  7. * Class Rebate
  8. * @package app\data\controller\api\auth
  9. */
  10. class Rebate extends Auth
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. private $table = 'DataUserRebate';
  17. /**
  18. * 获取用户返利记录
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\DbException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. */
  23. public function get()
  24. {
  25. $date = trim(input('date', date('Y-m')), '-');
  26. [$map, $year] = [['uid' => $this->uuid], substr($date, 0, 4)];
  27. $query = $this->_query($this->table)->where($map)->equal('type,status')->whereLike('date', "{$date}%");
  28. $this->success('获取返利统计', array_merge($query->order('id desc')->page(true, false, false, 10), [
  29. 'total' => [
  30. '年度' => $this->_query($this->table)->where($map)->equal('type,status')->whereLike('date', "{$year}%")->db()->sum('amount'),
  31. '月度' => $this->_query($this->table)->where($map)->equal('type,status')->whereLike('date', "{$date}%")->db()->sum('amount'),
  32. ],
  33. ]));
  34. }
  35. /**
  36. * 获取我的奖励
  37. */
  38. public function prize()
  39. {
  40. [$map, $data] = [['number' => $this->user['vip_code']], []];
  41. $prizes = $this->app->db->name($this->table)->group('name')->column('name');
  42. $rebate = $this->app->db->name('DataBaseUpgrade')->where($map)->value('rebate_rule', '');
  43. $codemap = array_merge($prizes, str2arr($rebate));
  44. foreach (RebateService::PRIZES as $prize) {
  45. if (in_array($prize['code'], $codemap)) $data[] = $prize;
  46. }
  47. $this->success('获取我的奖励', $data);
  48. }
  49. /**
  50. * 获取奖励配置
  51. */
  52. public function prizes()
  53. {
  54. $this->success('获取系统奖励', array_values(RebateService::PRIZES));
  55. }
  56. }