diff --git a/alipay/app.acss b/alipay/app.acss index f51494b8adeb1169d72ae28146616bf073c4e721..c5895806beb7c920e5b18f95710bc5ac52c1eb6b 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 4f45a4ad8b57a2020a4f1ed64e0ec6043a71090d..63e19ff24a442ff8c54bc115d6754016c0659c03 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 c851a018ef34ab5e005d081c23cc4f9c1da30a32..c33f9a3e05f8c6524fbec41fcf170a7846e27fa8 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 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..54933fa5b4a14fc201ff127d08f2d9f3a5137616 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 5a438de262ac7b5e849cbc43f8b874a10a794402..ed624547a81edcf988caf7882c140f68c2dcde57 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 cb7353625a9edde05b76294ab420d47536933906..3e5d493d7bcb1c38716fce6a313714d1d9a130b1 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 954595475fe5e318f0574db303867d9e35ff4ecc..3b49309442e77d27ea6e361aed9b12bbea240e56 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 4c0142fd56bd4d18a4f790586b6cc8afba742b08..88bbf07016563da161b080e8c7358ea03f0ccb72 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 0000000000000000000000000000000000000000..23e51bf8f8e7059a78f8b04be6ef52082caea2b8 --- /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 bb17b2b87488cafd9b1b168ef78073e93c7ad6df..45e5674e48c5516778680142b8c801c84490dd7a 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);