Rebate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\data\controller\user;
  3. use app\data\model\BaseUserUpgrade;
  4. use app\data\model\DataUser;
  5. use app\data\model\DataUserRebate;
  6. use app\data\model\ShopOrderItem;
  7. use app\data\service\RebateService;
  8. use app\data\service\UserRebateService;
  9. use think\admin\Controller;
  10. /**
  11. * 用户返利管理
  12. * Class Rebate
  13. * @package app\data\controller\user
  14. */
  15. class Rebate extends Controller
  16. {
  17. /**
  18. * 用户返利管理
  19. * @auth true
  20. * @menu true
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\DbException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. */
  25. public function index()
  26. {
  27. $this->title = '用户返利管理';
  28. // 统计所有返利
  29. $this->types = RebateService::PRIZES;
  30. $this->rebate = UserRebateService::amount(0);
  31. // 创建查询对象
  32. $query = DataUserRebate::mQuery()->equal('type')->like('name,order_no');
  33. // 会员条件查询
  34. $db = $this->_query('DataUser')->like('nickname#order_nickname,phone#order_phone')->db();
  35. if ($db->getOptions('where')) $query->whereRaw("order_uuid in {$db->field('id')->buildSql()}");
  36. // 代理条件查询
  37. $db = $this->_query('DataUser')->like('nickname#agent_nickname,phone#agent_phone')->db();
  38. if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
  39. // 查询分页
  40. $query->dateBetween('create_at')->order('id desc')->page();
  41. }
  42. /**
  43. * 商城订单列表处理
  44. * @param array $data
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. protected function _index_page_filter(array &$data)
  50. {
  51. $uids = array_merge(array_column($data, 'uuid'), array_column($data, 'order_uuid'));
  52. $userItem = DataUser::mk()->whereIn('id', array_unique($uids))->select();
  53. $goodsItem = ShopOrderItem::mk()->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select();
  54. foreach ($data as &$vo) {
  55. $vo['type'] = RebateService::name($vo['type']);
  56. [$vo['user'], $vo['agent'], $vo['list']] = [[], [], []];
  57. foreach ($userItem as $user) {
  58. if ($user['id'] === $vo['uuid']) $vo['agent'] = $user;
  59. if ($user['id'] === $vo['order_uuid']) $vo['user'] = $user;
  60. }
  61. foreach ($goodsItem as $goods) {
  62. if ($goods['order_no'] === $vo['order_no']) {
  63. $vo['list'][] = $goods;
  64. }
  65. }
  66. }
  67. }
  68. /**
  69. * 用户返利配置
  70. * @auth true
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public function config()
  76. {
  77. $this->skey = 'RebateRule';
  78. $this->title = '用户返利配置';
  79. if ($this->request->isGet()) {
  80. $this->data = sysdata($this->skey);
  81. $this->levels = BaseUserUpgrade::items();
  82. $this->fetch();
  83. } else {
  84. sysdata($this->skey, $this->request->post());
  85. $this->success('奖励修改成功');
  86. }
  87. }
  88. }