package com.lgx8.management.serviceImpl;
import java.util.Date;
import com.lgx8.gateway.dao.ICardDao;
import com.lgx8.management.dao.ICustmerXFDao;
import com.lgx8.management.dao.IMerchantDao;
import com.lgx8.management.dao.IOrganizationDao;
import com.lgx8.management.dao.IRebateDao;
import com.lgx8.management.dao.IRebateRuleDao;
import com.lgx8.management.entities.Custmerxf;
import com.lgx8.management.entities.Merchant;
import com.lgx8.management.entities.Organization;
import com.lgx8.management.entities.Rebate;
import com.lgx8.management.entities.Rebaterule;
import com.lgx8.management.service.ICustmerXFService;
import com.lgx8.right.dao.IUserDao;
import com.lgx8.right.entities.User;
public class CustmerXFServiceImpl implements ICustmerXFService {
private ICustmerXFDao custmerXFDao;
private IUserDao userDao;
private ICardDao cardDao;
private IMerchantDao merchantDao;
private IOrganizationDao organizationDao;
private IRebateDao rebateDao;
private IRebateRuleDao rebateRuleDao;
public ICardDao getCardDao() {
return cardDao;
}
public void setCardDao(ICardDao cardDao) {
this.cardDao = cardDao;
}
public ICustmerXFDao getCustmerXFDao() {
return custmerXFDao;
}
public void setCustmerXFDao(ICustmerXFDao custmerXFDao) {
this.custmerXFDao = custmerXFDao;
}
public IUserDao getUserDao() {
return userDao;
}
public void setUserDao(IUserDao userDao) {
this.userDao = userDao;
}
public IMerchantDao getMerchantDao() {
return merchantDao;
}
public void setMerchantDao(IMerchantDao merchantDao) {
this.merchantDao = merchantDao;
}
public IOrganizationDao getOrganizationDao() {
return organizationDao;
}
public void setOrganizationDao(IOrganizationDao organizationDao) {
this.organizationDao = organizationDao;
}
public IRebateDao getRebateDao() {
return rebateDao;
}
public void setRebateDao(IRebateDao rebateDao) {
this.rebateDao = rebateDao;
}
public IRebateRuleDao getRebateRuleDao() {
return rebateRuleDao;
}
public void setRebateRuleDao(IRebateRuleDao rebateRuleDao) {
this.rebateRuleDao = rebateRuleDao;
}
public Custmerxf createCustmerXF(Merchant m, User u,double xfje,double hdjfs) {
long p_type = 0l;
long p_id = 0l;
Custmerxf _xf = new Custmerxf();
if(u.getUsertype()==User.USER_TYPE_NORMAL){
p_type = u.getParenttype();
p_id = u.getOrganizationid();
}
if(p_type == 0&& p_id == 0)
{
p_type = 2l;
p_id = m.getID();
}
if(u!=null&&u.getCard()!=null){
double sc = u.getCard().getScore();
u.getCard().setScore(sc+hdjfs);
cardDao.updateCard(u.getCard());
}
Date date = new Date();
if(p_id!=0&&p_type!=0){
Rebate re = new Rebate();
Rebaterule re_rule = null;
double flje = 0.0;
if(p_type==3){
Organization or = organizationDao.getOrganizationById(p_id);
double qbsj = or.getFlqb();
_xf.setXFLX("02");
re_rule = rebateRuleDao.findRebateRuleByLx("02");
if(re_rule!=null){
flje = xfje*re_rule.getFLLV();
re.setFLED(flje);
re.setFLSJ(date);
re.setFLSYFBH(p_id);
re.setFLLX("02");
or.setFlqb(qbsj+flje);
re.setRESERVATION01(u.getTruename());
re.setRESERVATION02(u.getId()+"");
re.setRESERVATION03(or.getJGMC());
organizationDao.updateOrganization(or);
rebateDao.createRebate(re);
}
}
if(p_type==2){
if(p_id!=m.getID()){
re_rule = rebateRuleDao.findRebateRuleByLx("01");
Merchant _m = merchantDao.getMerchantById(p_id);
double qbsj = m.getFlqb();
if(re_rule!=null){
flje = xfje*re_rule.getFLLV();
re.setFLED(flje);
re.setFLSJ(date);
re.setFLSYFBH(p_id);
re.setFLLX("01");
re.setRESERVATION01(u.getTruename());
re.setRESERVATION02(u.getId()+"");
re.setRESERVATION03(_m.getSJMC());
_m.setFlqb(qbsj+flje);
merchantDao.updateMerchant(_m);
rebateDao.createRebate(re);
}
_xf.setXFLX("02");
}else{
_xf.setXFLX("01");
}
}
/**
* kou chu jf
*/
double syjfs = m.getSYJFSL();
m.setSYJFSL(syjfs-hdjfs);
merchantDao.updateMerchant(m);
_xf.setXfhy(u);
_xf.setXFJE(xfje);
_xf.setHDJFS(xfje);
_xf.setXFSJ(date);
_xf.setMerchant(m);
custmerXFDao.createCustmerXF(_xf);
return _xf;
}
return null;
}
}