| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- /**
- * 代理分页返回封装.
- *
- * @author nj
- * @date 2021-01-23 16:19:51
- */
- namespace Modules\AgentApi\Responses;
- use App\Models\Mongo\UsersModel;
- use App\Models\Mysql\CommissionLogModel;
- use Carbon\Carbon;
- use Illuminate\Contracts\Support\Responsable;
- class AgentPagesResponse implements Responsable
- {
- /**
- * 录入的数据.
- *
- * @var mixed
- */
- private $data = null;
- /**
- * 附加条件参数.
- *
- * @var array
- */
- private $params = [];
- public function __construct($data = null, $params = [])
- {
- $this->data = $data;
- $this->params = $params;
- }
- public function toResponse(
- $request = null
- ) {
- $result = $this->data;
- $startDate = Carbon::parse()->startOfDay()->toDateTimeString();
- $endDate = Carbon::parse()->endOfDay()->toDateTimeString();
- $userModel = new UsersModel();
- $commissionLogModel = new CommissionLogModel();
- if ($this->data->isNotEmpty()) {
- foreach ($result->items() as &$v) {
- //今日抽成
- $v->td_commission_money = $commissionLogModel::whereBetween('date', [$startDate, $endDate])->where('agent_uid', $v['uid'])->sum('commission_money');
- //今日注册(扣量后)
- $v->td_users_total = $userModel::whereBetween('created_at', [toMongoIsoDate($startDate), toMongoIsoDate($endDate)])->where(['is_deduction' => 0, 'agent_uid' => $v['uid']])->count();
- //总抽成
- $v->commission_money = $commissionLogModel::where('agent_uid', $v['uid'])->sum('commission_money');
- //总注册
- $v->users_total = $userModel::where(['is_deduction' => 0, 'agent_uid' => $v['uid']])->count();
- }
- }
- return json_success($result);
- }
- }
|