|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <?php
-
- namespace backend\modules\motorcade\controllers;
-
- use backend\modules\api\models\BaseSupplier;
- use Yii;
- use backend\modules\motorcade\models\BusDepartment;
- use backend\modules\motorcade\models\BusDepartmentLink;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use backend\modules\motorcade\models\BusOrder;
- use backend\modules\api\models\BaseUser;
- use common\models\BaseSupplierLink;
-
- /**
- * CustomerController implements the CRUD actions for BusDepartment model.
- */
- class CustomerController extends Controller
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
-
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- '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 "<script>z.pjaxFinish('success','{$info}','#float-div');</script>";
-
- } else {
- return "<script>z.pjaxFinish('error','操作失败','#float-div');</script>";
- }
- }
-
- }
-
- ?>
|