12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\api\controller;
- use app\model\Customer;
- use app\model\CustomerClue;
- use app\model\CustomerVisitLog;
- use think\facade\Db;
- class CrmWorkbench extends Base
- {
- /**
- * 数据统计
- */
- public function datacount()
- {
- // 日期
- $date = request()->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;
- }
- }
|