|
@@ -70,7 +70,7 @@ namespace MySystem.Areas.Api.Controllers.v1
|
|
|
|
|
|
|
|
|
#region 商户-绑定收款码
|
|
|
- // [Authorize]
|
|
|
+ [Authorize]
|
|
|
public JsonResult Bind(string value)
|
|
|
{
|
|
|
value = DesDecrypt(value);
|
|
@@ -83,30 +83,43 @@ namespace MySystem.Areas.Api.Controllers.v1
|
|
|
JsonData data = JsonMapper.ToObject(value);
|
|
|
int MerchantId = int.Parse(function.CheckInt(data["MerchantId"].ToString())); //商户
|
|
|
string SnNo = data["SnNo"].ToString(); //Sn编号
|
|
|
- // string MachineNo = data["Machine"].ToString(); //音箱码
|
|
|
- if(SnNo.Length > 20)
|
|
|
+ string MachineNo = data["Machine"].ToString(); //音箱码
|
|
|
+ if (SnNo.Length > 20)
|
|
|
{
|
|
|
SnNo = System.Web.HttpUtility.UrlDecode(SnNo);
|
|
|
- if(!SnNo.EndsWith("="))
|
|
|
+ if (!SnNo.EndsWith("="))
|
|
|
{
|
|
|
SnNo += "=";
|
|
|
}
|
|
|
SnNo = dbconn.Decrypt3DES(SnNo, "l2k0b2#3");
|
|
|
SnNo = SnNo.TrimEnd('\0');
|
|
|
- SnNo = SnNo.Substring(0, SnNo.Length - 8);
|
|
|
+ SnNo = SnNo.Substring(0, 20);
|
|
|
}
|
|
|
Dictionary<string, object> Obj = new Dictionary<string, object>();
|
|
|
MerchantQrCode query = new MerchantQrCodeService().Query(SnNo);
|
|
|
PosMachinesTwo pos = new PosMachinesTwoService().Query(SnNo);
|
|
|
+ PosMachines machines = new PosMachinesService().Query(SnNo);
|
|
|
MerchantInfo merchant = new MerchantInfoService().Query(MerchantId);
|
|
|
- if(pos.Id == 0)
|
|
|
+ int PosId = 0;
|
|
|
+ int Kind = 0;
|
|
|
+ if (SnNo == MachineNo || string.IsNullOrEmpty(MachineNo))
|
|
|
{
|
|
|
- return new AppResultJson() { Status = "-1", Info = "绑定失败" };
|
|
|
+ if (pos.Id == 0)
|
|
|
+ {
|
|
|
+ return new AppResultJson() { Status = "-1", Info = "绑定失败" };
|
|
|
+ }
|
|
|
+ PosId = pos.Id;
|
|
|
+ Kind = 1;
|
|
|
+ }
|
|
|
+ else if (SnNo != MachineNo)
|
|
|
+ {
|
|
|
+ if (machines.Id == 0)
|
|
|
+ {
|
|
|
+ return new AppResultJson() { Status = "-1", Info = "绑定失败" };
|
|
|
+ }
|
|
|
+ PosId = machines.Id;
|
|
|
+ Kind = 2;
|
|
|
}
|
|
|
- // if(pos.BuyUserId == 0)
|
|
|
- // {
|
|
|
- // return new AppResultJson() { Status = "-1", Info = "码牌未授权" };
|
|
|
- // }
|
|
|
if (query.Id > 0)
|
|
|
{
|
|
|
if (query.MerchantId > 0)
|
|
@@ -115,53 +128,62 @@ namespace MySystem.Areas.Api.Controllers.v1
|
|
|
}
|
|
|
}
|
|
|
Dictionary<string, object> fields = new Dictionary<string, object>();
|
|
|
- fields.Add("MerchantId", MerchantId);
|
|
|
- fields.Add("SnNo", SnNo);
|
|
|
- fields.Add("QueryCount", 1);
|
|
|
- new MerchantQrCodeService().Add(fields);
|
|
|
- // query = maindb.MerchantQrCode.Add(new MerchantQrCode()
|
|
|
- // {
|
|
|
- // CreateDate = DateTime.Now, //绑定时间
|
|
|
- // MerchantId = MerchantId, //商户
|
|
|
- // SnNo = SnNo,
|
|
|
- // }).Entity;
|
|
|
- // maindb.SaveChanges();
|
|
|
- // string DataId = query.Id + "_0";
|
|
|
- // MachineForQrCode forQrCode = maindb.MachineForQrCode.FirstOrDefault(m => m.DataId == DataId);
|
|
|
- // if (forQrCode == null)
|
|
|
- // {
|
|
|
- // forQrCode = maindb.MachineForQrCode.Add(new MachineForQrCode(){
|
|
|
- // DataId = DataId,
|
|
|
- // SnNo = SnNo,
|
|
|
- // // MachineSnNo = MachineNo,
|
|
|
- // BindDate = DateTime.Now,
|
|
|
- // MerchantId = MerchantId,
|
|
|
- // }).Entity;
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // forQrCode.SnNo = SnNo;
|
|
|
- // // forQrCode.MachineSnNo = MachineNo;
|
|
|
- // forQrCode.BindDate = DateTime.Now;
|
|
|
- // forQrCode.MerchantId = MerchantId;
|
|
|
- // }
|
|
|
- // maindb.SaveChanges();
|
|
|
- fields = new Dictionary<string, object>();
|
|
|
- fields.Add("BuyUserId", merchant.UserId);
|
|
|
- fields.Add("UserId", merchant.UserId);
|
|
|
- fields.Add("BindingTime", DateTime.Now);
|
|
|
- fields.Add("BindingState", 1);
|
|
|
- fields.Add("BindMerchantId", MerchantId);
|
|
|
- fields.Add("OpId", 1);
|
|
|
- new PosMachinesTwoService().Edit(fields, pos.Id);
|
|
|
- // pos.BuyUserId = merchant.UserId;
|
|
|
- // pos.UserId = merchant.UserId;
|
|
|
- // pos.BindingTime = DateTime.Now;
|
|
|
- // pos.BindingState = 1;
|
|
|
- // pos.BindMerchantId = MerchantId;
|
|
|
- // maindb.SaveChanges();
|
|
|
-
|
|
|
- PublicFunction.BindUserMachineData(maindb, merchant.UserId, 0, 1, SnNo);
|
|
|
+ if (SnNo == MachineNo || string.IsNullOrEmpty(MachineNo))
|
|
|
+ {
|
|
|
+ fields.Add("MerchantId", MerchantId);
|
|
|
+ fields.Add("SnNo", SnNo);
|
|
|
+ fields.Add("QueryCount", 1);
|
|
|
+ new MerchantQrCodeService().Add(fields);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string DataId = PosId + "_" + Kind;
|
|
|
+ MachineForQrCode forQrCode = maindb.MachineForQrCode.FirstOrDefault(m => m.DataId == DataId);
|
|
|
+ if (forQrCode == null)
|
|
|
+ {
|
|
|
+ forQrCode = maindb.MachineForQrCode.Add(new MachineForQrCode(){
|
|
|
+ DataId = DataId,
|
|
|
+ SnNo = SnNo,
|
|
|
+ MachineSnNo = MachineNo,
|
|
|
+ BindDate = DateTime.Now,
|
|
|
+ MerchantId = MerchantId,
|
|
|
+ }).Entity;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ forQrCode.SnNo = SnNo;
|
|
|
+ forQrCode.MachineSnNo = MachineNo;
|
|
|
+ forQrCode.BindDate = DateTime.Now;
|
|
|
+ forQrCode.MerchantId = MerchantId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ maindb.SaveChanges();
|
|
|
+ if (SnNo == MachineNo || string.IsNullOrEmpty(MachineNo))
|
|
|
+ {
|
|
|
+ fields = new Dictionary<string, object>();
|
|
|
+ fields.Add("BuyUserId", merchant.UserId);
|
|
|
+ fields.Add("UserId", merchant.UserId);
|
|
|
+ fields.Add("BindingTime", DateTime.Now);
|
|
|
+ fields.Add("BindingState", 1);
|
|
|
+ fields.Add("BindMerchantId", MerchantId);
|
|
|
+ fields.Add("OpId", 1);
|
|
|
+ new PosMachinesTwoService().Edit(fields, pos.Id);
|
|
|
+ }
|
|
|
+ else if (SnNo != MachineNo && !string.IsNullOrEmpty(MachineNo))
|
|
|
+ {
|
|
|
+ fields = new Dictionary<string, object>();
|
|
|
+ fields.Add("BindMerchantId", MerchantId);
|
|
|
+ // fields.Add("DeviceName", deviceId);
|
|
|
+ new PosMachinesService().Edit(fields, machines.Id);
|
|
|
+ }
|
|
|
+ if (SnNo == MachineNo || string.IsNullOrEmpty(MachineNo))
|
|
|
+ {
|
|
|
+ PublicFunction.BindUserMachineData(maindb, merchant.UserId, 0, 1, SnNo);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ PublicFunction.BindUserMachineData(maindb, merchant.UserId, 1, 1, SnNo);
|
|
|
+ }
|
|
|
|
|
|
return new AppResultJson() { Status = "1", Info = "绑定成功" };
|
|
|
}
|