123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- package com.iamberry.wechat.service.drp;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.commons.lang3.time.DateFormatUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.iamberry.wechat.core.entity.PageBean;
- import com.iamberry.wechat.core.entity.ResultMsg;
- import com.iamberry.wechat.core.entity.admin.ShopSystemRule;
- import com.iamberry.wechat.core.entity.drp.PlaceInfo;
- import com.iamberry.wechat.core.entity.drp.PlaceLogs;
- import com.iamberry.wechat.core.entity.drp.PlaceWithDrawalsLogs;
- import com.iamberry.wechat.core.entity.member.Member;
- import com.iamberry.wechat.face.admin.SystemService;
- import com.iamberry.wechat.face.drp.PlaceWithDrawalsLogsService;
- import com.iamberry.wechat.face.member.WithdrawService;
- import com.iamberry.wechat.service.mapper.AdminOrderMapper;
- import com.iamberry.wechat.service.mapper.MemberMapper;
- import com.iamberry.wechat.service.mapper.PlaceInfoMapper;
- import com.iamberry.wechat.service.mapper.PlaceLogsMapper;
- import com.iamberry.wechat.service.mapper.PlaceWithDrawalsLogsMapper;
- import com.iamberry.wechat.tools.NameUtils;
- import com.iamberry.wechat.tools.ResultInfo;
- import com.iamberry.wechat.tools.StaticInfo;
- /**
- * @description 提现申请处理
- * @author ouyang
- * @date 2016-4-20
- */
- @Service("placeWithDrawalsLogsServiceImpl")
- @SuppressWarnings(value="unchecked")
- public class PlaceWithDrawalsLogsServiceImpl implements
- PlaceWithDrawalsLogsService {
- @Autowired
- private PlaceWithDrawalsLogsMapper placeWithDrawalsLogsMapper;
-
- @Autowired
- private PlaceInfoMapper placeInfoMapper;
-
- @Autowired
- private PlaceLogsMapper placeLogsMapper;
-
- @Autowired
- private AdminOrderMapper adminOrderMapper;
-
- @Autowired
- private SystemService systemService;
-
- //提现规则页面返回信息
- public String getTheRule() {
- return null;
- }
- //申请页面
- public Map<String,Object> apply(String openid) {
- PlaceInfo placeInfo= placeInfoMapper.getOnePlaceInfo2(openid);
- //int role=placeInfo.getPlaceRole();
- Map<String,Object> map=new HashMap<String,Object>();
- map.put("amount", placeInfo.getAmount());
- map.put("withdrawalsCount", systemService.selectOneShopRuleById(100).getRuleNum().intValue());
- map.put("lessMoney",systemService.selectOneShopRuleById(101).getRuleNum().intValue());
- /** 拼装数据 */
- //获取当前用户上一次的提款记录
- PlaceWithDrawalsLogs withdrawalslogs = new PlaceWithDrawalsLogs();
- PageBean pb = new PageBean();
- pb.setPageNumber(1);
- pb.setPageSize(1);
- withdrawalslogs.setPage(pb);
- withdrawalslogs.setOpenid(openid);
- List<PlaceWithDrawalsLogs> list = placeWithDrawalsLogsMapper.selectAll(withdrawalslogs); //这里有且最多一条数据,或者没有数据
- if(list!=null && list.size()>0 ){
- map.put("Withdraw", list.get(0)); //最大可取金额
- }
- //map.put("lessMoney", ResultInfo.getMoneyLimitDown);
- return map;
- }
- //提现申请提交
- public ResultMsg submitApply(PlaceWithDrawalsLogs placeWithDrawalsLogs) {
- ResultMsg remsg=new ResultMsg();
- HashMap countMap=new HashMap();
- placeWithDrawalsLogs.setWithDrawalsNum(placeWithDrawalsLogs.getWithDrawalsNum() * 100);
- countMap.put("dateMonth", DateFormatUtils.format(new Date(), "yyyyMM"));
- countMap.put("id", placeWithDrawalsLogs.getOpenid());
- int count=placeWithDrawalsLogsMapper.getApplyCount(countMap);
- //提现的次数
- ShopSystemRule sr=systemService.selectOneShopRuleById(100);
-
- if(count>=sr.getRuleNum().intValue()){
- remsg.setResultCode(ResultInfo.ERRORCODE);
- remsg.setMessage(ResultInfo.getMoneyCountError);
- remsg.setStatus(false);
- return remsg;
- }
-
- placeWithDrawalsLogs.setCreateDate(new Date());
- placeWithDrawalsLogs.setStatus(1);
- //根据openid设置placeId
- PlaceInfo placeInfo=placeInfoMapper.getOnePlaceInfo2(placeWithDrawalsLogs.getOpenid());
- placeWithDrawalsLogs.setPlaceId(placeInfo.getId());
-
- int money=placeWithDrawalsLogs.getWithDrawalsNum();
- //int role=placeInfo.getPlaceRole();
- Member member=null;
- //判断是否是导购
- /*if(role==5 || role==6){
- member=memberMapper.getMemberByUserOpenId(placeWithDrawalsLogs.getOpenid());
- placeInfo.setAmount(member.getUserIncome());
- }*/
- //取现金额大于账户余额
- if(money>placeInfo.getAmount()){
- remsg.setResultCode(ResultInfo.ERRORCODE);
- remsg.setMessage(ResultInfo.getMoneyLimitError);
- return remsg;
- }
- //提现的下限金额
- ShopSystemRule sr2=systemService.selectOneShopRuleById(101);
- int limitDown=sr2.getRuleNum().intValue() / 100;
- //每一次的取现金额 大小限制
- //if(money<ResultInfo.getMoneyLimitDown || money>ResultInfo.getMoneyLimitTop){
- if(money<limitDown || money>ResultInfo.getMoneyLimitTop){
- remsg.setResultCode(ResultInfo.ERRORCODE);
- remsg.setMessage(ResultInfo.getMoneyconditionGT + limitDown
- + ResultInfo.getMoneyconditionLT +ResultInfo.getMoneyLimitTop);
- return remsg;
- }
-
- int i=placeWithDrawalsLogsMapper.insert(placeWithDrawalsLogs);
- int backMoney=placeWithDrawalsLogs.getWithDrawalsNum();
-
- /*if(role==5 || role==6){
- member.setUserIncome(-backMoney);
- // i=memberMapper.updateUserIncomeByOpenId(member);
- i=adminOrderMapper.updateUserByUserId(member);
- }else{
- placeInfo.setAmount(-backMoney);
- // i=placeInfoMapper.update(placeInfo);
- i=adminOrderMapper.updatePlaceInfo(placeInfo);
- }*/
-
- placeInfo.setAmount(-backMoney);
- i=adminOrderMapper.updatePlaceInfo(placeInfo);
-
- if(i>0){
- remsg.setResultCode(ResultInfo.SUCCESSCODE);
- remsg.setMessage(NameUtils.getConfig("SUCCESSINFO"));
- remsg.setStatus(true);
- }else{
- remsg.setResultCode(ResultInfo.ERRORCODE);
- remsg.setMessage(NameUtils.getConfig("ERRORINFO"));
- remsg.setStatus(false);
- }
- return remsg;
- }
- //处理提现申请
- public ResultMsg dealApply(PlaceWithDrawalsLogs placeWithDrawalsLogs) {
- ResultMsg remsg=new ResultMsg();
- int status=placeWithDrawalsLogs.getStatus();
- placeWithDrawalsLogs=placeWithDrawalsLogsMapper.getOneWithDrawalsLogs(placeWithDrawalsLogs.getId());
- placeWithDrawalsLogs.setStatus(status);
- int i=10;
- if(placeWithDrawalsLogs.getStatus()==2){
-
- //更新提现的状态
- i=placeWithDrawalsLogsMapper.update(placeWithDrawalsLogs);
- //插入提现记录到现金记录表
- placeWithDrawalsLogs=placeWithDrawalsLogsMapper.getOneWithDrawalsLogs(placeWithDrawalsLogs.getId());
- PlaceLogs placeLogs=new PlaceLogs();
- placeLogs.setPlaceId(placeWithDrawalsLogs.getPlaceId());
- placeLogs.setType(2);
- placeLogs.setResType(2);
- placeLogs.setNums(placeWithDrawalsLogs.getWithDrawalsNum());
- placeLogs.setIntroduction("现金提现");
- placeLogs.setCreateDate(new Date());
- i=placeLogsMapper.insert(placeLogs);
-
- }else{
- PlaceInfo placeInfo=placeInfoMapper.getOnePlaceInfo(placeWithDrawalsLogs.getPlaceId());
- int num=placeWithDrawalsLogs.getWithDrawalsNum();
-
- /*if(placeInfo.getPlaceRole()==5 || placeInfo.getPlaceRole()==6){
- Member member=memberMapper.getMemberByUserOpenId(placeInfo.getOpenid());
- member.setUserIncome(num);
- //i=memberMapper.updateUserIncomeByOpenId(member);
- i=adminOrderMapper.updateUserByUserId(member);
- }else{
- placeInfo.setAmount(num);
- //更新总金额数据
- // i=placeInfoMapper.update(placeInfo);
- i=adminOrderMapper.updatePlaceInfo(placeInfo);
- }*/
-
- placeInfo.setAmount(num);
- //更新总金额数据
- // i=placeInfoMapper.update(placeInfo);
- i=adminOrderMapper.updatePlaceInfo(placeInfo);
-
- i=placeWithDrawalsLogsMapper.update(placeWithDrawalsLogs);
- }
- if(i>0){
- remsg.setResultCode(ResultInfo.SUCCESSCODE);
- remsg.setMessage(NameUtils.getConfig("SUCCESSINFO"));
- remsg.setStatus(true);
- }else{
- remsg.setResultCode(ResultInfo.ERRORCODE);
- remsg.setMessage(NameUtils.getConfig("ERRORINFO"));
- remsg.setStatus(false);
- }
- return remsg;
- }
-
- //历史提现记录
- public Map HistoryRecords(String openid) {
- Map hm=new HashMap();
- PlaceInfo placeInfo= placeInfoMapper.getOnePlaceInfo2(openid);
- /*int role=placeInfo.getPlaceRole();
-
- if(role==5 || role==6){
- Member member=memberMapper.getMemberByUserOpenId(openid);
- hm.put("amount", member.getUserIncome());
- }else{
- hm.put("amount", placeInfo.getAmount());
- }*/
- hm.put("amount", placeInfo.getAmount());
- PlaceWithDrawalsLogs pwd=new PlaceWithDrawalsLogs();
- pwd.setOpenid(openid);
- //pwd.setStatus(2);
- PageBean pb=new PageBean();
- pwd.setPage(pb);
-
- List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList=
- placeWithDrawalsLogsMapper.selectAll(pwd);
- hm.put("list",placeWithDrawalsLogsList);
-
- //pb.setCount(placeWithDrawalsLogsMapper.getAllCount(pwd));
- hm.put("page",pb);
-
- return hm;
- }
-
- //后台提现记录的查询
- public Map HistoryRecordsManager(PageBean pb) {
- Map hm=new HashMap();
- PlaceWithDrawalsLogs pwd=
- (PlaceWithDrawalsLogs)pb.getCondition();
- if(pwd.getEndDate()!=null && !"".equals(pwd.getEndDate()) ){
- String enddate=pwd.getEndDate();
- pwd.setEndDate(enddate+StaticInfo.endDateC);
- }
-
- //作为查询条件的
- PageBean page=new PageBean();
- page.setPageNumber(pb.getPageNumber());
- page.setPageSize(pb.getPageSize());
-
- if(pb.getPageCount()>0){
- page.setCount(pb.getPageCount());
- }else{
- page.setCount(placeWithDrawalsLogsMapper.getAllCountMore(pwd));
- }
-
- pwd.setPage(page);
- page.initRecordBegin();
-
- List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList=
- placeWithDrawalsLogsMapper.selectAllMore(pwd);
- hm.put("data",placeWithDrawalsLogsList);
-
- hm.put("page",page);
-
- return hm;
- }
- //后台提现记录的查询 -- list
- public List<PlaceWithDrawalsLogs> HistoryRecordsManager(PlaceWithDrawalsLogs placeWD) {
- List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList = placeWithDrawalsLogsMapper.selectAllMore(placeWD);
- return placeWithDrawalsLogsList;
- }
- //后台提现记录的查询 个数
- public int HistoryRMCount(PlaceWithDrawalsLogs placeWD) {
- int flag = placeWithDrawalsLogsMapper.getAllCountMore(placeWD);
- return flag;
- }
- /**
- * 获取下一个提现分页记录
- * @param pwd 提现记录
- * pwd 必须带有placeId,page的分页 页码pageNumber
- * @return
- */
- public Map HistoryRecordsNext(PlaceWithDrawalsLogs pwd) {
- HashMap hm=new HashMap();
-
- PageBean page=pwd.getPage();
- page.initRecordBegin();
-
- page.setCount(placeWithDrawalsLogsMapper.getAllCount(pwd));
- PlaceInfo placeInfo= placeInfoMapper.getOnePlaceInfo2(pwd.getOpenid());
- /*int role=placeInfo.getPlaceRole();
- if(role==5 || role==6){
- Member member=memberMapper.getMemberByUserOpenId(pwd.getOpenid());
- hm.put("amount", member.getUserIncome());
- }else{
- hm.put("amount", placeInfo.getAmount());
- }*/
- hm.put("amount",placeInfo.getAmount());
-
- //pwd.setStatus(2);
- List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList=
- placeWithDrawalsLogsMapper.selectAll(pwd);
- hm.put("list", placeWithDrawalsLogsList);
- hm.put("pageCount",page.getPageCount());
-
- return hm;
- }
-
- //测试插入对象
- public void insertTest(PlaceWithDrawalsLogs pwd){
- placeWithDrawalsLogsMapper.insert(pwd);
- }
- @Override
- public PlaceWithDrawalsLogs getOne(int id) {
- return placeWithDrawalsLogsMapper.getOneWithDrawalsLogs(id);
- }
- @Override
- public int getTotalMoneyByPlaceId(int placeId) {
- // TODO Auto-generated method stub
- return placeWithDrawalsLogsMapper.getTotalMoneyByPlaceId(placeId);
- }
- @Override
- public List<PlaceWithDrawalsLogs> selectAllMore(
- PlaceWithDrawalsLogs placeWithDrawalsLogs) {
- // TODO Auto-generated method stub
- return placeWithDrawalsLogsMapper.selectAllMore(placeWithDrawalsLogs);
- }
- }
|