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


PHP Item::findAll方法代码示例

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


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

示例1: actionIndex

 /**
  * Lists all BillItem models.
  * @return mixed
  */
 public function actionIndex()
 {
     if (isset($_POST['hasEditable']) && $_POST['hasEditable'] == 1) {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         if (isset($_POST['item'], $_POST['quantity_user'])) {
             if (!isset(Yii::$app->session['item'])) {
                 Yii::$app->session['item'] = [];
             }
             $item = Yii::$app->session['item'];
             $item[$_POST['item']] = $_POST['quantity_user'];
             Yii::$app->session['item'] = $item;
             return ['output' => $_POST['quantity_user'], 'message' => ''];
         } else {
             return ['output' => '', 'message' => 'Validation error'];
         }
     } elseif (isset($_POST['iks'], $_POST['bks'], $_POST['assign_mode'])) {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         //Create assignment
         if ($_POST['assign_mode'] == 1) {
             $items = Item::findAll($_POST['iks']);
             $bill = Bill::findOne($_POST['bks'][0]);
             $billItem = null;
             $transaction = Bill::getDb()->beginTransaction();
             try {
                 foreach ($items as $item) {
                     $billItem = BillItem::find()->where(['item_id' => $item->id, 'bill_id' => $bill->id])->one();
                     if ($billItem == null) {
                         $billItem = new BillItem();
                         $billItem->bill_id = $bill->id;
                         $billItem->item_id = $item->id;
                     }
                     $itemSession = Yii::$app->session['item'];
                     $oldQuantity = $billItem->quantity;
                     $billItem->quantity = $itemSession[$item->id];
                     if ($oldQuantity > $billItem->quantity) {
                         $item->quantity += $billItem->quantity;
                     } elseif ($oldQuantity < $billItem->quantity) {
                         $item->quantity -= $billItem->quantity;
                     }
                     $item->save(false);
                     if (!$billItem->save(false)) {
                         throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($billItem->tableName())), 'msj' => print_r($billItem->getErrors(), true)]), 500);
                     }
                 }
                 $transaction->commit();
                 Yii::$app->session['item'] = [];
                 return ['error' => false, 'message' => Yii::t('app', 'Saved')];
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 return ['error' => true, 'message' => print_r($e, true)];
             }
         }
     }
     $searchModel = new BillSearch();
     $dataProvider = $searchModel->searchWithItem(Yii::$app->request->queryParams);
     $itemSearchModel = new ItemSearch();
     $itemDataProvider = $itemSearchModel->searchWithItem(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'itemSearchModel' => $itemSearchModel, 'itemDataProvider' => $itemDataProvider]);
 }
开发者ID:edarkzero,项目名称:mi_taller,代码行数:63,代码来源:ItemAssignController.php


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