ShippingCostRulerApiController.php
3.08 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
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\LogService;
use App\Http\Services\ShippingCostRulerService;
use App\Http\Transformers\ShippingCostRulerTransformer;
use App\Model\LogModel;
use App\Model\ShippingCostRulerModel;
use Illuminate\Http\Request;
class ShippingCostRulerApiController extends Controller
{
public function Entrance(Request $request, $id)
{
$this->$id($request, $id);
}
public function GetShippingCostRulerList($request)
{
$supplierId = $request->get('supplier_id');
$limit = $request->get('limit', 10);
$model = new ShippingCostRulerModel();
$model->where('supplier_id', $supplierId)->paginate();
$list = $model->where('supplier_id', $supplierId)->orderBy('id', 'desc')
->paginate($limit)->toArray();
$transformer = new ShippingCostRulerTransformer();
$list['data'] = $transformer->transformList($list['data']);
$this->response(0, 'ok', $list['data'], $list['total']);
}
public function SaveShippingCostRuler($request)
{
$id = $request->input('id');
$currency = $request->input('currency');
$orderAmount = $request->input('order_amount');
$shippingCost = $request->input('shipping_cost');
$supplierId = $request->input('supplier_id');
$rulerText = $request->input('ruler_text');
if (!$supplierId) {
$this->response(-1,'供应商id不能为空');
}
if (!$currency) {
$this->response(-1,'订单币种不能为空');
}
if (!$orderAmount) {
$this->response(-1,'单笔订单金额不能为空');
}
$ruler = $request->only([
'id',
'supplier_id',
'order_amount',
'shipping_cost',
'currency',
'condition',
'ruler_text',
]);
$rulerService = new ShippingCostRulerService();
$result = $rulerService->saveShippingCostRuler($id,$ruler);
if (!$result) {
$this->response(-1, '操作失败');
} else {
$logService = new LogService();
$content = !empty($ruler['id']) ? '修改运费规则' : '添加运费规则';
$supplierId = $ruler['supplier_id'];
$ruler = json_encode($ruler);
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, $content, $content, $ruler);
$this->response(0, '保存成功');
}
}
public function DeleteShippingCostRuler($request)
{
$id = $request->get('id');
$model = new ShippingCostRulerModel();
$ruler = $model->where('id', $id)->first()->toArray();
$result = $model->where('id', $id)->delete();
if ($result) {
$logService = new LogService();
$content = "删除运费规则";
$logService->AddLog($ruler['supplier_id'], LogModel::UPDATE_OPERATE, '删除运费规则', $content);
$this->response(0, '操作成功');
}
$this->response(-1, '操作失败');
}
}