param('date'); $condition = []; if ($dataCondition = $this->getDate($date, 'addtime')) { $condition[] = $dataCondition; } //设计师、业务员 $field = $this->request->token['org_type'] == 2 ? 'designer_id|employee_id' : 'employee_id'; //查询出属于我的客户 $customer_id = Customer::where($field, $this->request->token['employee_id'])->column('id'); // 确认到店数量统计 $visit = CustomerVisitLog::where(array_merge([CustomerVisitLog::changeState(['state', '=', '确认到店'])], [['customer_id', 'in', $customer_id]], $condition))->count(); // 交定数量统计 $ding = CustomerVisitLog::where(array_merge([CustomerVisitLog::changeState(['state', '=', '交定'])], [['customer_id', 'in', $customer_id]], $condition))->count(); // 签单数量统计 $sign = CustomerVisitLog::where(array_merge([CustomerVisitLog::changeState(['state', '=', '签单'])], [['customer_id', 'in', $customer_id]], $condition))->count(); //客户线索数量统计 $clueCount = CustomerClue::where('employee_id',$this->request->token['employee_id'])->where($condition)->count(); return json(['code' => 0, 'data' => ['visit' => $visit, 'ding' => $ding, 'sign' => $sign, 'clueCount' => $clueCount]]); } /** * 获取查询的时间范围 */ private function getDate($dateType, $column) { switch ($dateType) { case 'today': return [$column, 'between', [date('Y-m-d 00:00:00'), date('Y-m-d 00:00:00', strtotime('tomorrow'))]]; case 'yesterday': return [$column, 'between', [date('Y-m-d 00:00:00', strtotime('yesterday')), date('Y-m-d 00:00:00')]]; case 'serven': return [$column, 'between', [date('Y-m-d 00:00:00', strtotime('6 days ago')), date('Y-m-d 00:00:00', strtotime('tomorrow'))]]; case 'month': return [$column, 'between', [date('Y-m-d 00:00:00', strtotime('previous month')), date('Y-m-d 00:00:00', strtotime('tomorrow'))]]; } return null; } }