SupplierSkuAuditRulerService.php
2.37 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
<?php
namespace App\Http\Services;
//后台用户相关信息服务
use Illuminate\Support\Facades\DB;
class SupplierSkuAuditRulerService
{
//获取商品上传规则的具体描述
public function getSkuAuditRulerDesc($ruler)
{
if (empty($ruler)) {
return '允许库存为空:否 允许起订量为空:否 允许阶梯价为空:否';
}
$ruler = json_decode($ruler, true);
$skipDesc = $ruler['skip'] ? "无需审核" : "需要审核内容";
$auditRuler =$ruler['audit_ruler'];
$desc = '';
foreach ($auditRuler as $key => $value) {
$name = array_get(config('fixed.SkuAuditRuler.name_map'), $key);
$valueName = $value ? '是' : '否';
$desc .= $name . ':' . $valueName . ' | ';
}
if ($ruler['skip']) {
$desc = $skipDesc;
} else {
$desc = $skipDesc . ',' . $desc;
}
return $desc;
}
//给展示详情使用
public function getSkuAuditRuler($ruler)
{
if (empty($ruler)) {
$defaultRuler = config('fixed.SkuAuditRuler');
unset($defaultRuler['name_map']);
return config('fixed.SkuAuditRuler');
} else {
return json_decode($ruler, true);
}
}
//获取需要存储到数据库的数据格式
public function getSkuAuditRulerForDB($auditData)
{
/**
* 无需审核规则,满足直接审核通过 优先级2
* audit_rule
* 1代表 型号与品牌已存在
* 2型号不存在,品牌存在
* 3型号不存在,品牌不存在
* 4型号存在,品牌不存在
*/
$defaultRuler = [
'1' => 1,
'2' => 1,
'3' => 1,
'4' => 1
];
if (empty($auditData)) {
$auditRuler['skip'] = 0;
$auditRuler['audit_ruler'] = $defaultRuler;
return json_encode($auditRuler);
}
$rulers = [];
foreach ($defaultRuler as $key => $ruler) {
if (empty($auditData[$key])) {
$rulers[$key] = 0;
} else {
$rulers[$key] = 1;
}
}
$isSkip = (int)$auditData['skip'];
$auditRuler['skip'] = $isSkip;
$auditRuler['audit_ruler'] = $rulers;
return json_encode($auditRuler);
}
}