SupplierStatisticsService.php
3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace App\Http\Services;
use App\Http\Controllers\Filter\SupplierFilter;
use App\Model\RedisModel;
use App\Model\SupplierChannelModel;
use Illuminate\Support\Facades\DB;
class SupplierStatisticsService
{
//获取供应商列表需要统计的信息
public function getSupplierListStatistics()
{
$statisticsKey = 'supplier_list_statistics_' . request()->user->userId;
$redis = new RedisModel();
$result = json_decode($redis->get($statisticsKey), true);
if ($result) {
return $result;
}
$total = $this->getStatisticsCount('all');
//待复审
$needReview = $this->getStatisticsCount('need_review');
//待审核
$pending = $this->getStatisticsCount('pending');
//审核中
$inReview = $this->getStatisticsCount('in_review');
//通过
$passed = $this->getStatisticsCount('passed');
//未通过
$rejected = $this->getStatisticsCount('rejected');
//禁用
$disable = $this->getStatisticsCount('disable');
//没有渠道开发员
$noPurchaseUid = $this->getStatisticsCount('no_purchase_uid');
//没有采购
$noChannelUid = $this->getStatisticsCount('no_channel_uid');
//存在无效(离职)采购员
$invalidChannelUid = $this->getStatisticsCount('invalid_channel_uid');
//存在无效(离职)开发员
$invalidPurchaseUid = $this->getStatisticsCount('invalid_purchase_uid');
//需要跟进的
$toFollowUp = $this->getStatisticsCount('to_follow_up');
//没有sku的
$noSku = $this->getStatisticsCount('no_sku');
//拉黑的
$block = $this->getStatisticsCount('block');
//没有品牌协议附件的
$noQualityAssuranceAgreement = $this->getStatisticsCount('no_quality_assurance_agreement');
//有标签的(客户指定供应商)
$hasTagSupplier = $this->getStatisticsCount('has_supplier_tag');
//联系人未完善
$concatNoComplete = $this->getStatisticsCount('contact_no_complete');
$result = [
'total' => $total,
'need_review' => $needReview,
'pending' => $pending,
'in_review' => $inReview,
'passed' => $passed,
'rejected' => $rejected,
'disable' => $disable,
'block' => $block,
'no_purchase_uid' => $noPurchaseUid,
'no_channel_uid' => $noChannelUid,
'invalid_channel_uid' => $invalidChannelUid,
'invalid_purchase_uid' => $invalidPurchaseUid,
'to_follow_up' => $toFollowUp,
'no_sku' => $noSku,
'no_quality_assurance_agreement' => $noQualityAssuranceAgreement,
'has_supplier_tag' => $hasTagSupplier,
'contact_no_complete' => $concatNoComplete,
];
$result = array_map(function ($value) {
if ($value > 999) {
$value = '999+';
}
return $value;
}, $result);
$redis->set($statisticsKey, json_encode($result));
$redis->expire($statisticsKey, 50);
return $result;
}
private function getStatisticsCount($type)
{
$model = new SupplierChannelModel();
//显示默认的数据(有权限逻辑)
$filter = new SupplierFilter();
$model = $model->where('supplier_code', '!=', '');
if ($type=='contact_no_complete') {
// dd($filter->defaultFilter($model, $type)->count(DB::raw("distinct(lie_supplier_channel.supplier_id)")));
$subQuery = $filter->defaultFilter($model, $type);
// dd($subQuery->toSql());
// return DB::connection('web')->table(DB::raw("({$subQuery->toSql()}) as sub"))->count();
return $subQuery->get()->count();
}
return $filter->defaultFilter($model, $type)->count();
}
}