public int PushUpCar(string carid)
{
using (var conn = Helper.GetConnection())
{
const string sqlSelectTotal = "select b.topnum,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.Topnum == 0)
{
return 401;
}
var tran = conn.BeginTransaction();
try
{
//更新Top数值
const string sql = @"set @maxtop=(select max(istop) as num from car_info where istop>1) + 1;
update car_info set istop = @maxtop where innerid=@carid;";
conn.Execute(sql, new { carid }, tran);
//更新Top剩余次数
const string sqlUt = "update cust_total_info set topnum=topnum-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 = 2,
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;
}
}
}