From af770c20a495194162b5c688c96e64cdfa3037c9 Mon Sep 17 00:00:00 2001
From: gongfuxiang <2499232802@qq.com>
Date: Wed, 21 Nov 2018 02:02:34 +0800
Subject: [PATCH] cart
---
alipay/app.acss | 2 +-
alipay/app.js | 1 +
alipay/app.json | 4 +-
alipay/pages/cart/cart.acss | 60 +++++++
alipay/pages/cart/cart.axml | 30 +++-
alipay/pages/cart/cart.js | 146 +++++++++++++++++-
.../user-order-detail/user-order-detail.axml | 2 +-
alipay/pages/user-order/user-order.acss | 3 -
.../Api/Controller/CartController.class.php | 100 ++++++++++++
.../Application/Service/BuyService.class.php | 1 +
10 files changed, 338 insertions(+), 11 deletions(-)
create mode 100644 service/Application/Api/Controller/CartController.class.php
diff --git a/alipay/app.acss b/alipay/app.acss
index f51494b8a..c5895806b 100755
--- a/alipay/app.acss
+++ b/alipay/app.acss
@@ -186,7 +186,7 @@ textarea {
.sales-price {
color: #f40;
font-weight: bold;
- font-size: 38rpx;
+ font-size: 32rpx;
}
.original-price {
color: #ccc;
diff --git a/alipay/app.js b/alipay/app.js
index 4f45a4ad8..63e19ff24 100755
--- a/alipay/app.js
+++ b/alipay/app.js
@@ -42,6 +42,7 @@ App({
"user_answer_list": "我的留言",
"user": "用户中心",
"goods_category": "分类",
+ "cart": "购物车",
},
// 请求地址
diff --git a/alipay/app.json b/alipay/app.json
index c851a018e..c33f9a3e0 100755
--- a/alipay/app.json
+++ b/alipay/app.json
@@ -1,8 +1,8 @@
{
- "pages": [
+ "pages": ["pages/cart/cart",
"pages/index/index",
"pages/goods-category/goods-category",
- "pages/cart/cart",
+
"pages/user/user",
"pages/web-view/web-view",
"pages/login/login",
diff --git a/alipay/pages/cart/cart.acss b/alipay/pages/cart/cart.acss
index e69de29bb..54933fa5b 100644
--- a/alipay/pages/cart/cart.acss
+++ b/alipay/pages/cart/cart.acss
@@ -0,0 +1,60 @@
+/**
+ * 商品列表
+ */
+.goods-title {
+ line-height: 36rpx;
+}
+.goods-item {
+ padding: 20rpx 10rpx;
+ position: relative;
+}
+.goods-item:not(:last-child) {
+ border-bottom: 1px solid #eee;
+}
+.goods-title, .goods-attribute {
+ margin-bottom: 10rpx;
+}
+.goods-image {
+ width: 160rpx;
+ height: 160rpx;
+ margin-right: 20rpx;
+}
+.goods-base {
+ min-height: 160rpx;
+}
+.goods-price {
+ position: relative;
+}
+.buy-number {
+ margin-left: 20rpx;
+}
+
+/**
+ * 数量操作
+ */
+.number-content {
+ position: absolute;
+ right: 20rpx;
+ top: 120rpx;
+}
+.number-content button
+{
+ background: #eee;
+ height: 64rpx;
+ line-height: 64rpx;
+ font-weight: bold;
+ color: #666;
+}
+.number-content input {
+ width: 50px;
+ margin: 2rpx 10rpx 0 10rpx;
+ height: 60rpx;
+ line-height: 60rpx;
+ border-radius: 2px;
+}
+.number-content button,
+.number-content input
+{
+ border: 1px solid #ddd;
+ padding: 0;
+}
\ No newline at end of file
diff --git a/alipay/pages/cart/cart.axml b/alipay/pages/cart/cart.axml
index 5a438de26..ed624547a 100644
--- a/alipay/pages/cart/cart.axml
+++ b/alipay/pages/cart/cart.axml
@@ -1,3 +1,29 @@
-
- New Page
+
+
+
+
+
+
+
+
+ {{item.title}}
+
+
+ {{attr.attr_type_name}}:{{attr.attr_name}}
+
+
+
+
+
+
+
+
+
+
+
+
+ ¥{{item.price}}
+ ¥{{item.original_price}}
+ x{{item.stock}}
+
\ No newline at end of file
diff --git a/alipay/pages/cart/cart.js b/alipay/pages/cart/cart.js
index cb7353625..3e5d493d7 100644
--- a/alipay/pages/cart/cart.js
+++ b/alipay/pages/cart/cart.js
@@ -1,4 +1,146 @@
+const app = getApp();
Page({
- data: {},
- onLoad() {},
+ data: {
+ data_list_loding_status: 1,
+ data_list_loding_msg: '',
+ data_bottom_line_status: false,
+ data_list: [],
+ value: 8,
+ },
+
+ onShow() {
+ my.setNavigationBar({ title: app.data.common_pages_title.cart });
+ this.init();
+ },
+
+ init() {
+ this.setData({
+ data_list_loding_status: 1
+ });
+
+ my.httpRequest({
+ url: app.get_request_url("Index", "Cart"),
+ method: "POST",
+ data: {},
+ dataType: "json",
+ success: res => {
+ my.stopPullDownRefresh();
+ if (res.data.code == 0) {
+ this.setData({
+ data_list: res.data.data,
+ data_list_loding_status: 3,
+ data_bottom_line_status: true,
+ data_list_loding_msg: '',
+ });
+ } else {
+ self.setData({
+ data_list_loding_status: 2,
+ data_bottom_line_status: false,
+ data_list_loding_msg: res.data.msg,
+ });
+ my.showToast({
+ type: "fail",
+ content: res.data.msg
+ });
+ }
+ },
+ fail: () => {
+ my.stopPullDownRefresh();
+ self.setData({
+ data_list_loding_status: 2,
+ data_bottom_line_status: false,
+ data_list_loding_msg: '服务器请求出错',
+ });
+
+ my.showToast({
+ type: "fail",
+ content: "服务器请求出错"
+ });
+ }
+ });
+ },
+
+ // 下拉刷新
+ onPullDownRefresh() {
+ this.init();
+ },
+
+ // 数量输入事件
+ goods_buy_number_blur(e) {
+ var index = e.currentTarget.dataset.index || 0;
+ var buy_number = parseInt(e.detail.value) || 1;
+ this.goods_buy_number_func(index, buy_number);
+ },
+
+ // 数量操作事件
+ goods_buy_number_event(e) {
+ var index = e.currentTarget.dataset.index || 0;
+ var type = parseInt(e.currentTarget.dataset.type) || 0;
+ var temp_buy_number = parseInt(this.data.data_list[index]['stock']);
+ if (type == 0) {
+ var buy_number = temp_buy_number - 1;
+ } else {
+ var buy_number = temp_buy_number + 1;
+ }
+ this.goods_buy_number_func(index, buy_number);
+ },
+
+ // 数量处理方法
+ goods_buy_number_func(index, buy_number) {
+ var buy_min_number = parseInt(this.data.data_list[index]['buy_min_number']) || 1;
+ var buy_max_number = parseInt(this.data.data_list[index]['buy_max_number']) || 0;
+ var inventory = parseInt(this.data.data_list[index]['inventory']);
+ var inventory_unit = this.data.data_list[index]['inventory_unit'];
+ if (buy_number < buy_min_number) {
+ buy_number = buy_min_number;
+ if (buy_min_number > 1) {
+ my.showToast({ content: '起购' + buy_min_number + inventory_unit });
+ return false;
+ }
+ }
+ if (buy_max_number > 0 && buy_number > buy_max_number) {
+ buy_number = buy_max_number;
+ my.showToast({ content: '限购' + buy_max_number + inventory_unit });
+ return false;
+ }
+ if (buy_number > inventory) {
+ buy_number = inventory;
+ my.showToast({ content: '库存数量' + inventory + inventory_unit });
+ return false;
+ }
+
+ var temp_data_list = this.data.data_list;
+ if (temp_data_list[index]['stock'] == 1 && buy_number == 1)
+ {
+ return false;
+ }
+
+ // 更新数据库
+ my.httpRequest({
+ url: app.get_request_url("Stock", "Cart"),
+ method: "POST",
+ data: { "id": temp_data_list[index]['id'], "goods_id": temp_data_list[index]['goods_id'], "stock": buy_number},
+ dataType: "json",
+ success: res => {
+ my.stopPullDownRefresh();
+ if (res.data.code == 0) {
+ temp_data_list[index]['stock'] = buy_number
+ this.setData({ data_list: temp_data_list });
+ my.showToast({ content: res.data.msg });
+ } else {
+ my.showToast({
+ type: "fail",
+ content: res.data.msg
+ });
+ }
+ },
+ fail: () => {
+ my.showToast({
+ type: "fail",
+ content: "服务器请求出错"
+ });
+ }
+ });
+ },
+
});
diff --git a/alipay/pages/user-order-detail/user-order-detail.axml b/alipay/pages/user-order-detail/user-order-detail.axml
index 954595475..3b4930944 100755
--- a/alipay/pages/user-order-detail/user-order-detail.axml
+++ b/alipay/pages/user-order-detail/user-order-detail.axml
@@ -48,7 +48,7 @@
-
+
\ No newline at end of file
diff --git a/alipay/pages/user-order/user-order.acss b/alipay/pages/user-order/user-order.acss
index 4c0142fd5..88bbf0701 100755
--- a/alipay/pages/user-order/user-order.acss
+++ b/alipay/pages/user-order/user-order.acss
@@ -64,9 +64,6 @@
position: absolute;
right: 0;
bottom: 0;
-}
-.item-base {
-
}
.item-base, .item-describe, .item-operation {
padding: 25rpx 10rpx 20rpx 10rpx;
diff --git a/service/Application/Api/Controller/CartController.class.php b/service/Application/Api/Controller/CartController.class.php
new file mode 100644
index 000000000..23e51bf8f
--- /dev/null
+++ b/service/Application/Api/Controller/CartController.class.php
@@ -0,0 +1,100 @@
+error(L('common_unauthorized_access'));
+ }
+
+ // 是否登录
+ $this->Is_Login();
+ }
+
+ /**
+ * [Index 首页]
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 0.0.1
+ * @datetime 2017-02-22T16:50:32+0800
+ */
+ public function Index()
+ {
+ $ret = BuyService::CartList(['user'=>$this->user]);
+ $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
+ }
+
+ /**
+ * 购物车保存
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-09-13
+ * @desc description
+ */
+ public function Save()
+ {
+ $params = $this->data_post;
+ $params['user'] = $this->user;
+ $ret = BuyService::CartAdd($params);
+ $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
+ }
+
+ /**
+ * 购物车删除
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-09-14
+ * @desc description
+ */
+ public function Delete()
+ {
+
+ $params = $this->data_post;
+ $params['user'] = $this->user;
+ $ret = BuyService::CartDelete($params);
+ $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
+ }
+
+ /**
+ * 数量保存
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2018-09-14
+ * @desc description
+ */
+ public function Stock()
+ {
+ $params = $this->data_post;
+ $params['user'] = $this->user;
+ $ret = BuyService::CartStock($params);
+ $this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
+ }
+}
+?>
\ No newline at end of file
diff --git a/service/Application/Service/BuyService.class.php b/service/Application/Service/BuyService.class.php
index bb17b2b87..45e5674e4 100755
--- a/service/Application/Service/BuyService.class.php
+++ b/service/Application/Service/BuyService.class.php
@@ -175,6 +175,7 @@ class BuyService
$v['images'] = empty($v['images']) ? null : $images_host.$v['images'];
$v['attribute'] = empty($v['attribute']) ? null : json_decode($v['attribute'], true);
$v['total_price'] = $v['stock']*$v['price'];
+ $v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number'];
}
return DataReturn(L('common_operation_success'), 0, $data);
--
GitLab