[
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all BusDepartment models.
* @return mixed
*/
// public function actionIndex()
// {
// $dataProvider = new ActiveDataProvider([
// 'query' => BusDepartment::find(),
// ]);
//
// return $this->render('index', [
// 'dataProvider' => $dataProvider,
// ]);
// }
/**
* Displays a single BusDepartment model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new BusDepartment model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new BusDepartment();
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 BusDepartment 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 BusDepartment 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 BusDepartment model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return BusDepartment the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = BusDepartment::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
public function actionIndex($op = 'customer')
{
if ($op == 'customer') {
$model = new BusDepartment();
// $model->load(Yii::$app->request->get());
$dataProvider = $model->getIndex();
}
$data['view'] = 'index';
$data['op'] = $op;
return $this->render('_base', ['data' => $data, 'dataProvider' => $dataProvider]);
}
/**
* User:Steven
* Desc:添加客户(用车单位)
*/
public function actionAddCustomer()
{
$bus_depart = new BusDepartment(['scenario' => 'add_customer']);
$bus_depart->status = 610;
if ($bus_depart->load(Yii::$app->request->post())) {
$transaction = Yii::$app->db->beginTransaction();
try {
if (!$bus_depart->save()) {
throw new \Exception();
}
$department_id = $bus_depart->attributes['ID'];
$link_arr = array_values(Yii::$app->request->post('BusDepartmentLink'));
foreach ($link_arr as $key => $item) {
if ($item['contact_name'] == '') {
continue;
}
$depart_link = new BusDepartmentLink();
$depart_link->department_id = $department_id;
$depart_link->setAttributes($item, false);
if (!$depart_link->save()) {
throw new \Exception();
}
}
$transaction->commit();
Yii::$app->session->setFlash('success', "添加成功!");
return $this->redirect(array('customer/index'));
} catch (\Exception $e) {
Yii::$app->session->setFlash('success', "添加失败!");
$transaction->rollBack();
}
}
$bus_depart->depart_type = 469;
$bus_depart->settle_type = 474;
$bus_depart->settle_cycle = 295;
//获取业务员
$user = BaseUser::find()->select(['ID', 'USER_NAME', 'TRUE_NAME'])->where(['CANCEL_FLAG' => 0])->andWhere(['<>', 'TRUE_NAME', ''])->andFilterWhere(['MAIN_CORP_ID2' => Yii::$app->user->identity->MAIN_CORP_ID2])->asArray()->all();
$data['Salesman'] = $user;
$data['busDepartment'] = $bus_depart;
$SupplierLink = new BusDepartmentLink();
$data['SupplierLink'][] = $SupplierLink;
return $this->render('_base', ['view' => 'addCustomer', 'data' => $data]);
}
/**
* User:Steven
* Desc:更新客户信息
* @param $id
*/
public function actionUpdateCustomer($id, $op = '')
{
$bus_department = BusDepartment::findOne($id);
$bus_department->setScenario('add_customer');
$SupplierLink = BusDepartmentLink::find()->where(['department_id' => $id, 'cancel_flag' => 0])->all();
if (Yii::$app->request->post() && $bus_department->load(Yii::$app->request->post())) {
//审核通过则把状态置为611 已审核 ,不通过则置为612 已停用, 只要在已审核状态下进行修改则把状态置为待审核
if ($bus_department->status == 611)
$bus_department->status = 610;
if (isset($_POST['pass']))
$bus_department->status = 611;
elseif (isset($_POST['reject']))
$bus_department->status = 612;
$transaction = Yii::$app->db->beginTransaction();
try {
if (!$bus_department->save()) {
throw new \Exception();
}
$department_id = $bus_department->attributes['ID'];
BusDepartmentLink::updateAll(['cancel_flag' => 1], ['department_id' => $department_id]);
$link_arr = array_values(Yii::$app->request->post('BusDepartmentLink'));
foreach ($link_arr as $key => $item) {
if ($item['contact_name'] == '') {
continue;
}
$depart_link = (BusDepartmentLink::findOne($item['id']) != null) ? BusDepartmentLink::findOne($item['id']) : new BusDepartmentLink();
$depart_link->department_id = $department_id;
$depart_link->cancel_flag = 0;
$depart_link->setAttributes($item, false);
if (!$depart_link->save()) {
throw new \Exception();
}
}
$transaction->commit();
$info = isset($_POST['pass']) ? '审核通过!' : '驳回成功!';
Yii::$app->session->setFlash('success', $info);
return $this->redirect(array('customer/index'));
} catch (\Exception $e) {
Yii::$app->session->setFlash('success', $info);
$transaction->rollBack();
}
}
$user = BaseUser::find()->select(['ID', 'USER_NAME', 'TRUE_NAME'])
->where(['CANCEL_FLAG' => 0])
->andWhere(['<>', 'TRUE_NAME', ''])
->andFilterWhere(['MAIN_CORP_ID2' => Yii::$app->user->identity->MAIN_CORP_ID2])
->asArray()->all();
$data['Salesman'] = $user;
$data['busDepartment'] = $bus_department;
// $SupplierLink = new BusDepartmentLink();
$data['SupplierLink'] = $SupplierLink;
$data['op'] = $op;
return $this->render('_base', ['view' => 'addCustomer', 'data' => $data]);
}
public function actionDoCustomer($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()) {
return "";
} else {
return "";
}
}
}
?>