| | |
| | | import com.ks.goldcorn.exception.GoldAppException; |
| | | import com.ks.goldcorn.exception.GoldTradeException; |
| | | import com.ks.goldcorn.exception.GoldUserException; |
| | | import com.ks.goldcorn.pojo.DO.GoldCornGetSource; |
| | | import com.ks.goldcorn.pojo.DO.GoldCornRecord; |
| | | import com.ks.goldcorn.pojo.DO.GoldCornRecordCountMap; |
| | | import com.ks.goldcorn.pojo.Query.GoldCornRecordQuery; |
| | | import com.ks.goldcorn.service.remote.GoldCornBalanceService; |
| | | import com.ks.goldcorn.service.remote.GoldCornGetSourceService; |
| | | import com.ks.goldcorn.service.remote.GoldCornRecordService; |
| | | import com.ks.goldcorn.service.remote.GoldCornTradeService; |
| | | import com.yeshi.buwan.domain.goldcorn.CodeCornGetSourceType; |
| | | import com.yeshi.buwan.domain.vip.OrderType; |
| | | import com.yeshi.buwan.domain.vip.OrderRecord; |
| | | import com.yeshi.buwan.exception.goldcorn.GoldCornException; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | public class GoldCornManager { |
| | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | @Reference(version = "1.0") |
| | | @Reference(version = "1.0", check = false) |
| | | private GoldCornTradeService goldCornTradeService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private GoldCornRecordService goldCornRecordService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private GoldCornBalanceService goldCornBalanceService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private GoldCornGetSourceService goldCornGetSourceService; |
| | | |
| | | public void init(String uid) throws Exception { |
| | | goldCornBalanceService.init(getAppCode(), getUid(uid)); |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | throw new GoldAppException(GoldAppException.CODE_NOT_EXIST, "应用不存在"); |
| | | } |
| | | return appCode; |
| | | } |
| | | |
| | | public long getBalance(String uid) { |
| | | if (StringUtil.isNullOrEmpty(uid)) |
| | | return 0; |
| | | try { |
| | | Long count = goldCornBalanceService.getBalance(getAppCode(), getUid(uid)); |
| | | if (count == null) { |
| | | init(uid); |
| | | } |
| | | return count == null ? 0 : count; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | |
| | | consumeGoldCorn(appCode, tuid, sourceCode, goldCornCount, title, desc); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加金币 |
| | | * |
| | | * @param uid |
| | | * @param source |
| | | * @param goldCorn |
| | | * @param title |
| | | * @param desc |
| | | * @throws GoldUserException |
| | | * @throws GoldAppException |
| | | * @throws GoldTradeException |
| | | * @throws Exception |
| | | */ |
| | | public void addGoldCorn(String uid, CodeCornGetSourceType source, Integer goldCorn, String title, String desc) throws GoldUserException, GoldAppException, GoldTradeException, Exception { |
| | | addGoldCorn(getAppCode(), getUid(uid), source.name(), goldCorn, title, desc); |
| | | } |
| | | |
| | | public GoldCornGetSource getGoldCornGetSource(CodeCornGetSourceType source) throws GoldAppException { |
| | | return goldCornGetSourceService.selectByAppAndCode(getAppCode(), source.name()); |
| | | } |
| | | |
| | | /** |
| | | * 返回影视豆 |
| | | * |
| | |
| | | addGoldCorn(appCode, tuid, sourceCode, record.getGoldCorn(), title, desc); |
| | | } |
| | | |
| | | public List<GoldCornRecord> getRecordList(GoldCornRecordQuery query, String uid) throws Exception { |
| | | query.setAppCode(getAppCode()); |
| | | query.setUid(getUid(uid)); |
| | | return goldCornRecordService.listUserRecord(query); |
| | | } |
| | | |
| | | |
| | | public long getRecordCount(GoldCornRecordQuery query, String uid) throws Exception { |
| | | query.setAppCode(getAppCode()); |
| | | query.setUid(getUid(uid)); |
| | | return goldCornRecordService.countUserRecord(query); |
| | | } |
| | | |
| | | private void addGoldCorn(String appCode, String uid, String sourceCode, Integer goldCornCount, String title, String desc) throws GoldUserException, GoldAppException, GoldTradeException { |
| | | goldCornTradeService.addGoldCorn(appCode, uid, sourceCode, goldCornCount, title, desc); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public List<GoldCornGetSource> listGetCornSource(int page, int pageSize) throws GoldAppException { |
| | | return goldCornGetSourceService.listShow(getAppCode(), page, pageSize); |
| | | } |
| | | |
| | | public List<GoldCornRecordCountMap> countRecordByGetSource(String uid, List<String> sourceCodes, Date minCreateTime, Date maxCreateTime) throws Exception { |
| | | if (StringUtil.isNullOrEmpty(uid)) { |
| | | return new ArrayList<>(); |
| | | } |
| | | GoldCornRecordQuery query = new GoldCornRecordQuery(); |
| | | query.setUid(getUid(uid)); |
| | | query.setAppCode(getAppCode()); |
| | | query.setSourceCodes(sourceCodes); |
| | | query.setMinCreateTime(minCreateTime); |
| | | query.setMaxCreateTime(maxCreateTime); |
| | | query.setType(GoldCornRecord.TYPE_GET); |
| | | return goldCornRecordService.countUserRecordBySource(query); |
| | | } |
| | | |
| | | /** |
| | | * 获取下一次可以做任务的时间 |
| | | * |
| | | * @param source |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public long getNextDoTaskTime(CodeCornGetSourceType source, String uid) { |
| | | if (StringUtil.isNullOrEmpty(uid)) { |
| | | return -1; |
| | | } |
| | | try { |
| | | return goldCornTradeService.getNextDoTaskTime(getAppCode(), getUid(uid), source.name()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return -1; |
| | | } |
| | | |
| | | |
| | | } |