public int RefreshCar(string carid)
{
using (var conn = Helper.GetConnection())
{
const string sqlSelectTotal = "select b.refreshnum,b.custid from car_info as a inner join cust_total_info as b on a.custid=b.custid where a.innerid=@carid;";
var totalModel = conn.Query<CustomerTotalModel>(sqlSelectTotal, new { carid }).FirstOrDefault();
if (totalModel == null || totalModel.Refreshnum == 0)
{
return 401;
}
var tran = conn.BeginTransaction();
try
{
//更新刷新时间
var ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
string sql = $"update car_info set refreshtime={(long)ts.TotalSeconds} where innerid=@carid;";
conn.Execute(sql, new { carid }, tran);
//更新刷新剩余次数
const string sqlUt = "update cust_total_info set refreshnum=refreshnum-1 where custid=@custid;";
conn.Execute(sqlUt, new { custid = totalModel.Custid }, tran);
//保存刷新次数变更记录
const string sqlIRecord = "insert into cust_total_record (innerid, custid, count, type, remark, spare1, createrid, createdtime) values (@innerid, @custid, @count, @type, @remark, @spare1, @createrid, @createdtime);";
conn.Execute(sqlIRecord, new
{
innerid = Guid.NewGuid().ToString(),
custid = totalModel.Custid,
count = -1,
type = 1,
remark = "正常刷新:减1次",
createrid = totalModel.Custid,
createdtime = DateTime.Now
}, tran);
tran.Commit();
return 1;
}
catch (Exception ex)
{
tran.Rollback();
LoggerFactories.CreateLogger().Write("刷新车辆异常:" + ex.Message, TraceEventType.Information);
return 0;
}
}
}