PlaceWithDrawalsLogsServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. package com.iamberry.wechat.service.drp;
  2. import java.util.Date;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.apache.commons.lang3.time.DateFormatUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import com.iamberry.wechat.core.entity.PageBean;
  10. import com.iamberry.wechat.core.entity.ResultMsg;
  11. import com.iamberry.wechat.core.entity.admin.ShopSystemRule;
  12. import com.iamberry.wechat.core.entity.drp.PlaceInfo;
  13. import com.iamberry.wechat.core.entity.drp.PlaceLogs;
  14. import com.iamberry.wechat.core.entity.drp.PlaceWithDrawalsLogs;
  15. import com.iamberry.wechat.core.entity.member.Member;
  16. import com.iamberry.wechat.face.admin.SystemService;
  17. import com.iamberry.wechat.face.drp.PlaceWithDrawalsLogsService;
  18. import com.iamberry.wechat.face.member.WithdrawService;
  19. import com.iamberry.wechat.service.mapper.AdminOrderMapper;
  20. import com.iamberry.wechat.service.mapper.MemberMapper;
  21. import com.iamberry.wechat.service.mapper.PlaceInfoMapper;
  22. import com.iamberry.wechat.service.mapper.PlaceLogsMapper;
  23. import com.iamberry.wechat.service.mapper.PlaceWithDrawalsLogsMapper;
  24. import com.iamberry.wechat.tools.NameUtils;
  25. import com.iamberry.wechat.tools.ResultInfo;
  26. import com.iamberry.wechat.tools.StaticInfo;
  27. /**
  28. * @description 提现申请处理
  29. * @author ouyang
  30. * @date 2016-4-20
  31. */
  32. @Service("placeWithDrawalsLogsServiceImpl")
  33. @SuppressWarnings(value="unchecked")
  34. public class PlaceWithDrawalsLogsServiceImpl implements
  35. PlaceWithDrawalsLogsService {
  36. @Autowired
  37. private PlaceWithDrawalsLogsMapper placeWithDrawalsLogsMapper;
  38. @Autowired
  39. private PlaceInfoMapper placeInfoMapper;
  40. @Autowired
  41. private PlaceLogsMapper placeLogsMapper;
  42. @Autowired
  43. private AdminOrderMapper adminOrderMapper;
  44. @Autowired
  45. private SystemService systemService;
  46. //提现规则页面返回信息
  47. public String getTheRule() {
  48. return null;
  49. }
  50. //申请页面
  51. public Map<String,Object> apply(String openid) {
  52. PlaceInfo placeInfo= placeInfoMapper.getOnePlaceInfo2(openid);
  53. //int role=placeInfo.getPlaceRole();
  54. Map<String,Object> map=new HashMap<String,Object>();
  55. map.put("amount", placeInfo.getAmount());
  56. map.put("withdrawalsCount", systemService.selectOneShopRuleById(100).getRuleNum().intValue());
  57. map.put("lessMoney",systemService.selectOneShopRuleById(101).getRuleNum().intValue());
  58. /** 拼装数据 */
  59. //获取当前用户上一次的提款记录
  60. PlaceWithDrawalsLogs withdrawalslogs = new PlaceWithDrawalsLogs();
  61. PageBean pb = new PageBean();
  62. pb.setPageNumber(1);
  63. pb.setPageSize(1);
  64. withdrawalslogs.setPage(pb);
  65. withdrawalslogs.setOpenid(openid);
  66. List<PlaceWithDrawalsLogs> list = placeWithDrawalsLogsMapper.selectAll(withdrawalslogs); //这里有且最多一条数据,或者没有数据
  67. if(list!=null && list.size()>0 ){
  68. map.put("Withdraw", list.get(0)); //最大可取金额
  69. }
  70. //map.put("lessMoney", ResultInfo.getMoneyLimitDown);
  71. return map;
  72. }
  73. //提现申请提交
  74. public ResultMsg submitApply(PlaceWithDrawalsLogs placeWithDrawalsLogs) {
  75. ResultMsg remsg=new ResultMsg();
  76. HashMap countMap=new HashMap();
  77. placeWithDrawalsLogs.setWithDrawalsNum(placeWithDrawalsLogs.getWithDrawalsNum() * 100);
  78. countMap.put("dateMonth", DateFormatUtils.format(new Date(), "yyyyMM"));
  79. countMap.put("id", placeWithDrawalsLogs.getOpenid());
  80. int count=placeWithDrawalsLogsMapper.getApplyCount(countMap);
  81. //提现的次数
  82. ShopSystemRule sr=systemService.selectOneShopRuleById(100);
  83. if(count>=sr.getRuleNum().intValue()){
  84. remsg.setResultCode(ResultInfo.ERRORCODE);
  85. remsg.setMessage(ResultInfo.getMoneyCountError);
  86. remsg.setStatus(false);
  87. return remsg;
  88. }
  89. placeWithDrawalsLogs.setCreateDate(new Date());
  90. placeWithDrawalsLogs.setStatus(1);
  91. //根据openid设置placeId
  92. PlaceInfo placeInfo=placeInfoMapper.getOnePlaceInfo2(placeWithDrawalsLogs.getOpenid());
  93. placeWithDrawalsLogs.setPlaceId(placeInfo.getId());
  94. int money=placeWithDrawalsLogs.getWithDrawalsNum();
  95. //int role=placeInfo.getPlaceRole();
  96. Member member=null;
  97. //判断是否是导购
  98. /*if(role==5 || role==6){
  99. member=memberMapper.getMemberByUserOpenId(placeWithDrawalsLogs.getOpenid());
  100. placeInfo.setAmount(member.getUserIncome());
  101. }*/
  102. //取现金额大于账户余额
  103. if(money>placeInfo.getAmount()){
  104. remsg.setResultCode(ResultInfo.ERRORCODE);
  105. remsg.setMessage(ResultInfo.getMoneyLimitError);
  106. return remsg;
  107. }
  108. //提现的下限金额
  109. ShopSystemRule sr2=systemService.selectOneShopRuleById(101);
  110. int limitDown=sr2.getRuleNum().intValue() / 100;
  111. //每一次的取现金额 大小限制
  112. //if(money<ResultInfo.getMoneyLimitDown || money>ResultInfo.getMoneyLimitTop){
  113. if(money<limitDown || money>ResultInfo.getMoneyLimitTop){
  114. remsg.setResultCode(ResultInfo.ERRORCODE);
  115. remsg.setMessage(ResultInfo.getMoneyconditionGT + limitDown
  116. + ResultInfo.getMoneyconditionLT +ResultInfo.getMoneyLimitTop);
  117. return remsg;
  118. }
  119. int i=placeWithDrawalsLogsMapper.insert(placeWithDrawalsLogs);
  120. int backMoney=placeWithDrawalsLogs.getWithDrawalsNum();
  121. /*if(role==5 || role==6){
  122. member.setUserIncome(-backMoney);
  123. // i=memberMapper.updateUserIncomeByOpenId(member);
  124. i=adminOrderMapper.updateUserByUserId(member);
  125. }else{
  126. placeInfo.setAmount(-backMoney);
  127. // i=placeInfoMapper.update(placeInfo);
  128. i=adminOrderMapper.updatePlaceInfo(placeInfo);
  129. }*/
  130. placeInfo.setAmount(-backMoney);
  131. i=adminOrderMapper.updatePlaceInfo(placeInfo);
  132. if(i>0){
  133. remsg.setResultCode(ResultInfo.SUCCESSCODE);
  134. remsg.setMessage(NameUtils.getConfig("SUCCESSINFO"));
  135. remsg.setStatus(true);
  136. }else{
  137. remsg.setResultCode(ResultInfo.ERRORCODE);
  138. remsg.setMessage(NameUtils.getConfig("ERRORINFO"));
  139. remsg.setStatus(false);
  140. }
  141. return remsg;
  142. }
  143. //处理提现申请
  144. public ResultMsg dealApply(PlaceWithDrawalsLogs placeWithDrawalsLogs) {
  145. ResultMsg remsg=new ResultMsg();
  146. int status=placeWithDrawalsLogs.getStatus();
  147. placeWithDrawalsLogs=placeWithDrawalsLogsMapper.getOneWithDrawalsLogs(placeWithDrawalsLogs.getId());
  148. placeWithDrawalsLogs.setStatus(status);
  149. int i=10;
  150. if(placeWithDrawalsLogs.getStatus()==2){
  151. //更新提现的状态
  152. i=placeWithDrawalsLogsMapper.update(placeWithDrawalsLogs);
  153. //插入提现记录到现金记录表
  154. placeWithDrawalsLogs=placeWithDrawalsLogsMapper.getOneWithDrawalsLogs(placeWithDrawalsLogs.getId());
  155. PlaceLogs placeLogs=new PlaceLogs();
  156. placeLogs.setPlaceId(placeWithDrawalsLogs.getPlaceId());
  157. placeLogs.setType(2);
  158. placeLogs.setResType(2);
  159. placeLogs.setNums(placeWithDrawalsLogs.getWithDrawalsNum());
  160. placeLogs.setIntroduction("现金提现");
  161. placeLogs.setCreateDate(new Date());
  162. i=placeLogsMapper.insert(placeLogs);
  163. }else{
  164. PlaceInfo placeInfo=placeInfoMapper.getOnePlaceInfo(placeWithDrawalsLogs.getPlaceId());
  165. int num=placeWithDrawalsLogs.getWithDrawalsNum();
  166. /*if(placeInfo.getPlaceRole()==5 || placeInfo.getPlaceRole()==6){
  167. Member member=memberMapper.getMemberByUserOpenId(placeInfo.getOpenid());
  168. member.setUserIncome(num);
  169. //i=memberMapper.updateUserIncomeByOpenId(member);
  170. i=adminOrderMapper.updateUserByUserId(member);
  171. }else{
  172. placeInfo.setAmount(num);
  173. //更新总金额数据
  174. // i=placeInfoMapper.update(placeInfo);
  175. i=adminOrderMapper.updatePlaceInfo(placeInfo);
  176. }*/
  177. placeInfo.setAmount(num);
  178. //更新总金额数据
  179. // i=placeInfoMapper.update(placeInfo);
  180. i=adminOrderMapper.updatePlaceInfo(placeInfo);
  181. i=placeWithDrawalsLogsMapper.update(placeWithDrawalsLogs);
  182. }
  183. if(i>0){
  184. remsg.setResultCode(ResultInfo.SUCCESSCODE);
  185. remsg.setMessage(NameUtils.getConfig("SUCCESSINFO"));
  186. remsg.setStatus(true);
  187. }else{
  188. remsg.setResultCode(ResultInfo.ERRORCODE);
  189. remsg.setMessage(NameUtils.getConfig("ERRORINFO"));
  190. remsg.setStatus(false);
  191. }
  192. return remsg;
  193. }
  194. //历史提现记录
  195. public Map HistoryRecords(String openid) {
  196. Map hm=new HashMap();
  197. PlaceInfo placeInfo= placeInfoMapper.getOnePlaceInfo2(openid);
  198. /*int role=placeInfo.getPlaceRole();
  199. if(role==5 || role==6){
  200. Member member=memberMapper.getMemberByUserOpenId(openid);
  201. hm.put("amount", member.getUserIncome());
  202. }else{
  203. hm.put("amount", placeInfo.getAmount());
  204. }*/
  205. hm.put("amount", placeInfo.getAmount());
  206. PlaceWithDrawalsLogs pwd=new PlaceWithDrawalsLogs();
  207. pwd.setOpenid(openid);
  208. //pwd.setStatus(2);
  209. PageBean pb=new PageBean();
  210. pwd.setPage(pb);
  211. List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList=
  212. placeWithDrawalsLogsMapper.selectAll(pwd);
  213. hm.put("list",placeWithDrawalsLogsList);
  214. //pb.setCount(placeWithDrawalsLogsMapper.getAllCount(pwd));
  215. hm.put("page",pb);
  216. return hm;
  217. }
  218. //后台提现记录的查询
  219. public Map HistoryRecordsManager(PageBean pb) {
  220. Map hm=new HashMap();
  221. PlaceWithDrawalsLogs pwd=
  222. (PlaceWithDrawalsLogs)pb.getCondition();
  223. if(pwd.getEndDate()!=null && !"".equals(pwd.getEndDate()) ){
  224. String enddate=pwd.getEndDate();
  225. pwd.setEndDate(enddate+StaticInfo.endDateC);
  226. }
  227. //作为查询条件的
  228. PageBean page=new PageBean();
  229. page.setPageNumber(pb.getPageNumber());
  230. page.setPageSize(pb.getPageSize());
  231. if(pb.getPageCount()>0){
  232. page.setCount(pb.getPageCount());
  233. }else{
  234. page.setCount(placeWithDrawalsLogsMapper.getAllCountMore(pwd));
  235. }
  236. pwd.setPage(page);
  237. page.initRecordBegin();
  238. List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList=
  239. placeWithDrawalsLogsMapper.selectAllMore(pwd);
  240. hm.put("data",placeWithDrawalsLogsList);
  241. hm.put("page",page);
  242. return hm;
  243. }
  244. //后台提现记录的查询 -- list
  245. public List<PlaceWithDrawalsLogs> HistoryRecordsManager(PlaceWithDrawalsLogs placeWD) {
  246. List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList = placeWithDrawalsLogsMapper.selectAllMore(placeWD);
  247. return placeWithDrawalsLogsList;
  248. }
  249. //后台提现记录的查询 个数
  250. public int HistoryRMCount(PlaceWithDrawalsLogs placeWD) {
  251. int flag = placeWithDrawalsLogsMapper.getAllCountMore(placeWD);
  252. return flag;
  253. }
  254. /**
  255. * 获取下一个提现分页记录
  256. * @param pwd 提现记录
  257. * pwd 必须带有placeId,page的分页 页码pageNumber
  258. * @return
  259. */
  260. public Map HistoryRecordsNext(PlaceWithDrawalsLogs pwd) {
  261. HashMap hm=new HashMap();
  262. PageBean page=pwd.getPage();
  263. page.initRecordBegin();
  264. page.setCount(placeWithDrawalsLogsMapper.getAllCount(pwd));
  265. PlaceInfo placeInfo= placeInfoMapper.getOnePlaceInfo2(pwd.getOpenid());
  266. /*int role=placeInfo.getPlaceRole();
  267. if(role==5 || role==6){
  268. Member member=memberMapper.getMemberByUserOpenId(pwd.getOpenid());
  269. hm.put("amount", member.getUserIncome());
  270. }else{
  271. hm.put("amount", placeInfo.getAmount());
  272. }*/
  273. hm.put("amount",placeInfo.getAmount());
  274. //pwd.setStatus(2);
  275. List<PlaceWithDrawalsLogs> placeWithDrawalsLogsList=
  276. placeWithDrawalsLogsMapper.selectAll(pwd);
  277. hm.put("list", placeWithDrawalsLogsList);
  278. hm.put("pageCount",page.getPageCount());
  279. return hm;
  280. }
  281. //测试插入对象
  282. public void insertTest(PlaceWithDrawalsLogs pwd){
  283. placeWithDrawalsLogsMapper.insert(pwd);
  284. }
  285. @Override
  286. public PlaceWithDrawalsLogs getOne(int id) {
  287. return placeWithDrawalsLogsMapper.getOneWithDrawalsLogs(id);
  288. }
  289. @Override
  290. public int getTotalMoneyByPlaceId(int placeId) {
  291. // TODO Auto-generated method stub
  292. return placeWithDrawalsLogsMapper.getTotalMoneyByPlaceId(placeId);
  293. }
  294. @Override
  295. public List<PlaceWithDrawalsLogs> selectAllMore(
  296. PlaceWithDrawalsLogs placeWithDrawalsLogs) {
  297. // TODO Auto-generated method stub
  298. return placeWithDrawalsLogsMapper.selectAllMore(placeWithDrawalsLogs);
  299. }
  300. }