You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

293 lines
8.8 KiB

  1. <?php
  2. namespace backend\modules\zzcs\controllers;
  3. use backend\modules\zzcs\logic\BaseTailor;
  4. use backend\modules\zzcs\models\BaseSupplier;
  5. use backend\modules\zzcs\models\BaseSupplierPurchase;
  6. use backend\modules\zzcs\models\BaseUser;
  7. use backend\modules\zzcs\models\OperaTailorProduct;
  8. use backend\modules\zzcs\models\OrderMain;
  9. use Yii;
  10. use backend\modules\zzcs\models\BaseTailorStation;
  11. use yii\data\ActiveDataProvider;
  12. use yii\web\Controller;
  13. use yii\web\NotFoundHttpException;
  14. use yii\filters\VerbFilter;
  15. /**
  16. * TailorController implements the CRUD actions for BaseTailorStation model.
  17. */
  18. class TailorController extends Controller
  19. {
  20. public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
  21. public $enableCsrfValidation = false;
  22. /**
  23. * @inheritdoc
  24. */
  25. public function behaviors()
  26. {
  27. return [
  28. 'verbs' => [
  29. 'class' => VerbFilter::className(),
  30. 'actions' => [
  31. 'delete' => ['POST'],
  32. ],
  33. ],
  34. ];
  35. }
  36. /**
  37. * Lists all BaseTailorStation models.
  38. * @return mixed
  39. * 列表页
  40. */
  41. public function actionIndex()
  42. {
  43. $filter = Yii::$app->request->get();
  44. $data['view'] = 'index';
  45. $model = new BaseTailorStation();
  46. $dataProvider = $model->getIndex($filter);
  47. return $this->render('_base', [
  48. 'dataProvider' => $dataProvider,
  49. 'data' => $data,
  50. ]);
  51. }
  52. // /**
  53. // * Displays a single BaseTailorStation model.
  54. // * @param integer $id
  55. // * @return mixed
  56. // * 查看数据
  57. // */
  58. // public function actionView($id)
  59. // {
  60. // return $this->render('view', [
  61. // 'model' => $this->findModel($id),
  62. // ]);
  63. // }
  64. /**
  65. * Creates a new BaseTailorStation model.
  66. * If creation is successful, the browser will be redirected to the 'view' page.
  67. * @return mixed
  68. * 创建数据
  69. */
  70. public function actionCreate()
  71. {
  72. $tailor_type = Yii::$app->request->get('tailor_type', 0);
  73. $product_id = Yii::$app->request->get('product_id', 0);
  74. $model = new BaseTailorStation();
  75. $data['view'] = 'create';
  76. $data['products'] = OperaTailorProduct::getProduct($tailor_type);
  77. $data['stations'] = OperaTailorProduct::getStation($product_id);
  78. //将地址中的英文头号(,)替换为中文逗号(,)
  79. $post_data = Yii::$app->request->post();
  80. if (isset($post_data['BaseTailorStation']['address'])) {
  81. $post_data['BaseTailorStation']['address'] = trim(str_replace(',', ',', $post_data['BaseTailorStation']['address']));
  82. }
  83. if ($model->load($post_data) && $model->save()) {
  84. //要求下单后再把原单的order_price给置0
  85. if ($post_data['BaseTailorStation']['original_order_id'] != "") {
  86. $order_id = $post_data['BaseTailorStation']['original_order_id'];
  87. $order_main_models = OrderMain::find()->where(['and', ['or', ['=', 'parent_order_id', $order_id], ['=', 'order_id', $order_id]], ['=', 'cancel_flag', 0]])->all();
  88. if (!$order_main_models) {
  89. return $this->redirect(['index']);
  90. }
  91. foreach ($order_main_models as $order_main_model) {
  92. $order_main_model->ORDER_PRICE = 0.00;
  93. $order_main_model->save(false);
  94. }
  95. }
  96. return $this->redirect(['index']);
  97. } else {
  98. return $this->render('_base', [
  99. 'model' => $model,
  100. 'data' => $data,
  101. ]);
  102. }
  103. }
  104. /**
  105. * Updates an existing BaseTailorStation model.
  106. * If update is successful, the browser will be redirected to the 'view' page.
  107. * @param integer $id
  108. * @return mixed
  109. * 更新数据
  110. */
  111. public function actionUpdate($id)
  112. {
  113. $tailor_type = Yii::$app->request->get('tailor_type', 0);
  114. $product_id = Yii::$app->request->get('product_id', 0);
  115. $model = $this->findModel($id);
  116. $data['products'] = OperaTailorProduct::getProduct($tailor_type == 0 ? $model->tailor_type : $tailor_type);
  117. $data['stations'] = OperaTailorProduct::getStation($product_id == 0 ? $model->product_id : $product_id);
  118. $data['view'] = 'update';
  119. //将地址中的英文头号(,)替换为中文逗号(,)
  120. $post_data = Yii::$app->request->post();
  121. if (isset($post_data['BaseTailorStation']['address'])) {
  122. $post_data['BaseTailorStation']['address'] = trim(str_replace(',', ',', $post_data['BaseTailorStation']['address']));
  123. }
  124. if ($model->load($post_data) && $model->save()) {
  125. return $this->redirect(['index']);
  126. } else {
  127. return $this->render('_base', [
  128. 'model' => $model,
  129. 'data' => $data
  130. ]);
  131. }
  132. }
  133. // /**
  134. // * Deletes an existing BaseTailorStation model.
  135. // * If deletion is successful, the browser will be redirected to the 'index' page.
  136. // * @param integer $id
  137. // * @return mixed
  138. // */
  139. // public function actionDelete($id)
  140. // {
  141. // $this->findModel($id)->delete();
  142. //
  143. // return $this->redirect(['index']);
  144. // }
  145. /**
  146. * Function Description:生成线路页面
  147. * Function Name: actionLine
  148. *
  149. * @return string
  150. *
  151. * @author LUOCJ
  152. */
  153. public function actionLine()
  154. {
  155. $product_id = Yii::$app->request->post('product_id', 0);
  156. $run_date = Yii::$app->request->post('run_date', '');
  157. $model = new BaseTailorStation();
  158. $data['data'] = $model->getPointInfo($product_id, $run_date);
  159. $data['view'] = 'line';
  160. $data['product_id'] = $product_id;
  161. $data['run_date'] = $run_date;
  162. return $this->render('_base', [
  163. 'model' => $model,
  164. 'data' => $data
  165. ]);
  166. }
  167. /**
  168. * Function Description:点查找
  169. * Function Name: actionLineSearch
  170. *
  171. * @return string
  172. *
  173. * @author LUOCJ
  174. */
  175. public function actionLineSearch()
  176. {
  177. $product_id = Yii::$app->request->post('product_id', 0);
  178. $run_date = Yii::$app->request->post('run_date', '');
  179. $model = new BaseTailorStation();
  180. $data = $model->getPointInfo($product_id, $run_date);
  181. return $data;
  182. }
  183. /**
  184. * Function Description:获取line页面所需数据
  185. * Function Name: actionGetLineInfo
  186. *
  187. * @return string
  188. *
  189. * @author LUOCJ
  190. */
  191. public function actionGetLineInfo()
  192. {
  193. $model_supplier = new BaseSupplierPurchase();
  194. $data = $model_supplier->getLineInfo();
  195. return json_encode($data);
  196. }
  197. /**
  198. * Function Description:生成线路前检查
  199. * Function Name: actionCheckLine
  200. *
  201. * @return string
  202. *
  203. * @author LUOCJ
  204. */
  205. public function actionCheckLine()
  206. {
  207. $points = Yii::$app->request->post('points');
  208. $data = BaseTailor::CheckLine($points);
  209. return json_encode($data);
  210. }
  211. /**
  212. * Function Description:保存line
  213. * Function Name: actionSaveLine
  214. *
  215. *
  216. * @author LUOCJ
  217. */
  218. public function actionSaveLine()
  219. {
  220. $transaction = Yii::$app->db->beginTransaction();
  221. $sum_data = Yii::$app->request->post('sum_data');
  222. $model = new BaseTailor($sum_data);
  223. $data = $model->generateDynamicHub();
  224. //$res=BaseTailorStation::find()->where(['id'=>12])->asArray()->one();
  225. $transaction->commit();
  226. return json_encode($data);
  227. }
  228. /**
  229. * Finds the BaseTailorStation model based on its primary key value.
  230. * If the model is not found, a 404 HTTP exception will be thrown.
  231. * @param integer $id
  232. * @return BaseTailorStation the loaded model
  233. * @throws NotFoundHttpException if the model cannot be found
  234. */
  235. protected function findModel($id)
  236. {
  237. if (($model = BaseTailorStation::findOne($id)) !== null) {
  238. return $model;
  239. } else {
  240. throw new NotFoundHttpException('The requested page does not exist.');
  241. }
  242. }
  243. /**
  244. * Function Description:获取原有订单数据
  245. * Function Name: actionGetOrgOrderInfo
  246. *
  247. * @return string
  248. *
  249. * @author LUOCJ
  250. */
  251. public function actionGetOrderInfo()
  252. {
  253. $order_id = Yii::$app->request->post('order_id');
  254. $data = BaseTailor::getOldOrderInfo($order_id);
  255. return json_encode($data);
  256. }
  257. /**
  258. * 修改订单状态
  259. */
  260. public function actionModify()
  261. {
  262. $post = Yii::$app->request->post();
  263. if (isset($post['id']) && isset($post['op'])) {
  264. $data = BaseTailor::isOnSaleControl($post['id'], $post['op']);
  265. } else {
  266. $data['code'] = 2;
  267. }
  268. echo json_encode($data);
  269. }
  270. }