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


PHP DB::commit方法代码示例

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


在下文中一共展示了DB::commit方法的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


//.........这里部分代码省略.........
                 $product->calories_from_fat = $row[17];
                 $product->protein = $row[18];
                 $product->carbs = $row[19];
                 $product->fibre = $row[20];
                 $product->sugar = $row[21];
                 $product->total_fat = $row[22];
                 $product->saturated_fats = $row[23];
                 $product->sodium = $row[24];
                 //rows 25, 26, 27, 28, 29, 30, 31, 32, 33 are allergens
                 // Product Image
                 if ($row[34] !== '') {
                     if ($pio->isDownloadImages()) {
                         try {
                             $newFilename = $uploader->getRemoteFile($row[34], null, public_path(config('app.product_storage')));
                             $product->product_image = $newFilename;
                         } catch (Exception $ex) {
                             /* If the image can't be downloaded, just don't set the field */
                         }
                     } else {
                         $product->product_image = $row[34];
                     }
                 }
                 $product->description = $row[35];
                 $product->preparation = $row[36];
                 $product->ingredient_deck = $row[37];
                 $product->features_benefits = $row[38];
                 $product->allergen_disclaimer = '';
                 $product->net_weight = 0;
                 $product->gross_weight = 0;
                 $product->tare_weight = 0;
                 $product->serving_size = 0;
                 $product->vendor_logo = '';
                 $product->pos_pdf = '';
                 if (!$isExisting) {
                     $product->published = $pio->isAddAsActive();
                 }
                 // Only create record, relationships and commit if not simulated
                 if (!$pio->isSimulate() || $isExisting && !$pio->isIgnoreExisting()) {
                     $product->save();
                     // Create any categories for the user product
                     $catIdRoot = $this->createCategory($row[0], null);
                     $catIdSub1 = $this->createCategory($row[1], $row[0]);
                     $catIdSub2 = $this->createCategory($row[2], $row[1]);
                     $this->createProductCategory($catIdRoot, $product->id);
                     $this->createProductCategory($catIdSub1, $product->id);
                     $this->createProductCategory($catIdSub2, $product->id);
                     // Create any allergens for the user product
                     if ($row[25] == 'Y') {
                         $this->createProductAllergen(6, $product->id);
                     }
                     if ($row[26] == 'Y') {
                         $this->createProductAllergen(9, $product->id);
                     }
                     if ($row[27] == 'Y') {
                         $this->createProductAllergen(5, $product->id);
                     }
                     if ($row[28] == 'Y') {
                         $this->createProductAllergen(4, $product->id);
                     }
                     if ($row[29] == 'Y') {
                         $this->createProductAllergen(1, $product->id);
                     }
                     if ($row[30] == 'Y') {
                         $this->createProductAllergen(2, $product->id);
                     }
                     if ($row[31] == 'Y') {
                         $this->createProductAllergen(7, $product->id);
                     }
                     if ($row[32] == 'Y') {
                         $this->createProductAllergen(8, $product->id);
                     }
                     if ($row[33] == 'Y') {
                         $this->createProductAllergen(3, $product->id);
                     }
                     \DB::commit();
                 }
                 if ($isExisting && !$pio->isIgnoreExisting()) {
                     $recordsUpdated += 1;
                 } else {
                     $recordsAdded += 1;
                 }
             } catch (\Exception $ex) {
                 if (!$pio->isSimulate()) {
                     \DB::rollBack();
                 }
                 $recordsFailed += 1;
             }
             $recordCount += 1;
             return true;
             // Continue processing file
         }
     });
     // Create a record of the import in the database
     //$productImport = new \App\Models\ProductImport();
     //$productImport->user_id = $pio->getVendorId();
     //$productImport->uuid = $pio->getUuid();
     //$productImport->filename = $pio->getFileName();
     //$productImport->save();
     echo sprintf('Import complete, %s records added, %s records updated, %s records failed %s', $recordsAdded, $recordsUpdated, $recordsFailed, $pio->isSimulate() ? '(Simulated)' : '');
 }
开发者ID:gabwhite,项目名称:fsh,代码行数:101,代码来源:CsvProductImporter.php


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