Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

555 linhas
20 KiB

  1. <?php
  2. namespace backend\modules\zzcs\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use backend\modules\zzcs\models\BaseBus;
  6. use backend\modules\zzcs\models\BaseSupplier;
  7. use backend\modules\zzcs\models\BaseResource;
  8. use backend\modules\zzcs\models\DictType;
  9. use common\models\zzcsUtils;
  10. use yii\base\Exception;
  11. use backend\modules\zzcs\models\BaseUser;
  12. class CarController extends Controller
  13. {
  14. public $enableCsrfValidation = false;
  15. public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
  16. /**
  17. * Function Description:
  18. * Function Name: actionIndex
  19. *
  20. * @return string
  21. *
  22. * @author 温依莅
  23. */
  24. public function actionIndex()
  25. {
  26. return $this->render('index');
  27. }
  28. /**
  29. * Function Description:获取车辆列表
  30. * Function Name: actionList
  31. *
  32. * @return string
  33. *
  34. * @author 温依莅
  35. */
  36. public function actionList()
  37. {
  38. $supplier = new BaseSupplier();
  39. $busInfo = new BaseBus();
  40. Yii::$app->view->title = '车辆列表';
  41. $request = Yii::$app->request;
  42. //1.获取get参数
  43. $bus_no = $request->get('bus_no', '');
  44. $car_team = $request->get('car_team', -1);
  45. $team_no = $request->get('team_no', -1);
  46. $brand = $request->get('brand', -1);
  47. $page_size = $request->get('page_size', 10);
  48. $current_page = $request->get('current_page', 1);
  49. //2.品牌列表
  50. $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->all();
  51. //3.车队列表
  52. $motorcade_list = $supplier->getMotorcadeInfo();
  53. $data['brand_list'] = $brand_list;
  54. $data['motorcade_list'] = $motorcade_list;
  55. //4.列表信息
  56. $tempData = $busInfo->getBusList($bus_no, $car_team, $team_no, $brand, $page_size, $current_page);
  57. return $this->render('list', ['data' => $data, 'listData' => $tempData['bus_list'], 'param' => $tempData['param'], 'page_arr' => $tempData['page_arr']]);
  58. }
  59. /**
  60. * @return array
  61. * 品牌列表
  62. */
  63. public function actionBrandList()
  64. {
  65. try {
  66. $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->all();
  67. $json["code"] = '0';
  68. $json["info"] = '获取成功';
  69. $json['data'] = $brand_list;
  70. return json_encode($json);
  71. } catch (Exception $e) {
  72. $json["code"] = '1';
  73. $json["info"] = '品牌获取失败';
  74. return json_encode($json);
  75. }
  76. }
  77. /**
  78. * @return array
  79. * 客座数选项
  80. * seat-num-list
  81. */
  82. public function actionSeatNumList()
  83. {
  84. $request = Yii::$app->request;
  85. $parent_id = $request->post('parent_id');
  86. try {
  87. $list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 69, 'cancel_flag' => 0, 'parent_id' => $parent_id])->orderBy(['res_name' => SORT_ASC])->asArray()->all();
  88. $json["code"] = '0';
  89. $json["info"] = '获取座位数列表成功';
  90. $json['data'] = $list;
  91. return json_encode($json);
  92. } catch (Exception $e) {
  93. $json["code"] = '1';
  94. $json["info"] = '获取座位数列表失败';
  95. return json_encode($json);
  96. }
  97. }
  98. /**
  99. * Function Description:获取车辆详情
  100. * Function Name: actionGetBaseInfo
  101. *
  102. * @return bool
  103. *
  104. * @author 温依莅
  105. */
  106. public function actionGetBaseInfo()
  107. {
  108. try {
  109. //1.品牌列表
  110. $brand_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 134, 'cancel_flag' => 0])->asArray()->all();
  111. $supplier = new BaseSupplier();
  112. $motorcade_list = $supplier->getMotorcadeInfo();
  113. //2.车辆颜色
  114. $color_list = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 338, 'cancel_flag' => 0])->asArray()->all();
  115. //3.座位类型
  116. $seat_type = BaseResource::find()->select(['b.id as seat_id', 'b.type_name'])->distinct()->from('base_resource a')->leftJoin('dict_type as b', 'a.parent_id=b.id')->where(['a.res_type_id' => 69, 'cancel_flag' => 0])->asArray()->all();
  117. //4.车辆图片类型
  118. $pic_type = DictType::find()->select(['id as img_id', 'type_name'])->where(['parent_id' => 360])->asArray()->all();
  119. } catch (Exception $e) {
  120. return false;
  121. }
  122. $data['brand_list'] = $brand_list;
  123. $data['motorcade_list'] = $motorcade_list;
  124. $data['color_list'] = $color_list;
  125. $data['seat_type'] = $seat_type;
  126. $data['pic_type'] = $pic_type;
  127. return $data;
  128. }
  129. /**
  130. * Function Description:添加车辆页面
  131. * Function Name: actionAdd
  132. *
  133. * @return string
  134. *
  135. * @author 温依莅
  136. */
  137. public function actionAdd()
  138. {
  139. Yii::$app->view->title = '添加车辆';
  140. $data = $this->actionGetBaseInfo();
  141. if (false === $data) {
  142. }
  143. return $this->render('add', ['baseData' => $data]);
  144. }
  145. /*==================================================================ajax=======================================================================================*/
  146. /**
  147. * Function Description:添加车辆ajax
  148. * Function Name: actionAddConfirm
  149. *
  150. * @return string
  151. *
  152. * @author 温依莅
  153. */
  154. public function actionAddConfirm()
  155. {
  156. $request = Yii::$app->request;
  157. $baseBus = new BaseBus();
  158. try {
  159. $imgMeta = zzcsUtils::uploadMultiple('bus_img');
  160. } catch (Exception $e) {
  161. $json = array();
  162. $json["code"] = "1";
  163. $json["info"] = "图片上传失败!";
  164. return json_encode($json);
  165. }
  166. $imgType = '';
  167. $imgPath = '';
  168. if ($imgMeta) {
  169. $imgType = $imgMeta['type'];
  170. $imgPath = $imgMeta['path'];
  171. }
  172. $user_id = $request->cookies->getValue('user_id', 0);;//用户id
  173. //运营主体
  174. $main_corp_id = BaseUser::find()->select('main_corp_id')->where(['id' => $user_id,'cancel_flag' => 0])->asArray()->one();
  175. $bus_number = $request->post("bus_number");//车牌号
  176. $bus_team = $request->post("bus_team");//车队
  177. $bus_brand = $request->post("bus_brand");//品牌
  178. $bus_version = $request->post("bus_version");//型号
  179. $buy_date = $request->post("buy_date");//购买日期
  180. $seat_type = $request->post("seat_type");//座位类型
  181. $seat_number = $request->post("seat_number");//座位数量res_id
  182. $seat_real_number = $request->post("seat_real_number");//座位数量
  183. $driver = $request->post("driver");//司机
  184. $guider = $request->post("guider");//导游
  185. $auxiliary_seat = $request->post("auxiliary_seat");//辅座
  186. $consumption = $request->post("consumption");//油耗
  187. $res_date = $request->post("res_date");//注册登记日期
  188. $day_cost = $request->post("day_cost");//成本
  189. $status_select = $request->post("status_select");//状态
  190. $bus_color = $request->post("bus_color");//颜色
  191. $bus_desc = $request->post("bus_desc");//车型描述
  192. //$bus_img_type = $request->post("bus_img_type");//车辆图片类型
  193. if ($bus_number === false || $bus_team === false || $bus_brand === false || $bus_version === false || $buy_date === false || $seat_type === false || $seat_number === false || $driver === false || $guider === false || $auxiliary_seat === false || $consumption === false || $day_cost === false || $status_select === false || $bus_color === false || $bus_desc === false) {
  194. $json["code"] = "2";
  195. $json["info"] = "缺少必要参数";
  196. return json_encode($json);
  197. } else {
  198. //座位数量前台没有传入具体数值
  199. $seat_count = preg_replace('/[^\d]/', '', $seat_real_number);
  200. if (empty($driver)) {
  201. $driver = '';
  202. }
  203. if (empty($guider)) {
  204. $guider = '';
  205. }
  206. if (empty($auxiliary_seat)) {
  207. $auxiliary_seat = '';
  208. }
  209. if (empty($consumption)) {
  210. $consumption = '';
  211. }
  212. if (empty($day_cost)) {
  213. $day_cost = '';
  214. }
  215. if (empty($bus_color)) {
  216. $bus_color = 0;
  217. }
  218. $tmpArray = explode(',', $imgPath);
  219. $newArray = array_reverse($tmpArray);
  220. $csArray = array();
  221. foreach ($newArray as $k => $v) {
  222. if ($v) {
  223. $csArray[$k] = 'http://' . CS1_DOMAIN .'' . $v;
  224. }
  225. }
  226. $imgPath = implode(',', $newArray);
  227. $imgPath2 = implode(',', $csArray);
  228. $tmpArray = explode(',', $imgType);
  229. $newArray = array_reverse($tmpArray);
  230. $imgType = implode(',', $newArray);
  231. $values = [
  232. 'CREATE_USER_ID' => $user_id,
  233. 'CREATE_TIME' => date('Y-m-d H:i:s', time()),
  234. 'UPDATE_USER_ID' => $user_id,
  235. 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
  236. 'CANCEL_FLAG' => 0,
  237. 'BUS_NO' => $bus_number,
  238. 'BUS_TYPE_RES_ID' => $seat_number,
  239. 'SEAT_COUNT' => $seat_count,
  240. 'BRAND_ID' => $bus_brand,
  241. 'ORG_ID' => $bus_team,
  242. 'SEAT_DESC' => $bus_desc,
  243. 'BUY_DATE' => $buy_date,
  244. 'BUS_LICENSE' => $bus_version,
  245. 'DRIVER_COUNT' => $driver,
  246. 'TOUR_COUNT' => $guider,
  247. 'EXTRA_COUNT' => $auxiliary_seat,
  248. 'MPG' => $consumption,
  249. 'REGISTER_TIME' => $res_date,
  250. 'COST' => $day_cost,
  251. 'BUS_STATE' => $status_select,
  252. 'SEAT_TYPE' => $seat_type,
  253. 'BUS_COLOR' => $bus_color,
  254. //'BUS_IMG_TYPE' => $bus_img_type,
  255. 'BUS_IMG_PATH_ORI' => $imgPath,
  256. 'BUS_IMG_PATH' => $imgPath2,
  257. 'BUS_IMG_TYPE' => $imgType,
  258. 'MAIN_CORP_ID' => $main_corp_id['main_corp_id'],//运营主体
  259. ];
  260. $baseBus->attributes = $values;
  261. try {
  262. $res = $baseBus->insert();
  263. if (!$res) {
  264. $json = array();
  265. $json["code"] = "2";
  266. $json["info"] = "新增车辆失败!";
  267. $json["error"] = $baseBus->getErrors();
  268. return json_encode($json);
  269. }
  270. } catch (Exception $e) {
  271. $json = array();
  272. $json["code"] = "1";
  273. $json["info"] = "新增车辆失败!";
  274. return json_encode($json);
  275. }
  276. $json = array();
  277. $json["code"] = "0";
  278. $json["info"] = "新增车辆成功!";
  279. return json_encode($json);
  280. }
  281. }
  282. /**
  283. * Function Description:修改车辆信息
  284. * Function Name: actionModifyConfirm
  285. *
  286. * @return string
  287. *
  288. * @author 张帅
  289. */
  290. public function actionModifyConfirm()
  291. {
  292. $request = Yii::$app->request;
  293. $user_id = $request->cookies->getValue('user_id', 0);;//用户id
  294. $bus_id = $request->post("bus_id");//需要更新的bus_id
  295. $bus_number = $request->post("bus_number");//车牌号
  296. $bus_team = $request->post("bus_team");//车队
  297. $bus_brand = $request->post("bus_brand");//品牌
  298. $bus_version = $request->post("bus_version");//型号
  299. $buy_date = $request->post("buy_date");//购买日期
  300. $seat_type = $request->post("seat_type");//座位类型
  301. $seat_number = $request->post("seat_number");//座位数量res_id
  302. $seat_real_number = $request->post("seat_real_number");//座位数量
  303. $driver = $request->post("driver");//司机
  304. $guider = $request->post("guider");//导游
  305. $auxiliary_seat = $request->post("auxiliary_seat");//辅座
  306. $consumption = $request->post("consumption");//油耗
  307. $res_date = $request->post("res_date");//注册登记日期
  308. $day_cost = $request->post("day_cost");//成本
  309. $status_select = $request->post("status_select");//状态
  310. $bus_color = $request->post("bus_color");//颜色
  311. $bus_desc = $request->post("bus_desc");//车型描述
  312. $old_path = '';
  313. $old_type = '';
  314. $img_path_old = $request->post('bus_img_path_old');
  315. $img_type_old = $request->post('bus_img_type_old');
  316. if (isset($img_path_old)) {
  317. foreach ($img_path_old as $key => $item) {
  318. if ($item != '' || $img_type_old[$key] != '') {
  319. $type = $img_type_old[$key];
  320. if ($old_path == '') {
  321. $old_path .= $item;
  322. $old_type .= $type;
  323. } else {
  324. $old_path .= ',' . $item;
  325. $old_type .= ',' . $type;
  326. }
  327. }
  328. }
  329. }
  330. if ($bus_id === false || $bus_number === false || $bus_team === false || $bus_brand === false || $bus_version === false || $buy_date === false || $seat_type === false || $seat_number === false || $driver === false || $guider === false || $auxiliary_seat === false || $consumption === false || $day_cost === false || $status_select === false || $bus_color === false || $bus_desc === false) {
  331. $json = array();
  332. $json["code"] = "2";
  333. $json["info"] = "缺少必要参数";
  334. return $json;
  335. } else {
  336. //座位数量前台没有传入具体数值
  337. //$seat_count = preg_replace('/[^\d]/', '', $bus_desc);
  338. $seat_count = preg_replace('/[^\d]/', '', $seat_real_number);
  339. //更新操作
  340. if (empty($driver)) {
  341. $driver = '';
  342. }
  343. if (empty($guider)) {
  344. $guider = '';
  345. }
  346. if (empty($auxiliary_seat)) {
  347. $auxiliary_seat = '';
  348. }
  349. if (empty($consumption)) {
  350. $consumption = '';
  351. }
  352. if (empty($day_cost)) {
  353. $day_cost = '';
  354. }
  355. if (empty($bus_color)) {
  356. $bus_color = 0;
  357. }
  358. $imgType = '';
  359. $imgPath = '';
  360. $imgMeta = zzcsUtils::uploadMultiple('bus_img');
  361. if ($imgMeta) {
  362. $imgType = $imgMeta['type'];
  363. $imgPath = $imgMeta['path'];
  364. }
  365. $imgPath = $old_path == '' ? $imgPath : $old_path . ($imgPath != '' ? (',' . $imgPath) : '');
  366. $imgType = $old_type == '' ? $imgType : $old_type . ($imgType != '' ? (',' . $imgType) : '');
  367. $tmpArray = explode(',', $imgPath);
  368. $newArray = array_reverse($tmpArray);
  369. $csArray = array();
  370. foreach ($newArray as $k => $v) {
  371. if ($v) {
  372. $csArray[$k] = 'http://' . CS1_DOMAIN .'' . $v;
  373. }
  374. }
  375. $imgPath = implode(',', $newArray);
  376. $imgPath2 = implode(',', $csArray);
  377. $tmpArray = explode(',', $imgType);
  378. $newArray = array_reverse($tmpArray);
  379. $imgType = implode(',', $newArray);
  380. //删除旧图片
  381. zzcsUtils::deleteFiles($request->post('bus_img_allpath_old'), $imgPath);
  382. //更新数据
  383. $values = [
  384. 'UPDATE_USER_ID' => $user_id,
  385. 'UPDATE_TIME' => date('Y-m-d H:i:s', time()),
  386. 'BUS_NO' => $bus_number,
  387. 'BUS_TYPE_RES_ID' => $seat_number,
  388. 'SEAT_COUNT' => $seat_count,
  389. 'BRAND_ID' => $bus_brand,
  390. 'ORG_ID' => $bus_team,
  391. 'SEAT_DESC' => $bus_desc,
  392. 'BUY_DATE' => $buy_date,
  393. 'BUS_LICENSE' => $bus_version,
  394. 'DRIVER_COUNT' => $driver,
  395. 'TOUR_COUNT' => $guider,
  396. 'EXTRA_COUNT' => $auxiliary_seat,
  397. 'MPG' => $consumption,
  398. 'REGISTER_TIME' => $res_date,
  399. 'COST' => $day_cost,
  400. 'BUS_STATE' => $status_select,
  401. 'SEAT_TYPE' => $seat_type,
  402. 'BUS_COLOR' => $bus_color,
  403. 'BUS_IMG_PATH_ORI' => $imgPath,
  404. 'BUS_IMG_PATH' => $imgPath2,
  405. 'BUS_IMG_TYPE' => $imgType,
  406. ];
  407. $specBus = BaseBus::findOne(['bus_id' => $bus_id, 'cancel_flag' => 0]);
  408. $specBus->attributes = $values;
  409. //$specBus->save(false);
  410. try {
  411. $res = $specBus->update();
  412. if (!$res) {
  413. $json = array();
  414. $json["code"] = "2";
  415. $json["info"] = "修改车辆信息失败!";
  416. $json["error"] = $specBus->getErrors();
  417. return json_encode($json);
  418. }
  419. } catch (Exception $e) {
  420. $json = array();
  421. $json["code"] = "1";
  422. $json["info"] = "修改车辆信息失败!";
  423. return json_encode($json);
  424. }
  425. $json = array();
  426. $json["code"] = "0";
  427. $json["info"] = "修改车辆信息成功!";
  428. return json_encode($json);
  429. }
  430. }
  431. /**
  432. * Function Description:修改车辆
  433. * Function Name: actionModify
  434. *
  435. * @return string
  436. *
  437. * @author 温依莅
  438. */
  439. public function actionModify()
  440. {
  441. $request = Yii::$app->request;
  442. $type = $request->get('type', '');
  443. if ($type) {
  444. Yii::$app->view->title = '查看车辆';
  445. } else {
  446. Yii::$app->view->title = '编辑车辆';
  447. }
  448. $data = $this->actionGetBaseInfo();
  449. $bus_info = BaseBus::find()->where(['bus_id' => $request->get('bus_id'), 'cancel_flag' => 0])->asArray()->one();
  450. $bus_info = array_change_key_case($bus_info, CASE_LOWER);
  451. //这里要对图片做特别的处理
  452. $data['bus_info'] = $bus_info;
  453. $data['seat_num_list'] = BaseResource::find()->select(['res_id', 'res_name'])->where(['res_type_id' => 69, 'cancel_flag' => 0, 'parent_id' => $bus_info['seat_type']])->orderBy(['res_name' => SORT_ASC])->asArray()->all();
  454. return $this->render('modify', ['baseData' => $data, 'type' => $type]);
  455. }
  456. /**
  457. * Function Description:获取图片ajax
  458. * Function Name: actionGetImages
  459. *
  460. * @return string
  461. *
  462. * @author 温依莅
  463. */
  464. public function actionGetImages()
  465. {
  466. $request = Yii::$app->request;
  467. try {
  468. $arr = BaseBus::find()->select(['register_time', 'bus_img_path_ori', 'bus_img_type'])->where(['bus_id' => $request->post('bus_id'), 'cancel_flag' => 0])->asArray()->one();
  469. $img_info = array_change_key_case($arr, CASE_LOWER);
  470. //print_r($img_info);exit;
  471. $json["code"] = '0';
  472. $json["info"] = '获取图片信息成功';
  473. $json['data'] = $img_info;
  474. return json_encode($json);
  475. } catch (Exception $e) {
  476. $json["code"] = '1';
  477. $json["info"] = '获取图片信息失败';
  478. return json_encode($json);
  479. }
  480. }
  481. /**
  482. * Function Description:删除车辆ajax
  483. * Function Name: actionDelete
  484. *
  485. * @return string
  486. *
  487. * @author 温依莅
  488. */
  489. public function actionDelete()
  490. {
  491. $request = Yii::$app->request;
  492. $bus_id = $request->post("bus_id");//需要更新的bus_id
  493. $specBus = BaseBus::findOne(['bus_id' => $bus_id, 'cancel_flag' => 0]);
  494. $specBus->CANCEL_FLAG = 1;
  495. try {
  496. $res = $specBus->update();
  497. if (!$res) {
  498. $json = array();
  499. $json["code"] = "2";
  500. $json["info"] = "删除车辆信息失败!";
  501. $json["error"] = $specBus->getErrors();
  502. return json_encode($json);
  503. }
  504. } catch (Exception $e) {
  505. $json = array();
  506. $json["code"] = "1";
  507. $json["info"] = "删除车辆信息失败!";
  508. return json_encode($json);
  509. }
  510. $json = array();
  511. $json["code"] = "0";
  512. $json["info"] = "已删除";
  513. return json_encode($json);
  514. }
  515. }