Пример #1
0
 private async Task<SimpleResult> SyncSupplierInfo(ProductItem product)
 {
     using (var helper = new WBHelper(true))
     {
         var success = false;
         //查找供应商
         var supplier = await this.InvokeTask(supplierInfo, helper, product.SpuId);
         if (supplier != null && supplier.profitData != null && supplier.profitData.Any())
         {
             product.OnSupplierInfoUpdate(AppDatabase.db.ProductItems, supplier);
             success = true;
         }
         return new SimpleResult { Success = success, ProductId = product.Id };
     }
 }
Пример #2
0
 public async Task<bool> SetProductProfit(ProductItem product, Func<ProductItem, decimal> Getprofit, bool forceModify = false, bool isUserOperation = false)
 {
     try
     {
         decimal profit = Getprofit(product);
         SuplierInfo supplier = null;
         if (!string.IsNullOrEmpty(product.SupplierId))
         {
             supplier = product.GetSuplierInfo();
         }
         else
         {
             await CheckIfLoginRequired();
             using (var wbHelper = new WBHelper(true))
             {
                 supplier = await this.InvokeTask(supplierInfo, wbHelper, product.SpuId);
                 if (supplier == null || !supplier.profitData.Any())
                 {
                     AppendText("【{0}】暂无供应商,改价操作取消。", product.ItemName);
                     return false;
                 }
                 product.OnSupplierInfoUpdate(AppDatabase.db.ProductItems, supplier);
             }
         }
         if (supplier != null && supplier.profitData != null && supplier.profitData.Any())
         {
             if (supplier.profitData[0].price == 0)
             {
                 AppendText("【{0}】暂无供应商,改价操作取消。", product.ItemName);
                 return false;
             }
             if (supplier.profitData[0].price == product.进价 && product.利润 == profit && !forceModify)
             {
                 //价格无变化不处理
                 AppendText("商品【{0}】进价及利润无变化,跳过。", product.ItemName);
                 BindDGViewProduct();
                 return true;
             }
             string profitString = "0.00";
             profitString = profit.ToString("f2");
             var oneprice = (supplier.profitData[0].price + profit).ToString("f2");
             await CheckIfLoginRequired();
             using (var wbHelper = new WBHelper(false))
             {
                 var save = await this.InvokeTask(supplierSave, wbHelper, supplier.profitData[0].id, product.SpuId, profitString, oneprice, product.Id, tbcpCrumbs);
                 if (save.status != 200)
                 {
                     AppendText("为商品{0}设置利润时失败。错误消息:{1}", product.Id, save.msg);
                     return false;
                 }
                 else
                 {
                     product.ModifyProfitSubmitted = true;
                     if (isUserOperation)
                     {
                         //备份原始利润
                         product.原利润 = profit;
                     }
                     AppDatabase.db.ProductItems.Update(product);
                     BindDGViewProduct();
                     return true;
                 }
             }
         }
         else
         {
             AppendText("为商品{0}设置利润时失败,因为没有查询到供应商信息。", product.Id);
             return false;
         }
     }
     catch (Exception ex)
     {
         AppendException(ex);
         return false;
     }
 }