const system = require("../../../system");
const ServiceBase = require("../../sve.base")
/**
 * 订单产品表
 */
class CfollowlogService extends ServiceBase {
    constructor() {
        super("order", ServiceBase.getDaoName(CfollowlogService));
        this.cclueDao = system.getObject("db.chance.cclueDao");
    }

    /**
     * fn:保存跟进进度
     * @param params
     * @returns {Promise<void>}
     */
    async saveCfollowLog(params){
        if(!params.deliver_id){
            return system.getResult(null, `参数错误 交付商ID不能为空`);
        }
        if(!params.clue_id){
            return system.getResult(null, `参数错误 线索ID不能为空`);
        }
        if(!params.follow_date){
            return system.getResult(null, `参数错误 跟进时间不能为空`);
        }
        if(!params.record){
            return system.getResult(null, `参数错误 沟通记录不能为空`);
        }
        let cclueBean = await  this.cclueDao.getCclueInfo({id:this.trim(params.clue_id),deliver_id:this.trim(params.deliver_id)});
        if(!cclueBean){
            return system.getResult(null,`线索不存在`);
        }
        try{
            let cfollowlogProperties = {
                clue_id: this.trim(params.clue_id),
                follow_date: this.trim(params.follow_date),
                record: this.trim(params.record),
                operator: this.trim(params.operator)
            };
            let res = await this.dao.create(cfollowlogProperties);
            return system.getResult(res);
        }catch (e) {
            console.log(e);
            return system.getResult(null, `系统错误`);
        }
    }

}

module.exports = CfollowlogService;