Browse Source

Issue 完善下单流程

enilu 6 years ago
parent
commit
3f61994070

+ 8 - 2
flash-waimai-api/src/main/java/cn/enilu/flash/api/controller/business/AddressController.java

@@ -5,9 +5,11 @@ import cn.enilu.flash.bean.entity.front.Address;
 import cn.enilu.flash.bean.entity.front.Ids;
 import cn.enilu.flash.bean.enumeration.BizExceptionEnum;
 import cn.enilu.flash.bean.exception.ApplicationException;
+import cn.enilu.flash.bean.vo.business.City;
 import cn.enilu.flash.bean.vo.front.Rets;
 import cn.enilu.flash.dao.MongoRepository;
 import cn.enilu.flash.service.front.IdsService;
+import cn.enilu.flash.service.front.PositionService;
 import cn.enilu.flash.utils.Maps;
 import cn.enilu.flash.utils.ToolUtil;
 import org.slf4j.Logger;
@@ -30,19 +32,23 @@ public class AddressController extends BaseController {
     private MongoRepository mongoRepository;
     @Autowired
     private IdsService idsService;
+    @Autowired
+    private PositionService positionService;
     @RequestMapping(value = "/v1/users/{user_id}/addresses",method = RequestMethod.GET)
     public Object address(@PathVariable("user_id")Long userId){
         return Rets.success(mongoRepository.findAll(Address.class,"user_id",userId));
     }
-    @RequestMapping(value = "/v1/usres/{user_id}/addresses",method =  RequestMethod.POST)
+    @RequestMapping(value = "/v1/users/{user_id}/addresses",method =  RequestMethod.POST)
     public Object save(@PathVariable("user_id")Long userId){
+        City city = positionService.guessCity(getIp());
         Address address = getRequestPayload(Address.class);
         address.setUser_id(userId);
+        address.setCity_id(city.getId());
         address.setId(idsService.getId(Ids.ADDRESS_ID));
         mongoRepository.save(address);
         return Rets.success("添加地址成功");
     }
-    @RequestMapping(value = "/v1/usres/${user_id}/addresses/${address_id}",method =  RequestMethod.POST)
+    @RequestMapping(value = "/v1/users/${user_id}/addresses/${address_id}",method =  RequestMethod.POST)
     public Object delete(@PathVariable("user_id")Long userId,@PathVariable("address_id") Long addressId){
         mongoRepository.delete("addresses", Maps.newHashMap("user_id",userId,"id",addressId));
         return Rets.success("删除地址成功");

+ 39 - 19
flash-waimai-api/src/main/java/cn/enilu/flash/api/controller/business/CartController.java

@@ -31,8 +31,8 @@ public class CartController extends BaseController {
     @Autowired
     private PositionService positionService;
 
-    @RequestMapping(value = "/v1/carts/checkout",method = RequestMethod.POST)
-    public Object checkout(HttpServletRequest request){
+    @RequestMapping(value = "/v1/carts/checkout", method = RequestMethod.POST)
+    public Object checkout(HttpServletRequest request) {
 
         Map data = getRequestPayload(Map.class);
         System.out.println(Json.toJson(data));
@@ -40,15 +40,15 @@ public class CartController extends BaseController {
         Long restaurantId = Long.valueOf(data.get("restaurant_id").toString());
         Carts carts = new Carts();
         List<Payment> paymentList = mongoRepository.findAll(Payment.class);
-        Shop shop = mongoRepository.findOne(Shop.class,restaurantId);
-        String to =  shop.getLatitude()+","+shop.getLongitude();
-        Map distance = positionService.getDistance(from,to);
-        String deliver_time = distance!=null?distance.get("duration").toString():"";
+        Shop shop = mongoRepository.findOne(Shop.class, restaurantId);
+        String to = shop.getLatitude() + "," + shop.getLongitude();
+        Map distance = positionService.getDistance(from, to);
+        String deliver_time = distance != null ? distance.get("duration").toString() : "";
         carts.setDelivery_reach_time(deliver_time);
         carts.setId(idsService.getId(Ids.CART_ID));
         carts.setPayments(paymentList);
-        carts.setSig(String.valueOf(Math.ceil(Math.random()*1000000)));
-        carts.setInvoice(Maps.newHashMap("status_text","不需要开发票","is_available",true));
+        carts.setSig(String.valueOf(Math.ceil(Math.random() * 1000000)));
+        carts.setInvoice(Maps.newHashMap("status_text", "不需要开发票", "is_available", true));
 
         Cart cart = new Cart();
         cart.setId(carts.getId());
@@ -58,29 +58,49 @@ public class CartController extends BaseController {
         List<List> entities = (List<List>) data.get("entities");
         List<List> groups = Lists.newArrayList(Lists.newArrayList());
         BigDecimal total = new BigDecimal(0);
-        for(int i=0;i<entities.get(0).size();i++){
+        List extraList = Lists.newArrayList();
+        Map extra = Maps.newHashMap(
+                "description", "",
+                "name", "",
+                "price", 0,
+                "quantity", 1,
+                "type", 0);
+        for (int i = 0; i < entities.get(0).size(); i++) {
             Map map = (Map) entities.get(0).get(i);
             Map items = Maps.newHashMap();
-            items.put("id",Long.valueOf(map.get("id").toString()));
-            items.put("name",map.get("name"));
-            items.put("packing_fee",map.get("packing_fee"));
-            items.put("price",map.get("price"));
-            items.put("quantity",map.get("quantity"));
+            items.put("id", Long.valueOf(map.get("id").toString()));
+            items.put("name", map.get("name"));
+            items.put("packing_fee", map.get("packing_fee"));
+            items.put("price", map.get("price"));
+            items.put("quantity", map.get("quantity"));
+            Double amount= Double.valueOf(map.get("packing_fee").toString()) * Integer.valueOf(map.get("quantity").toString());
+            extra = Maps.newHashMap(
+                    "description", "",
+                    "name", extra.get("name").toString() + " " + map.get("name").toString() + "-" + ((List) map.get("specs")).get(0),
+                    "price", Double.valueOf(extra.get("price").toString()) + amount,
+                    "quantity", Integer.valueOf(extra.get("quantity").toString()) + Integer.valueOf(map.get("quantity").toString()),
+                    "type", 0
+            );
 
             total = total.add(new BigDecimal(items.get("price").toString()).multiply(new BigDecimal(items.get("quantity").toString())));
 
             groups.get(0).add(items);
         }
+
+        extraList.add(extra);
+        cart.setExtra(extraList);
+
         cart.setTotal(total.toPlainString());
         cart.setGroups(groups);
         carts.setCart(cart);
-        data.put("id",idsService.getId(Ids.CATEGORY_ID));
+
         //todo 暂时不保存,开发中
-//        mongoRepository.save(data,"carts");
-        return  Rets.success(carts);
+        mongoRepository.save(carts, "carts");
+        return Rets.success(carts);
     }
-    @RequestMapping(value = "/v1/carts/{cart_id}/remarks",method = RequestMethod.GET)
-    public Object remarks(@PathVariable("cart_id")Long cartId, @RequestParam(value = "sig",required = false) String sig){
+
+    @RequestMapping(value = "/v1/carts/{cart_id}/remarks", method = RequestMethod.GET)
+    public Object remarks(@PathVariable("cart_id") Long cartId, @RequestParam(value = "sig", required = false) String sig) {
         return Rets.success(mongoRepository.findOne("remarks"));
     }
 }

+ 51 - 1
flash-waimai-api/src/main/java/cn/enilu/flash/api/controller/business/OrderController.java

@@ -2,15 +2,25 @@ package cn.enilu.flash.api.controller.business;
 
 import cn.enilu.flash.api.controller.BaseController;
 import cn.enilu.flash.bean.constant.factory.PageFactory;
+import cn.enilu.flash.bean.entity.front.Carts;
+import cn.enilu.flash.bean.entity.front.Ids;
 import cn.enilu.flash.bean.entity.front.Order;
+import cn.enilu.flash.bean.entity.front.Shop;
+import cn.enilu.flash.bean.entity.front.sub.OrderBasket;
+import cn.enilu.flash.bean.entity.front.sub.OrderFee;
+import cn.enilu.flash.bean.entity.front.sub.OrderStatusBar;
+import cn.enilu.flash.bean.vo.business.OrderVo;
 import cn.enilu.flash.bean.vo.front.Rets;
 import cn.enilu.flash.dao.MongoRepository;
-import cn.enilu.flash.utils.Maps;
+import cn.enilu.flash.service.front.IdsService;
+import cn.enilu.flash.utils.*;
 import cn.enilu.flash.utils.factory.Page;
 import org.nutz.lang.Strings;
+import org.nutz.mapl.Mapl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Date;
 import java.util.Map;
 
 /**
@@ -22,6 +32,8 @@ import java.util.Map;
 public class OrderController extends BaseController {
     @Autowired
     private MongoRepository mongoRepository;
+    @Autowired
+    private IdsService idsService;
     @RequestMapping(value = "/bos/v2/users/{user_id}/orders" ,method = RequestMethod.GET)
     public Object orders(@PathVariable("user_id")Long userId,@RequestParam("limit") Integer limit,
     @RequestParam("offset")Integer offset){
@@ -54,5 +66,43 @@ public class OrderController extends BaseController {
         page = mongoRepository.queryPage(page,Order.class,params);
         return Rets.success(page);
     }
+    @RequestMapping(value="/v1/users/{userId}/carts/{cartId}/orders")
+    public Object save(@PathVariable("userId")Long userId,@PathVariable("cartId")Long cartId){
+        OrderVo orderVo = getRequestPayload(OrderVo.class);
+        //获取购物车信息
+        Carts cart = mongoRepository.findOne(Carts.class,cartId);
+        Date createTime = new Date();
+        Shop shop = mongoRepository.findOne(Shop.class,cart.getCart().getRestaurant_id());
+        Order order = new Order();
+        order.setId(idsService.getId(Ids.ORDER_ID));
+        order.setRestaurant_id(shop.getId());
+        order.setRestaurant_name(shop.getName());
+        order.setRestaurant_image_url(shop.getImage_path());
+        order.setFormatted_create_at(DateUtil.format(createTime,"yyyy-MM-dd HH:mm"));
+        order.setOrder_time(createTime.getTime());
+        order.setTime_pass(900);
+        OrderBasket basket = order.getBasket();
+        basket.setGroup(cart.getCart().getGroups());
+        if(!cart.getCart().getExtra().isEmpty()){
+              cart.getCart().getExtra().get(0);
+            OrderFee orderFee = (OrderFee) Mapl.maplistToObj( cart.getCart().getExtra().get(0),OrderFee.class);
+            basket.setDeliver_fee( orderFee);
+            basket.setPacking_fee(Maps.newHashMap("price",cart.getCart().getDeliver_amount()));
+
+        }
+        order.setBasket(basket);
+        OrderStatusBar statusBar = new OrderStatusBar();
+        statusBar.setColor("f60");
+        statusBar.setSub_title("15分钟内支付");
+        statusBar.setTitle("等待支付");
+        order.setStatus_bar(statusBar);
+        order.setTotal_amount(Integer.valueOf(cart.getCart().getTotal()));
+        order.setTotal_quantity(Integer.valueOf(basket.getGroup().get(0).size()));
+        order.setUnique_id(order.getId());
+        order.setUser_id(userId);
+        order.setAddress_id(Long.valueOf(orderVo.getAddress_id()));
+        mongoRepository.save(order);
+        return Rets.success();
+    }
 
 }

+ 32 - 0
flash-waimai-api/src/main/java/cn/enilu/flash/api/controller/business/PaymentController.java

@@ -0,0 +1,32 @@
+package cn.enilu.flash.api.controller.business;
+
+import cn.enilu.flash.api.controller.BaseController;
+import cn.enilu.flash.bean.vo.front.Rets;
+import cn.enilu.flash.utils.Maps;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author :microapp.store
+ * @date :Created in 2019/10/24 15:58
+ */
+@RestController
+@RequestMapping("/payapi/payment")
+public class PaymentController extends BaseController {
+    @RequestMapping(value = "/queryOrder",method = RequestMethod.GET)
+    public Object queryOrder(@RequestParam("merchantId") Long merchantId,
+                             @RequestParam("merchantOrderNo") String merchantOrderNo,
+                             @RequestParam("source") String source,
+                             @RequestParam("userId") Long userId,
+                             @RequestParam("version") String version){
+        return Rets.success(
+                Maps.newHashMap(
+                        "status", 0,
+                        "type","PAY_FAILED",
+                        "message","暂不开放支付功能"
+                )
+        );
+    }
+}

+ 5 - 5
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Address.java

@@ -25,11 +25,11 @@ public class Address extends BaseMongoEntity{
     private String address_detail;
     private Integer tag_type;
     private Long user_id;
-    private Boolean phone_had_bound;
-    private Integer deliver_amount;
-    private Integer agent_fee;
-    private Boolean is_deliverable;
-    private Boolean is_user_default;
+    private Boolean phone_had_bound=true;
+    private Integer deliver_amount=0;
+    private Integer agent_fee=0;
+    private Boolean is_deliverable=true;
+    private Boolean is_user_default=true;
     private String tag;
     private Integer city_id;
     private Integer sex;

+ 1 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Ids.java

@@ -20,6 +20,7 @@ public class Ids extends BaseMongoEntity{
     public static  final String CART_ID = "cart_id";
     public static  final String ADDRESS_ID="address_id";
     public static  final String USER_ID="user_id";
+    public static  final String ORDER_ID="order_id";
     @Id
     private String _id;
     private Long restaurant_id;

+ 18 - 17
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/Order.java

@@ -19,8 +19,8 @@ public class Order extends BaseMongoEntity {
     @Id
     private String _id;
     private Long id;
-    private Double total_amount;
-    private Double total_quantity;
+    private Integer total_amount;
+    private Integer total_quantity;
     private Long unique_id;
     private Long user_id;
     private Long address_id;
@@ -29,25 +29,26 @@ public class Order extends BaseMongoEntity {
     private OrderStatusBar status_bar;
     private OrderTimelineNode timeline_node;
     private String formatted_create_at;
-    private Double order_time;
-    private Integer time_pass;
-    private Integer is_brand;
-    private Integer is_deletable;
-    private Integer is_new_pay;
-    private Integer is_pindan;
-    private Integer operation_confirm;
-    private Integer operation_rate;
-    private Integer operation_rebuy;
-    private Integer operation_upload_photo;
-    private Integer pay_remain_seconds;
-    private Integer rated_point;
-    private Integer remind_reply_count;
+    private Long order_time;
+    private Integer time_pass=900;
+    private Integer is_brand=0;
+    private Integer is_deletable=1;
+    private Integer is_new_pay=1;
+    private Integer is_pindan=0;
+    private Integer operation_confirm=0;
+    private Integer operation_rate=0;
+    private Integer operation_rebuy=2;
+    private Integer operation_pay=0;
+    private Integer operation_upload_photo=0;
+    private Integer pay_remain_seconds=0;
+    private Integer rated_point=0;
+    private Integer remind_reply_count=0;
     private Long restaurant_id;
     private String restaurant_image_hash;
     private String restaurant_image_url;
     private String restaurant_name;
-    private Integer restaurant_type;
-    private Integer status_code;
+    private Integer restaurant_type=0;
+    private Integer status_code=0;
     @JSONField(name="_id")
     public String get_id() {
         return _id;

+ 4 - 2
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/sub/OrderBasket.java

@@ -1,9 +1,11 @@
 package cn.enilu.flash.bean.entity.front.sub;
 
+import cn.enilu.flash.utils.Maps;
 import lombok.Data;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Created  on 2018/1/5 0005.
@@ -15,9 +17,9 @@ public class OrderBasket {
 
     private List<OrderFee> abandoned_extra = new ArrayList<OrderFee>();
     private OrderFee deliver_fee = new OrderFee();
-    private OrderFee packing_fee = new OrderFee();
+    private Map packing_fee = Maps.newHashMap();
     private List extra = new ArrayList();
     private List pindan_map = new ArrayList();
-    private List<List<OrderGroup>> group = new ArrayList<List<OrderGroup>>();
+    private List<List<OrderItem>> group = new ArrayList<List<OrderItem>>();
 
 }

+ 14 - 1
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/sub/OrderGroup.java

@@ -1,5 +1,6 @@
 package cn.enilu.flash.bean.entity.front.sub;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import lombok.Data;
 import org.springframework.data.annotation.Id;
 
@@ -11,9 +12,10 @@ import java.util.List;
  * @author zt
  */
 @Data
-public class OrderGroup {
+public class OrderItem {
     @Id
     private String _id;
+    private Long id;
     private String name;
     private Double price;
     private Double quantity;
@@ -21,6 +23,17 @@ public class OrderGroup {
     private List specs;
     private List attrs;
     private List new_specs;
+    private Integer packing_fee;
+
+
+    @JSONField(name="_id")
+    public String get_id() {
+        return _id;
+    }
+    @JSONField(name="_id")
+    public void set_id(String _id) {
+        this._id = _id;
+    }
 
 
 }

+ 2 - 2
flash-waimai-core/src/main/java/cn/enilu/flash/bean/entity/front/sub/OrderStatusBar.java

@@ -10,8 +10,8 @@ import lombok.Data;
 @Data
 public class OrderStatusBar {
     private String color;
-    private String image_type;
+    private String image_type="";
     private String sub_title;
-    private String title;
+    private String title="";
 
 }

+ 20 - 0
flash-waimai-core/src/main/java/cn/enilu/flash/bean/vo/business/OrderVo.java

@@ -0,0 +1,20 @@
+package cn.enilu.flash.bean.vo.business;
+
+import lombok.Data;
+
+/**
+ * 订单信息
+ * @author :enilu
+ * @date :Created in 2019/10/24 14:18
+ */
+@Data
+public class OrderVo {
+    private String address_id;
+    private String come_from;
+    private String deliver_time;
+    private String description;
+    private String geohash;
+    private Long paymethod_id;
+    private String sig;
+
+}

+ 2 - 2
flash-waimai-mobile/src/page/confirmOrder/children/children/addAddress.vue

@@ -35,7 +35,7 @@
             <section class="section_list">
                 <span class="section_left">送餐地址</span>
                 <section class="section_right">
-                    <router-link to="/confirmOrder/chooseAddress/addAddress/searchAddress" tag="div" class="choose_address">{{searchAddress? searchAddress.name : '小区/写字楼/学校等'}}</router-link>
+                    <router-link to="/confirmOrder/chooseAddress/addAddress/searchAddress" tag="div" class="choose_address">{{searchAddress? searchAddress.address : '小区/写字楼/学校等'}}</router-link>
                     <input type="text" name="address_detail" placeholder="详细地址(如门牌号等)" v-model="address_detail" class="input_style">
 
                 </section>
@@ -122,7 +122,7 @@
                 }else if(this.tag == '公司'){
                     this.tag_type = 4;
                 }
-                let res = await postAddAddress(this.userInfo.user_id, this.searchAddress.name, this.address_detail, this.geohash, this.name, this.phone, this.anntherPhoneNumber, 0, this.sex, this.tag, this.tag_type);
+                let res = await postAddAddress(this.userInfo.user_id, this.searchAddress.address, this.address_detail, this.geohash, this.name, this.phone, this.anntherPhoneNumber, 0, this.sex, this.tag, this.tag_type);
                 //保存成功返沪上一页,否则弹出提示框
                 if (res.message) {
                     this.showAlert = true;

+ 1 - 0
flash-waimai-mobile/src/page/confirmOrder/children/children/children/searchAddress.vue

@@ -49,6 +49,7 @@
             },
             //选择搜素结果
             choooedAddress(item){
+              console.log('item',item)
                 this.CHOOSE_SEARCH_ADDRESS(item);
                 this.$router.go(-1);
             },

+ 1 - 0
flash-waimai-mobile/src/store/mutations.js

@@ -163,6 +163,7 @@ export default {
 	},
 	//选择搜索的地址
 	[CHOOSE_SEARCH_ADDRESS](state, place) {
+	  console.log('place',place);
 		state.searchAddress = place;
 	},
 	//保存geohash