Пример #1
0
        /// <summary>
        /// 快跑者配送配置
        /// </summary>
        /// <returns></returns>

        public ActionResult KPZPeiSongConfig(int aId = 0, string act = "", int storeId = 0, KPZStoreRelation model = null)
        {
            //参数验证
            if (aId <= 0)
            {
                _result.msg = "参数错误";
                return(Json(_result));
            }
            //显示
            if (string.IsNullOrEmpty(act))
            {
                EditModel <KPZStoreRelation> em = new EditModel <KPZStoreRelation>();
                em.appId   = aId;
                em.storeId = storeId;
                em.aId     = aId;
                KPZStoreRelation storemodel = KPZStoreRelationBLL.SingleModel.GetModelBySidAndAid(aId, storeId);
                if (storemodel == null)
                {
                    storemodel = new KPZStoreRelation();
                }
                em.DataModel = storemodel;
                return(View(em));
            }
            else
            {
                if (act == "edit")
                {
                    if (model == null)
                    {
                        _result.msg = "参数出错";
                        return(Json(_result));
                    }
                    if (string.IsNullOrEmpty(model.TelePhone))
                    {
                        _result.msg = "请输入商户手机号";
                        return(Json(_result));
                    }
                    if (string.IsNullOrEmpty(model.TeamToken))
                    {
                        _result.msg = "请输入与您合作的快跑者团队的token";
                        return(Json(_result));
                    }
                    bool success = KPZStoreRelationBLL.SingleModel.AddStore(aId, storeId, model.TeamToken, model.TelePhone);
                    _result.code = success ? 1 : 0;
                    _result.msg  = success ? "保存成功" : "保存失败";
                }
            }
            return(Json(_result));
        }
Пример #2
0
        /// <summary>
        /// 快跑者配送推单
        /// </summary>
        /// <param name="orderid">小程序订单表ID</param>
        /// <param name="rid"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public string GetKPZOrderUpdateSql(int orderid, int aid, int storeid, ref TransactionModel tran, bool gettransql = false)
        {
            KPZOrder order = GetModelByOrerId(aid, storeid, orderid);

            if (order == null)
            {
                return("快跑者配送:订单不存在");
            }

            KPZStoreRelation kpzstore = KPZStoreRelationBLL.SingleModel.GetModel(order.shop_id);

            if (kpzstore == null)
            {
                return("快跑者配送:关联店铺不存在");
            }

            KPZResult <OrderTradeNo> result = KPZApi.CreateOrder(order, kpzstore.TeamToken);

            if (result == null)
            {
                return("快跑者配送:新增订单接口异常");
            }
            if (result.code == 200)
            {
                order.status = (int)KPZOrderEnum.待发单;
                if (result.data == null || string.IsNullOrEmpty(result.data.trade_no))
                {
                    LogHelper.WriteInfo(this.GetType(), "快跑者新增订单接口返回值异常" + JsonConvert.SerializeObject(result));
                    return("快跑者新增订单接口返回值异常");
                }
                order.trade_no = result.data.trade_no;
                if (gettransql)
                {
                    return(base.ExecuteNonQuery($"update KPZOrder set status={order.status},trade_no='{order.trade_no}' where id={order.id}") > 0 ? "" : "修改快跑者订单状态出错");
                }
                else
                {
                    tran.Add($"update KPZOrder set status={order.status},trade_no='{order.trade_no}' where id={order.id}");
                }

                return("");
            }

            return(result.message);
        }
Пример #3
0
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="storeid"></param>
        /// <param name="orderid"></param>
        /// <param name="reason"></param>
        /// <returns></returns>
        public bool CancelOrder(int aid, int storeid, int orderid, string reason = "")
        {
            bool     success = false;
            KPZOrder model   = GetModelByOrerId(aid, storeid, orderid);

            if (model == null)
            {
                LogHelper.WriteInfo(this.GetType(), $"快跑者配送:取消订单失败,没有找到快跑者订单数据_{aid}_{storeid}_{orderid}");
                return(success);
            }
            KPZStoreRelation storemodel = KPZStoreRelationBLL.SingleModel.GetModel(model.shop_id);

            if (storemodel == null)
            {
                LogHelper.WriteInfo(this.GetType(), $"快跑者配送:取消订单失败,快跑者配送没配置_{aid}_{storeid}_{orderid}");
                return(success);
            }
            if (model.status == (int)KPZOrderEnum.已送达)
            {
                LogHelper.WriteInfo(this.GetType(), $"快跑者配送:取消订单失败,该订单已送达_{aid}_{storeid}_{orderid}");
                return(success);
            }

            KPZResult <object> result = KPZApi.CancelOrder(model.trade_no, reason, storemodel.TeamToken);

            if (result == null || result.code != 200)
            {
                LogHelper.WriteInfo(this.GetType(), $"快跑者配送:取消订单失败,接口返回异常_{model.trade_no}_{storemodel.TeamToken}" + (result != null?result.message:""));
            }
            else
            {
                model.status = (int)KPZOrderEnum.已撤销;
                success      = base.Update(model, "status");
                if (!success)
                {
                    LogHelper.WriteInfo(this.GetType(), $"快跑者配送:更新系统订单状态失败_{model.id}");
                }
            }
            return(success);
        }
