CCN.Modules.Customer.DataAccess.CustomerDA.RebindFans C# (CSharp) Метод

RebindFans() публичный Метод

public RebindFans ( CustRebindFansModel model ) : int
model CCN.Modules.Customer.BusinessEntity.CustRebindFansModel
Результат int
        public int RebindFans(CustRebindFansModel model)
        {
            const string sqlS = "select innerid from cust_info where mobile=@mobile;";
            using (var conn = Helper.GetConnection())
            {
                try
                {
                    var custid = conn.Query<string>(sqlS, new { mobile = model.Mobile }).FirstOrDefault();
                    if (string.IsNullOrWhiteSpace(custid))
                    {
                        //非会员
                        return 0;
                    }

                    const string sqlSFans = "select count(1) from cust_wechat where custid=@custid;";
                    var i = conn.Query<int>(sqlSFans, new { custid }).FirstOrDefault();
                    if (i == 0)
                    {
                        const string sql = "insert into cust_wechat (innerid, custid, openid, createdtime) values (@innerid, @custid, @openid, @createdtime);";
                        conn.Execute(sql, new
                        {
                            innerid = Guid.NewGuid().ToString(),
                            custid,
                            model.Openid,
                            createdtime = DateTime.Now
                        });
                    }
                    else
                    {
                        const string sql = "update cust_wechat set openid=@openid,modifiedtime=@modifiedtime where custid=@custid;";
                        conn.Execute(sql, new
                        {
                            custid,
                            model.Openid,
                            modifiedtime = DateTime.Now
                        });
                    }
                    return 1;
                }
                catch (Exception ex)
                {
                    return 0;
                }
            }
        }