|
@@ -9,9 +9,12 @@ import com.gexin.fastjson.JSON;
|
|
|
import com.hboxs.ViewObject.ProductVo;
|
|
|
import com.hboxs.common.Message;
|
|
|
import com.hboxs.common.utils.PushUtils;
|
|
|
+import com.hboxs.entity.Equipment;
|
|
|
import com.hboxs.entity.Product;
|
|
|
+import com.hboxs.entity.Proportion;
|
|
|
import com.hboxs.service.EquipmentService;
|
|
|
import com.hboxs.service.ProductService;
|
|
|
+import com.hboxs.service.ProportionService;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -39,6 +42,8 @@ public class ProductController extends BaseController {
|
|
|
@Resource(name = "equipmentServiceImpl")
|
|
|
private EquipmentService equipmentService;
|
|
|
|
|
|
+ @Resource(name = "proportionServiceImpl")
|
|
|
+ private ProportionService proportionService;
|
|
|
/**
|
|
|
* 更新商品
|
|
|
*/
|
|
@@ -46,6 +51,8 @@ public class ProductController extends BaseController {
|
|
|
@ResponseBody
|
|
|
public Message update(@RequestBody List<Map<String,String>> products, RedirectAttributes redirectAttributes) {
|
|
|
String equipmentId = "";
|
|
|
+ Double f=0.00;
|
|
|
+ int num=0;
|
|
|
List<ProductVo> list = new ArrayList<>();
|
|
|
for (Map<String,String> map:products) {
|
|
|
Product product = new Product();
|
|
@@ -56,7 +63,29 @@ public class ProductController extends BaseController {
|
|
|
product1.setCodePrice(new BigDecimal(map.get("codePrice")));
|
|
|
product1.setRmbPrice(new BigDecimal( map.get("rmbPrice")));
|
|
|
equipmentId = map.get("equipmentId");
|
|
|
-
|
|
|
+ //根据equipmentId查找adminid
|
|
|
+ Equipment equipment = equipmentService.find(Long.parseLong(equipmentId));
|
|
|
+ Long adminId = equipment.getAdminId();
|
|
|
+ //根据id获取分销比例
|
|
|
+ Proportion proportion = proportionService.getUniqueness(adminId);
|
|
|
+ //平台分销比例
|
|
|
+ BigDecimal adminProportion = proportion.getAdminProportion();
|
|
|
+ Double pricePro = adminProportion.doubleValue()/100;
|
|
|
+ //平台最低收入
|
|
|
+ Double minProportion = 0.005;
|
|
|
+ //获取重新设定的价格
|
|
|
+ Double rmbPrice = new BigDecimal( map.get("rmbPrice")).doubleValue();
|
|
|
+ //价格和平台分销比例要大于0
|
|
|
+ if(pricePro>0&&rmbPrice>0){
|
|
|
+ //重新设定价格后平台收入和平台最低收入比较
|
|
|
+ if(rmbPrice*pricePro<minProportion){
|
|
|
+ num++;
|
|
|
+ //保留3位小数点
|
|
|
+ BigDecimal b = new BigDecimal(minProportion/pricePro);
|
|
|
+ f = b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
productService.update(product1, "equipmentId", "productName", "sellStatus");
|
|
|
productVo.setId(map.get("id"));
|
|
|
productVo.setCodePrice(new Double(map.get("codePrice")));
|
|
@@ -66,9 +95,20 @@ public class ProductController extends BaseController {
|
|
|
Collections.sort(list);
|
|
|
System.out.println(list);
|
|
|
PushUtils.push(equipmentService.find(Long.parseLong(equipmentId)).getGtClientId(), "更新棉花价格", "更新棉花价格", PushUtils.buildJson("products", JSON.toJSONString(list)).toString());
|
|
|
- addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
|
|
|
- return SUCCESS_MESSAGE;
|
|
|
- }
|
|
|
+ if(f>0){
|
|
|
+// JsonMessage.error("最低价格应为"+f+"元,或者设为0元。有"+num+"处价格设置不合理!!!");
|
|
|
+// Message.error("最低价格应为"+f+"元,或者设为0元。有"+num+"处价格设置不合理!!!");
|
|
|
+ String errorData = "最低价格应大于"+f+"元,或者设为0元。有"+num+"处价格设置不合理!!!";
|
|
|
+ ERROR_MESSAGE.setContent(errorData);
|
|
|
+ addFlashMessage(redirectAttributes, ERROR_MESSAGE);
|
|
|
+ return ERROR_MESSAGE;
|
|
|
+ }else {
|
|
|
+ addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
|
|
|
+ return SUCCESS_MESSAGE;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|