AgentPagesCriteria.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * 代理分页查询.
  4. *
  5. * @author nj
  6. * @date 2021-01-23 15:35:04
  7. */
  8. namespace App\Repositories\Criterias;
  9. use Illuminate\Database\Eloquent\Builder;
  10. use KZ2\Laravel\Repositories\Contracts\RepositoryInterface;
  11. use KZ2\Laravel\Repositories\Criteria\Criteria;
  12. class AgentPagesCriteria extends Criteria
  13. {
  14. private $params = [];
  15. public function __construct($params = [])
  16. {
  17. $this->params = $params;
  18. }
  19. /**
  20. * @param Builder $model
  21. * @param RepositoryInterface $repository
  22. * @return mixed|void
  23. */
  24. public function apply(
  25. $model,
  26. RepositoryInterface $repository
  27. ) {
  28. if (!empty($this->params['uid'])) {
  29. $model = $model->where('uid', $this->params['uid']);
  30. }
  31. if (!empty($this->params['agent_uid'])) {
  32. $model = $model->where('uid', $this->params['agent_uid']);
  33. }
  34. if (!empty($this->params['nick'])) {
  35. $model = $model->where('nick', 'LIKE', '%' . $this->params['nick'] . '%');
  36. }
  37. if (!empty($this->params['username'])) {
  38. $model = $model->where('username', 'LIKE', '%' . $this->params['username'] . '%');
  39. }
  40. if (!empty($this->params['manage'])) {
  41. if ($this->params['deduction_switch'] == 2) {
  42. $model = $model->whereIn('deduction_switch', [$this->params['deduction_switch'], 3]);
  43. } elseif ($this->params['deduction_switch'] == 10) {
  44. // 前端自定义查询CPA
  45. $model = $model->where('deduction_switch', 2);
  46. } else {
  47. $model = $model->where('deduction_switch', $this->params['deduction_switch']);
  48. }
  49. }
  50. if (!empty($this->params['parent_uid'])) {
  51. $model = $model->where('parent_uid', $this->params['parent_uid']);
  52. }
  53. if (!empty($this->params['status'])) {
  54. $status = intval($this->params['status']);
  55. $model = $model->where('status', $status);
  56. }
  57. if (!empty($this->params['today_date'])) {
  58. $todayDate = $this->params['today_date'];
  59. $model = $model->with([
  60. 'attrsDay' => function ($query) use ($todayDate) {
  61. $query->where('td_date', $todayDate);
  62. }
  63. ]);
  64. }
  65. if (!empty($this->params['end_date']) && !empty($this->params['start_date'])) {
  66. $endDate = $this->params['end_date'];
  67. $startDate = $this->params['start_date'];
  68. $model = $model->with([
  69. 'everyDay' => function ($query) use ($endDate, $startDate) {
  70. $query->select(
  71. 'agent_uid',
  72. \DB::raw('sum(td_order_success_money) as all_success_money'),
  73. \DB::raw('sum(td_deduction_success_money) as add_deduction_success_money'),
  74. \DB::raw('sum(td_users_total) as all_users_total'),
  75. \DB::raw('sum(td_users_deduction) as add_users_deduction'),
  76. )
  77. ->whereBetween(
  78. 'td_date',
  79. [
  80. $startDate,
  81. $endDate,
  82. ]
  83. )
  84. ->groupBy('agent_uid');
  85. }
  86. ]);
  87. }
  88. // $model = $model->with(['channels'=>function($query){
  89. // $query->select('name','agent_uid','uid');
  90. // }]);
  91. return $model;
  92. }
  93. }