/** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Customer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function deleteCus($id) { $model = Customer::findOne($id); if (!$model) { return false; } if ($model->delete()) { Customer::deleteAll(['parentId' => $id]); return true; } return false; }
public function actionDetails() { $session = new Sitesession(); $user_id = $session->getUserId(); $goods = $session->getGoods($user_id); $order_id = $session->getOrderId(); $order = null; if (!empty($order_id)) { $order = Orders::findOne($order_id); } $user = null; if ($user_id) { //获取user_id用户信息 /*$connection = \Yii::$app->db; $command = $connection->createCommand('SELECT * FROM customer WHERE id='.$user_id); $user = $command->queryOne();*/ $user = Customer::findOne($user_id); } $count = 0; if (is_array($goods) && !empty($goods)) { /*$str = ''; foreach ($goods as $key => $value) { if(empty($str)) { $str = $str." ".$value; } else { $str = $str.", ".$value; } } */ $count = count($goods); //获取goods $connection = \Yii::$app->db; $transaction = $connection->beginTransaction(); try { // 所有的查询都在主服务器上执行 //$goods = $connection->createCommand('SELECT * FROM goods WHERE goods_id in ('.$str.')')->queryAll(); $goods = Goods::findAll($goods); $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); throw $e; } } else { $goods = false; } return $this->render('details', ['user' => $user, 'goods' => $goods, 'count' => $count, 'order' => $order]); }
public function actionEditpointimg() { $user = new AdminUser(); if (!$user->checkUserIsLogin()) { $this->redirect(Variable::$home_url); return; } $req = Yii::$app->request; //创建一个请求对象 $form = new CustomerForm(); $form->level = Variable::$customer_type_w; $form->setScenario('img'); $id = trim($req->get('id')); if (!is_numeric($id) || $id == 0) { $this->redirect(Variable::$customerBrand_url); return; } //修改 if ($form->load($req->post()) && $form->validate()) { $isSuccess = (new Customer())->updateCus($id, $form->name, $form->sort, $form->level, $form->blogo, $form->clogo, $form->img1, $form->img2, $form->img3, $form->img4, $form->img5); if ($isSuccess) { Yii::$app->session->setFlash(Variable::$flash_success, '设置成功'); } else { // $form->addError('','更新失败'); Yii::$app->session->setFlash(Variable::$flash_error, '设置失败,请重试'); } } $customerModel = Customer::findOne($id); $form->img1 = $customerModel->img1; $form->img2 = $customerModel->img2; $form->img3 = $customerModel->img3; $form->img4 = $customerModel->img4; $form->img5 = $customerModel->img5; $form->name = $customerModel->name; $form->id = $customerModel->id; $list = []; if (!empty($form->img1)) { array_push($list, $form->img1); } if (!empty($form->img2)) { array_push($list, $form->img2); } if (!empty($form->img3)) { array_push($list, $form->img3); } if (!empty($form->img4)) { array_push($list, $form->img4); } if (!empty($form->img5)) { array_push($list, $form->img5); } return $this->render(Variable::$editPointImg_view, ['model' => $form, 'customerModel' => $customerModel, 'list' => $list]); }