Exemplo n.º 1
0
        /// <summary>
        /// 售后申请状态处理
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateRefundApplyState(int aid = 0, int storeId = 0, int state = 0, int id = 0)
        {
            if (aid <= 0 || storeId <= 0 || id <= 0)
            {
                result.msg = "参数错误";
                return(Json(result));
            }
            PinRefundApply apply = PinRefundApplyBLL.SingleModel.GetModel(id);

            if (apply == null || apply.id == (int)RefundApplyState.除)
            {
                result.msg = "申请不存在";
                return(Json(result));
            }
            PinStore store = PinStoreBLL.SingleModel.GetModelByAid_Id(aid, storeId);

            if (store == null)
            {
                result.msg = "店铺信息错误";
                return(Json(result));
            }
            string msg    = string.Empty;
            bool   status = false;

            apply.state      = state;
            apply.updateTime = DateTime.Now;
            switch (state)
            {
            case (int)RefundApplyState.已退款:
                status = orderBLL.RefundByApply(apply, ref msg);
                break;

            case (int)RefundApplyState.已重新发货:
            case (int)RefundApplyState.申请失败:
                status = PinRefundApplyBLL.SingleModel.ApplyFail(apply, ref msg);
                break;

            case (int)RefundApplyState.除:
                status = PinRefundApplyBLL.SingleModel.Update(apply, "state,updatetime");
                break;

            case (int)RefundApplyState.申请成功:
                status = PinRefundApplyBLL.SingleModel.ApplySuccess(apply, store, ref msg);
                break;

            default:
                result.msg = "参数错误!";
                return(Json(result));
            }
            if (status)
            {
                result.code = 1;
                result.msg  = "操作成功";
            }
            else
            {
                result.msg = "操作失败";
            }
            return(Json(result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据售后申请退款
        /// </summary>
        /// <param name="apply"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool RefundByApply(PinRefundApply apply, ref string msg)
        {
            bool          result = false;
            PinGoodsOrder order  = GetModel(apply.id);

            if (order == null || order.state == (int)PinOrderState.已删除)
            {
                msg = "订单不存在";
                return(result);
            }
            if (order.state <= 0)
            {
                msg = "当前订单状态无法退款";
                return(result);
            }
            int money = 0;//订单实际剩余金额

            if (order.isReturnMoney == 1)
            {
                money = order.money - order.refundMoney - order.returnMoney;
            }
            else
            {
                money = order.money - order.refundMoney;
            }
            if (money < apply.money)
            {
                msg = "当前订单支付剩余金额不足以退款";
                return(result);
            }
            //交易完成的订单要扣会商家的收益
            if (order.state > (int)PinOrderState.交易成功)
            {
                PinStore pinStore = PinStoreBLL.SingleModel.GetModelByAid_Id(order.aid, order.storeId);
                if (pinStore == null)
                {
                    msg = "店铺信息错误";
                    return(result);
                }
                if ((order.sourceType == 0 && pinStore.cash < apply.money) || (order.sourceType == 1 && pinStore.qrcodeCash < apply.money))
                {
                    msg = "店铺可提现金额不足以退款";
                    return(result);
                }
                if (order.sourceType == 0)
                {
                    pinStore.cash -= apply.money;
                    result         = PinStoreBLL.SingleModel.Update(pinStore, "cash");
                }
                else
                {
                    pinStore.qrcodeCash -= apply.money;
                    result = PinStoreBLL.SingleModel.Update(pinStore, "qrcodecash");
                }
                if (!result)
                {
                    msg = "操作失败,扣减商家收益异常";
                    return(result);
                }
            }
            apply.state      = (int)RefundApplyState.已退款;
            apply.updateTime = DateTime.Now;
            if (PinRefundApplyBLL.SingleModel.Update(apply, "state,updatetime"))
            {
                order.refundMoney += apply.money;
                result             = RefundMoney(order, apply.money, ref msg) && Update(order, "refundmoney");
            }
            return(result);
        }