public void OnCancelOrderRefund(ResturantPlatformType platformType, OrderRefundInfo info)
 {
     using (Way.Lib.CLog log = new Way.Lib.CLog("用户取消退单"))
     {
         log.LogJson(info);
     }
 }
 public void OnOrderCancel(ResturantPlatformType platformType, OrderCancelInfo orderInfo)
 {
     using (Way.Lib.CLog log = new Way.Lib.CLog("取消订单"))
     {
         log.LogJson(orderInfo);
     }
 }
        public void OnReceiveNewOrder(ResturantPlatformType platformType, OrderInfo orderInfo)
        {
            using (Way.Lib.CLog log = new Way.Lib.CLog("新订单"))
            {
                log.LogJson(orderInfo);
            }

            var resturant = ResturantFactory.CreateResturant(platformType);

            //取消订单
            //resturant.CancelOrder(new CancelOrderParameter() {
            //    OrderID = orderInfo.ThirdOrderId,
            //    Reason = CancelOrderReason.Busy,
            //    Token = StoreInfos[orderInfo.ErpStoreID.Value]
            //});


            //确认订单

            ConfirmOrderParameter parameter = new ConfirmOrderParameter();

            parameter.OrderID = orderInfo.ThirdOrderId;
            parameter.Token   = "f8b8211858f6307d24b97e67aa3915e3e5aa78d0dbc7765618fb8485901db153";
            resturant.ConfirmOrder(parameter);

            return;

            //发起配送
            resturant.Delivering(new DeliverParameter()
            {
                CourierName  = "刘培松",
                CourierPhone = "13261952754",
                OrderID      = orderInfo.ThirdOrderId,
                Token        = StoreInfos[orderInfo.ErpStoreID.Value],
            });

            resturant.Delivered(new DeliveredParameter()
            {
                OrderID = orderInfo.ThirdOrderId,
                Token   = StoreInfos[orderInfo.ErpStoreID.Value],
            });
        }
        public static void SentNotify(DBModels.Transaction tran, string secret)
        {
            SortedDictionary <string, object> data = null;

            try
            {
                using (var db = new MainDB())
                {
                    data = Helper.SignResult(new
                    {
                        outTradeNo  = tran.OutTradeNo,
                        payedAmount = tran.PayedAmount,
                        status      = (int)tran.Status,
                        //取出比特币交易信息,并转成json字符串
                        cyptoCoinTrans = Newtonsoft.Json.JsonConvert.SerializeObject((from m in db.CyptoCoinTran
                                                                                      where m.TransactionId == tran.id
                                                                                      select new
                        {
                            cyptoCoinTransId = m.CyptoCoinTransId,
                            confirmations = m.Confirmations,
                            payedAmount = m.PayedAmount,
                            payTime = m.PayTime                                                               // 接收到款项的时间
                        }).ToArray())
                    }, secret);
                }
                var result = Helper.PostJson(tran.NotifyUrl, data, 8000);
            }
            catch (Exception ex)
            {
                using (Way.Lib.CLog log = new Way.Lib.CLog("SentNotify error", false))
                {
                    log.Log($"DBModels.Transaction.Id:{tran.id}");
                    if (data != null)
                    {
                        log.LogJson(data);
                    }
                    log.Log(ex.ToString());
                }
            }
        }
        /// <summary>
        /// 发起btc支付交易
        /// </summary>
        /// <returns></returns>
        public object Pay([FromBody] NullableSortedDict <string, object> postData)
        {
            using (var db = new MainDB())
                using (Way.Lib.CLog log = new Way.Lib.CLog("Pay"))
                {
                    try
                    {
                        double?amount     = postData.GetValue <double?>("amount");
                        string account    = postData.GetValue <string>("account");
                        string sign       = postData.GetValue <string>("sign");
                        string outTradeNo = postData.GetValue <string>("outTradeNo");
                        string notifyUrl  = postData.GetValue <string>("notifyUrl");
                        string currency   = postData.GetValue <string>("currency");

                        if (amount <= 0)
                        {
                            throw new Exception("金额无效");
                        }

                        var wallet = db.Wallet.FirstOrDefault(m => m.Account == account);
                        if (wallet == null)
                        {
                            throw new Exception($"账户“{account}”不存在");
                        }

                        log.LogJson(postData);
                        currency = currency.ToUpper();

                        var signResult = Helper.Sign(postData, wallet.Secret);
                        if (signResult != sign)
                        {
                            throw new Exception("签名校验失败");
                        }

                        var newTran = new DBModels.Transaction {
                            Amount     = amount,
                            NotifyUrl  = notifyUrl,
                            OutTradeNo = outTradeNo
                        };

                        //根据币种创建ICyptoCoinClient
                        var client = Activator.CreateInstance(typeof(ApiController).Assembly.GetType($"Cailutong.CyptoCoinGateway.CyptoCoinPlatform.Impls.{currency}.{currency}_Client")) as CyptoCoinPlatform.ICyptoCoinClient;
                        if (client == null)
                        {
                            throw new Exception("不支持" + currency);
                        }

                        //填充交易里面的付款地址
                        transactionGetCyptoCoinAddress(db, account, currency, client, newTran);
                        newTran.WalletId = wallet.id;
                        db.Insert(newTran);

                        return(Helper.SignResult(new
                        {
                            status = "success",
                            outTradeNo = outTradeNo,
                            targetAddress = newTran.CyptoCoinAddress
                        }, wallet.Secret));
                    }
                    catch (Exception ex)
                    {
                        log.Log(ex.ToString());
                        return(new
                        {
                            status = "error",
                            errMsg = ex.Message
                        });
                    }
                }
        }