Rebate.php 3.3 KB

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