Exemplo n.º 1
0
        /// <summary>
        /// 新增预约信息
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public bool InsertCRM_APT_Info(AptInfo obj, Log log)
        {
            var  pk  = _wxHelper.CreatePK("APT");
            bool ret = true;

            using (var unitOfWork = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    var apt = new CrmAptMstr();
                    apt.Id            = pk;
                    apt.APT_NO        = pk;//预约单号
                    apt.APT_TYPE      = "主动";
                    apt.APT_CLASS     = obj.APT_CLASS;
                    apt.APT_CHANNEL   = "微信";
                    apt.CUS_NAME      = obj.NAME; //客户姓名
                    apt.UDF1          = obj.SEX;  //性别
                    apt.CUS_NO        = obj.CUS_NO;
                    apt.CUS_PHONE_NO  = obj.CUS_PHONE_NO;
                    apt.UDF2          = obj.MILEAGE;
                    apt.UDF3          = obj.BRAND_NAME;      //品牌
                    apt.UDF4          = obj.CARCLASS_NAME;   //车系
                    apt.UDF5          = obj.CARTYPE_NAME;    //车型
                    apt.UDF6          = obj.CARTYPEDET_NAME; //车型细分
                    apt.VIN           = obj.VIN;             //vin码
                    apt.CAR_ID        = obj.CAR_ID;          //车牌号
                    apt.UDF8          = obj.BU_NAME;         //门店名称
                    apt.UDF9          = obj.DISCOUNT;        //工时折扣
                    apt.UDF10         = obj.APT_PROJECT;     //预约项目
                    apt.APT_DATE      = obj.APT_DATE;
                    apt.APT_TIMESPAN  = obj.APT_TIMESPAN;    //时段
                    apt.IS_SA_APPOINT = 0;
                    apt.SERVICE_DESK  = obj.CONSULTANT_NAME;
                    apt.APT_BU_NO     = obj.orgNo;
                    apt.APT_STATUS    = "未完成";
                    apt.APT_RMK       = obj.APT_RMK;
                    apt.CREATE_ORG_NO = obj.orgNo;
                    apt.CREATE_PSN    = obj.BPM_USRID;
                    apt.CREATE_DATE   = DateTime.Now;
                    apt.UPDATE_PSN    = obj.BPM_USRID;
                    apt.UPDATE_DATE   = DateTime.Now;
                    apt.DEL_FLAG      = 1;
                    apt.BG_NO         = obj.BG_NO;
                    apt.BOOKING_TYPE  = obj.APT_TYPE;
                    apt.OPENID        = obj.openId;
                    _crmAptMstrRepository.Insert(apt);
                    SysUsrMstr userInfo = new SysUsrMstr();
                    var        basInfo  = _wxHelper.GetBasConfig(obj.BG_NO);
                    if (obj.APT_TYPE == 1)//售前
                    {
                        if (basInfo != null)
                        {
                            if (basInfo.IS_IRIS == 1)//对接iris
                            {
                                //预约试驾调用iris接口
                                string url = basInfo.IRIS_APT_URL;
                                log.Write("url:" + url + "");
                                Dictionary <string, object> dic = new Dictionary <string, object>();

                                //obj.APT_TIMESPAN; 预约时间段解析
                                string[] arr       = obj.APT_TIMESPAN.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                                string   aptDate   = obj.APT_DATE.ToString("yyyy-MM-dd");
                                string   startTime = aptDate + " " + arr[0];
                                string   endTime   = aptDate + " " + arr[1];

                                dic.Add("appCode", "iris");
                                dic.Add("custName", obj.NAME);
                                dic.Add("custSex", obj.SEX == "女" ? 0 : 1);
                                dic.Add("custMobile", obj.CUS_PHONE_NO);
                                dic.Add("startTime", startTime);
                                dic.Add("endTime", endTime);
                                dic.Add("storeCode", obj.orgNo);
                                dic.Add("brandCode", obj.BRAND_CODE);
                                dic.Add("brandName", obj.BRAND_NAME);
                                dic.Add("seriesCode", obj.CARCLASS_CODE);
                                dic.Add("seriesName", obj.CARCLASS_NAME);
                                dic.Add("carType", obj.CARTYPE_CODE);
                                dic.Add("carCode", obj.CARTYPEDET_CODE);
                                dic.Add("displayName", obj.CARTYPEDET_NAME);

                                string json   = JsonConvert.SerializeObject(dic);
                                string result = IrisHelper.RequestIrisApi(url, basInfo.IRIS_CHAT_URL, json, log);
                                log.Write("预约试驾推送Iris接口结果:" + result);

                                var code = JObject.Parse(result)["code"] + "";
                                obj.APT_RMK = code == "fail" ? "预约试驾推送Iris失败" : obj.APT_RMK;
                                //推送微信公众号模板消息
                                if (code == "fail")
                                {
                                    ret = false;
                                    ret = WxToMessage(obj, basInfo.APT_URL, code, log);
                                }
                                else
                                {
                                    ret = SendAptSuccessMessage(obj, basInfo.APT_URL, log);
                                }
                            }
                            else
                            {
                                if (basInfo.IS_SEND_MSG == 1)
                                {
                                    ret = GetWxUsrAptInfo(obj, basInfo, log, ref userInfo);
                                    if (!ret)
                                    {
                                        return(ret);
                                    }
                                    ret = _smsHelper.SendMessage(obj, userInfo.USR_MOBILE, basInfo, log);
                                    if (!ret)
                                    {
                                        log.Write("发送短消息失败");
                                    }
                                    //推送微信公众号模板消息
                                    ret = SendAptSuccessMessage(obj, basInfo.APT_URL, log);
                                    if (!ret)
                                    {
                                        log.Write("发送模板消息失败");
                                    }
                                }
                                else
                                {
                                    //推送微信公众号模板消息
                                    ret = SendAptSuccessMessage(obj, basInfo.APT_URL, log);
                                }
                            }
                        }
                        else
                        {
                            ret = false;
                            log.Write("请先维护基础配置");
                            return(ret);
                        }
                    }
                    else if (obj.APT_TYPE == 2)//售后
                    {
                        if (basInfo.IS_TOERP == 1)
                        {
                            ret = AptToErp(basInfo, obj, log);
                        }
                        else if (basInfo.IS_BZT == 1)
                        {
                            ret = PushAptInfoToOdm(basInfo, obj, log);
                        }
                        if (ret)
                        {
                            if (basInfo == null)
                            {
                                ret = false;
                                log.Write("请先维护基础配置");
                                return(ret);
                            }
                            if (basInfo.IS_SEND_MSG == 1)
                            {
                                ret = GetWxUsrAptInfo(obj, basInfo, log, ref userInfo);
                                if (!ret)
                                {
                                    return(ret);
                                }
                                ret = _smsHelper.SendMessage(obj, userInfo.USR_MOBILE, basInfo, log);
                                if (!ret)
                                {
                                    log.Write("发送短消息失败");
                                }
                                ret = SendAptSuccessMessage(obj, basInfo.APT_URL, log);
                                if (!ret)
                                {
                                    log.Write("发送模板消息失败");
                                }
                            }
                            else
                            {
                                ret = SendAptSuccessMessage(obj, basInfo.APT_URL, log);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ret = false;
                    log.Write("预约服务-" + ex.Message + "");
                    return(ret);
                }
                unitOfWork.Complete();
            }


            return(ret);
        }