当前位置: 首页>>代码示例>>PHP>>正文


PHP DB::beginTransaction方法代码示例

本文整理汇总了PHP中app\DB::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::beginTransaction方法的具体用法?PHP DB::beginTransaction怎么用?PHP DB::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\DB的用法示例。


在下文中一共展示了DB::beginTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: finalizePurchaseOrder

 public function finalizePurchaseOrder($poId)
 {
     $returnData = [];
     try {
         \DB::beginTransaction();
         // Mark completed field for all work orders for this PO
         WorkOrder::where('purchase_order_id', $poId)->update(['completed' => 1]);
         // Get all work orders for this PO
         $workOrderIds = WorkOrder::where('purchase_order_id', $poId)->select(['id'])->get();
         // Get all WorkOrderTask statuses
         $workOrderTaskIds = WorkOrderTask::select(['id'])->where('active', 1)->get();
         foreach ($workOrderIds as $woId) {
             // Delete all existing progress rows first
             WorkOrderProgress::where('work_order_id', $woId)->delete();
         }
         /*
         foreach($workOrderIds as $woId)
         {
             // Create full set of statuses for this work order
             foreach($workOrderTaskIds as $woTaskId)
             {
                 WorkOrderProgress::create([
                     'work_order_id' => $woId,
                     'work_order_task_id' => $woTaskId
                 ]);
             }
         }
         */
         // Future PO finalization stuff goes here.
         \DB::commit();
         //return $returnData;
     } catch (\Exception $ex) {
         \DB::rollBack();
         throw $ex;
     }
 }
开发者ID:breenyoung,项目名称:wfadmin,代码行数:36,代码来源:OrderLogicService.php

示例2: doImport

 public function doImport(ProductImportOptions $pio)
 {
     //\Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix()
     $path = $pio->getUuid() . '/' . $pio->getFileName();
     $fileContents = \Storage::disk('imports')->get($path);
     $csv = Reader::createFromString($fileContents);
     $csv->setDelimiter(',');
     if ($pio->isIncludeHeaders()) {
         $csv->setOffset(1);
         //because we don't want to insert the header
     }
     $recordsAdded = 0;
     $recordsUpdated = 0;
     $recordsFailed = 0;
     $recordCount = 0;
     $uploader = new UploadHandler();
     $csv->each(function ($row) use(&$pio, &$recordsAdded, &$recordsUpdated, &$recordsFailed, &$recordCount, &$uploader) {
         /* Row Structure
          *
          *CSV row format:
          *
          * Main,
          * Sub1,
          * Sub2,
          * Description,
          * Brand,
          * Pack,
          * Size,
          * UOM,
          * MPC,
          * Contact,
          * GTIN,
          * Halal,
          * IsOrganicProduct,
          * KosherClassification,
          * CalculationSize,
          * CalculationSizeUnitofMeasure,
          * Calories,
          * CaloriesfromFat,
          * Protein,
          * Carbohydrates,
          * TotalDietaryFibre,
          * TotalSugar,
          * TotalFat,
          * SaturatedFat,
          * Sodium mg,
          * AllergenPeanuts,
          * AllergenTreeNuts,
          * AllergenMilk,
          * AllergenLactose,
          * AllergenEggs,
          * AllergenFish,
          * AllergenShellfish,
          * AllergenSoy,
          * AllergenGluten,
          * Image URL,
          * ItemDetail,
          * Preparation,
          * IngredientsEnglish,
          * BenefitsEnglish
          *
          */
         if ($row[0] != null) {
             if (!$pio->isSimulate()) {
                 \DB::beginTransaction();
             }
             try {
                 // Check to see if the record already exists (update) if not ignore existing items
                 //$product = \App\Models\Product::where('uniquekey', '=', $row[8])
                 //                ->orWhere('uniquekey', '=', $row[11])->first();
                 $isExisting = false;
                 //if(!is_null($product) && isset($product))
                 //{
                 //$isExisting = true;
                 //}
                 if ($isExisting && !$pio->isSimulate() && !$pio->isIgnoreExisting()) {
                     // Clear any existing categories
                     //\DB::table('product_categories')->where('product_id', '=', $product->id)->delete();
                     // Clear any existing allergens
                     //\DB::table('product_allergens')->where('product_id', '=', $product->id)->delete();
                 } else {
                     $product = new \App\Models\Product();
                     $product->vendor_id = $pio->getVendorId();
                     $product->uniquekey = isset($row[8]) ? $row[8] : $row[11];
                     // MPC or GTIN
                 }
                 $product->name = ucfirst(mb_strtolower($row[3]));
                 $product->brand = ucfirst(mb_strtolower($row[4]));
                 $product->pack = $row[5];
                 $product->size = $row[6];
                 $product->uom = $row[7];
                 $product->serving_size_uom = $row[7];
                 // Not sure this should be duplicated
                 $product->mpc = $row[8];
                 $product->broker_contact = $row[9];
                 $product->gtin = $row[10];
                 $product->is_halal = $this->normalizeTrueFalseField($row[11]);
                 $product->is_organic = $this->normalizeTrueFalseField($row[12]);
                 $product->is_kosher = $this->normalizeTrueFalseField($row[13]);
                 $product->calc_size = $row[14];
//.........这里部分代码省略.........
开发者ID:gabwhite,项目名称:fsh,代码行数:101,代码来源:CsvProductImporter.php


注:本文中的app\DB::beginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。