package com.sinata.modular.member.controller;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.google.common.collect.Lists;
|
import com.sinata.common.enums.EnumIsDelete;
|
import com.sinata.core.base.controller.BaseController;
|
import com.sinata.core.base.tips.ErrorTip;
|
import com.sinata.core.common.annotion.BussinessLog;
|
import com.sinata.core.common.annotion.Permission;
|
import com.sinata.core.common.constant.factory.PageFactory;
|
import com.sinata.core.log.LogObjectHolder;
|
import com.sinata.core.shiro.ShiroKit;
|
import com.sinata.core.util.DateUtils2;
|
import com.sinata.core.util.ExcelExportUtil;
|
import com.sinata.core.util.ToolUtil;
|
import com.sinata.modular.mall.model.MallGoodsSku;
|
import com.sinata.modular.mall.service.IMallGoodsSkuService;
|
import com.sinata.modular.member.model.MemMerchant;
|
import com.sinata.modular.member.model.MerchantSysUser;
|
import com.sinata.modular.member.service.IMemMerchantService;
|
import com.sinata.modular.member.service.IMemUserService;
|
import com.sinata.modular.member.service.IMerchantSysUserService;
|
import com.sinata.modular.system.model.AreaCity;
|
import com.sinata.modular.system.model.StoreService;
|
import com.sinata.modular.system.service.IAreaCityService;
|
import com.sinata.modular.system.service.IStoreServiceService;
|
import java.util.HashMap;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 商家信息控制器
|
*
|
* @author goku
|
*/
|
@Controller
|
@RequestMapping("/memMerchant")
|
public class MemMerchantController extends BaseController {
|
|
private String PREFIX = "/member/memMerchant/";
|
|
@Autowired
|
private IMemUserService memUserService;
|
|
@Autowired
|
private IMemMerchantService memMerchantService;
|
@Resource
|
private IStoreServiceService storeServiceService;
|
@Resource
|
private IAreaCityService areaCityService;
|
|
@Resource
|
private IMallGoodsSkuService mallGoodsSkuService;
|
|
@Resource
|
private IMerchantSysUserService sysUserService;
|
|
|
/**
|
* 跳转到商家信息首页
|
*/
|
@RequestMapping("")
|
public String index(Model model) {
|
Wrapper wrapper = new EntityWrapper<AreaCity>().orderBy("id", false);
|
wrapper.eq("is_open", 1);
|
wrapper.eq("is_delete", EnumIsDelete.EXISTED.index);
|
//model.addAttribute("cityAreaList", areaCityService.selectList(wrapper));
|
wrapper.groupBy("province_code");
|
model.addAttribute("provinceList", areaCityService.selectList(wrapper));
|
return PREFIX + "memMerchant.html";
|
}
|
|
/**
|
* 跳转到商家审核信息首页
|
*/
|
@RequestMapping("/auditeIndex")
|
public String auditeIndex() {
|
return PREFIX + "memMerchant-audite.html";
|
}
|
|
/**
|
* 跳转到添加商家信息
|
*/
|
@RequestMapping("/memMerchant_add")
|
public String memMerchantAdd(Model model) {
|
Wrapper wrapper = new EntityWrapper<StoreService>().orderBy("id", false);
|
wrapper.eq("status", 1);
|
wrapper.eq("is_delete", EnumIsDelete.EXISTED.index);
|
model.addAttribute("serviceList", storeServiceService.selectList(wrapper));
|
Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
|
wrapper2.eq("is_open", 1);
|
wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
|
model.addAttribute("cityAreaList", areaCityService.selectList(wrapper2));
|
return PREFIX + "memMerchant_add.html";
|
}
|
|
/**
|
* 跳转到修改商家信息
|
*/
|
@RequestMapping("/memMerchant_update/{memMerchantId}")
|
public String memMerchantUpdate(@PathVariable Integer memMerchantId, Model model) {
|
Wrapper wrapper = new EntityWrapper<StoreService>().orderBy("id", false);
|
wrapper.eq("status", 1);
|
wrapper.eq("is_delete", EnumIsDelete.EXISTED.index);
|
model.addAttribute("serviceList", storeServiceService.selectList(wrapper));
|
MemMerchant memMerchant = memMerchantService.selectById(memMerchantId);
|
model.addAttribute("item", memMerchant);
|
Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
|
wrapper2.eq("is_open", 1);
|
wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
|
model.addAttribute("cityAreaList", areaCityService.selectList(wrapper2));
|
List<HashMap<String, Object>> list = mallGoodsSkuService.queryMerchantGoodsList(
|
memMerchant.getId());
|
model.addAttribute("merchantGoodsList", list);
|
LogObjectHolder.me().set(memMerchant);
|
return PREFIX + "memMerchant_edit.html";
|
}
|
|
/**
|
* 跳转商家信息详情
|
*/
|
@RequestMapping(value = "/detail/{memMerchantId}")
|
public Object detail(@PathVariable("memMerchantId") Integer memMerchantId, Model model) {
|
Wrapper wrapper = new EntityWrapper<StoreService>().orderBy("id", false);
|
wrapper.eq("status", 1);
|
wrapper.eq("is_delete", EnumIsDelete.EXISTED.index);
|
model.addAttribute("serviceList", storeServiceService.selectList(wrapper));
|
MemMerchant memMerchant = memMerchantService.selectById(memMerchantId);
|
model.addAttribute("item", memMerchant);
|
Wrapper wrapper2 = new EntityWrapper<AreaCity>().orderBy("id", false);
|
wrapper2.eq("is_open", 1);
|
wrapper2.eq("is_delete", EnumIsDelete.EXISTED.index);
|
model.addAttribute("cityAreaList", areaCityService.selectList(wrapper2));
|
model.addAttribute("merchantGoodsList", mallGoodsSkuService.queryMerchantGoodsList(memMerchant.getId()));
|
LogObjectHolder.me().set(memMerchant);
|
return PREFIX + "memMerchant_detail.html";
|
}
|
|
/**
|
* 跳转到修改商家信息
|
*/
|
@RequestMapping("/memMerchantAudite/{memMerchantId}")
|
public String memMerchantAudite(@PathVariable Integer memMerchantId, Model model) {
|
MemMerchant memMerchant = memMerchantService.selectById(memMerchantId);
|
model.addAttribute("item", memMerchant);
|
LogObjectHolder.me().set(memMerchant);
|
return PREFIX + "memMerchant_edit.html";
|
}
|
|
/**
|
* 新增商家信息
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "新增商家信息")
|
@RequestMapping(value = "/add")
|
@Transactional(rollbackFor = {Exception.class})
|
public Object add(MemMerchant memMerchant) {
|
try {
|
verifMerchantPhone(memMerchant.getImAccount(),null);
|
}catch (Exception e){
|
return new ErrorTip(400,e.getMessage());
|
}
|
memMerchantService.insert(memMerchant);
|
addMerchantGoods(memMerchant.getProductId(), memMerchant.getId());
|
MerchantSysUser sysUser = new MerchantSysUser();
|
sysUser.setId(memMerchant.getId());
|
sysUser.setAccount(memMerchant.getImAccount());
|
sysUser.setPhone(memMerchant.getImAccount());
|
sysUser.setSalt(ShiroKit.getRandomSalt(5));
|
sysUser.setPassword(ShiroKit.md5(memMerchant.getImPassword(), sysUser.getSalt()));
|
sysUser.setName(memMerchant.getMerchantName());
|
sysUserService.insertOrUpdate(sysUser);
|
return SUCCESS_TIP;
|
}
|
private void verifMerchantPhone(String phone,Integer userId){
|
Wrapper<MemMerchant> wrapper = new EntityWrapper<>();
|
wrapper.eq("im_account",phone);
|
wrapper.eq("is_delete",0);
|
if(Objects.nonNull(userId)){
|
wrapper.ne("id",userId);
|
}
|
List<MemMerchant> merchantList = memMerchantService.selectList(wrapper);
|
if(merchantList.size() > 0){
|
throw new IllegalArgumentException("该账号已经绑定商户");
|
}
|
}
|
|
private void addMerchantGoods(String productId, Integer merchantId) {
|
if (StrUtil.isNotEmpty(productId)) {
|
JSONArray jsonArray = JSONArray.parseArray(productId);
|
List<MallGoodsSku> goodsList = new ArrayList<>();
|
for (int i = 0; i < jsonArray.size(); i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
Wrapper wrapper = new EntityWrapper<MallGoodsSku>();
|
wrapper.eq("goods_id", jsonObject.getInteger("goodsId"));
|
if (Objects.nonNull(jsonObject.get("goodsSkuId"))) {
|
MallGoodsSku sku = new MallGoodsSku();
|
sku.setPriceMerchant(jsonObject.getBigDecimal("price"));
|
sku.setState(jsonObject.getInteger("state"));
|
wrapper.eq("merchant_id", merchantId)
|
.eq("id", jsonObject.getInteger("goodsSkuId"));
|
mallGoodsSkuService.update(sku, wrapper);
|
} else {
|
//查询门店sku,防止重复添加
|
wrapper.eq("merchant_id", merchantId).
|
eq("spec_ids", jsonObject.getInteger("specIds"));
|
MallGoodsSku specSku = mallGoodsSkuService.selectOne(wrapper);
|
if (Objects.nonNull(specSku)) {
|
specSku.setPriceMerchant(jsonObject.getBigDecimal("price"));
|
specSku.setState(jsonObject.getInteger("state"));
|
mallGoodsSkuService.updateById(specSku);
|
} else {
|
wrapper = new EntityWrapper<MallGoodsSku>();
|
wrapper.eq("spec_ids", jsonObject.getInteger("specIds"))
|
.eq("merchant_id", 0)
|
.eq("goods_id", jsonObject.getInteger("goodsId"));
|
MallGoodsSku sku = mallGoodsSkuService.selectOne(wrapper);
|
MallGoodsSku goodsSku = new MallGoodsSku();
|
BeanUtils.copyProperties(sku, goodsSku);
|
goodsSku.setPriceMerchant(jsonObject.getBigDecimal("price"));
|
goodsSku.setPrice(sku.getPrice());
|
goodsSku.setPriceMember(sku.getPriceMember());
|
goodsSku.setPriceSale(sku.getPriceSale());
|
goodsSku.setId(null);
|
goodsSku.setState(jsonObject.getInteger("state"));
|
goodsSku.setSkuId(sku.getId());
|
goodsSku.setMerchantId(merchantId);
|
goodsList.addAll(Lists.newArrayList(goodsSku));
|
}
|
}
|
}
|
if (goodsList.size() > 0) {
|
mallGoodsSkuService.insertBatch(goodsList);
|
}
|
}
|
}
|
|
/**
|
* 删除/批量删除
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "删除/批量删除商家信息")
|
@RequestMapping(value = "/delete")
|
public Object delete(@RequestParam String ids) {
|
// 逻辑删除
|
memMerchantService.updateForSet("is_delete = 1", new EntityWrapper<MemMerchant>().in("id", ids.split(",")));
|
sysUserService.updateForSet("status = 3", new EntityWrapper<MerchantSysUser>().in("id", ids.split(",")));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改商家信息
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "修改商家信息")
|
@RequestMapping(value = "/update")
|
@Transactional(rollbackFor = {Exception.class})
|
public Object update(MemMerchant memMerchant) {
|
try {
|
verifMerchantPhone(memMerchant.getImAccount(),memMerchant.getId());
|
}catch (Exception e){
|
return new ErrorTip(400,e.getMessage());
|
}
|
memMerchantService.updateById(memMerchant);
|
addMerchantGoods(memMerchant.getProductId(), memMerchant.getId());
|
MerchantSysUser sysUser = new MerchantSysUser();
|
sysUser.setId(memMerchant.getId());
|
sysUser.setAccount(memMerchant.getImAccount());
|
sysUser.setPhone(memMerchant.getImAccount());
|
sysUser.setSalt(ShiroKit.getRandomSalt(5));
|
sysUser.setPassword(ShiroKit.md5(memMerchant.getImPassword(), sysUser.getSalt()));
|
sysUser.setName(memMerchant.getMerchantName());
|
sysUserService.insertOrUpdate(sysUser);
|
return SUCCESS_TIP;
|
}
|
|
|
@ResponseBody
|
@RequestMapping(value = "/list")
|
public Object list(String beginTime, String endTime, String merchantName, Integer cityCode1, Integer cityCode2, Integer cityCode3) {
|
Page<MemMerchant> page = new PageFactory().defaultPage();
|
// 时间搜索
|
if (ToolUtil.isNotEmpty(beginTime)) {
|
beginTime = beginTime + " 00:00:00";
|
}
|
if (ToolUtil.isNotEmpty(endTime)) {
|
endTime = endTime + " 23:59:59";
|
}
|
|
// 查询数据列表
|
List<MemMerchant> list = memMerchantService.queryMerchantList(page, beginTime, endTime, merchantName, cityCode1, cityCode2, cityCode3);
|
|
page.setRecords(list);
|
return super.packForBT(page);
|
}
|
|
/**
|
* 导出用户信息列表
|
*/
|
@RequestMapping(value = "/export")
|
@ResponseBody
|
public void export(String beginTime, String endTime, String merchantName, Integer cityCode1, Integer cityCode2, Integer cityCode3, HttpServletResponse response) {
|
Page<MemMerchant> page = new PageFactory().defaultPage();
|
|
// 时间搜索
|
if (StrUtil.isNotBlank(beginTime)) {
|
beginTime = beginTime + " 00:00:00";
|
}
|
if (StrUtil.isNotBlank(endTime)) {
|
endTime = endTime + " 23:59:59";
|
}
|
|
// 查询数据列表
|
List<MemMerchant> list = memMerchantService.queryMerchantList(page, beginTime, endTime, merchantName, cityCode1, cityCode2, cityCode3);
|
|
// 表格数据【封装】
|
List<List<Object>> dataList = new ArrayList<>();
|
|
// 头部列【封装】
|
List<Object> shellList = new ArrayList<>();
|
shellList.add("添加时间");
|
shellList.add("门店运营时间");
|
shellList.add("商家名称");
|
shellList.add("所在城市");
|
shellList.add("详细地址");
|
shellList.add("负责人");
|
shellList.add("门店电话");
|
shellList.add("营业时间");
|
shellList.add("商品数量");
|
shellList.add("门店服务");
|
dataList.add(shellList);
|
|
// 详细数据列【封装】
|
for (MemMerchant map : list) {
|
shellList = new ArrayList<>();
|
shellList.add(DateUtils2.getTime(map.getCreateTime()));
|
shellList.add(map.getStartTime());
|
shellList.add(map.getMerchantName());
|
shellList.add(map.getCityName());
|
shellList.add(map.getAddress());
|
shellList.add(map.getLinkman());
|
shellList.add(map.getLinkPhone());
|
shellList.add(getDate(map.getWorkStartDate()) + "至" + getDate(map.getWorkEndDate()) + " "
|
+ map.getWorkStartTime() + "-" + map.getWorkEndTime());
|
shellList.add(map.getNumber());
|
shellList.add(map.getServiceName());
|
dataList.add(shellList);
|
}
|
try {
|
// 调用工具类进行导出
|
ExcelExportUtil.easySheet("导出数据" + DateUtils2.formatDate(new Date(), "YYYYMMddHHmmSS"), "导出数据", dataList, response);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
private String getDate(String key) {
|
String value = "周一";
|
switch (key) {
|
case "2":
|
value = "周二";
|
break;
|
case "3":
|
value = "周三";
|
break;
|
case "4":
|
value = "周四";
|
break;
|
case "5":
|
value = "周五";
|
break;
|
case "6":
|
value = "周六";
|
break;
|
case "7":
|
value = "周日";
|
break;
|
default:
|
break;
|
}
|
return value;
|
}
|
|
|
}
|