/** * Finds the Orders model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Orders the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Orders::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * start MPDF */ protected function createMpdf($view, $isfac = false) { $data = Yii::$app->request->get(); if (isset($data['order_id'])) { $order_id = $data['order_id']; $connection = \Yii::$app->db; $command = $connection->createCommand('SELECT * FROM orders WHERE order_id=' . $order_id); $order = $command->queryOne(); $user = $connection->createCommand('SELECT * FROM customer WHERE id =' . $order['action_user'])->queryOne(); $ordergoods = $connection->createCommand('SELECT * FROM order_goods WHERE order_id =' . $order_id)->queryAll(); if ($isfac && $order['fac_no'] == 0) { Dictionary::handleData("system", "factory_no"); $dic = Dictionary::findOne("system:factory_no"); $fac_no = $dic->auto; $order_model = Orders::findOne($order_id); $order_model->fac_no = $fac_no; $order_model->save(); $order['fac_no'] = $fac_no; } $mpdf = new Pdf(); $header = $this->renderPartial('mpdf/header', ['title' => 'nagoya']); $footer = $this->renderPartial('mpdf/footer'); $mpdf->setHeader($header); //设置PDF页眉内容 $mpdf->setFooter($footer); //设置PDF页脚内容 $content = $this->renderPartial($view, ['order' => $order, 'ordergoods' => $ordergoods, 'user' => $user]); $mpdf->Output($content); exit; } else { echo "缺少参数"; exit; } }
/** * Deletes an existing Listofgoods model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); $order_id = $model->orders_order_id; $order = Orders::findOne($order_id); $amount = $order->order_amount / 100; $price = $model->goodsGoodId->good_price / 100; $count = $model->good_count; $amount2 = $amount - $price * $count; $order->order_amount = $amount2 * 100; $order->save(); $model->delete(); return $this->redirect(['orders/view', 'id' => $order_id]); }