yuhaitao14 7 years ago
parent
commit
101a825aa0

+ 9 - 10
shop/src/main/java/com/zskk/shop/controller/GlobalErrorController.java

@@ -52,16 +52,7 @@ public class GlobalErrorController {
 		
 		String accept = request.getHeader("Accept");
 		HttpHeaders headers = new HttpHeaders();
-		if (accept.contains(MediaType.APPLICATION_JSON_UTF8_VALUE) 
-				|| accept.contains(MediaType.APPLICATION_JSON_VALUE)){
-			//JS请求 返回JSON数据
-			headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
-			if (e instanceof ZSKKException){
-				return new HttpEntity<String>(JSON.toJSONString(new ControllerResult(e)), headers);
-			}else{
-				return new HttpEntity<String>(JSON.toJSONString(new ControllerResult(ErrorConstant.SERVER_ERROR)), headers);
-			}
-		}else{
+		if (accept.contains(MediaType.TEXT_HTML_VALUE)){
 			//为登录 跳转到登录页面
 			if (e instanceof ZSKKException){
 				if (((ZSKKException)e).getError().getCode() == ErrorConstant.NO_LOGIN_ERROR.getCode()){
@@ -74,6 +65,14 @@ public class GlobalErrorController {
 			ModelAndView mv = new ModelAndView(errorPath);
 			mv.addObject("msg", e.getMessage());
 			return mv;
+		}else{
+			//JS请求 返回JSON数据
+			headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+			if (e instanceof ZSKKException){
+				return new HttpEntity<String>(JSON.toJSONString(new ControllerResult(e)), headers);
+			}else{
+				return new HttpEntity<String>(JSON.toJSONString(new ControllerResult(ErrorConstant.SERVER_ERROR)), headers);
+			}
 		}
 	}
 	

+ 52 - 0
shop/src/main/java/com/zskk/shop/controller/admin/GoodsManagerController.java

@@ -26,7 +26,11 @@ import com.zskk.shop.controller.bean.GoodBean;
 import com.zskk.shop.controller.bean.PageBean;
 import com.zskk.shop.controller.bean.UserBean;
 import com.zskk.shop.dao.entry.GoodBase;
+import com.zskk.shop.dao.entry.GoodDescribe;
 import com.zskk.shop.dao.entry.GoodPrice;
+import com.zskk.shop.exception.ErrorConstant;
+import com.zskk.shop.exception.ZSKKError;
+import com.zskk.shop.exception.ZSKKException;
 import com.zskk.shop.service.GoodService;
 
 @Controller
@@ -68,6 +72,13 @@ public class GoodsManagerController extends AbstractController{
 		return new ControllerResult(pageBean);
 	}
 	
+	/**
+	 * 维护基本信息
+	 * @param base
+	 * @param price
+	 * @param discountPrice
+	 * @return
+	 */
 	@RequestMapping("editbase")
 	@ResponseBody
 	public ControllerResult exitbase(GoodBase base, @RequestParam("price") BigDecimal price, @RequestParam("discountPrice") BigDecimal discountPrice){
@@ -75,4 +86,45 @@ public class GoodsManagerController extends AbstractController{
 		goodService.saveGoodBase(user, base, price, discountPrice);
 		return new ControllerResult(Boolean.TRUE);
 	}
+	
+	@RequestMapping("setGoodStatus")
+	@ResponseBody
+	public ControllerResult setGoodStatus(@RequestParam("gid") Integer gid, @RequestParam("status") Boolean status){
+		GoodBase base = goodService.queryOneGoodBase(gid);
+		if (base == null){
+			throw new ZSKKException(ErrorConstant.PARAM_ERROR);
+		}
+		
+		if (status){ //设置为上线 验证数据
+			if (base.getPackageid().equals("")){
+				throw new ZSKKException(ErrorConstant.NO_SET_PACKAGE);
+			}
+			List<GoodDescribe> describes = goodService.queryGoodDescribes(base.getGid());
+			if (describes.isEmpty()){
+				throw new ZSKKException(ErrorConstant.NO_SET_DESCRIBE);
+			}
+		}
+		
+		return new ControllerResult(goodService.setGoodStatus(base, status? GoodService.GOOD_ONLINE: GoodService.GOOD_OFFLINE));
+	}
+	
+	
+
+	@RequestMapping("getGoodDescribe")
+	@ResponseBody
+	public ControllerResult getGoodDescribe(@RequestParam("gid") Integer gid){
+		List<GoodDescribe> list = goodService.queryGoodDescribes(gid);
+		return new ControllerResult(goodService.toGoodDescribeBeans(list));
+	}
+	
+	@RequestMapping("getOneGood")
+	@ResponseBody
+	public ControllerResult getOneGood(@RequestParam("gid") Integer gid){
+		GoodBase base = goodService.queryOneGoodBase(gid);
+		if (base == null){
+			throw new ZSKKException(ErrorConstant.PARAM_ERROR);
+		}
+		GoodPrice price = goodService.queryGoodPrice(gid);
+		return new ControllerResult(goodService.toSimpleGoodBean(base, price));
+	}
 }

+ 2 - 0
shop/src/main/java/com/zskk/shop/exception/ErrorConstant.java

@@ -13,6 +13,8 @@ public class ErrorConstant {
 	
 	public static final ZSKKError BUY_ORDER_ID_ERROR 	= new ZSKKError(10000, "订单号不存在");
 	public static final ZSKKError ORDER_PAYED_ERROR		= new ZSKKError(10001, "已支付");
+	public static final ZSKKError NO_SET_PACKAGE 		= new ZSKKError(100002, "您还没有设置套餐");
+	public static final ZSKKError NO_SET_DESCRIBE		= new ZSKKError(100002, "您还没有设置商品详细");
 	
 	
 }

+ 1 - 1
shop/src/main/java/com/zskk/shop/service/BuyOrderService.java

@@ -134,7 +134,7 @@ public class BuyOrderService {
 			item.setBid(buyOrder.getId());
 			item.setCtime(now);
 			item.setGid(good.getGid());
-			item.setNum(num);
+			item.setNum(1);
 			item.setPrice(price.getDiscountPrice());
 			item.setTotalPrice(item.getPrice());
 			items.add(item);

+ 12 - 1
shop/src/main/java/com/zskk/shop/service/GoodService.java

@@ -81,11 +81,11 @@ public class GoodService {
 	 */
 	@Transactional
 	public Integer saveGoodBase(UserBean user, GoodBase base, BigDecimal price, BigDecimal discountPrice){
-		base.setStatus(GOOD_OFFLINE);
 		base.setSort(0);
 		base.setUid(user.getUserid());
 		base.setCtime(ToolsUtil.getNow());
 		if (base.getGid().equals(0)){
+			base.setStatus(GOOD_OFFLINE);
 			goodMapper.addGoodBase(base);
 			
 			GoodPrice priceObj = new GoodPrice();
@@ -110,6 +110,17 @@ public class GoodService {
 		return base.getGid();
 	}
 	
+	/**
+	 * 设置商品状态
+	 * @param good
+	 * @param status
+	 * @return
+	 */
+	public Boolean setGoodStatus(GoodBase good, Integer status){
+		good.setStatus(status);
+		return goodMapper.updateGoodBase(good) == 1;
+	}
+	
 	/**
 	 * 查询商品价格 1.0版本没有支持时间和类型
 	 * @param gid

+ 1 - 1
shop/src/main/resource/mapper/GoodMapper.xml

@@ -65,7 +65,7 @@
 		values(#{name}, #{describe}, #{icon}, #{sort}, #{status}, #{uid}, #{ctime})
 	</insert>
 	<update id="updateGoodBase" parameterType="com.zskk.shop.dao.entry.GoodBase">
-		update good_base set name=#{name}, `describe`=#{describe}, icon=#{icon}, sort=#{sort}, status=#{status}]
+		update good_base set name=#{name}, `describe`=#{describe}, icon=#{icon}, sort=#{sort}, status=#{status}
 		where gid=#{gid}
 	</update>
 	<update id="delGoodBase">

+ 6 - 3
shop/static/manager/src/api/index.js

@@ -1,7 +1,8 @@
 import axios from 'axios'
 var serverPath = process.env.SERVER_PATH
 axios.defaults.headers = {
-    'Content-Type': 'application/x-www-form-urlencoded'
+    'Content-Type': 'application/x-www-form-urlencoded',
+    'Accept': 'application/json'
 }
 axios.defaults.withCredentials = true
 
@@ -61,6 +62,8 @@ var post = function(url, params, vue) {
 
 export default {
     getGoods: (params, vue) => post(`${serverPath}manage/goods`, params, vue),
-    editGoodsBase: (params, vue) => post(`${serverPath}manage/editbase`, params, vue)
-
+    getOneGood: (params, vue) => post(`${serverPath}manage/getOneGood`, params, vue),
+    editGoodsBase: (params, vue) => post(`${serverPath}manage/editbase`, params, vue),
+    setGoodStatus: (params, vue) => post(`${serverPath}manage/setGoodStatus`, params, vue),
+    getGoodDescribe: (params, vue) => post(`${serverPath}manage/getGoodDescribe`, params, vue)
 }

+ 31 - 14
shop/static/manager/src/components/page/EditGoods.vue

@@ -1,5 +1,5 @@
 <template>
-    <el-form ref="form" :model="form" label-width="80px">
+    <el-form ref="form" :model="form" label-width="120px">
         <el-form-item label="商品名称">
             <el-input v-model="form.name"></el-input>
         </el-form-item>
@@ -23,7 +23,7 @@
         </el-form-item>
         <el-form-item>
             <el-button type="primary" @click="save">保存</el-button>
-            <el-button>取消</el-button>
+            <el-button @click="goBack">取消</el-button>
         </el-form-item>
     </el-form>
 </template>
@@ -36,8 +36,8 @@ export default {
         gid: 0,
         name: '',
         describe: '',
-        price:'',
-        discountPrice:'',
+        price: '',
+        discountPrice: '',
         icon: '',
         status: false
       }
@@ -75,20 +75,37 @@ export default {
         price: this.form.price,
         discountPrice: this.form.discountPrice
       }
-        let that = this
+      let that = this
       this.$http.editGoodsBase(goods, this).then(data => {
-        if (data.code === 0){
-            this.$message({
-                message: '操作成功',
-                type: 'success',
-                onClose: function (){
-                    that.$router.push("/goodsManager")
-                }
-            });
+        if (data.code === 0) {
+          this.$message({
+            message: '操作成功',
+            type: 'success',
+            duration: 1000,
+            onClose: function() {
+              that.$router.push('/goodsManager')
+            }
+          })
         }
       })
-      
+    },
+    goBack: function(){
+        this.$router.back();
     }
+  },
+  mounted: function() {
+    var gid = this.$route.query.gid
+    this.$http.getOneGood({gid:gid}, this).then(res=>{
+        if (res.code === 0){
+            var base = res.obj;
+            this.form.gid = base.gid;
+            this.form.name = base.name
+            this.form.describe = base.describe
+            this.form.price = base.price.price
+            this.form.discountPrice = base.price.discountPrice
+            this.form.icon = base.icon
+        }
+    })
   }
 }
 </script>

+ 56 - 8
shop/static/manager/src/components/page/GoodsManager.vue

@@ -1,20 +1,33 @@
 <template>
     <div>
         <el-row>
-            <el-col :span="6">
+            <el-col :span="3">
+                <el-input v-model="search" placeholder="请输入商品名称"></el-input>
+            </el-col>
+            <el-col :span="1">
+                &nbsp;
+            </el-col>
+            <el-col :span="3">
                 <el-select v-model="status">
                     <el-option value="-1" label="全部"></el-option>
                     <el-option value="1" label="在线"></el-option>
                     <el-option value="0" label="离线"></el-option>
                 </el-select>
             </el-col>
+            <el-col :span="1">
+                &nbsp;
+            </el-col>
             <el-col :span="4">
                 <el-button type="primary" @click="getItems">查询</el-button>
             </el-col>
         </el-row>
         <el-table :data="items">
             <el-table-column label="商品ID" prop="gid"></el-table-column>
-            <el-table-column label="商品图标" prop="icon">图标</el-table-column>
+            <el-table-column label="商品图标" width="110px">图标
+                <template slot-scope="scope">
+                    <img :src="scope.row.icon" style="width:100px;" />
+                </template>
+            </el-table-column>
             <el-table-column label="商品名称" prop="name"></el-table-column>
             <el-table-column label="简介" prop="describe"></el-table-column>
             <el-table-column label="原价" prop="price.price"></el-table-column>
@@ -27,10 +40,18 @@
             <el-table-column label="状态" prop="status" :formatter="statusFormater">
             </el-table-column>
             <el-table-column label="绑定套餐" prop="packageName"></el-table-column>
-            <el-table-column label="操作">
+            <el-table-column label="操作" width="250px">
                 <template slot-scope="scope">
-                    <el-button type="text" size="small">预览</el-button>
-                    <el-button type="text" size="small">编辑</el-button>
+                    <template v-if="scope.row.status == 0">
+                        <el-button type="success"  @click="setStatus(scope.row)">启用</el-button>
+                    </template>
+                    <template v-else>
+                        <el-button type="warning"    @click="setStatus(scope.row)">禁用</el-button>
+                    </template>
+                    <el-button type="text" size="small" @click="goEdit(scope.row)">编辑</el-button>
+                    <a :href="serverPath + 'good/detail/' + scope.row.gid" target="_black">
+                        <el-button type="text" size="small">预览</el-button>
+                    </a>
                 </template>
             </el-table-column>
         </el-table>
@@ -49,7 +70,10 @@ export default {
       pageSize: 20,
       items: [],
       totalCount: 0,
-      status: '-1'
+      status: '-1',
+      search:'',
+
+      serverPath:process.env.SERVER_PATH
     }
   },
   methods: {
@@ -59,7 +83,8 @@ export default {
           {
             page: this.page,
             pageSize: this.pageSize,
-            status: this.status
+            status: this.status,
+            search: this.search
           },
           this
         )
@@ -73,12 +98,35 @@ export default {
       this.getItems()
     },
     statusFormater: function(row) {
-        console.log(row.status)
       if (row.status === 1) {
         return '在线'
       } else {
         return '离线'
       }
+    },
+    setStatus: function(row){
+        let msg = row.status === 1? "禁用": "启用"
+
+        this.$confirm('您确定要将此商品设置为 "' + msg + '" , 是否继续?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          this.$http.setGoodStatus({gid: row.gid, status:(row.status === 1? false: true)}).then(res =>{
+              if (res.code === 0){
+                  row.status = row.status === 1? 0: 1;
+                  this.$message({
+                      message: '操作成功',
+                      type:'success'
+                  })
+              }
+          })
+        }).catch(() => {
+                  
+        });
+    },
+    goEdit: function (row){
+        this.$router.push({path:'/editGoods', query:{gid: row.gid}})
     }
   },
   mounted: function() {

+ 8 - 3
shop/static/manager/src/router/index.js

@@ -11,9 +11,14 @@ export default new Router({
             name: 'home',
             component: Home,
             children: [{
-                path: '/goodsManager',
-                component: resolve => require(['../components/page/GoodsManager'], resolve)
-            }]
+                    path: '/goodsManager',
+                    component: resolve => require(['../components/page/GoodsManager'], resolve)
+                },
+                {
+                    path: '/editGoods',
+                    component: resolve => require(['../components/page/EditGoods'], resolve)
+                }
+            ]
         },
         {
             path: '/demo',