Exemple #1
0
 public async Task <string> Process()
 {
     return($"{await RoyaltyHelper.Process()} {await CommissionHelper.Process()}");
 }
        protected void cbk_Buy_Callback(object sender, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            #region 验证是否通过消费
            if ((sdt_account.Number > sdt_paid_in.Number) && mode_cd.Value.ToString() != "挂账")
            {
                e.Result = Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = "收银金额不正确" });
                return;
            }
            if (_card.GetItem(txt_card_no.Text) != null)
            {
                e.Result = Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = "会员卡已经存在" });
                return;
            }
            #endregion
            //更新客户信息
            T_Vip_Customer customer = null;
            if (glp_cust.Text == "")
            {
                customer          = new T_Vip_Customer(); customer.SetState(EntityState.Added);
                customer.id       = Guid.NewGuid();
                customer.cust_no  = UIHelper.InitCustomerCode();
                customer.add_date = DateTime.Now;
            }
            else
            {
                customer = _cust.GetItem(Guid.Parse(hfd_cust_id.Value)); customer.SetState(EntityState.Modified);
            }
            customer.cust_name = txt_cust_name.Text;
            customer.telphone  = txt_telphone.Text;
            customer.cert_no   = txt_cert_no.Text;
            customer.is_member = true;
            if (cbb_sex_ind.Value != null)
            {
                customer.sex_ind = (int)cbb_sex_ind.Value;
            }
            if (det_birthday.Value != null)
            {
                customer.birthday = det_birthday.Date;
            }
            customer.shop_id     = UIHelpers.UserProvide.GetCurrentShopGuid();
            customer.update_date = DateTime.Now;
            customer.update_opr  = UIHelpers.UserProvide.GetCurrentUserName();
            Consume.customer     = customer;
            //增加卡信息
            decimal sale_amt = (decimal)sdt_sale_amt.Value + (sdt_credit_amt.Value == null ? 0 : (decimal)sdt_credit_amt.Value);
            //decimal account = (decimal)sdt_rich_amt.Value + sale_amt;
            var card = new T_Vip_Card(); card.SetState(EntityState.Added);
            card.id      = Guid.NewGuid();
            card.cust_id = customer.id;
            Guid cardtype_id = (Guid)gvw_CardType.GetSelectedFieldValues(gvw_CardType.KeyFieldName).First();
            card.cardtype_id = cardtype_id;
            card.card_no     = txt_card_no.Text;
            card.card_pwd    = txt_card_pwd.Text;
            //card.card_pwd = MicroTeam.Common.DEncrypt.Encrypt(txt_card_pwd.Text);
            card.card_status = true;
            if (det_end_date.Value != null)
            {
                card.end_date = det_end_date.Date;
            }
            if (det_start_date.Value != null)
            {
                card.start_date = det_start_date.Date;
            }
            //card.rate = (decimal)sdt_rate.Value;
            card.rich_amt   = card.surplus_bal = (decimal)sdt_rich_amt.Value;
            card.add_date   = card.update_date = DateTime.Now;
            card.update_opr = UIHelpers.UserProvide.GetCurrentUserName();
            #region 积分
            T_Vip_CardType cardType = _cardType.GetItem(cardtype_id);

            if (!card.surplus_integral.HasValue)
            {
                card.surplus_integral = 0;
            }
            card.surplus_integral += (int)sale_amt * cardType.integral_set;

            #endregion
            Consume.card = card;
            //更新车辆信息
            T_Vip_Car car = null;
            if (string.IsNullOrEmpty(hfd_car_id.Value))
            {
                car         = new T_Vip_Car(); car.SetState(EntityState.Added);
                car.id      = Guid.NewGuid();
                car.shop_id = UIHelpers.UserProvide.GetCurrentShopGuid();
                car.cust_id = customer.id; car.add_date = DateTime.Now;
            }
            else
            {
                car = _car.GetItem(Guid.Parse(hfd_car_id.Value)); car.SetState(EntityState.Modified);
            }
            car.car_no = cbb_car_area.Text + txt_car_no.Text;
            if (cbb_brand.Value != null)
            {
                car.brand = cbb_brand.Value.ToString();
            }
            if (cbb_car_sales.Value != null)
            {
                car.car_sales = ConvertHelper.ObjectToInt(cbb_car_sales.Value);
            }
            if (cbb_car_type.Value != null)
            {
                car.car_type = cbb_car_type.Value.ToString();
            }
            car.card_id       = card.id;
            car.motor_no      = txt_motor_no.Text;
            car.chariotest_no = txt_chariotest_no.Text;
            car.color         = txt_color.Text;
            car.num           = txt_num.Text;
            if (det_year_date.Value != null)
            {
                car.year_date = det_year_date.Date;
            }
            if (det_insurance_date.Value != null)
            {
                car.insurance_date = det_insurance_date.Date;
            }
            car.update_date = DateTime.Now;
            car.update_opr  = UIHelpers.UserProvide.GetCurrentUserName();
            string cars = dde_car_no.Text;
            if (!string.IsNullOrEmpty(cars))
            {
                foreach (string car_no in cars.Split(','))
                {
                    var car_1 = _car.GetItem(car_no);
                    if (car_1 != null)
                    {
                        car_1.card_id = card.id;
                        car_1.SetState(EntityState.Modified);
                    }
                    else
                    {
                        car_1 = new T_Vip_Car();
                        car_1.SetState(EntityState.Added);
                        car_1.id          = Guid.NewGuid();
                        car_1.car_no      = car_no;
                        car_1.card_id     = card.id;
                        car_1.cust_id     = customer.id;
                        car_1.update_date = car_1.add_date = DateTime.Now;
                        car_1.update_opr  = UIHelpers.UserProvide.GetCurrentUserName();
                    }
                    Consume.cars.Add(car_1);
                }
            }
            Consume.cars.Add(car);
            //增加卡套餐
            var servers = _cardTypeService.GetList(new QueryInfo <T_Vip_CardType_Service>().SetQuery("cardtype_id", card.cardtype_id.Value));
            List <T_Vip_CardServices_Rela> relas = new List <T_Vip_CardServices_Rela>();
            foreach (var server in servers)
            {
                if (server.is_order_detail.HasValue && !server.is_order_detail.Value && server.consume_cnt.HasValue)
                {
                    T_Vip_CardServices_Rela rela = new T_Vip_CardServices_Rela();
                    rela.SetState(EntityState.Added);
                    rela.card_id     = card.id;
                    rela.cnt_rate    = server.cnt_rate;
                    rela.surplus_cnt = rela.consume_cnt = server.consume_cnt;
                    rela.is_free     = server.is_free;
                    rela.pro_id      = server.pro_id;
                    rela.add_date    = rela.update_date = DateTime.Now;
                    rela.update_opr  = UIHelpers.UserProvide.GetCurrentUserName();
                    relas.Add(rela);
                }
            }
            Consume.cardServices = relas;
            //增加订单明细
            var detail = new T_Sal_Consume_Detail(); detail.SetState(EntityState.Added);
            detail.id          = Guid.NewGuid();
            detail.account_det = sale_amt;
            detail.car_id      = car.id;
            detail.card_amt    = 0;
            if (sdt_handsel_amt.Value != null)
            {
                detail.cash_coupon = (decimal)sdt_handsel_amt.Value;
            }
            var odServer = servers.FirstOrDefault(p => p.is_order_detail.Value);
            if (odServer != null)
            {
                var pro = BLL.T_Prd_Info.provide.GetModel(odServer.pro_id.Value);
                if (pro != null)
                {
                    detail.consume_type_cd = pro.service_as;
                    detail.pro_id          = pro.id;
                    detail.unit_amt        = pro.sales_amt ?? 0;
                }
            }

            detail.consume_type_cd = "package";
            ///detail.pro_id = null;
            detail.unit_amt = Convert.ToDecimal(sdt_sale_amt.Value);
            detail.mode_cd  = Convert.ToString(mode_cd.KeyValue);
            detail.number   = 1;
            detail.order_id = Consume.consume.id;
            detail.rate     = 10;
            detail.remarks  = txt_remarks.Text;
            decimal sum_bal = (decimal)sdt_sum_bal.Value;
            detail.sum_bal    = detail.cope_amt = sum_bal;
            detail.add_date   = detail.update_date = DateTime.Now;
            detail.update_opr = UIHelpers.UserProvide.GetCurrentUserName();
            Consume.details.Add(detail);
            #region 销售、施工、提成
            List <object> crew_ids = gl_Crews.GridView.GetSelectedFieldValues(gl_Crews.GridView.KeyFieldName);
            decimal       account_det = 0, account_royalty = 0;
            decimal       costunit = detail.cost * detail.number;
            account_det = account_royalty = (decimal)detail.account_det + (decimal)detail.card_amt;
            if (crew_ids.Count > 0)
            {
                account_det = account_det / crew_ids.Count;
                costunit    = costunit / crew_ids.Count;
            }
            foreach (Guid crew in crew_ids)
            {
                T_Sal_Consume_Crew crewItem = new T_Sal_Consume_Crew(); crewItem.SetState(EntityState.Added);
                crewItem.id           = Guid.NewGuid();
                crewItem.consume_id   = detail.id;
                crewItem.emp_id       = crew;
                crewItem.royalty_type = 3;
                RoyaltyHelper.Royalty(crew, detail, account_royalty, crew_ids.Count, crewItem);
                //Royalty(crew, detail, account_royalty, crew_ids.Count, crewItem);
                crewItem.consume_amt = account_det;
                crewItem.gross_amt   = account_det - costunit;
                crewItem.add_date    = crewItem.update_date = DateTime.Now;
                crewItem.update_opr  = UIHelpers.UserProvide.GetCurrentUserName();
                Consume.crews.Add(crewItem);
            }
            #endregion
            //订单信息
            Consume.consume.cust_id     = customer.id;
            Consume.consume.account     = Consume.consume.cash = sale_amt;
            Consume.consume.sales_amt   = sum_bal;
            Consume.consume.paid_in     = (decimal)sdt_paid_in.Value;     //实收
            Consume.consume.give_change = (decimal)sdt_give_change.Value; //找钱
            Consume.consume.remarks     = txt_remarks.Text;
            Consume.consume.amt_mode_cd = Convert.ToString(mode_cd.KeyValue);
            Consume.consume.status_cd   = "1";
            Consume.consume.card_id     = card.id;
            Consume.consume.card_no     = card.card_no;
            //提交办卡订单
            car_nos.Clear();
            int result = _consume.Batch(Consume);
            if (result > 0)
            {
                e.Result = Newtonsoft.Json.JsonConvert.SerializeObject(new { success = true, msg = "结算成功", id = Consume.consume.id });
            }
            else
            {
                e.Result = Newtonsoft.Json.JsonConvert.SerializeObject(new { success = false, msg = "提交失败" });
            }

            //增加短信发送功能(吴,2013.9.26)
            if (e.Result.IndexOf("结算成功") >= 0)
            {
                try
                {
                    string  jsonText = "[" + e.Result.ToString() + "]";
                    JArray  ja       = (JArray)JsonConvert.DeserializeObject(jsonText);
                    JObject o        = (JObject)ja[0];
                    string  order_id = o["id"].ToString().Replace("\"", ""); //订单编号
                    DataSet ds_order = DbHelperSQL.Query("select * from T_Sal_Consume_Detail where order_id='" + order_id + "'");
                    if (ds_order.Tables[0].Rows.Count > 0)
                    {
                        Decimal unit_cmt     = Decimal.Parse(ds_order.Tables[0].Rows[0]["unit_amt"].ToString());    //办卡金额(套餐金额)
                        Decimal cash_coupon  = Decimal.Parse(ds_order.Tables[0].Rows[0]["cash_coupon"].ToString()); //充值赠送金额
                        Decimal account_det1 = Decimal.Parse(ds_order.Tables[0].Rows[0]["account_det"].ToString()); //实收金额
                        Decimal cz           = account_det1 - unit_cmt;                                             //充值金额(实收金额-办卡金额)
                        string  car_id       = ds_order.Tables[0].Rows[0]["car_id"].ToString();
                        DataSet ds_car       = DbHelperSQL.Query("select * from T_Vip_Car where id='" + car_id + "'");
                        if (ds_car.Tables[0].Rows.Count > 0)
                        {
                            string  cust_id = ds_car.Tables[0].Rows[0]["cust_id"].ToString(); //对应T_Vip_Customer表id
                            string  shop_id = ds_car.Tables[0].Rows[0]["shop_id"].ToString(); //对应T_Cm_Shop表id
                            string  card_id = ds_car.Tables[0].Rows[0]["card_id"].ToString(); //对应T_Vip_Card表id
                            string  car_no1 = ds_car.Tables[0].Rows[0]["car_no"].ToString();  //车牌号码
                            DataSet ds_cust = DbHelperSQL.Query("select * from T_Vip_Customer where id='" + cust_id + "'");
                            DataSet ds_card = DbHelperSQL.Query("select * from T_Vip_Card where id='" + card_id + "'");
                            if ((ds_cust.Tables[0].Rows.Count > 0) && (ds_card.Tables[0].Rows.Count > 0))
                            {
                                DataSet ds_cardtype = DbHelperSQL.Query("select * from T_Vip_CardType where id='" + ds_card.Tables[0].Rows[0]["cardtype_id"].ToString() + "'");
                                DataSet ds_shop     = DbHelperSQL.Query("select * from T_Cm_Shop where id='" + shop_id + "'");
                                string  tel         = ds_cust.Tables[0].Rows[0]["telphone"].ToString();  //手机号码
                                string  cust_name   = ds_cust.Tables[0].Rows[0]["cust_name"].ToString(); //客户姓名
                                string  content     = "恭喜您从即刻起成为我们“" + ds_cardtype.Tables[0].Rows[0]["type_name"].ToString() + "”会员;";
                                if (unit_cmt > 0)
                                {
                                    content += "购买套餐:" + unit_cmt.ToString() + "元,";
                                }
                                if (cz > 0)
                                {
                                    content += "充值:" + cz.ToString() + "元,";
                                }
                                if (cash_coupon > 0)
                                {
                                    content += "充值赠送:" + cash_coupon.ToString() + "元";
                                }
                                content += "[" + ds_shop.Tables[0].Rows[0]["shop_name"].ToString() + "]";
                                Model.T_Sms_Result model = new Model.T_Sms_Result();
                                model.template_id = car_id;
                                model.model       = "carsale";
                                model.model_type  = "Credit";
                                model.sms_date    = DateTime.Now;
                                model.sms_content = content;
                                model.cust_name   = cust_name;
                                model.telphone    = tel;
                                model.car_no      = car_no1;
                                model.shop_id     = shop_id;
                                SendSms.sendMessage(model);
                            }
                        }
                    }
                }
                catch
                {
                }
            }
        }