|
|
|
@ -0,0 +1,223 @@ |
|
|
|
using BWP.B3ClientService.BO; |
|
|
|
using BWP.B3Frameworks.Utils; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
|
using Forks.EnterpriseServices.JsonRpc; |
|
|
|
using Forks.EnterpriseServices.SqlDoms; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Net; |
|
|
|
using System.Text; |
|
|
|
using TSingSoft.WebPluginFramework; |
|
|
|
|
|
|
|
namespace BWP.B3ClientService.Rpcs |
|
|
|
{ |
|
|
|
[Rpc] |
|
|
|
public static class MiniProgramRpc |
|
|
|
{ |
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static WeiUserBind GetBindID(string code) |
|
|
|
{ |
|
|
|
var url = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&grant_type=authorization_code&js_code={2}"; |
|
|
|
var request = (HttpWebRequest)WebRequest.Create(string.Format(url, "wx106e1fc979e5fad5", "57883555a451434569cbcb58d2047aac", code)); |
|
|
|
var response = request.GetResponse(); |
|
|
|
using (var stream = response.GetResponseStream()) |
|
|
|
{ |
|
|
|
using (var reader = new StreamReader(stream, Encoding.UTF8)) |
|
|
|
{ |
|
|
|
var weiID = JsonConvert.DeserializeObject<WeiSer>(reader.ReadToEnd()).openid; |
|
|
|
var user = GetBindWeiUser(weiID); |
|
|
|
if (user == null) |
|
|
|
user = new WeiUserBind { WeiID = weiID }; |
|
|
|
return user; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static long InsertBind(string json) |
|
|
|
{ |
|
|
|
var entity = JsonConvert.DeserializeObject<WeiUserBind>(json); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
session.Insert(entity); |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
return entity.ID; |
|
|
|
} |
|
|
|
|
|
|
|
static WeiUserBind GetBindWeiUser(string weiID) |
|
|
|
{ |
|
|
|
var query = new DmoQuery(typeof(WeiUserBind)); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("WeiID", weiID)); |
|
|
|
return query.EExecuteScalar<WeiUserBind>(); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static string GetLastInfo(long id) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(SendPigRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("bType")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("carNum")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("carIDCard")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("supplier")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("supplierIDCard")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("receive")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("bank")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("bankNum")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("userID", id)); |
|
|
|
query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); |
|
|
|
query.Range = SelectRange.Top(1); |
|
|
|
var entity = new MinDmo() { bType = 0 }; |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
if (reader.Read()) |
|
|
|
{ |
|
|
|
entity.bType = (int)reader[0]; |
|
|
|
entity.carNum = (string)reader[1]; |
|
|
|
entity.carIDCard = (string)reader[2]; |
|
|
|
entity.supplier = (string)reader[3]; |
|
|
|
entity.supplierIDCard = (string)reader[4]; |
|
|
|
entity.receive = (string)reader[5]; |
|
|
|
entity.bank = (string)reader[6]; |
|
|
|
entity.bankNum = (string)reader[7]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return JsonConvert.SerializeObject(entity); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static long Submit(string json) |
|
|
|
{ |
|
|
|
var entity = JsonConvert.DeserializeObject<SendPigRecord>(json); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
session.Insert(entity); |
|
|
|
foreach (var item in entity.farmers) |
|
|
|
{ |
|
|
|
item.SendPigRecord_ID = entity.ID; |
|
|
|
session.Insert(item); |
|
|
|
} |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
|
|
|
|
return entity.ID; |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static string GetHistoryList(int type, long userID) |
|
|
|
{ |
|
|
|
var query = new DQueryDom(new JoinAlias(typeof(SendPigRecord))); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("ID")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("date")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("supplier")); |
|
|
|
query.Columns.Add(DQSelectColumn.Field("carNum")); |
|
|
|
query.Where.Conditions.Add(DQCondition.EQ("userID", userID)); |
|
|
|
var list = new List<HistoryObj>(); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
using (var reader = session.ExecuteReader(query)) |
|
|
|
{ |
|
|
|
while (reader.Read()) |
|
|
|
{ |
|
|
|
var entity = new HistoryObj(); |
|
|
|
entity.ID = (long)reader[0]; |
|
|
|
entity.Date = (string)reader[1]; |
|
|
|
entity.Supplier = (string)reader[2]; |
|
|
|
entity.Car = (string)reader[3]; |
|
|
|
list.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return JsonConvert.SerializeObject(list); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static string GetRecord(long id, long userID) |
|
|
|
{ |
|
|
|
var query = new DmoQuery(typeof(SendPigRecord)); |
|
|
|
query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ID", id), DQCondition.EQ("userID", userID))); |
|
|
|
var entity = query.EExecuteScalar<SendPigRecord>(); |
|
|
|
var detail = new DmoQuery(typeof(FarmerRecord)); |
|
|
|
detail.Where.Conditions.Add(DQCondition.EQ("SendPigRecord_ID", id)); |
|
|
|
var list = detail.EExecuteList().Cast<FarmerRecord>(); |
|
|
|
entity.farmers = list.ToArray(); |
|
|
|
return JsonConvert.SerializeObject(entity); |
|
|
|
} |
|
|
|
|
|
|
|
[Rpc(RpcFlags.SkipAuth)] |
|
|
|
public static long Save(string json) |
|
|
|
{ |
|
|
|
var entity = JsonConvert.DeserializeObject<SendPigRecord>(json); |
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
{ |
|
|
|
var dids = entity.farmers.Select(x => x.ID).Where(x => x > 0); |
|
|
|
Delete(session, entity.ID, dids); |
|
|
|
session.Update(entity); |
|
|
|
foreach (var item in entity.farmers) |
|
|
|
{ |
|
|
|
if (item.ID == 0) |
|
|
|
{ |
|
|
|
item.SendPigRecord_ID = entity.ID; |
|
|
|
session.Insert(item); |
|
|
|
} |
|
|
|
else |
|
|
|
session.Update(item); |
|
|
|
} |
|
|
|
session.Commit(); |
|
|
|
} |
|
|
|
|
|
|
|
return entity.ID; |
|
|
|
} |
|
|
|
|
|
|
|
static void Delete(IDmoSession session, long id, IEnumerable<long> exist) |
|
|
|
{ |
|
|
|
var delete = new DQDeleteDom(typeof(FarmerRecord)); |
|
|
|
delete.Where.Conditions.Add(DQCondition.EQ("SendPigRecord_ID", id)); |
|
|
|
if (exist.Any()) |
|
|
|
delete.Where.Conditions.Add(DQCondition.NotInList(DQExpression.Field("ID"), exist.Select(x => DQExpression.Value(x)).ToArray())); |
|
|
|
session.ExecuteNonQuery(delete); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class HistoryObj |
|
|
|
{ |
|
|
|
public long ID { get; set; } |
|
|
|
|
|
|
|
public string Date { get; set; } |
|
|
|
|
|
|
|
public string Supplier { get; set; } |
|
|
|
|
|
|
|
public string Car { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
class MinDmo |
|
|
|
{ |
|
|
|
public int bType { get; set; } |
|
|
|
|
|
|
|
public string carNum { get; set; } |
|
|
|
|
|
|
|
public string carIDCard { get; set; } |
|
|
|
|
|
|
|
public string supplier { get; set; } |
|
|
|
|
|
|
|
public string supplierIDCard { get; set; } |
|
|
|
|
|
|
|
public string receive { get; set; } |
|
|
|
|
|
|
|
public string bank { get; set; } |
|
|
|
|
|
|
|
public string bankNum { get; set; } |
|
|
|
} |
|
|
|
|
|
|
|
class WeiSer |
|
|
|
{ |
|
|
|
public string openid { get; set; } |
|
|
|
} |
|
|
|
} |