package com.yeshi.fanli.service.impl.integral;
|
|
import java.util.Date;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.yeshi.fanli.entity.integral.IntegralTask;
|
import com.yeshi.fanli.entity.integral.IntegralTask.FrequencyEnum;
|
import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
|
import com.yeshi.fanli.exception.integral.IntegralGetException;
|
import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
|
import com.yeshi.fanli.service.inter.integral.IntegralGetService;
|
import com.yeshi.fanli.service.inter.integral.IntegralTaskRecordService;
|
import com.yeshi.fanli.service.inter.integral.IntegralTaskService;
|
|
import net.sf.json.JSONObject;
|
|
@Service
|
public class IntegralGetServiceImpl implements IntegralGetService {
|
|
@Resource
|
private IntegralTaskService integralTaskService;
|
|
@Resource
|
private IntegralTaskRecordService integralTaskRecordService;
|
|
@Override
|
public IntegralTaskRecord addEventStatistic(Long uid, String event, JSONObject params) throws IntegralGetException {
|
Date nowDate = new Date();
|
IntegralTask task = integralTaskService.getByCidAndUniqueKey(null, event);
|
if (task == null)
|
throw new IntegralGetException(1, "事件类型不存在");
|
if (task.getFrequency() == FrequencyEnum.everyday) {
|
int count = integralTaskRecordService.countGetCountByTaskIdAndDay(task.getId(), uid, nowDate);
|
if (count >= task.getUpperLimit())
|
throw new IntegralGetException(2, "事件触发达到上限");
|
} else if (task.getFrequency() == FrequencyEnum.onlyOne) {
|
int count = integralTaskRecordService.countGetCountByTaskIdAndDay(task.getId(), uid, null);
|
if (count > 0)
|
throw new IntegralGetException(2, "事件触发达到上限");
|
}
|
|
int goldCoin = task.getGoldCoin();
|
if (task.getDoubleNum() != null && task.getDoubleNum() > 0)
|
goldCoin = task.getDoubleNum() * goldCoin;
|
|
IntegralTaskRecord record = new IntegralTaskRecord();
|
record.setCid(task.getTaskClass().getId());
|
record.setGoldCoin(goldCoin);
|
record.setState(IntegralTaskRecord.STATE_WAITING_RECIEVE);
|
record.setTaskId(task.getId());
|
record.setUid(uid);
|
|
try {
|
return integralTaskRecordService.addRecord(record);
|
} catch (IntegralTaskRecordException e) {
|
throw new IntegralGetException(3, "添加记录失败");
|
}
|
|
// switch (event) {
|
// case "recommendSearch":
|
// break;
|
// case "shareInvite":
|
// break;
|
// case "inShop":
|
// break;
|
// case "scanPush":
|
// break;
|
// case "scanGoods":
|
// break;
|
// case "scanHomeBanner":
|
// break;
|
// case "scanSpecial":
|
// break;
|
// case "scanTBCart":
|
// break;
|
// }
|
}
|
|
@Override
|
public void addRecommendSearch(Long uid) throws IntegralGetException {
|
|
}
|
|
@Override
|
public void addSearchResultScan(Long uid) throws IntegralGetException {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addShareInvite(Long uid) throws IntegralGetException {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addIntoShop(Long uid) throws IntegralGetException {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addScanPushHistory(Long uid) throws IntegralGetException {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addScanGoodsDetail(Long uid, int goodsType, Long goodsId) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addScanRecommendBanner(Long uid) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addScanRecommendSpecial(Long uid) {
|
// TODO Auto-generated method stub
|
|
}
|
|
@Override
|
public void addScanTaoBaoCart(Long uid) {
|
// TODO Auto-generated method stub
|
|
}
|
|
}
|