package nuoshang.bluejay.modules;
import com.sun.glass.ui.Cursor;
import javafx.scene.*;
import nuoshang.bluejay.base.exception.AppRuntimeException;
import nuoshang.bluejay.bean.Collect_good;
import nuoshang.bluejay.bean.Shopping_cart;
import nuoshang.bluejay.services.ShopCartService;
import org.apache.commons.collections.CursorableLinkedList;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.service.EntityService;
import java.awt.*;
import java.time.temporal.TemporalAccessor;
import java.util.List;
/**
* Created by Administrator on 2016/8/17.
*/
@IocBean
@At("/shop")
@Fail("http:500")
public class ShopCartModule {
@Inject
private ShopCartService shopCartService;
//添加到商品到购物车
@At
@Ok("json")
public Object add(@Param("uId")Integer uId,
@Param("gId")Integer gId,
@Param("skuId")Integer skuId){
NutMap ap=new NutMap();
if (uId==null|gId==null|skuId==null){
return ap.addv("ok",false).addv("msg", "用户id,商品id,库存id不能为空").addv("result","03");
}
try {
Shopping_cart sc = shopCartService.addShop(uId, gId, skuId);
ap.addv("result", "01").addv("id",sc.getCart_id());
} catch (AppRuntimeException e) {
ap.addv("sc", e.getMessage()).addv("result", "02");
}
return ap;
}
//购物车商品列表
@At
@Ok("json:{ignoreNull:false}")
public Object List(@Param("caid") Integer caid){
NutMap lm = new NutMap();
if (caid == null) {
lm.addv("result", "购物车不能为空").addv("result", "03");
}else{
lm.addv("result","01");
}
try {
shopCartService.shopList(caid);
} catch (AppRuntimeException e) {
lm.addv("result","02");
}
return lm;
}
@At("/dele")
@Ok("json")
//删除购物车
public Object dele(@Param("spId") Integer spId){
NutMap dl=new NutMap();
if (spId==null){
return dl.addv("ok", false).addv("msg","购物车id不能为空").addv("return","00");
}else{
shopCartService.deShop(spId);
return dl.addv("ok",true).addv("result","01");
}
}
}
//添加商品到购物车Service
public Shopping_cart addShop(Integer uId, Integer gId, Integer skuId) {
Goods goods=dao.fetch(Goods.class,gId);
Sku sku=dao.fetch(Sku.class,skuId);
Shopping_cart sc = new Shopping_cart();
sc.setCart_user_id(uId);//用户id
sc.setCart_good_id(gId);//商品id
sc.setSku_id(skuId);//库存id
sc.setGood_name(goods.getName());//商品名称
sc.setPrefere_price(goods.getPicture());//商品价格
sc.setCount(sku.getCount());//购买数量
sc.setImg(sku.getImg());//选择图片
sc.setCart_add_time(new Timestamp(System.currentTimeMillis())); //添加时间
Shopping_cart sctemp = dao.insert(sc);
// String msg="";
return sctemp;
}