|
@@ -16,19 +16,22 @@ class ShopcarController extends Controller
|
16
|
16
|
public function add(Request $request) {
|
17
|
17
|
$product_id = $request->input("product_id");
|
18
|
18
|
$wechat_id = $request->header("openid");
|
|
19
|
+ $amount = $request->input("product_amount");
|
19
|
20
|
|
20
|
21
|
if($product_id) {
|
21
|
22
|
$shopcar = Shopcar::where("wechat_id", $wechat_id)->where("product_id", $product_id)->first();
|
22
|
|
- if($shopcar) {
|
23
|
|
- $shopcar->product_amount = $shopcar->product_amount + 1;
|
24
|
|
- $shopcar->save();
|
25
|
|
- } else {
|
|
23
|
+ if(!$shopcar) {
|
26
|
24
|
$shopcar = new Shopcar;
|
27
|
25
|
$shopcar->wechat_id = $wechat_id;
|
28
|
26
|
$shopcar->product_id = $product_id;
|
29
|
|
- $shopcar->product_amount = 1;
|
30
|
|
- $shopcar->save();
|
31
|
27
|
}
|
|
28
|
+ if($amount) {
|
|
29
|
+ $shopcar->product_amount = $amount;
|
|
30
|
+ } else {
|
|
31
|
+ $shopcar->product_amount = $shopcar->product_amount + 1;
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ $shopcar->save();
|
32
|
35
|
return response()->json([
|
33
|
36
|
"status" => 0,
|
34
|
37
|
"message" => "已加入购物车!"
|
|
@@ -41,6 +44,35 @@ class ShopcarController extends Controller
|
41
|
44
|
}
|
42
|
45
|
}
|
43
|
46
|
|
|
47
|
+ /**
|
|
48
|
+ * 批量添加/修改购物车数量
|
|
49
|
+ * @param Request $request
|
|
50
|
+ * @return \Illuminate\Http\JsonResponse
|
|
51
|
+ */
|
|
52
|
+ public function pstore(Request $request) {
|
|
53
|
+
|
|
54
|
+ $wechat_id = $request->header("openid");
|
|
55
|
+ $jsonStr = $request->getContent();
|
|
56
|
+ foreach(json_decode($jsonStr, true) as $data){
|
|
57
|
+ $id = $data["id"];
|
|
58
|
+ $amount = $data["amount"];
|
|
59
|
+ $shopcar = Shopcar::where("wechat_id", $wechat_id)->where("product_id", $id)->first();
|
|
60
|
+ if(!$shopcar) {
|
|
61
|
+ $shopcar = new Shopcar;
|
|
62
|
+ $shopcar->wechat_id = $wechat_id;
|
|
63
|
+ $shopcar->product_id = $id;
|
|
64
|
+ }
|
|
65
|
+ $shopcar->product_amount = $amount;
|
|
66
|
+
|
|
67
|
+ $shopcar->save();
|
|
68
|
+ }
|
|
69
|
+ return response()->json([
|
|
70
|
+ "status" => 0,
|
|
71
|
+ "message" => "修改成功!"
|
|
72
|
+ ]);
|
|
73
|
+
|
|
74
|
+ }
|
|
75
|
+
|
44
|
76
|
/**
|
45
|
77
|
* 修改购物内产品数量
|
46
|
78
|
* @param Request $request
|
|
@@ -96,6 +128,29 @@ class ShopcarController extends Controller
|
96
|
128
|
}
|
97
|
129
|
}
|
98
|
130
|
|
|
131
|
+ /**
|
|
132
|
+ * 批量删除ids
|
|
133
|
+ * @param Request $request
|
|
134
|
+ * @return \Illuminate\Http\JsonResponse
|
|
135
|
+ */
|
|
136
|
+ public function pdelete(Request $request) {
|
|
137
|
+ $ids = $request->input("ids");
|
|
138
|
+ $wechat_id = $request->header("openid");
|
|
139
|
+
|
|
140
|
+ if($ids) {
|
|
141
|
+ foreach ($ids as $id) {
|
|
142
|
+ $shopcar = Shopcar::where("wechat_id", $wechat_id)->where("product_id", $id)->first();
|
|
143
|
+ if($shopcar) {
|
|
144
|
+ $shopcar->delete();
|
|
145
|
+ }
|
|
146
|
+ }
|
|
147
|
+ return response()->json([
|
|
148
|
+ "status" => 0,
|
|
149
|
+ "message" => "批量删除成功!"
|
|
150
|
+ ]);
|
|
151
|
+ }
|
|
152
|
+ }
|
|
153
|
+
|
99
|
154
|
/**
|
100
|
155
|
* 列出购物车列表
|
101
|
156
|
* @param Request $request
|