Пример #4
0
        /// <summary>
        /// 生成快跑者配送订单
        /// </summary>
        /// <param name="rid">权限表ID</param>
        /// <param name="userinfo">用户信息</param>
        /// <param name="orderid">订单ID</param>
        /// <param name="price">订单价格</param>
        /// <param name="receviename">收货人姓名</param>
        /// <param name="receviephone">收货人电话</param>
        /// <param name="address">收货人地址</param>
        /// <param name="lat">纬度</param>
        /// <param name="lnt">经度</param>
        /// <param name="ordertype">看枚举TmpType</param>
        /// <returns></returns>
        public string AddKPZOrder(DistributionApiModel model)
        {
            string           msg           = "";
            KPZStoreRelation storerelation = KPZStoreRelationBLL.SingleModel.GetModelBySidAndAid(model.aid, model.storeid);

            if (storerelation == null)
            {
                msg = "请先配置快跑者配送";
                return(msg);
            }

            //再请求一次腾讯地图,获取准确的坐标
            AddressApi addressModel = AddressHelper.GetLngAndLatByAddress(model.address);

            if (addressModel != null && addressModel.result != null && addressModel.result.location != null)
            {
                model.lnt = addressModel.result.location.lng;
                model.lat = addressModel.result.location.lat;
            }

            TransactionModel tran     = new TransactionModel();
            string           orderno  = CommonCore.GetOrderNumByUserId(model.userid.ToString());
            float            buyprice = model.buyprice / 100.0f;
            float            payfee   = model.fee / 100.0f;
            int paystatus             = 0;
            //店铺信息
            ShopInfo shopinfo = GetStoreAddressPoint(storerelation.AId, storerelation.StoreId, model.temptype);

            //生成订单实体类对象
            KPZOrder data = new KPZOrder(storerelation.Id, shopinfo.ShopName, storerelation.TelePhone, shopinfo.ShopAddress, shopinfo.ShopTag, model.ordercontent, model.remark, orderno, model.accepterName, model.accepterTelePhone, model.address, model.lnt + "," + model.lat, buyprice, buyprice, paystatus, payfee, model.orderid, model.aid, model.temptype, model.storeid);

            tran.Add(base.BuildAddSql(data));

            if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray))
            {
                msg = "添加快跑者配送订单出错";
            }
            return(msg);
        }
Пример #5
0
        /// <summary>
        /// 获取运费
        /// </summary>
        /// <param name="storeid"></param>
        /// <param name="aid"></param>
        /// <param name="lat"></param>
        /// <param name="lnt"></param>
        /// <param name="orderprice"></param>
        /// <returns></returns>
        public int GetKPZFee(int storeid, int aid, string address, string lat, string lnt, int orderprice, ref string msg)
        {
            int fee = 0;
            KPZResult <KPZFee> result = new KPZResult <KPZFee>();

            if (!string.IsNullOrEmpty(address))
            {
                //再请求一次腾讯地图,获取准确的坐标
                AddressApi addressModel = AddressHelper.GetLngAndLatByAddress(address);
                if (addressModel != null && addressModel.result != null && addressModel.result.location != null)
                {
                    lnt = addressModel.result.location.lng.ToString();
                    lat = addressModel.result.location.lat.ToString();
                }
                else
                {
                    msg = "快跑者配送:获取腾讯地址失败";
                    return(0);
                }
            }

            XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModel(aid);

            if (xcxrelation == null)
            {
                msg = "快跑者配送:权限模板不存在";
                return(fee);
            }

            XcxTemplate xcxtemplate = XcxTemplateBLL.SingleModel.GetModel(xcxrelation.TId);

            if (xcxtemplate == null)
            {
                msg = "快跑者配送:小程序模板不存在";
                return(fee);
            }

            KPZStoreRelation storerelation = KPZStoreRelationBLL.SingleModel.GetModelBySidAndAid(aid, storeid);

            if (storerelation == null)
            {
                msg = "快跑者配送:未设置快跑者配送配置";
                return(fee);
            }

            int    shopid  = storerelation.Id;
            string sendtag = lnt + "," + lat;
            //店铺信息
            ShopInfo shopinfo = GetStoreAddressPoint(storerelation.AId, storerelation.StoreId, xcxtemplate.Type);
            string   payfee   = "0";

            if (shopinfo.ShopTag.Length <= 0)
            {
                msg = "快跑者配送:店铺经纬不能为空";
                return(fee);
            }

            if (sendtag.Length <= 1)
            {
                msg = "快跑者配送:取货经纬不能为空";
                return(fee);
            }
            result = KPZApi.GetFee(shopid, sendtag, shopinfo.ShopTag, (orderprice * 0.01).ToString("0.00"), payfee, storerelation.TeamToken);

            if (result == null)
            {
                log4net.LogHelper.WriteInfo(this.GetType(), "快跑者配送:返回结果为null,");
                return(fee);
            }
            if (result.data == null)
            {
                log4net.LogHelper.WriteInfo(this.GetType(), "快跑者配送:返回运费为null,");
                return(fee);
            }
            if (result.code == 200)
            {
                fee = Convert.ToInt32(result.data.pay_fee);
                return(fee);
            }
            else
            {
                msg = result.message;
            }

            if (result == null)
            {
                result      = new KPZResult <KPZFee>();
                result.code = 204;
            }
            //msg = "获取运费出错";

            log4net.LogHelper.WriteInfo(this.GetType(), $"快跑者配送:请求参数,shopid【{shopid}】sendtag【{sendtag}】gettag【{shopinfo.ShopTag}】orderprice【{orderprice}】payfee【{payfee}】" + JsonConvert.SerializeObject(result));

            return(fee);
        }