1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285 |
- <?php
- declare(strict_types=1);
- namespace app\empcrm\controller;
- use app\model\Company;
- use app\model\Customer;
- use app\model\CustomerDropPool;
- use app\model\CustomerExtension;
- use app\model\CustomerInvalidLog;
- use app\model\CustomerRecycle;
- use app\model\CustomerSource;
- use app\model\CustomerStateCheck;
- use app\model\CustomerVisitLog;
- use app\model\Employee;
- use app\model\FishCampaign;
- use app\model\FishData;
- use app\model\Org;
- use think\facade\Db;
- use think\facade\View;
- class Statistics2
- {
- private $employee;
- private $root_id;
- private $loginEmployeeOrg;
- private $searchOrg;
- private $saleOrg;
- private $designerOrg;
- private $designerList;
- private $request;
- private $param;
- private $searchEmployee;
- private $searchDesigner;
- public function __construct()
- {
- $this->request = request();
- $this->employee = $this->request->empcrm;
- $this->root_id = $this->request->empcrm->root_id;
- $orgId = $this->request->param('org_id');
- if (empty($orgId)) $orgId = $this->employee->org_id;
- $this->loginEmployeeOrg = Org::where([['id', '=', $orgId], ['path', 'like', $this->root_id . '-%']])->find();
- if (empty($this->loginEmployeeOrg)) abort(404, '页面异常');
- $this->searchOrg = Org::where([['path', 'like', $this->root_id . '-%']])->column('id');
- // 时间设置
- $start = '2020-01-01';
- $end = date('Y-m-d');
- $date = $this->request->param('date');
- empty($date) ?: list($start, $end) = explode(' - ', $date);
- $param['start'] = date('Y-m-d 00:00:00', strtotime($start));
- $param['end'] = date('Y-m-d 00:00:00', strtotime($end) + 86400);
- $this->param = $param;
- }
- /**
- * 渠道统计
- */
- public function source()
- {
- if (!$this->request->isAjax()) {
- $data = CustomerSource::where([
- ['root_id', '=', $this->root_id]
- ])->column('id as value,source as name');
- view::assign('source', $data);
- View::assign('org', $this->org());
- return View::fetch();
- }
- $sourceIdList = $this->request->param('source');
- $condition = [['root_id', '=', $this->root_id]];
- if (!empty($sourceIdList)) $condition[] = ['id', 'in', $sourceIdList];
- // 渠道查询
- $data = CustomerSource::where($condition)->column('id,source');
- $count = count($data);
- // 投放记录获取
- $this->searchOrg = Org::where([['path', 'like', $this->loginEmployeeOrg->path . '%']])->column('id');
- $putIn = CustomerExtension::with('source')->where([
- ['root_id', '>=', $this->root_id],
- ['org_id', 'in', $this->searchOrg],
- ['addtime', '>=', $this->param['start']],
- ['addtime', '<=', $this->param['end']],
- ])->group('source_id')->column('sum(money) as money', 'source_id');
- // 线索量获取
- $clue = $this->sourceClue();
- // 飞鱼线索获取
- $fishclue = $this->fish('source');
- // 有效线索
- $valid = $this->sourceValid();
- // 见面量
- $meet = $this->sourceMeet();
- // 定金量
- $deposit = $this->sourceDeposit();
- // 合同量/合同金额
- $sign = $this->customer('sign');
- // 数据合并
- $this->dealData($data, $putIn, 'money');
- $this->dealData($data, $clue, 'clue');
- $this->dealData($data, $valid, 'valid');
- $this->dealData($data, $meet, 'meet');
- $this->dealData($data, $deposit, 'deposit');
- $this->dealData($data, $sign, ['sign', 'sign_money']);
- foreach ($data as &$item) {
- if (!in_array($item['source'], ['飞鱼线索', '腾讯线索', '欧派线索'])) continue;
- foreach ($fishclue as $f => $n) {
- if (($f == 1 || $f == 4) && $item['source'] == '飞鱼线索') {
- $item['clue'] += $n;
- continue;
- } elseif ($f == 2 && $item['source'] == '腾讯线索') {
- $item['clue'] += $n;
- break;
- } elseif ($f == 3 && $item['source'] == '欧派线索') {
- $item['clue'] += $n;
- break;
- }
- }
- }
- $this->dealRowData($data, [
- 'clue_money' => ['division' => 'money/clue', '*' => 0, 'islv' => 0],
- 'valid_money' => ['division' => 'money/valid', '*' => 0, 'islv' => 0],
- 'valid_percen' => ['division' => 'valid/clue', '*' => 100, 'islv' => 1],
- 'meet_percen' => ['division' => 'meet/valid', '*' => 100, 'islv' => 1],
- 'grant' => ['division' => 'meet/clue', '*' => 100, 'islv' => 1],
- 'meet_money' => ['division' => 'money/meet', '*' => 0, 'islv' => 0],
- 'deposit_percen' => ['division' => 'deposit/meet', '*' => 100, 'islv' => 1],
- 'sign_agv_money' => ['division' => 'sign_money/sign', '*' => 0, 'islv' => 0],
- 'ROI' => ['division' => 'money/sign_money', '*' => 100, 'islv' => 0, 'lv' => 0],
- ], ['source' => '求和']);
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /**
- * 销售/客服统计
- */
- public function sale()
- {
- View::assign('org', $this->org());
- if (!$this->request->isAjax()) return View::fetch();
- $this->saleOrg = Org::where([['path', 'like', $this->loginEmployeeOrg->path . '%'], ['org_type', '=', 1]])->column('id');
- // 获取员工列表和员工数
- $data = Employee::where([
- ['root_id', '=', $this->root_id],
- ['org_id', 'in', $this->saleOrg],
- ['state', '=', '在职'],
- ['verified', '=', 1],
- ['uid', '<>', 0]
- ])->column('id,name');
- $count = count($data);
- if ($count == 0) return json(['code' => 0, 'data' => $data, 'count' => $count]);
- // 线索量
- $clue = $this->employeeClue();
- // 飞鱼线索获取
- $fishclue = $this->fish('employee');
- // 有效量
- $valid = $this->employeeValid();
- // 待确认
- $toBeConfirmed = $this->employeeToBeConfirmed();
- // 见面量
- $meet = $this->employeeMeet();
- // 定金量
- $deposit = $this->employeeDeposit();
- // 合同量
- $sign = $this->customer('employee_sign');
- $this->dealData($data, $clue, 'clue');
- $this->dealData($data, $valid, 'valid');
- $this->dealData($data, $toBeConfirmed, 'to_be_confirmed');
- $this->dealData($data, $meet, 'meet');
- $this->dealData($data, $deposit, 'deposit');
- $this->dealData($data, $sign, ['sign', 'sign_money']);
- $validState = CustomerStateCheck::where([
- ['root_id', '=', $this->root_id],
- ['org_id', 'in', $this->saleOrg],
- ['check_state', '=', 1]
- ])->column('count(*) as num', 'employee_id');
- foreach ($data as &$item) {
- if (isset($fishclue[$item['id']])) $item['clue'] += $fishclue[$item['id']];
- $item['valid_check_num'] = $validState[$item['id']] ?? 0;
- }
- $this->dealRowData($data, [
- 'valid_percen' => ['division' => 'valid/clue', '*' => 100, 'islv' => 1],
- 'meet_percen' => ['division' => 'meet/valid', '*' => 100, 'islv' => 1],
- 'grant' => ['division' => 'meet/clue', '*' => 100, 'islv' => 1],
- 'deposit_percen' => ['division' => 'deposit/meet', '*' => 100, 'islv' => 1]
- ], ['name' => '求和']);
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /**
- * 设计师统计
- */
- public function designer()
- {
- if (!$this->request->isAjax()) {
- View::assign('org', $this->org());
- return View::fetch();
- }
- $this->designerOrg = Org::where([['path', 'like', $this->loginEmployeeOrg->path . '%'], ['org_type', '=', 2]])->column('id');
- $data = Employee::where([
- ['root_id', '=', $this->root_id],
- ['org_id', 'in', $this->designerOrg],
- ['state', '=', '在职'],
- ['verified', '=', 1],
- ['uid', '<>', 0]
- ])->column('id,name');
- $this->designerList = array_column($data, 'id');
- // 获取员工列表和员工数
- $count = count($data);
- if ($count == 0) return json(['code' => 0, 'data' => $data, 'count' => $count]);
- // 见面量
- $meet = $this->designerMeet();
- // 定金量
- $deposit = $this->designerDeposit();
- // 合同量/业绩总额
- $sign = $this->customer('designer_sign');
- $this->dealData($data, $meet, 'meet');
- $this->dealData($data, $deposit, 'deposit');
- $this->dealData($data, $sign, ['sign', 'sign_money']);
- $this->dealRowData($data, [
- 'deposit_percen' => ['division' => 'deposit/meet', '*' => 100, 'islv' => 1]
- ], ['name' => '求和']);
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /**
- * 设计师部门统计
- */
- public function designerDepartment()
- {
- if (!$this->request->isAjax()) return View::fetch();
- $this->designerOrg = Org::where([['path', 'like', $this->loginEmployeeOrg->path . '%'], ['org_type', '=', 2]])->column('id');
- $data = Employee::where([
- ['root_id', '=', $this->root_id],
- ['org_id', 'in', $this->designerOrg],
- ['state', '=', '在职'],
- ['verified', '=', 1],
- ['uid', '<>', 0]
- ])->column('id,org_id');
- $this->designerList = array_column($data, 'id');
- // 获取员工列表和员工数
- if (count($data) == 0) return json(['code' => 0, 'data' => $data, 'count' => 0]);
- // 见面量
- $meet = $this->designerMeet();
- // 定金量
- $deposit = $this->designerDeposit();
- // 合同量/业绩总额
- $sign = $this->customer('designer_sign');
- $this->dealData($data, $meet, 'meet');
- $this->dealData($data, $deposit, 'deposit');
- $this->dealData($data, $sign, ['sign', 'sign_money']);
- $departmentData = Org::where([['path', 'like', $this->loginEmployeeOrg->path . '%'], ['org_type', '=', 2]])->column('id,name');
- $dealData = [];
- foreach ($data as $designer) {
- if (!isset($dealData[$designer['org_id']])) $dealData[$designer['org_id']] = ['meet' => 0, 'deposit' => 0, 'sign' => 0, 'sign_money' => 0];
- $dealData[$designer['org_id']]['meet'] += $designer['meet'];
- $dealData[$designer['org_id']]['deposit'] += $designer['deposit'];
- $dealData[$designer['org_id']]['sign'] += $designer['sign'];
- $dealData[$designer['org_id']]['sign_money'] += $designer['sign_money'];
- }
- foreach ($departmentData as $k => $depart) {
- if (isset($dealData[$depart['id']])) {
- $departmentData[$k]['meet'] = $dealData[$depart['id']]['meet'];
- $departmentData[$k]['deposit'] = $dealData[$depart['id']]['deposit'];
- $departmentData[$k]['sign'] = $dealData[$depart['id']]['sign'];
- $departmentData[$k]['sign_money'] = $dealData[$depart['id']]['sign_money'];
- } else {
- $departmentData[$k] = array_merge($depart, ['meet' => 0, 'deposit' => 0, 'sign' => 0, 'sign_money' => 0]);
- }
- }
- $count = count($departmentData);
- $this->dealRowData($departmentData, [
- 'deposit_percen' => ['division' => 'deposit/meet', '*' => 100, 'islv' => 1]
- ], ['name' => '求和']);
- return json(['code' => 0, 'data' => $departmentData, 'count' => $count]);
- }
- /**
- * 飞鱼线索统计
- */
- private function fish($type)
- {
- $data = [];
- switch ($type) {
- case 'source':
- $data = FishData::where([
- ['org_id', 'in', $this->searchOrg],
- ['is_allocation', '=', 0],
- ['create_time_detail', '>=', $this->param['start']],
- ['create_time_detail', '<', $this->param['end']]
- ])->group('type')->column('count(id) as num', 'type');
- break;
- case 'employee':
- $data = FishData::where([
- ['org_id', 'in', $this->saleOrg],
- ['is_allocation', '=', 0],
- ['create_time_detail', '>=', $this->param['start']],
- ['create_time_detail', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- break;
- }
- return $data;
- }
- /**
- * 投放数据获取
- */
- private function putin($type, $adid)
- {
- $data = [];
- switch ($type) {
- case 'money': // 投放金额
- $data = FishCampaign::where([
- ['advertiser_id', 'in', $adid],
- ['data_time', '>=', $this->param['start']],
- ['data_time', '<', $this->param['end']]
- ])->group('advertiser_id')->column('sum(`cost`) as exten_money', 'advertiser_id');
- break;
- case 'clue': // 线索量
- $data = FishData::where([
- ['advertiser_id', 'in', $adid],
- ['create_time', '>=', $this->param['start']],
- ['create_time', '<', $this->param['end']]
- ])->column('count(*) as clue_num', 'advertiser_id');
- break;
- case 'valid': // 有效量
- $data = Customer::alias('customer')->join('fish_data fish', 'customer.id=fish.customer_id')
- ->where([
- ['fish.advertiser_id', 'in', $adid],
- ['fish.create_time', '>=', $this->param['start']],
- ['fish.create_time', '<', $this->param['end']],
- ['customer.source_id', 'NOTNULL', ''],
- ['customer.source_id', '<>', 0],
- ['customer.valid_time', 'NOTNULL', '']
- ])->column('count(*) as valid_num', 'fish.advertiser_id');
- break;
- case 'meet':
- $logQuery = CustomerVisitLog::alias('customer_visit_log')->join('fish_data fish', 'customer_visit_log.customer_id=fish.customer_id')
- ->where([
- ['fish.advertiser_id', 'in', $adid],
- ['fish.create_time', '>=', $this->param['start']],
- ['fish.create_time', '<', $this->param['end']],
- ['customer_visit_log.state', 'in', [2, 3, 7, 8, 9]],
- ])->group('customer_visit_log.customer_id')->fetchSql(true)->column('customer_visit_log.customer_id as id, fish.advertiser_id');
- $data = Db::table('(' . $logQuery . ') a')
- ->group('advertiser_id')->column('count(id) as meet_num', 'advertiser_id');
- break;
- case 'deposit':
- $logQuery = CustomerVisitLog::alias('customer_visit_log')->join('fish_data fish', 'customer_visit_log.customer_id=fish.customer_id')
- ->where([
- ['fish.advertiser_id', 'in', $adid],
- ['fish.create_time', '>=', $this->param['start']],
- ['fish.create_time', '<', $this->param['end']],
- ['customer_visit_log.state', 'in', [2, 3]],
- ])->group('customer_visit_log.customer_id')->fetchSql(true)->column('customer_visit_log.customer_id as id, fish.advertiser_id');
- $data = Db::table('(' . $logQuery . ') a')
- ->group('advertiser_id')->column('count(id) as meet_num', 'advertiser_id');
- break;
- case 'sign':
- $logQuery = CustomerVisitLog::alias('customer_visit_log')
- ->join('fish_data fish', 'customer_visit_log.customer_id=fish.customer_id')
- ->join('customer customer', 'customer.id=customer_visit_log.customer_id')
- ->where([
- ['fish.advertiser_id', 'in', $adid],
- ['fish.create_time', '>=', $this->param['start']],
- ['fish.create_time', '<', $this->param['end']],
- ['customer_visit_log.state', 'in', [3]],
- ])->group('customer_visit_log.customer_id')->fetchSql(true)->column('customer_visit_log.customer_id as id, fish.advertiser_id, customer.signed_money');
- $data = Db::table('(' . $logQuery . ') a')
- ->group('advertiser_id')->column('count(id) as meet_num, sum(signed_money) as signed_money', 'advertiser_id');
- break;
- }
- return $data;
- }
- /**
- * 线索量(按来源)
- */
- private function sourceClue()
- {
- $data = [];
- $this->merge($data, $this->customer('clue'));
- // 回收站表线索统计
- $this->merge($data, $this->customerRecycle('clue'));
- // 自动回收表线索统计
- $this->merge($data, $this->customerDropPool('clue'));
- return $data;
- }
- /**
- * 有效量(按来源)
- */
- private function sourceValid()
- {
- //客户有效统计
- $data = $this->customer('valid');
- // 回收站表线索统计
- $rdata = $this->customerRecycle('valid');
- $this->merge($data, $rdata);
- // 自动回收表线索统计
- $ddata = $this->customerDropPool('valid');
- $this->merge($data, $ddata);
- return $data;
- }
- /**
- * 见面量(按来源)
- */
- private function sourceMeet()
- {
- $data = [];
- $this->merge($data, $this->customer('meet'));
- $this->merge($data, $this->customerRecycle('meet'));
- $this->merge($data, $this->customerDropPool('meet'));
- return $data;
- }
- /**
- * 定金量(按来源)
- */
- private function sourceDeposit()
- {
- $data = [];
- $this->merge($data, $this->customer('deposit'));
- $this->merge($data, $this->customerRecycle('deposit'));
- $this->merge($data, $this->customerDropPool('deposit'));
- return $data;
- }
- /**
- * 线索量(按员工)
- */
- private function employeeClue()
- {
- $data = [];
- // 客户表线索统计
- $cdata = $this->customer('employee_clue');
- $this->merge($data, $cdata);
- // 客户无效表(获取无效时,客户所属员工)
- $iData = $this->customerRecycle('employee_clue');
- $this->merge($data, $iData);
- // 自动回收表线索统计
- $ddata = $this->customerDropPool('employee_clue');
- $this->merge($data, $ddata);
- return $data;
- }
- /**
- * 待确认
- */
- private function employeeToBeConfirmed()
- {
- $data = [];
- // 客户表待确认统计
- $this->merge($data, $this->customer("employee_to_be_confirmed"));
- // 客户回收表待确认统计
- $this->merge($data, $this->customerDropPool("employee_to_be_confirmed"));
- return $data;
- }
- /**
- * 有效量
- */
- private function employeeValid()
- {
- //客户有效统计
- $data = $this->customer('employee_valid');
- // 回收站表线索统计
- $rdata = $this->customerRecycle('employee_valid');
- $this->merge($data, $rdata);
- // 自动回收表线索统计
- $ddata = $this->customerDropPool('employee_valid');
- $this->merge($data, $ddata);
- return $data;
- }
- /**
- * 见面量
- */
- private function employeeMeet()
- {
- $data = [];
- $this->merge($data, $this->customer('employee_meet'));
- $this->merge($data, $this->customerRecycle('employee_meet'));
- $this->merge($data, $this->customerDropPool('employee_meet'));
- return $data;
- }
- /**
- * 定金量
- */
- private function employeeDeposit()
- {
- $data = [];
- $this->merge($data, $this->customer('employee_deposit'));
- $this->merge($data, $this->customerRecycle('employee_deposit'));
- $this->merge($data, $this->customerDropPool('employee_deposit'));
- return $data;
- }
- /**
- * 见面量(设计师)
- */
- private function designerMeet()
- {
- $data = [];
- $this->merge($data, $this->customer('designer_meet'));
- $this->merge($data, $this->customerDropPool('designer_meet'));
- return $data;
- }
- /**
- * 定金量(设计师)
- */
- private function designerDeposit()
- {
- $data = [];
- $this->merge($data, $this->customer('designer_deposit'));
- $this->merge($data, $this->customerDropPool('designer_deposit'));
- return $data;
- }
- /**
- * customer表查询
- */
- private function customer($type)
- {
- $data = [];
- switch ($type) {
- case 'clue':
- // 客户表线索统计
- $data = Customer::where([
- ['org_id', 'in', $this->searchOrg],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']],
- ['source_id', 'NOTNULL', ''],
- ['source_id', '<>', 0]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_clue':
- $data = Customer::where([
- ['org_id', 'in', $this->saleOrg],
- ['employee_id', 'NOTNULL', ''],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- $start = $this->param['start'];
- $end = $this->param['end'];
- $saleOrg = $this->saleOrg;
- $data1 = CustomerInvalidLog::where([['id', 'in', function ($query) use ($start, $end, $saleOrg) {
- $query->name('customer_invalid_log')->where('customer_id', 'in', function ($query) use ($start, $end, $saleOrg) {
- $query->name('Customer')->where([
- ['org_id', 'in', $saleOrg],
- ['employee_id', 'NULL', ''],
- ['sign_time', '>=', $start],
- ['sign_time', '<', $end]
- ])->field('id');
- })->group('customer_id')->field('max(id)');
- }]])->group('employee_id')->column('count(id) as num', 'employee_id');
- foreach ($data1 as $k => $n) {
- if (isset($data[$k])) $data[$k] += $n;
- else $data[$k] = $n;
- }
- break;
- case 'employee_to_be_confirmed':
- $data = Customer::where([
- ['org_id', 'in', $this->saleOrg],
- ['employee_id', 'NOTNULL', ''],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']],
- ['state', '=', 0]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- break;
- case 'valid':
- $data = Customer::where([
- ['org_id', 'in', $this->searchOrg],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']],
- ['source_id', 'NOTNULL', ''],
- ['source_id', '<>', 0],
- ['valid_time', 'NOTNULL', '']
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_valid':
- $data = Customer::where([
- ['org_id', 'in', $this->saleOrg],
- ['valid_time', '>=', $this->param['start']],
- ['valid_time', '<', $this->param['end']],
- ['employee_id', 'NOTNULL', '']
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- $customerIdList = Customer::where([
- ['org_id', 'in', $this->saleOrg],
- ['employee_id', 'NULL', ''],
- ['valid_time', '>=', $this->param['start']],
- ['valid_time', '<', $this->param['end']]
- ])->group('id')->column('id');
- $lastLogId = CustomerInvalidLog::where([['customer_id', 'in', $customerIdList]])->group('customer_id')->column('max(id)');
- $data1 = CustomerInvalidLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'employee_id');
- foreach ($data1 as $k => $n) {
- if (isset($data[$k])) $data[$k] += $n;
- else $data[$k] = $n;
- }
- break;
- case 'meet':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', 'in', [2, 3, 7, 8, 9]],
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.source_id as source_id, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case "employee_meet":
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['customer_visit_log.state', 'in', [2, 3, 7, 8, 9]],
- ['customer.employee_id', 'NOTNULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.employee_id as employee_id, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- $logQuery1 = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['customer_visit_log.state', 'in', [2, 3, 7, 8, 9]],
- ['customer.employee_id', 'NULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, min(customer_visit_log.confirm_date) as first_meet_time');
- $customerIdList = Db::table('(' . $logQuery1 . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->fetchSql(true)->column('id');
- $lastLogId = CustomerInvalidLog::where([['customer_id', 'in', $customerIdList]])->fetchSql(true)->group('customer_id')->column('max(id)');
- $data1 = CustomerInvalidLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'employee_id');
- foreach ($data1 as $k => $n) {
- if (isset($data[$k])) $data[$k] += $n;
- else $data[$k] = $n;
- }
- break;
- case "designer_meet":
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', 'in', [2, 3, 7, 8, 9]],
- ['customer.designer_id', 'NOTNULL', ''],
- ['customer.designer_id', 'in', $this->designerList]
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.designer_id as employee_id, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- $logQuery1 = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', 'in', [2, 3, 7, 8, 9]],
- ['customer.employee_id', 'NULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, min(customer_visit_log.confirm_date) as first_meet_time');
- $customerIdList = Db::table('(' . $logQuery1 . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->fetchSql(true)->column('id');
- $lastLogId = CustomerInvalidLog::where([['customer_id', 'in', $customerIdList]])->group('customer_id')->column('max(id)');
- $data1 = CustomerInvalidLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'designer_id');
- foreach ($data1 as $k => $n) {
- if (isset($data[$k])) $data[$k] += $n;
- else $data[$k] = $n;
- }
- break;
- case 'deposit':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', 'in', [2, 3]],
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.source_id as source_id, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_deposit':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['customer_visit_log.state', 'in', [2, 3]],
- ['customer.employee_id', 'NOTNULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.employee_id as employee_id, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- $logQuery1 = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['customer_visit_log.state', 'in', [2, 3]],
- ['customer.employee_id', 'NULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, min(customer_visit_log.confirm_date) as first_meet_time');
- $customerIdList = Db::table('(' . $logQuery1 . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->fetchSql(true)->column('id');
- $lastLogId = CustomerInvalidLog::where([['customer_id', 'in', $customerIdList]])->fetchSql(true)->group('customer_id')->column('max(id)');
- $data1 = CustomerInvalidLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'employee_id');
- foreach ($data1 as $k => $n) {
- if (isset($data[$k])) $data[$k] += $n;
- else $data[$k] = $n;
- }
- break;
- case 'designer_deposit':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', 'in', [2, 3]],
- ['customer.designer_id', 'NOTNULL', ''],
- ['customer.designer_id', 'in', $this->designerList]
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.designer_id as employee_id, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- $logQuery1 = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', 'in', [2, 3]],
- ['customer.employee_id', 'NULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, min(customer_visit_log.confirm_date) as first_meet_time');
- $customerIdList = Db::table('(' . $logQuery1 . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->fetchSql(true)->column('id');
- $lastLogId = CustomerInvalidLog::where([['customer_id', 'in', $customerIdList]])->fetchSql(true)->group('customer_id')->column('max(id)');
- $data1 = CustomerInvalidLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'designer_id');
- foreach ($data1 as $k => $n) {
- if (isset($data[$k])) $data[$k] += $n;
- else $data[$k] = $n;
- }
- break;
- case 'sign':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', '=', 3],
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.source_id as source_id, customer.signed_money as signed_money, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as sign, sum(signed_money) as sign_money', 'source_id');
- break;
- case 'employee_sign':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['customer_visit_log.state', '=', 3],
- ['customer.employee_id', 'NOTNULL', '']
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.employee_id as employee_id, customer.signed_money as signed_money, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as sign, sum(signed_money) as sign_money', 'employee_id');
- break;
- case 'designer_sign':
- $logQuery = CustomerVisitLog::withJoin('customer')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['customer_visit_log.state', '=', 3],
- ['customer.designer_id', 'NOTNULL', ''],
- ['customer.designer_id', 'in', $this->designerList]
- ])->group('customer.id')->fetchSql(true)->column('customer.id as id, customer.designer_id as employee_id, customer.signed_money as signed_money, min(customer_visit_log.confirm_date) as first_meet_time');
- $data = Db::table('(' . $logQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as sign, sum(signed_money) as sign_money', 'employee_id');
- break;
- }
- return $data;
- }
- /**
- * customer表查询
- */
- private function customerRecycle($type)
- {
- $data = [];
- switch ($type) {
- case 'clue':
- // 客户表线索统计
- $data = CustomerRecycle::where([
- ['org_id', 'in', $this->searchOrg],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']],
- ['source_id', 'NOTNULL', ''],
- ['source_id', '<>', 0]
- ])->group("source_id")->column('count(id) as num', "source_id");
- break;
- case 'employee_clue':
- $customerIdList = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_recycle customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['log.customer_employee_id', '<>', 0],
- ['customer.sign_time', '>=', $this->param['start']],
- ['customer.sign_time', '<', $this->param['end']]
- ])
- ->group('log.customer_id')
- ->column('log.customer_id');
- if (empty($customerIdList)) {
- $data = [];
- break;
- }
- $lastLogId = CustomerVisitLog::where([['customer_id', 'in', $customerIdList], ['customer_employee_id', '<>', 0]])->group('customer_id')->column('max(id)');
- $data = CustomerVisitLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'customer_employee_id');
- break;
- case 'valid':
- $data = CustomerRecycle::where([
- ['org_id', 'in', $this->searchOrg],
- ['valid_time', '>=', $this->param['start']],
- ['valid_time', '<', $this->param['end']],
- ['source_id', 'NOTNULL', ''],
- ['source_id', '<>', 0]
- ])->group("source_id")->column('count(id) as num', "source_id");
- break;
- case 'employee_valid':
- $customerIdList = CustomerRecycle::where([
- ['org_id', 'in', $this->saleOrg],
- ['valid_time', '>=', $this->param['start']],
- ['valid_time', '<', $this->param['end']]
- ])->column('customer_id');
- if (empty($customerIdList)) {
- $data = [];
- break;
- }
- $lastLogId = CustomerVisitLog::where([['customer_id', 'in', $customerIdList], ['customer_employee_id', '<>', 0]])->group('customer_id')->column('max(id)');
- $data = CustomerVisitLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'customer_employee_id');
- break;
- case 'meet':
- $recycleQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_recycle customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['log.state', 'in', [2, 3, 7, 8, 9]],
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.source_id as source_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($recycleQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_meet':
- $recycleQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_recycle customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['log.state', 'in', [2, 3, 7, 8, 9]],
- ['log.customer_employee_id', '<>', 0]
- ])
- ->group('log.customer_id')
- ->fetchSql(true)
- ->column('log.customer_id as id, min(log.confirm_date) as first_meet_time');
- $customerIdList = Db::table('(' . $recycleQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->column('id');
- if (empty($customerIdList)) {
- $data = [];
- break;
- }
- $lastLogId = CustomerVisitLog::where([['customer_id', 'in', $customerIdList], ['customer_employee_id', '<>', 0]])->group('customer_id')->column('max(id)');
- $data = CustomerVisitLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'customer_employee_id');
- break;
- case 'deposit':
- $recycleQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_recycle customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['log.state', 'in', [2, 3]],
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.source_id as source_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($recycleQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_deposit':
- $recycleQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_recycle customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['log.state', 'in', [2, 3]],
- ['log.customer_employee_id', '<>', 0]
- ])
- ->group('log.customer_id')
- ->fetchSql(true)
- ->column('log.customer_id as id, min(log.confirm_date) as first_meet_time');
- $customerIdList = Db::table('(' . $recycleQuery . ') a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->column('id');
- if (empty($customerIdList)) {
- $data = [];
- break;
- }
- $lastLogId = CustomerVisitLog::where([['customer_id', 'in', $customerIdList], ['customer_employee_id', '<>', 0]])->group('customer_id')->column('max(id)');
- $data = CustomerVisitLog::where([['id', 'in', $lastLogId]])->group('employee_id')->column('count(id) as num', 'customer_employee_id');
- break;
- }
- return $data;
- }
- /**
- * customer表查询
- */
- private function customerDropPool($type)
- {
- $data = [];
- switch ($type) {
- case 'clue':
- // 客户表线索统计
- $data = CustomerDropPool::where([
- ['org_id', 'in', $this->searchOrg],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']],
- ['source_id', 'NOTNULL', ''],
- ['source_id', '<>', 0]
- ])->group("source_id")->column('count(id) as num', "source_id");
- break;
- case 'employee_clue':
- $data = CustomerDropPool::where([
- ['org_id', 'in', $this->saleOrg],
- ['employee_id', 'NOTNULL', ''],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']]
- ])->group("employee_id")->column('count(id) as num', "employee_id");
- break;
- case 'employee_to_be_confirmed':
- $data = CustomerDropPool::where([
- ['org_id', 'in', $this->saleOrg],
- ['employee_id', 'NOTNULL', ''],
- ['sign_time', '>=', $this->param['start']],
- ['sign_time', '<', $this->param['end']],
- ['state', '=', 0]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- case 'valid':
- $data = CustomerDropPool::where([
- ['org_id', 'in', $this->searchOrg],
- ['valid_time', '>=', $this->param['start']],
- ['valid_time', '<', $this->param['end']],
- ['source_id', 'NOTNULL', ''],
- ['source_id', '<>', 0]
- ])->group("source_id")->column('count(id) as num', "source_id");
- break;
- case 'employee_valid':
- $data = CustomerDropPool::where([
- ['org_id', 'in', $this->saleOrg],
- ['valid_time', '>=', $this->param['start']],
- ['valid_time', '<', $this->param['end']],
- ['employee_id', 'NOTNULL', '']
- ])->group("employee_id")->column('count(id) as num', "employee_id");
- break;
- case 'meet':
- $poolQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_drop_pool customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['log.state', 'in', [2, 3, 7, 8, 9]],
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.source_id as source_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($poolQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_meet':
- $poolQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_drop_pool customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['log.state', 'in', [2, 3, 7, 8, 9]],
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.employee_id as employee_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($poolQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- break;
- case 'designer_meet':
- $poolQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_drop_pool customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['log.state', 'in', [2, 3, 7, 8, 9]],
- ['customer.designer_id', 'NOTNULL', ''],
- ['customer.designer_id', 'in', $this->designerList]
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.designer_id as employee_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($poolQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- break;
- case 'deposit':
- $poolQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_drop_pool customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['log.state', 'in', [2, 3]],
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.source_id as source_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($poolQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('source_id')->column('count(id) as num', 'source_id');
- break;
- case 'employee_deposit':
- $poolQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_drop_pool customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->saleOrg],
- ['log.state', 'in', [2, 3]],
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.employee_id as employee_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($poolQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- break;
- case 'designer_deposit':
- $poolQuery = Db::name('customer_visit_log')
- ->alias('log')
- ->join('customer_drop_pool customer', 'log.customer_id = customer.customer_id')
- ->where([
- ['customer.org_id', 'in', $this->searchOrg],
- ['log.state', 'in', [2, 3]],
- ['customer.designer_id', 'NOTNULL', ''],
- ['customer.designer_id', 'in', $this->designerList]
- ])
- ->group('log.customer_id')
- ->field('log.customer_id as id, customer.designer_id as employee_id, min(log.confirm_date) as first_meet_time')
- ->BuildSql();
- $data = Db::table($poolQuery . ' a')
- ->where([
- ['first_meet_time', '>=', $this->param['start']],
- ['first_meet_time', '<', $this->param['end']]
- ])->group('employee_id')->column('count(id) as num', 'employee_id');
- break;
- }
- return $data;
- }
- /**
- * 数据合并
- */
- private function merge(&$data, $mergeData)
- {
- foreach ($mergeData as $k => $num) {
- if (isset($data[$k])) {
- $data[$k] += $num;
- } else {
- $data[$k] = $num;
- }
- }
- }
- /**
- * 数据处理
- */
- private function dealData(&$data, $mergeData, $kname, $searchK = 'id')
- {
- foreach ($data as &$d) {
- if (is_array($kname)) {
- foreach ($kname as $name) {
- if (isset($mergeData[$d[$searchK]])) {
- $d[$name] = floatval($mergeData[$d[$searchK]][$name]);
- } else {
- $d[$name] = 0;
- }
- }
- } else {
- if (isset($mergeData[$d[$searchK]])) {
- $d[$kname] = floatval($mergeData[$d[$searchK]]);
- } else {
- $d[$kname] = 0;
- }
- }
- }
- }
- /**
- * 除法
- */
- private function division($divisor, $dividend, $lv = true)
- {
- if (is_string($divisor)) $divisor = floatval($divisor);
- if (is_string($dividend)) $dividend = floatval($dividend);
- if ($dividend == 0) {
- if ($divisor == 0) return 0;
- return $lv ? $divisor : 0;
- }
- $lv ? $w = 4 : $w = 2;
- return floatval(round($divisor / $dividend, $w));
- }
- /**
- * 数据计算
- */
- private function dealRowData(&$data, $suan, $totalRow)
- {
- $excludeKey = array_keys($totalRow);
- foreach ($data as $row) {
- foreach ($row as $k => $col) {
- if (in_array($k, $excludeKey)) continue;
- if ($k == 'id') continue;
- if (!isset($totalRow[$k])) $totalRow[$k] = 0;
- $totalRow[$k] += $col;
- }
- }
- $data[] = $totalRow;
- foreach ($data as $k => $item) {
- foreach ($suan as $column => $s) {
- list($divisor, $dividend) = explode('/', $s['division']);
- isset($s['lv']) ? $lv = $s['lv'] : $lv = true;
- $rs = $this->division($item[$divisor], $item[$dividend], $lv);
- $s['*'] == 0 ?: $rs = $rs * $s['*'];
- $s['islv'] != 1 ?: $rs = $rs . '%';
- $data[$k][$column] = $rs;
- }
- }
- }
- /**
- * 部门获取
- */
- private function org()
- {
- $data = Org::where([['id', 'in', $this->searchOrg], ['pid', '<>', 0]])->field('id,name,pid')->order('pid,id')->select();
- return $data;
- }
- }
|