Browse Source

兑换码

yuhaitao14 7 years ago
parent
commit
10cf2aee38

+ 24 - 8
shop/src/main/java/com/zskk/shop/controller/admin/ExchangeCodeController.java

@@ -131,11 +131,23 @@ public class ExchangeCodeController extends AbstractController {
 	
 	@RequestMapping("/download")
 	public void download(@RequestParam("eid") Integer eid, HttpServletResponse response) throws IOException{
+		ExchangeCode exchangeCode = exchangeCodeService.queryOneExchangeCode(eid);
+		if (exchangeCode == null){
+			throw new ZSKKException(ErrorConstant.PARAM_ERROR);
+		}
+		GoodBase good = goodService.queryOneGoodBase(exchangeCode.getGid());
+		exchangeCodeService.addDownloadRecord(this.getUser(), eid);
 		List<ExchangeCodeItem> list = exchangeCodeService.getItems(eid, null);
-		this.exportItems(this.getUser(), list, response);
+		this.exportItems(this.getUser(), list, good, response);
+	}
+	
+	@RequestMapping("/downloadrecords")
+	@ResponseBody
+	public ControllerResult downloadRecords(@RequestParam("eid") Integer eid){
+		return new ControllerResult(exchangeCodeService.queryDownloadRecords(eid));
 	}
 	
-	private void exportItems(UserBean user, List<ExchangeCodeItem> items, HttpServletResponse response) throws IOException{
+	private void exportItems(UserBean user, List<ExchangeCodeItem> items, GoodBase good, HttpServletResponse response) throws IOException{
 		HSSFWorkbook workbook = new HSSFWorkbook();  
 		HSSFSheet sheet = workbook.createSheet("sheet1");
 		
@@ -146,9 +158,11 @@ public class ExchangeCodeController extends AbstractController {
 		for (int i = 0; i < items.size(); ++i){
 			ExchangeCodeItem item = items.get(i);
 			HSSFRow row = sheet.createRow(i + 1);
-			row.createCell(0).setCellValue(item.getEicode());
-			row.createCell(1).setCellValue(item.getEipwd());
-			row.createCell(2).setCellValue(item.getStatus().equals(ExchangeCodeService.ITEM_USE_STATUS_WAIT)? "未使用":"已使用");
+			row.createCell(0).setCellValue(good.getGid());
+			row.createCell(1).setCellValue(good.getName());
+			row.createCell(2).setCellValue(item.getEicode());
+			row.createCell(3).setCellValue(item.getEipwd());
+			row.createCell(4).setCellValue(item.getStatus().equals(ExchangeCodeService.ITEM_USE_STATUS_WAIT)? "未使用":"已使用");
 		}
 	
 		String fileName = "兑换码-" + user.getName() + "-" + user.getPhone() + "-" + ToolsUtil.formatTime(new Date(), ToolsUtil.getYYYYMMDDHHMMSS()) + ".xls";
@@ -160,8 +174,10 @@ public class ExchangeCodeController extends AbstractController {
 	
 	private void writeHead(HSSFSheet sheet){
 		HSSFRow row = sheet.createRow(0);
-		row.createCell(0).setCellValue("兑换码");
-		row.createCell(1).setCellValue("密码");
-		row.createCell(2).setCellValue("使用状态");
+		row.createCell(0).setCellValue("商品ID");
+		row.createCell(1).setCellValue("商品名称");
+		row.createCell(2).setCellValue("兑换码");
+		row.createCell(3).setCellValue("密码");
+		row.createCell(4).setCellValue("使用状态");
 	}
 }

+ 5 - 0
shop/src/main/java/com/zskk/shop/controller/admin/ManagerUserController.java

@@ -42,6 +42,11 @@ public class ManagerUserController extends AbstractController {
 	@RequestMapping("/add")
 	@ResponseBody
 	public ControllerResult add(@RequestParam("uid") String uid, @RequestParam("uname") String uname, @RequestParam("uphone") String uphone){
+		ManagerUser old = managerUserService.queryByUid(uid);
+		if (old != null){
+			throw new ZSKKException(ErrorConstant.USER_EXIST);
+		}
+		
 		UserInfoBean user = this.getUserInfo();
 		ManagerUser muser = new ManagerUser();
 		muser.setUid(uid);

+ 5 - 0
shop/src/main/java/com/zskk/shop/dao/ExchangeCodeMapper.java

@@ -14,6 +14,7 @@ import org.apache.ibatis.annotations.Param;
 
 import com.zskk.shop.dao.entry.ExchangeCode;
 import com.zskk.shop.dao.entry.ExchangeCodeItem;
+import com.zskk.shop.dao.entry.ExchangeCodeItemDownloadRecord;
 
 public interface ExchangeCodeMapper {
 	public List<ExchangeCode> queryAllExchangeCode(@Param("search") String search, @Param("status") Integer status, @Param("gid") Integer gid);
@@ -31,4 +32,8 @@ public interface ExchangeCodeMapper {
 	public void insertExchangeCodeItems(@Param("items") List<ExchangeCodeItem> items);
 	
 	public int updateExchangeCodeItems(ExchangeCodeItem item); 
+	
+	public List<ExchangeCodeItemDownloadRecord> queryDownloadRecords(@Param("eid") Integer eid);
+	
+	public void addDownloadRecord(ExchangeCodeItemDownloadRecord record);
 }

+ 47 - 0
shop/src/main/java/com/zskk/shop/dao/entry/ExchangeCodeItemDownloadRecord.java

@@ -0,0 +1,47 @@
+/**
+* @版权信息 (@copyright Copyright 2017-XXXX JDJR.COM All Right Reserved);
+* @see
+* @author 于海涛 京东金融【技术研发部-证券及营销平台研发部-营销平台研发部】
+* @version 1.0
+* @date 2018年7月18日
+*/
+
+package com.zskk.shop.dao.entry;
+
+public class ExchangeCodeItemDownloadRecord {
+	private Integer id;
+	private String uid;
+	private String uname;
+	private Integer eid;
+	private Integer ctime;
+	public Integer getId() {
+		return id;
+	}
+	public void setId(Integer id) {
+		this.id = id;
+	}
+	public String getUid() {
+		return uid;
+	}
+	public void setUid(String uid) {
+		this.uid = uid;
+	}
+	public String getUname() {
+		return uname;
+	}
+	public void setUname(String uname) {
+		this.uname = uname;
+	}
+	public Integer getEid() {
+		return eid;
+	}
+	public void setEid(Integer eid) {
+		this.eid = eid;
+	}
+	public Integer getCtime() {
+		return ctime;
+	}
+	public void setCtime(Integer ctime) {
+		this.ctime = ctime;
+	}
+}

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

@@ -17,6 +17,7 @@ public class ErrorConstant {
 	public static final ZSKKError NO_SET_PACKAGE 		= new ZSKKError(100002, "您还没有设置套餐");
 	public static final ZSKKError NO_SET_DESCRIBE		= new ZSKKError(100002, "您还没有设置商品详细");
 	public static final ZSKKError EICODE_ERROR			= new ZSKKError(100003, "兑换码不存在");
+	public static final ZSKKError USER_EXIST			= new ZSKKError(100004, "用户已存在");
 	
 	
 }

+ 14 - 0
shop/src/main/java/com/zskk/shop/service/ExchangeCodeService.java

@@ -24,6 +24,7 @@ import com.zskk.shop.controller.bean.UserBean;
 import com.zskk.shop.dao.ExchangeCodeMapper;
 import com.zskk.shop.dao.entry.ExchangeCode;
 import com.zskk.shop.dao.entry.ExchangeCodeItem;
+import com.zskk.shop.dao.entry.ExchangeCodeItemDownloadRecord;
 import com.zskk.shop.exception.ErrorConstant;
 import com.zskk.shop.exception.ZSKKException;
 import com.zskk.shop.utils.ToolsUtil;
@@ -158,6 +159,19 @@ public class ExchangeCodeService {
 		return exchangeCodeMapper.queryOneExchangeCodeItem(eicode);
 	}
 	
+	public List<ExchangeCodeItemDownloadRecord> queryDownloadRecords(Integer eid){
+		return exchangeCodeMapper.queryDownloadRecords(eid);
+	}
+	
+	public void addDownloadRecord(UserBean user, Integer eid){
+		ExchangeCodeItemDownloadRecord record = new ExchangeCodeItemDownloadRecord();
+		record.setUid(user.getUserid());
+		record.setUname(user.getName());
+		record.setEid(eid);
+		record.setCtime(ToolsUtil.getNow());
+		exchangeCodeMapper.addDownloadRecord(record);
+	}
+	
 	private String getTimesKey(String timeKey){
 		return "SHOP_EXCHANGE_CODE_DAY_TIMES" + timeKey;
 	}

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

@@ -100,13 +100,15 @@ public class UserCenterService {
 	public List<UserBean> queryUser(String search){
 		Map<String, String> params = new HashMap<>();
 		params.put("search", search);
+		params.put("page", "1");
+		params.put("pageSize", "10");
 		params.put("nonce", UUID.randomUUID().toString());
 		params.put("sign", this.sign(params));
 		try{
 			String content = HttpClient.doPost(uccenter + "account/queryUsers", params);
 			JSONObject obj = JSON.parseObject(content);
 			if (obj.containsKey("code") && obj.getInteger("code").equals(0)){
-				return JSON.parseArray(obj.getString("obj"), UserBean.class);
+				return JSON.parseArray(obj.getJSONObject("obj").getString("items"), UserBean.class);
 			}else{
 				return new ArrayList<>(0);
 			}

+ 10 - 0
shop/src/main/resource/mapper/ExchangeCodeMapper.xml

@@ -58,4 +58,14 @@
 		update eicode=#{eicode},eipwd=#{eipwd}, status=#{status}, utime=#{utime}, extend=#{extend}
 		where id=#{id}
 	</update>
+	
+	<select id="queryDownloadRecords" resultType="com.zskk.shop.dao.entry.ExchangeCodeItemDownloadRecord">
+		select * 
+		from exchange_code_item_download_record
+		where eid=#{eid}
+	</select>
+	<insert id="addDownloadRecord" parameterType="com.zskk.shop.dao.entry.ExchangeCodeItemDownloadRecord">
+		insert into exchange_code_item_download_record(uid, uname, eid, ctime)
+		values(#{uid}, #{uname}, #{eid}, #{ctime})
+	</insert>
 </mapper>

+ 2 - 0
shop/static/manager/src/api/index.js

@@ -101,6 +101,8 @@ export default {
     exchangeCodeUpdate: (params, vue) => post(`${serverPath}manage/exchangecode/update`, params, vue),
     echangeCodeGetitems: (params, vue) => post(`${serverPath}manage/exchangecode/getitems`, params, vue),
     echangeCodeGetItemdetail: (params, vue) => post(`${serverPath}manage/exchangecode/getitemdetail`, params, vue),
+    echangeCodeGetDownloadRecords: (params, vue) => post(`${serverPath}manage/exchangecode/downloadrecords`, params, vue),
+
 
     loginout: (params, vue) => post(`${serverPath}help/loginout`, params, vue),
 }

+ 45 - 0
shop/static/manager/src/components/page/exchange/DownloadRecord.vue

@@ -0,0 +1,45 @@
+<template>
+    <div>
+        <el-table :data="items">
+            <el-table-column label="下载人" prop="uname"></el-table-column>
+            <el-table-column label="下载时间" prop="ctime" :formatter="ctimeFormat"></el-table-column>
+        </el-table>
+    </div>
+</template>
+<script>
+import {timeDetailFormater} from '../../../util'
+export default {
+    data () {
+        return {
+            items:[],
+            eid:0
+        }
+    },
+    methods:{
+        getItems () {
+            this.$http.echangeCodeGetDownloadRecords({eid:this.eid}, this).then(res => {
+                if (res.code === 0){
+                    this.items = res.obj;
+                }
+            })
+        },
+        ctimeFormat (row) {
+            return timeDetailFormater(row.ctime)
+        }
+    },
+    mounted:function(){
+        this.eid = this.$route.query.id;
+        this.getItems()
+    }
+}
+</script>
+
+
+<style>
+.online {
+  color: #67c23a;
+}
+.offline {
+  color: #f56c6c;
+}
+</style>

+ 4 - 0
shop/static/manager/src/components/page/exchange/List.vue

@@ -26,6 +26,7 @@
                     <a :href="serverPath + 'manage/exchangecode/download?eid=' + scope.row.id">
                     <el-button type="text" size="small" >下载</el-button>
                     </a>
+                    <el-button type="text" size="small" @click="goDownloadRecords(scope.row)">下载记录</el-button>
                 </template>
             </el-table-column>
         </el-table>
@@ -60,6 +61,9 @@ export default {
         },
         goEdit (row) {
             this.$router.push({path:'/exchangeCodeEdit', query: {gid:this.gid,id:row.id}})
+        },
+        goDownloadRecords (row) {
+            this.$router.push({path:'/exchangeCodeDownloadRecord', query: {gid:this.gid,id:row.id}})
         }
     },
     mounted:function(){

+ 4 - 0
shop/static/manager/src/router/index.js

@@ -89,6 +89,10 @@ export default new Router({
                 {
                     path: 'exchangeCodeDetail',
                     component: resolve => require(['../components/page/exchange/Detail'], resolve)
+                },
+                {
+                    path: 'exchangeCodeDownloadRecord',
+                    component: resolve => require(['../components/page/exchange/DownloadRecord'], resolve)
                 }
             ]
         },

+ 56 - 30
shop/static/manager/src/util/index.js

@@ -1,83 +1,109 @@
-
 export const LOGIN_USER = "login_user"
 
 // 获取存储的数据
-export const getStorage = function(key){
+export const getStorage = function(key) {
     var val = sessionStorage.getItem(key)
-    if (val){
+    if (val) {
         return JSON.parse(val)
-    }else{
+    } else {
         return false
     }
 }
 
 // 存储数据
-export const setStorage = function(key, val){
+export const setStorage = function(key, val) {
     sessionStorage.setItem(key, JSON.stringify(val))
 }
 
 // 删除存储数据
-export const removeStorage = function(key){
+export const removeStorage = function(key) {
     sessionStorage.removeItem(key)
 }
 
 // 性别格式化
-export const sexFormater = function(sex){
+export const sexFormater = function(sex) {
     var val = sex
-    if (val === 1){
+    if (val === 1) {
         return '男'
-    }else if (val === 0){
+    } else if (val === 0) {
         return '女'
-    }else if (val === -1){
+    } else if (val === -1) {
         return '未知'
-    }else{
+    } else {
         return ''
     }
 }
 
-export const payTypeFormater = function (type){
-    if (type === 1){
+export const payTypeFormater = function(type) {
+    if (type === 1) {
         return '支付宝'
-    }else if (type === 2){
+    } else if (type === 2) {
         return '微信'
-    }else{
+    } else {
         return '未知'
     }
 }
 
-export const payStatusFormater = function (payStatus){
-    if (payStatus === 0){
+export const payStatusFormater = function(payStatus) {
+    if (payStatus === 0) {
         return '待支付'
-    }else if (payStatus === 10){
+    } else if (payStatus === 10) {
         return '支付完成'
-    }else{
+    } else {
         return '未知'
     }
 }
 
-export const checkStatusFormater = function(checkStatus){
-    if (checkStatus === 0){
+export const checkStatusFormater = function(checkStatus) {
+    if (checkStatus === 0) {
         return '未核对'
-    }else if (checkStatus === 10){
+    } else if (checkStatus === 10) {
         return '核对成功'
-    }else if (checkStatus === 20){
+    } else if (checkStatus === 20) {
         return '核对失败'
-    }else{
+    } else {
         return '未知'
     }
 }
 
-export const timeFormater = function(ctime){
-    var time    = new Date(ctime * 1000)
-    var month   = time.getMonth() + 1
-    var day     = time.getDate()
+export const timeFormater = function(ctime) {
+    var time = new Date(ctime * 1000)
+    var month = time.getMonth() + 1
+    var day = time.getDate()
 
-    if (month < 10){
+    if (month < 10) {
         month = '0' + month
     }
-    if (day < 10){
+    if (day < 10) {
         day = '0' + day
     }
 
     return time.getFullYear() + '-' + month + '-' + day
+}
+
+export const timeDetailFormater = function(ctime) {
+    var time = new Date(ctime * 1000)
+    var month = time.getMonth() + 1
+    var day = time.getDate()
+    var hour = time.getHours()
+    var minu = time.getMinutes()
+    var sec = time.getSeconds()
+
+    if (month < 10) {
+        month = '0' + month
+    }
+    if (day < 10) {
+        day = '0' + day
+    }
+    if (hour < 10) {
+        hour = '0' + hour
+    }
+    if (minu < 10) {
+        minu = '0' + minu
+    }
+    if (sec < 10) {
+        sec = '0' + sec
+    }
+
+    return time.getFullYear() + '-' + month + '-' + day + " " + hour + ":" + minu + ":" + sec
 }