|
- <?php
-
- namespace backend\modules\zzcs\controllers;
-
- use backend\modules\zzcs\logic\BaseTailor;
- use backend\modules\zzcs\models\BaseSupplier;
- use backend\modules\zzcs\models\BaseSupplierPurchase;
- use backend\modules\zzcs\models\BaseUser;
- use backend\modules\zzcs\models\OperaTailorProduct;
- use backend\modules\zzcs\models\OrderMain;
- use Yii;
- use backend\modules\zzcs\models\BaseTailorStation;
- use yii\data\ActiveDataProvider;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
-
- /**
- * TailorController implements the CRUD actions for BaseTailorStation model.
- */
- class TailorController extends Controller
- {
- public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
- public $enableCsrfValidation = false;
-
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
-
- /**
- * Lists all BaseTailorStation models.
- * @return mixed
- * 列表页
- */
- public function actionIndex()
- {
- $filter = Yii::$app->request->get();
- $data['view'] = 'index';
- $model = new BaseTailorStation();
- $dataProvider = $model->getIndex($filter);
-
- return $this->render('_base', [
- 'dataProvider' => $dataProvider,
- 'data' => $data,
- ]);
- }
-
- // /**
- // * Displays a single BaseTailorStation model.
- // * @param integer $id
- // * @return mixed
- // * 查看数据
- // */
- // public function actionView($id)
- // {
- // return $this->render('view', [
- // 'model' => $this->findModel($id),
- // ]);
- // }
-
- /**
- * Creates a new BaseTailorStation model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @return mixed
- * 创建数据
- */
- public function actionCreate()
- {
- $tailor_type = Yii::$app->request->get('tailor_type', 0);
- $product_id = Yii::$app->request->get('product_id', 0);
- $model = new BaseTailorStation();
- $data['view'] = 'create';
- $data['products'] = OperaTailorProduct::getProduct($tailor_type);
- $data['stations'] = OperaTailorProduct::getStation($product_id);
-
- //将地址中的英文头号(,)替换为中文逗号(,)
- $post_data = Yii::$app->request->post();
- if (isset($post_data['BaseTailorStation']['address'])) {
- $post_data['BaseTailorStation']['address'] = trim(str_replace(',', ',', $post_data['BaseTailorStation']['address']));
- }
- if ($model->load($post_data) && $model->save()) {
- //要求下单后再把原单的order_price给置0
- if ($post_data['BaseTailorStation']['original_order_id'] != "") {
- $order_id = $post_data['BaseTailorStation']['original_order_id'];
- $order_main_models = OrderMain::find()->where(['and', ['or', ['=', 'parent_order_id', $order_id], ['=', 'order_id', $order_id]], ['=', 'cancel_flag', 0]])->all();
- if (!$order_main_models) {
- return $this->redirect(['index']);
- }
- foreach ($order_main_models as $order_main_model) {
- $order_main_model->ORDER_PRICE = 0.00;
- $order_main_model->save(false);
- }
- }
- return $this->redirect(['index']);
- } else {
- return $this->render('_base', [
- 'model' => $model,
- 'data' => $data,
- ]);
- }
- }
-
-
- /**
- * Updates an existing BaseTailorStation model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- * 更新数据
- */
- public function actionUpdate($id)
- {
- $tailor_type = Yii::$app->request->get('tailor_type', 0);
- $product_id = Yii::$app->request->get('product_id', 0);
- $model = $this->findModel($id);
- $data['products'] = OperaTailorProduct::getProduct($tailor_type == 0 ? $model->tailor_type : $tailor_type);
- $data['stations'] = OperaTailorProduct::getStation($product_id == 0 ? $model->product_id : $product_id);
- $data['view'] = 'update';
- //将地址中的英文头号(,)替换为中文逗号(,)
- $post_data = Yii::$app->request->post();
- if (isset($post_data['BaseTailorStation']['address'])) {
- $post_data['BaseTailorStation']['address'] = trim(str_replace(',', ',', $post_data['BaseTailorStation']['address']));
- }
- if ($model->load($post_data) && $model->save()) {
- return $this->redirect(['index']);
- } else {
- return $this->render('_base', [
- 'model' => $model,
- 'data' => $data
- ]);
- }
- }
-
- // /**
- // * Deletes an existing BaseTailorStation 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']);
- // }
-
- /**
- * Function Description:生成线路页面
- * Function Name: actionLine
- *
- * @return string
- *
- * @author LUOCJ
- */
- public function actionLine()
- {
- $product_id = Yii::$app->request->post('product_id', 0);
- $run_date = Yii::$app->request->post('run_date', '');
- $model = new BaseTailorStation();
- $data['data'] = $model->getPointInfo($product_id, $run_date);
- $data['view'] = 'line';
- $data['product_id'] = $product_id;
- $data['run_date'] = $run_date;
- return $this->render('_base', [
- 'model' => $model,
- 'data' => $data
- ]);
- }
-
- /**
- * Function Description:点查找
- * Function Name: actionLineSearch
- *
- * @return string
- *
- * @author LUOCJ
- */
- public function actionLineSearch()
- {
- $product_id = Yii::$app->request->post('product_id', 0);
- $run_date = Yii::$app->request->post('run_date', '');
- $model = new BaseTailorStation();
- $data = $model->getPointInfo($product_id, $run_date);
- return $data;
- }
-
- /**
- * Function Description:获取line页面所需数据
- * Function Name: actionGetLineInfo
- *
- * @return string
- *
- * @author LUOCJ
- */
- public function actionGetLineInfo()
- {
- $model_supplier = new BaseSupplierPurchase();
- $data = $model_supplier->getLineInfo();
- return json_encode($data);
- }
-
- /**
- * Function Description:生成线路前检查
- * Function Name: actionCheckLine
- *
- * @return string
- *
- * @author LUOCJ
- */
-
- public function actionCheckLine()
- {
- $points = Yii::$app->request->post('points');
- $data = BaseTailor::CheckLine($points);
-
- return json_encode($data);
- }
-
- /**
- * Function Description:保存line
- * Function Name: actionSaveLine
- *
- *
- * @author LUOCJ
- */
- public function actionSaveLine()
- {
- $transaction = Yii::$app->db->beginTransaction();
- $sum_data = Yii::$app->request->post('sum_data');
- $model = new BaseTailor($sum_data);
- $data = $model->generateDynamicHub();
- //$res=BaseTailorStation::find()->where(['id'=>12])->asArray()->one();
- $transaction->commit();
- return json_encode($data);
- }
-
- /**
- * Finds the BaseTailorStation model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return BaseTailorStation the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = BaseTailorStation::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * Function Description:获取原有订单数据
- * Function Name: actionGetOrgOrderInfo
- *
- * @return string
- *
- * @author LUOCJ
- */
- public function actionGetOrderInfo()
- {
- $order_id = Yii::$app->request->post('order_id');
- $data = BaseTailor::getOldOrderInfo($order_id);
- return json_encode($data);
- }
-
- /**
- * 修改订单状态
- */
- public function actionModify()
- {
- $post = Yii::$app->request->post();
- if (isset($post['id']) && isset($post['op'])) {
- $data = BaseTailor::isOnSaleControl($post['id'], $post['op']);
- } else {
- $data['code'] = 2;
- }
- echo json_encode($data);
- }
- }
|