SkuStatisticsService.php
1.47 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
<?php
namespace App\Http\Services;
use App\Http\Controllers\Filter\SupplierFilter;
use App\Model\SupplierChannelModel;
use Illuminate\Support\Facades\DB;
class SkuStatisticsService
{
//获取供应商列表需要统计的信息
public function getSkuListStatistics()
{
$total = $this->getStatisticsCount('all');
//七天内过期的
$expire = $this->getStatisticsCount('expire');
//下架的
$offShelf = $this->getStatisticsCount('off_shelf');
$result = [
'all' => $total,
'expire' => $expire,
'off_shelf' => $offShelf,
];
$result = array_map(function ($value) {
if ($value > 999) {
$value = '999+';
}
return $value;
}, $result);
return $result;
}
private function getStatisticsCount($type)
{
$url = env('ES_SKU_URL', '');
$map['supplier_id'] = 17;
switch ($type) {
case "all":
break;
case "expire":
$map['expire_day'] = 7;
break;
case "off_shelf":
$map["goods_status/condition"] = 3;
break;
}
$result = curl($url, $map);
$result = json_decode($result, true);
$total = 0;
if (isset($result['error_code']) && $result['error_code'] == 0) {
$total = $result['data']['total'];
}
return $total;
}
}