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.

ResourceController.php 27 KiB

3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: luocj
  5. * Date: 2017/1/18
  6. * Time: 13:17
  7. */
  8. namespace backend\modules\motorcade\controllers;
  9. use backend\modules\motorcade\models\BaseBus;
  10. use backend\modules\motorcade\models\BusSearch;
  11. use yii\data\SqlDataProvider;
  12. use backend\modules\zzcs\models\BaseResource;
  13. use common\models\zzcsUtils;
  14. use yii\bootstrap\BootstrapAsset;
  15. use backend\modules\motorcade\models\BusReport;
  16. use Yii;
  17. use yii\grid\GridView;
  18. class ResourceController extends BaseController
  19. {
  20. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  21. public function actionIndex()
  22. {
  23. return $this->render('index');
  24. }
  25. public function actionBusList()
  26. {
  27. // $bus_no = isset($_REQUEST['bus_no']) && $_REQUEST['bus_no'] != '' ? $_REQUEST['bus_no'] : '-1';
  28. // $bus_company = isset($_REQUEST['bus_company']) ? $_REQUEST['bus_company'] : '-1';
  29. // $bus_supply = isset($_REQUEST['bus_supply']) ? $_REQUEST['bus_supply'] : '-1';
  30. // $brand = isset($_REQUEST['brand']) && $_REQUEST['bus_no'] != '' ? $_REQUEST['brand'] : '-1';
  31. $searchModel = new BusSearch(['scenario' => 'search']);
  32. $queryParams = Yii::$app->request->queryParams;
  33. $queryParams['BusSearch']['ORG_ID'] = isset($queryParams['BusSearch']['ORG_ID']) ? $queryParams['BusSearch']['ORG_ID'] : $_COOKIE['user_org_id'];
  34. $dataProvider = $searchModel->search($queryParams);
  35. // return $this->render('index', [
  36. // 'searchModel' => $searchModel,
  37. // 'dataProvider' => $dataProvider,
  38. // ]);
  39. $obj = new BaseResource();
  40. // $data = $obj->getBusList($bus_no, $bus_company, $bus_supply, $brand);
  41. $brand = $obj->getBrand();
  42. $bus_company = $obj->getBusCompany();
  43. return $this->render('resource', [
  44. 'view' => '_busList',
  45. 'brand' => $brand,
  46. 'bus_company' => $bus_company,
  47. 'searchModel' => $searchModel,
  48. 'dataProvider' => $dataProvider
  49. ]);
  50. }
  51. public function actionBusDetail()
  52. {
  53. $obj = new BaseResource();
  54. $bus_id = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : '';
  55. $data = $obj->getBusDetail($bus_id);
  56. $pic_type = $obj->getPicType();
  57. if (isset($data['data'][0]['bus_img_path_ori'])) {
  58. $path_tmp = explode(',', $data['data'][0]['bus_img_path_ori']);
  59. $type_tmp = explode(',', $data['data'][0]['bus_img_type']);
  60. foreach ($path_tmp as $k => $v) {
  61. $img_arr[$k]['img_path'] = $v;
  62. $img_arr[$k]['img_type'] = $type_tmp[$k];
  63. }
  64. }
  65. return $this->render('resource', ['view' => '_busDetail', 'data' => $data, 'img_arr' => isset($img_arr) ? $img_arr : '', 'pic_type' => $pic_type]);
  66. }
  67. public function actionBusDetailModify()
  68. {
  69. $get_seat_type = isset($_REQUEST['seat_type']) ? $_REQUEST['seat_type'] : '-1';
  70. $obj = new BaseResource();
  71. $bus_id = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : '';
  72. if ($bus_id == '') {
  73. $json = array();
  74. $json["code"] = "2";
  75. $json["info"] = "获取信息失败!";
  76. return json_encode($json);
  77. }
  78. $data = $obj->getBusDetail($bus_id);
  79. if (isset($data['data'][0]['bus_img_path_ori'])) {
  80. $path_tmp = explode(',', $data['data'][0]['bus_img_path_ori']);
  81. $type_tmp = explode(',', $data['data'][0]['bus_img_type']);
  82. foreach ($path_tmp as $k => $v) {
  83. $img_arr[$k]['img_path'] = $v;
  84. $img_arr[$k]['img_type'] = $type_tmp[$k];
  85. }
  86. }
  87. $user_bus_company = $obj->getUserCompany();
  88. $brand = $obj->getBrand();
  89. $bus_company = $obj->getBusCompany();
  90. $seat_type = $obj->getSeatType();
  91. $fuel = $obj->getFuel();
  92. $color = $obj->getColor();
  93. $pic_type = $obj->getPicType();
  94. $seat_count = $obj->getSeatCount($get_seat_type == '-1' ? $data['data'][0]['seat_type'] : $get_seat_type);
  95. return $this->render('resource', ['view' => '_busDetailModify', 'data' => $data, 'img_arr' => isset($img_arr) ? $img_arr : '', 'brand' => $brand, 'bus_company' => $bus_company, 'seat_type' => $seat_type, 'seat_count' => $seat_count, 'fuel' => $fuel, 'color' => $color, 'pic_type' => $pic_type, 'user_bus_company' => $user_bus_company]);
  96. }
  97. public function actionModify()
  98. {
  99. //车子所属公司
  100. $bus_company_type = $_REQUEST['bus_company_type'] ? $_REQUEST['bus_company_type'] : '';
  101. $bus_company_tp = $_REQUEST['bus_company'] ? $_REQUEST['bus_company'] : '';
  102. $model = Yii::$app->user->id;
  103. if ($bus_company_type == '1') {
  104. $bus_company_sql = "select org_id from base_user where id = '$model'";
  105. $bus_company_do = Yii::$app->db->createCommand($bus_company_sql)->queryOne();
  106. $bus_company = $bus_company_do['org_id'];
  107. } else if ($bus_company_type == '2') {
  108. $bus_company = $bus_company_tp;
  109. }
  110. //判断车牌是否重复
  111. $bus_no = $_REQUEST['bus_no'] ? $_REQUEST['bus_no'] : '';
  112. $bus_id = $_REQUEST['bus_id'];
  113. $sql_temp = "select bus_no from base_bus where bus_id = '$bus_id'";
  114. $sql_temp1 = "select count(bus_id) as num from base_bus where BUS_NO = '$bus_no'";
  115. $old_bus_no = Yii::$app->db->createCommand($sql_temp)->queryAll();
  116. $num = Yii::$app->db->createCommand($sql_temp1)->queryAll();
  117. if ($old_bus_no[0]['bus_no']==$bus_no){
  118. }else{
  119. if ($num[0]) {
  120. $json = array();
  121. $json["code"] = "2";
  122. $json["info"] = "车牌号不能重复";
  123. return json_encode($json);
  124. }
  125. }
  126. //end
  127. $brand_id = $_REQUEST['brand_id'] ? $_REQUEST['brand_id'] : '';
  128. $bus_license = $_REQUEST['bus_license'];
  129. $buy_date = $_REQUEST['buy_date'];
  130. $seat_type = $_REQUEST['seat_type'] ? $_REQUEST['seat_type'] : '';
  131. $seat_desc = $_REQUEST['seat_desc'] ? $_REQUEST['seat_desc'] : '';
  132. $seat_count = $_REQUEST['seat_count'] ? $_REQUEST['seat_count'] : '';
  133. $seat_count_num_temp = isset($_REQUEST['seat_count_num']) ? $_REQUEST['seat_count_num'] : '';
  134. $seat_count_num = mb_substr($seat_count_num_temp,0,strlen($seat_count_num_temp)-3);
  135. $driver_count = $_REQUEST['driver_count'];
  136. $tour_count = $_REQUEST['tour_count'];
  137. $extra_count = $_REQUEST['extra_count'];
  138. $fuel_id = $_REQUEST['fuel_id'];
  139. $mpg = $_REQUEST['mpg'];
  140. $register_time = $_REQUEST['register_time'];
  141. $bus_color = $_REQUEST['bus_color'];
  142. $old_path = '';
  143. $old_type = '';
  144. $img_path_old_tp = $_REQUEST['bus_img_path_old'];
  145. $img_type_old_tp = $_REQUEST['bus_img_type_old'];
  146. $img_path_old = explode(',', $img_path_old_tp);
  147. $img_type_old = explode(',', $img_type_old_tp);
  148. if (isset($img_path_old)) {
  149. foreach ($img_path_old as $key => $item) {
  150. if ($item != '' || $img_type_old[$key] != '') {
  151. $type = $img_type_old[$key];
  152. if ($old_path == '') {
  153. $old_path .= $item;
  154. $old_type .= $type;
  155. } else {
  156. $old_path .= ',' . $item;
  157. $old_type .= ',' . $type;
  158. }
  159. }
  160. }
  161. }
  162. $imgType = '';
  163. $imgPath = '';
  164. $imgMeta = zzcsUtils::uploadMultiple('bus_img');
  165. if ($imgMeta) {
  166. $imgType = $imgMeta['type'];
  167. $imgPath = $imgMeta['path'];
  168. }
  169. $imgPath = $old_path == '' ? $imgPath : $old_path . ($imgPath != '' ? (',' . $imgPath) : '');
  170. $imgType = $old_type == '' ? $imgType : $old_type . ($imgType != '' ? (',' . $imgType) : '');
  171. $tmpArray = explode(',', $imgPath);
  172. $newArray = array_reverse($tmpArray);
  173. $csArray = array();
  174. foreach ($newArray as $k => $v) {
  175. if ($v) {
  176. $csArray[$k] = 'http://' . CS1_DOMAIN .'' . $v;
  177. }
  178. }
  179. $imgPath = implode(',', $newArray);
  180. $imgPath2 = implode(',', $csArray);
  181. $tmpArray = explode(',', $imgType);
  182. $newArray = array_reverse($tmpArray);
  183. $imgType = implode(',', $newArray);
  184. if ($bus_company_type == '' || $bus_no == '' || $bus_company == '' || $brand_id == '' || $seat_type == '' || $seat_count == '') {
  185. $json = array();
  186. $json["code"] = "2";
  187. $json["info"] = "缺少必要参数";
  188. return json_encode($json);
  189. } else {
  190. $sql = "update base_bus set update_user_id = '$model',bus_no = '$bus_no',org_id='$bus_company',brand_id='$brand_id',bus_license = '$bus_license',seat_count='$seat_count_num',
  191. buy_date = '$buy_date',seat_type = '$seat_type',seat_desc = '$seat_desc',bus_type_res_id = '$seat_count',driver_count='$driver_count',tour_count='$tour_count',
  192. extra_count = '$extra_count',fuel_form = '$fuel_id',mpg='$mpg',register_time ='$register_time',bus_color = '$bus_color', bus_img_path_ori = '$imgPath',bus_img_path = '$imgPath2',bus_img_type = '$imgType'
  193. where bus_id = '$bus_id'";
  194. try {
  195. $res = Yii::$app->db->createCommand($sql)->query();
  196. if (!$res) {
  197. $json = array();
  198. $json["code"] = "2";
  199. $json["info"] = "修改车辆信息失败!";
  200. return json_encode($json);
  201. }
  202. } catch (\Exception $e) {
  203. $json = array();
  204. $json["code"] = "1";
  205. $json["info"] = "修改车辆信息失败!";
  206. return json_encode($json);
  207. }
  208. $json = array();
  209. $json["code"] = "0";
  210. $json["info"] = "修改车辆信息成功!";
  211. return json_encode($json);
  212. }
  213. }
  214. // 删除车辆
  215. public function actionCancelBus()
  216. {
  217. $bus_id = isset($_REQUEST['bus_id']) ? $_REQUEST['bus_id'] : '';
  218. if ($bus_id == '') {
  219. $json = array();
  220. $json["code"] = "1";
  221. $json["info"] = "删除车辆失败!";
  222. return json_encode($json);
  223. } else {
  224. $obj = new BaseResource();
  225. $data = $obj->cancelBus($bus_id);
  226. return json_encode($data);
  227. }
  228. }
  229. // 删除车辆
  230. public function actionCancelDriver()
  231. {
  232. $driver_id = isset($_REQUEST['driver_id']) ? $_REQUEST['driver_id'] : '';
  233. if ($driver_id == '') {
  234. $json = array();
  235. $json["code"] = "1";
  236. $json["info"] = "删除车辆失败!";
  237. return json_encode($json);
  238. } else {
  239. $obj = new BaseResource();
  240. $data = $obj->cancelDriver($driver_id);
  241. return json_encode($data);
  242. }
  243. }
  244. // 获取添加车辆信息
  245. public function actionAddBus()
  246. {
  247. $get_seat_type = isset($_REQUEST['seat_type']) ? $_REQUEST['seat_type'] : '-1';
  248. $obj = new BaseResource();
  249. $brand = $obj->getBrand();
  250. $bus_company = $obj->getBusCompany();
  251. $seat_type = $obj->getSeatType();
  252. $fuel = $obj->getFuel();
  253. $color = $obj->getColor();
  254. $pic_type = $obj->getPicType();
  255. $seat_count = $obj->getSeatCount($get_seat_type);
  256. return $this->render('resource', ['view' => '_addBus', 'brand' => $brand, 'bus_company' => $bus_company, 'seat_count' => $seat_count, 'seat_type' => $seat_type, 'fuel' => $fuel, 'color' => $color, 'pic_type' => $pic_type]);
  257. }
  258. // 添加车辆信息
  259. public function actionCommitAdd()
  260. {
  261. $bus_company_type = $_REQUEST['bus_company_type'] ? $_REQUEST['bus_company_type'] : '';
  262. $bus_company_tp = $_REQUEST['bus_company'] ? $_REQUEST['bus_company'] : '';
  263. $model = Yii::$app->user->id;
  264. $obj = new BusReport;
  265. $main_corp = $obj->getUserMainCorp();
  266. $main_corp_id = $main_corp;
  267. if ($bus_company_type == '1') {
  268. $bus_company_sql = "select org_id from base_user where id = '$model'";
  269. $bus_company_do = Yii::$app->db->createCommand($bus_company_sql)->queryOne();
  270. $bus_company = $bus_company_do['org_id'];
  271. } else if ($bus_company_type == '2') {
  272. $bus_company = $bus_company_tp;
  273. }
  274. //判断车牌是否重复
  275. $bus_no = $_REQUEST['bus_no'] ? $_REQUEST['bus_no'] : '';
  276. $sql_temp = "select count(bus_id) as num from base_bus where BUS_NO = '$bus_no'";
  277. $num = Yii::$app->db->createCommand($sql_temp)->queryAll();
  278. if ($num[0]['num']) {
  279. $json = array();
  280. $json["code"] = "2";
  281. $json["info"] = "车牌号不能重复";
  282. return json_encode($json);
  283. }
  284. //end
  285. $brand_id = isset($_REQUEST['brand_id']) ? $_REQUEST['brand_id'] : '';
  286. $bus_license = $_REQUEST['bus_license'];
  287. $buy_date = $_REQUEST['buy_date'];
  288. $seat_type = isset($_REQUEST['seat_type']) ? $_REQUEST['seat_type'] : '';
  289. $seat_desc = isset($_REQUEST['seat_desc']) ? $_REQUEST['seat_desc'] : '';
  290. $seat_count = isset($_REQUEST['seat_count']) ? $_REQUEST['seat_count'] : '';
  291. $seat_count_num_temp = isset($_REQUEST['seat_count_num']) ? $_REQUEST['seat_count_num'] : '';
  292. $seat_count_num = mb_substr($seat_count_num_temp,0,strlen($seat_count_num_temp)-3);
  293. $driver_count = $_REQUEST['driver_count'];
  294. $tour_count = $_REQUEST['tour_count'];
  295. $extra_count = $_REQUEST['extra_count'];
  296. $fuel_id = $_REQUEST['fuel_id'];
  297. $mpg = $_REQUEST['mpg'];
  298. $register_time = $_REQUEST['register_time'];
  299. $bus_color = $_REQUEST['bus_color'];
  300. $old_path = '';
  301. $old_type = '';
  302. $imgType = '';
  303. $imgPath = '';
  304. $imgMeta = zzcsUtils::uploadMultiple('bus_img');
  305. if ($imgMeta) {
  306. $imgType = $imgMeta['type'];
  307. $imgPath = $imgMeta['path'];
  308. }
  309. $imgPath = $old_path == '' ? $imgPath : $old_path . ($imgPath != '' ? (',' . $imgPath) : '');
  310. $imgType = $old_type == '' ? $imgType : $old_type . ($imgType != '' ? (',' . $imgType) : '');
  311. $tmpArray = explode(',', $imgPath);
  312. $newArray = array_reverse($tmpArray);
  313. $csArray = array();
  314. foreach ($newArray as $k => $v) {
  315. if ($v) {
  316. $csArray[$k] = 'http://' . CS1_DOMAIN .'' . $v;
  317. }
  318. }
  319. $imgPath = implode(',', $newArray);
  320. $imgPath2 = implode(',', $csArray);
  321. $tmpArray = explode(',', $imgType);
  322. $newArray = array_reverse($tmpArray);
  323. $imgType = implode(',', $newArray);
  324. if ($bus_company_type == '' || $bus_no == '' || $bus_company == '' || $brand_id == '' || $seat_type == '' || $seat_count == '') {
  325. $json = array();
  326. $json["code"] = "2";
  327. $json["info"] = "缺少必要参数";
  328. return $json;
  329. } else {
  330. $sql = "insert into base_bus (main_corp_id,create_user_id,bus_no,org_id,brand_id,bus_license,buy_date,seat_type,seat_desc,seat_count,
  331. bus_type_res_id,driver_count,tour_count,extra_count,fuel_form
  332. , mpg,register_time,bus_color,bus_img_path_ori,bus_img_path,bus_img_type) values
  333. ('$main_corp_id','$model','$bus_no','$bus_company','$brand_id','$bus_license','$buy_date','$seat_type','$seat_desc','$seat_count_num','$seat_count','$driver_count','$tour_count','$extra_count','$fuel_id',
  334. '$mpg','$register_time','$bus_color','$imgPath','$imgPath2','$imgType')";
  335. try {
  336. $res = Yii::$app->db->createCommand($sql)->query();
  337. if (!$res) {
  338. $json = array();
  339. $json["code"] = "2";
  340. $json["info"] = "添加车辆信息失败!";
  341. return json_encode($json);
  342. }
  343. } catch (\Exception $e) {
  344. $json = array();
  345. $json["code"] = "1";
  346. $json["info"] = "添加车辆信息失败!";
  347. return json_encode($json);
  348. }
  349. $json = array();
  350. $json["code"] = "0";
  351. $json["info"] = "添加车辆信息成功!";
  352. return json_encode($json);
  353. }
  354. }
  355. // 司机列表
  356. public function actionDriverList()
  357. {
  358. $sex = isset($_REQUEST['sex']) ? $_REQUEST['sex'] : '-1';
  359. $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : '-1';
  360. $driver_number = isset($_REQUEST['driver_number']) ? $_REQUEST['driver_number'] : '-1';
  361. $phone_no = isset($_REQUEST['phone_no']) ? $_REQUEST['phone_no'] : '-1';
  362. $license_no = isset($_REQUEST['license_no']) ? $_REQUEST['license_no'] : '-1';
  363. $bus_supply = isset($_REQUEST['bus_supply']) ? $_REQUEST['bus_supply'] : '-1';
  364. $bus_company = isset($_REQUEST['bus_company']) ? $_REQUEST['bus_company'] : '-1';
  365. $obj = new BaseResource();
  366. $data = $obj->getDriverList($sex, $name, $driver_number, $phone_no, $license_no, $bus_supply, $bus_company);
  367. $bus_company = $obj->getBusCompany();
  368. $driver = $obj->getDriver();
  369. $dataProvider = new SqlDataProvider([
  370. 'sql' => $data['sql'],
  371. 'totalCount' => $data['total'],
  372. 'pagination' => ['pagesize' => 20],
  373. ]);
  374. return $this->render('resource', ['view' => '_driverList', 'dataProvider' => $dataProvider, 'bus_company' => $bus_company, 'driver' => $driver]);
  375. }
  376. // 添加司机
  377. public function actionAddDriver()
  378. {
  379. $get_area1 = isset($_REQUEST['area1']) ? $_REQUEST['area1'] : '';
  380. $get_area2 = isset($_REQUEST['area2']) ? $_REQUEST['area2'] : '';
  381. // $get_area3 = isset($_REQUEST['area3'])?$_REQUEST['area3']:'';
  382. $obj = new BaseResource();
  383. $bus_company = $obj->getBusCompany();
  384. $area1 = $obj->getArea();
  385. if ($get_area1 != '') {
  386. $area2 = $obj->getArea($get_area1);
  387. }
  388. if ($get_area2 != '') {
  389. $area3 = $obj->getArea($get_area2);
  390. }
  391. return $this->render('resource', ['view' => '_addDriver', 'bus_company' => $bus_company, 'area1' => $area1, 'area2' => isset($area2) ? $area2 : '', 'area3' => isset($area3) ? $area3 : '']);
  392. }
  393. //提交添加
  394. public function actionCommitDriver()
  395. {
  396. $bus_company_type = $_REQUEST['bus_company_type'] ? $_REQUEST['bus_company_type'] : '';
  397. $bus_company_tp = $_REQUEST['bus_company'] ? $_REQUEST['bus_company'] : '';
  398. $model = Yii::$app->user->id;
  399. $obj = new BusReport;
  400. $main_corp = $obj->getUserMainCorp();
  401. $main_corp_id = $main_corp;
  402. if ($bus_company_type == '1') {
  403. $bus_company_sql = "select org_id from base_user where id = '$model'";
  404. $bus_company_do = Yii::$app->db->createCommand($bus_company_sql)->queryOne();
  405. $bus_company = $bus_company_do['org_id'];
  406. } else if ($bus_company_type == '2') {
  407. $bus_company = $bus_company_tp;
  408. }
  409. $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
  410. $status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
  411. $driver_number = isset($_REQUEST['driver_number']) ? $_REQUEST['driver_number'] : '';
  412. $license_no = isset($_REQUEST['license_no']) ? $_REQUEST['license_no'] : '';
  413. $phone_no = isset($_REQUEST['phone_no']) ? $_REQUEST['phone_no'] : '';
  414. $sex = isset($_REQUEST['sex']) ? $_REQUEST['sex'] : '-1';
  415. $birth = isset($_REQUEST['birth']) ? $_REQUEST['birth'] : '';
  416. $first_date = isset($_REQUEST['first_date']) ? $_REQUEST['first_date'] : '';
  417. $address = isset($_REQUEST['address']) ? $_REQUEST['address'] : '';
  418. $license_start_date = isset($_REQUEST['license_start_date']) ? $_REQUEST['license_start_date'] : '';
  419. $valid_years = isset($_REQUEST['valid_years']) ? $_REQUEST['valid_years'] : '';
  420. $area = isset($_REQUEST['area']) ? $_REQUEST['area'] : '';
  421. $cur_time = date('Y-m-d h:i:s', time());
  422. if ($bus_company_type == '' || $name == '' || $bus_company == '' || $status == '' || $license_no == '' || $phone_no == '' || $sex == '-1') {
  423. $json = array();
  424. $json["code"] = "1";
  425. $json["info"] = "添加车辆信息失败!";
  426. return json_encode($json);
  427. } else {
  428. $sql = "insert into base_driver (main_corp_id,create_user_id,driver_name,driver_status,org_id,driver_number,license_no,
  429. phone_no,sex,driver_birthday,first_license_date,address,license_start_date,valid_years,area_id,create_time) values (
  430. '$main_corp_id','$model','$name','$status','$bus_company','$driver_number','$license_no','$phone_no','$sex','$birth','$first_date','$address','$license_start_date','$valid_years','$area','$cur_time')";
  431. $res = Yii::$app->db->createCommand($sql)->query();
  432. if (!$res) {
  433. $json = array();
  434. $json["code"] = "2";
  435. $json["info"] = "添加司机信息失败!";
  436. return json_encode($json);
  437. }
  438. $json = array();
  439. $json["code"] = "0";
  440. $json["info"] = "添加司机信息成功!";
  441. return json_encode($json);
  442. }
  443. }
  444. public function actionDriverDetail()
  445. {
  446. $driver_id = isset($_REQUEST['driver_id']) ? $_REQUEST['driver_id'] : '';
  447. $obj = new BaseResource();
  448. if ($driver_id == '') {
  449. return false;
  450. }
  451. $sql = "select driver_id,driver_name,if(driver_status=0,'正常','有请假') as status,(select res_name from base_resource where res_id = org_id) as bus_company,org_id,driver_number,license_no,
  452. phone_no,if(sex=1,'男','女') as sex,driver_birthday,first_license_date,address,license_start_date,valid_years,area_id,(select area_name from base_area_view a where a.area_id=b.area_id ) as area_name,(select parent_area_name from base_area_view a where a.area_id=b.area_id ) as parent_area_name,(select top_area_name from base_area_view a where a.area_id=b.area_id ) as top_area_name from base_driver b where cancel_flag=0 and driver_id = $driver_id";
  453. $data = Yii::$app->db->createCommand($sql)->queryAll();
  454. $user_bus_company = $obj->getUserCompany();
  455. return $this->render('resource', ['view' => '_driverDetail', 'data' => $data,'user_bus_company'=>$user_bus_company]);
  456. }
  457. public function actionDriverModify()
  458. {
  459. $driver_id = isset($_REQUEST['driver_id']) ? $_REQUEST['driver_id'] : '';
  460. if ($driver_id == '') {
  461. return false;
  462. }
  463. $get_area1 = isset($_REQUEST['area1']) ? $_REQUEST['area1'] : '';
  464. $get_area2 = isset($_REQUEST['area2']) ? $_REQUEST['area2'] : '';
  465. // $get_area3 = isset($_REQUEST['area3'])?$_REQUEST['area3']:'';
  466. $obj = new BaseResource();
  467. $bus_company = $obj->getBusCompany();
  468. $area1 = $obj->getArea();
  469. $sql = "select driver_id,driver_name,driver_status,org_id,driver_number,license_no,
  470. phone_no,sex,driver_birthday,first_license_date,address,license_start_date,valid_years,area_id,(select parent_area_id from base_area_view a where a.area_id=b.area_id ) as parent_area_id,(select top_area_id from base_area_view a where a.area_id=b.area_id ) as top_area_id from base_driver b where cancel_flag=0 and driver_id = $driver_id";
  471. $data = Yii::$app->db->createCommand($sql)->queryAll();
  472. if ($get_area1 != '') {
  473. $area2 = $obj->getArea($get_area1);
  474. } else {
  475. $area2 = $obj->getArea($data[0]['top_area_id']);
  476. }
  477. if ($get_area2 != '') {
  478. $area3 = $obj->getArea($data[0]['parent_area_id']);
  479. }
  480. $user_bus_company = $obj->getUserCompany();
  481. return $this->render('resource', ['view' => '_driverDetailModify', 'data' => $data, 'bus_company' => $bus_company, 'area1' => $area1, 'area2' => isset($area2) ? $area2 : '', 'area3' => isset($area3) ? $area3 : '','user_bus_company'=>$user_bus_company]);
  482. }
  483. public function actionCommitModifyDriver()
  484. {
  485. $bus_company_type = $_REQUEST['bus_company_type'] ? $_REQUEST['bus_company_type'] : '';
  486. $bus_company_tp = $_REQUEST['bus_company'] ? $_REQUEST['bus_company'] : '';
  487. $model = Yii::$app->user->id;
  488. if ($bus_company_type == '1') {
  489. $bus_company_sql = "select org_id from base_user where id = '$model'";
  490. $bus_company_do = Yii::$app->db->createCommand($bus_company_sql)->queryOne();
  491. $bus_company = $bus_company_do['org_id'];
  492. } else if ($bus_company_type == '2') {
  493. $bus_company = $bus_company_tp;
  494. }
  495. $driver_id = isset($_REQUEST['driver_id']) ? $_REQUEST['driver_id'] : '';
  496. $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
  497. $status = isset($_REQUEST['status']) ? $_REQUEST['status'] : '';
  498. $driver_number = isset($_REQUEST['driver_number']) ? $_REQUEST['driver_number'] : '';
  499. $license_no = isset($_REQUEST['license_no']) ? $_REQUEST['license_no'] : '';
  500. $phone_no = isset($_REQUEST['phone_no']) ? $_REQUEST['phone_no'] : '';
  501. $sex = isset($_REQUEST['sex']) ? $_REQUEST['sex'] : '-1';
  502. $birth = isset($_REQUEST['birth']) ? $_REQUEST['birth'] : '';
  503. $first_date = isset($_REQUEST['first_date']) ? $_REQUEST['first_date'] : '';
  504. $address = isset($_REQUEST['address']) ? $_REQUEST['address'] : '';
  505. $license_start_date = isset($_REQUEST['license_start_date']) ? $_REQUEST['license_start_date'] : '';
  506. $valid_years = isset($_REQUEST['valid_years']) ? $_REQUEST['valid_years'] : '';
  507. $area = isset($_REQUEST['area']) ? $_REQUEST['area'] : '';
  508. $cur_time = date('Y-m-d h:i:s', time());
  509. if ($bus_company_type == '' || $driver_id == '' || $name == '' || $bus_company == '' || $status == '' || $license_no == '' || $phone_no == '' || $sex == '-1') {
  510. $json = array();
  511. $json["code"] = "1";
  512. $json["info"] = "修改司机信息失败!";
  513. return json_encode($json);
  514. } else {
  515. $sql = "update base_driver set UPDATE_USER_ID='$model',DRIVER_NAME= '$name',DRIVER_STATUS='$status',ORG_ID='$bus_company',DRIVER_NUMBER='$driver_number',LICENSE_NO='$license_no',
  516. PHONE_NO= '$phone_no',SEX= '$sex',DRIVER_BIRTHDAY='$birth',FIRST_LICENSE_DATE='$first_date',ADDRESS='$address',LICENSE_START_DATE='$license_start_date',
  517. VALID_YEARS='$valid_years',AREA_ID='$area' where DRIVER_ID = '$driver_id' and cancel_flag = 0";
  518. $res = Yii::$app->db->createCommand($sql)->query();
  519. if (!$res) {
  520. $json = array();
  521. $json["code"] = "2";
  522. $json["info"] = "修改司机信息失败!";
  523. return json_encode($json);
  524. }
  525. $json = array();
  526. $json["code"] = "0";
  527. $json["info"] = "修改司机信息成功!";
  528. return json_encode($json);
  529. }
  530. }
  531. }