SupplierExaminationApiController.php
5.03 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\SupplierExaminationService;
use App\Http\Transformers\SupplierLogTransformer;
use App\Http\Validators\SupplierExaminationValidator;
use App\Model\LogModel;
use App\Model\SupplierLogModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
//供应商检测
class SupplierExaminationApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
//获取供应商信息变更记录
public function GetSupplierExaminationList($request)
{
$model = new SupplierExaminationService();
$list = $model->getSupplierExaminationList($request);
$this->response(0, 'ok', $list['data'], $list['total']);
}
//添加
public function AddSupplierExamination($request)
{
$params = $request->only([
'order_sn',
'purchase_sn',
'examine_time',
'sales_name',
'purchase_name',
'ticket_type',
'supplier_name',
'sku_name',
'brand_name',
'amount',
'batch',
'producing_area',
'stock_in_date',
'income_sn',
'delivery_sn',
'tally_request',
'examine_request',
'unhealthy_amount',
'abnormal_level',
'unhealthy_content',
'examine_result',
'remark',
]);
$validator = new SupplierExaminationValidator();
$validateResult = $validator->checkSave($params);
if ($validateResult) {
$this->response(-1, $validateResult);
}
$result = (new SupplierExaminationService())->saveSupplierExamination($params);
if ($result) {
$this->response(0, '添加成功');
}
$this->response(-1, '添加失败', $result);
}
//修改
//添加
public function UpdateSupplierExamination($request)
{
$params = $request->only([
'id',
'order_sn',
'purchase_sn',
'examine_time',
'sales_name',
'purchase_name',
'ticket_type',
'supplier_name',
'sku_name',
'brand_name',
'amount',
'batch',
'producing_area',
'stock_in_date',
'income_sn',
'delivery_sn',
'tally_request',
'examine_request',
'unhealthy_amount',
'abnormal_level',
'unhealthy_content',
'examine_result',
'remark',
]);
$validator = new SupplierExaminationValidator();
$validateResult = $validator->checkSave($params);
if ($validateResult) {
$this->response(-1, $validateResult);
}
$result = (new SupplierExaminationService())->saveSupplierExamination($params);
if ($result) {
$this->response(0, '修改成功');
}
$this->response(-1, '修改失败', $result);
}
//删除
public function DeleteSupplierExaminations($request)
{
$ids = $request->get('ids');
$ids = explode(',', trim($ids));
if (empty($ids)) {
$this->response(-1, '请选择需要删除的数据');
}
$result = (new SupplierExaminationService())->deleteSupplierExaminations($ids);
if ($result) {
$this->response(0, '删除成功');
}
$this->response(-1, '删除失败', $result);
}
public function BatchUpdateSupplierExamination($request)
{
$params = $request->only([
'ids',
'examine_result'
]);
if (empty($params['ids'])) {
$this->response(-1, '请选择需要批量修改的检测数据');
}
$result = (new SupplierExaminationService())->batchUpdateSupplierExamination($params);
if ($result) {
$this->response(0, '修改成功');
}
$this->response(-1, '修改失败', $result);
}
//上传IQC检测记录
private function ImportSupplierExamination($request)
{
$file = $request->file('file');
if ($file->isValid()) {
$ext = $file->getClientOriginalExtension();
$realPath = $file->getRealPath();
if ($ext != 'xlsx') {
$this->response(-1, '上传格式错误');
}
// 上传文件
$filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . $ext;
$bool = Storage::put($filename, file_get_contents($realPath));
if (!$bool) {
$this->response(-1, '文件处理失败');
}
$filePath = storage_path('app/') . $filename;
$result = (new SupplierExaminationService())->ImportSupplierExamination($filePath);
if ($result !== true) {
$this->response(-1, $result);
}
$this->response(0, '上传成功');
}
}
}