[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } /** * Lists all BaseSupplier models. * @return mixed */ // public function actionIndex() // { // $dataProvider = new ActiveDataProvider([ // 'query' => BaseSupplier::find(), // ]); // // return $this->render('index', [ // 'dataProvider' => $dataProvider, // ]); // } /** * Displays a single BaseSupplier model. * @param integer $id * @return mixed */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new BaseSupplier model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new BaseSupplier(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->ID]); } else { return $this->render('create', [ 'model' => $model, ]); } } /** * Updates an existing BaseSupplier model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->ID]); } else { return $this->render('update', [ 'model' => $model, ]); } } /** * Deletes an existing BaseSupplier model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Finds the BaseSupplier model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return BaseSupplier the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BaseSupplier::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * User:Steven * Desc:添加供应商 * @return string */ public function actionAddSupplier() { $Supplier = new BaseSupplier(); $Supplier->SUPPLIER_TYPE = 187; //供应商或渠道商标志 187:供应商 $Supplier->MANAGE_TYPE = 1; //经营性质 1:公司 2:个人 if ($Supplier->load(Yii::$app->request->post())) { $transaction = Yii::$app->db->beginTransaction(); try { if (!$Supplier->save()) { throw new \Exception(); } $supplier_id = $Supplier->attributes['ID']; $supplier_parc = new BaseSupplierPurchase(); $supplier_parc->SUPPLIER_ID = $supplier_id; $supplier_parc->PRODUCT_TYPE = $Supplier->TYPE; $supplier_parc->PURCHASER_NAME = Yii::$app->user->id; if (!$supplier_parc->save()) { throw new \Exception(); } $link_arr = array_values(Yii::$app->request->post('BaseSupplierLink')); foreach ($link_arr as $key => $item) { if ($item['CONTACT_NAME'] == '') { continue; } $supplier_link = new BaseSupplierLink(); $supplier_link->SUPPLIER_ID = $supplier_id; $supplier_link->setAttributes($item, false); if (!$supplier_link->save()) { throw new \Exception(); } } $transaction->commit(); Yii::$app->session->setFlash('success', "添加成功!"); return $this->redirect(array('supplier/index')); } catch (\Exception $e) { Yii::$app->session->setFlash('success', "添加失败!"); $transaction->rollBack(); } } $SupplierLink = new BaseSupplierLink(); $Supplier->TYPE = 259; $Supplier->SETT_TYPE = 474; $Supplier->SETT_FREQUENCY = 295; $data['data']['SupplierLink'][] = $SupplierLink; $data['data']['Supplier'] = $Supplier; return $this->render('base', ['view' => 'addSupplier', 'data' => $data]); } /** * User:Steven * Desc:更新供应商 * @param $id */ public function actionUpdateSupplier($id, $op = '') //op如果为review 则为审核,没有则为更新 { $Supplier = BaseSupplier::findOne($id); $SupplierType = BaseSupplierPurchase::find()->select(['PRODUCT_TYPE'])->where(['SUPPLIER_ID' => $id, 'CANCEL_FLAG' => 0])->one(); $Supplier->TYPE = isset($SupplierType->PRODUCT_TYPE) ? $SupplierType->PRODUCT_TYPE : 259; $SupplierLink = BaseSupplierLink::find()->select(['ID', 'SUPPLIER_ID', 'LINK_NAME', 'CONTACT_TYPE', 'CONTACT_NAME', 'CONTACT_MOBILE'])->where(['SUPPLIER_ID' => $id, 'CANCEL_FLAG' => 0])->all(); if (Yii::$app->request->post() && $Supplier->load(Yii::$app->request->post())) { //审核通过则把状态置为611 已审核 ,不通过则置为612 已停用, 只要在已审核状态下进行修改则把状态置为待审核 if ($Supplier->STATUS == 611) $Supplier->STATUS = 610; if (isset($_POST['pass'])) $Supplier->STATUS = 611; elseif (isset($_POST['reject'])) $Supplier->STATUS = 612; $transaction = Yii::$app->db->beginTransaction(); try { if (!$Supplier->save()) { throw new \Exception(); } $SupplierType->SUPPLIER_ID = $id; $SupplierType->PRODUCT_TYPE = $Supplier->TYPE; $SupplierType->PURCHASER_NAME = Yii::$app->user->id; if (!$SupplierType->save()) { throw new \Exception(); } BaseSupplierLink::updateAll(['cancel_flag' => 1], ['SUPPLIER_ID' => $id]); $link_arr = Yii::$app->request->post('BaseSupplierLink'); foreach ($link_arr as $key => $item) { if ($item['CONTACT_NAME'] == '') { continue; } $sup_link = (isset($item['ID']) && BaseSupplierLink::findOne($item['ID']) != null) ? BaseSupplierLink::findOne($item['ID']) : new BaseSupplierLink(); $rs = $sup_link->load($item, ''); $sup_link->SUPPLIER_ID = $id; $sup_link->CANCEL_FLAG = 0; if (!$rs || !$sup_link->save()) { throw new \Exception(); } } $transaction->commit(); $info = isset($_POST['pass']) ? '审核通过!' : '驳回成功!'; Yii::$app->session->setFlash('success', $info); return $this->redirect(array('supplier/index')); } catch (\Exception $e) { Yii::$app->session->setFlash('success', $info); $transaction->rollBack(); } } empty($SupplierLink) ? $data['data']['SupplierLink'][0] = new BaseSupplierLink() : $data['data']['SupplierLink'] = $SupplierLink; $data['data']['Supplier'] = $Supplier; $data['op'] = $op; return $this->render('base', ['view' => 'addSupplier', 'data' => $data]); } public function actionIndex($op = 'supplier') { if ($op == 'supplier') { $model = new BaseSupplier(); $model->load(Yii::$app->request->get()); $dataProvider = $model->getIndex(); } $data['view'] = '../customer/index'; $data['op'] = $op; return $this->render('_base', ['data' => $data, 'dataProvider' => $dataProvider]); } //停用或启用或删除供应商 //1为停用 2为启用 3为删除 public function actionDoSupplier($id, $type) { $model = $this->findModel($id); $info = ''; if ($type == 1) { $model->STATUS = 612; $info = '停用成功'; } elseif ($type == 2) { $model->STATUS = 610; $info = '启用成功'; } /*elseif ($type == 3) { $model->CANCEL_FLAG = 1; $info = '删除成功'; }*/ if ($model->save()) { Yii::$app->session->setFlash('success', "$info"); return ""; } else { Yii::$app->session->setFlash('warning', $info); return ""; } } } ?>