AgentPagesResponse.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * 代理分页返回封装.
  4. *
  5. * @author nj
  6. * @date 2021-01-23 16:19:51
  7. */
  8. namespace Modules\AgentApi\Responses;
  9. use App\Models\Mongo\UsersModel;
  10. use App\Models\Mysql\CommissionLogModel;
  11. use Carbon\Carbon;
  12. use Illuminate\Contracts\Support\Responsable;
  13. class AgentPagesResponse implements Responsable
  14. {
  15. /**
  16. * 录入的数据.
  17. *
  18. * @var mixed
  19. */
  20. private $data = null;
  21. /**
  22. * 附加条件参数.
  23. *
  24. * @var array
  25. */
  26. private $params = [];
  27. public function __construct($data = null, $params = [])
  28. {
  29. $this->data = $data;
  30. $this->params = $params;
  31. }
  32. public function toResponse(
  33. $request = null
  34. ) {
  35. $result = $this->data;
  36. $startDate = Carbon::parse()->startOfDay()->toDateTimeString();
  37. $endDate = Carbon::parse()->endOfDay()->toDateTimeString();
  38. $userModel = new UsersModel();
  39. $commissionLogModel = new CommissionLogModel();
  40. if ($this->data->isNotEmpty()) {
  41. foreach ($result->items() as &$v) {
  42. //今日抽成
  43. $v->td_commission_money = $commissionLogModel::whereBetween('date', [$startDate, $endDate])->where('agent_uid', $v['uid'])->sum('commission_money');
  44. //今日注册(扣量后)
  45. $v->td_users_total = $userModel::whereBetween('created_at', [toMongoIsoDate($startDate), toMongoIsoDate($endDate)])->where(['is_deduction' => 0, 'agent_uid' => $v['uid']])->count();
  46. //总抽成
  47. $v->commission_money = $commissionLogModel::where('agent_uid', $v['uid'])->sum('commission_money');
  48. //总注册
  49. $v->users_total = $userModel::where(['is_deduction' => 0, 'agent_uid' => $v['uid']])->count();
  50. }
  51. }
  52. return json_success($result);
  53. }
  54. }