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.
 
 
 
 
 
 

331 lines
11 KiB

  1. <?php
  2. namespace backend\modules\zzcs\controllers;
  3. use backend\modules\zzcs\models\BaseSupplier;
  4. use Yii;
  5. use backend\modules\zzcs\models\BaseDriver;
  6. use backend\modules\zzcs\models\BaseArea;
  7. use backend\modules\zzcs\models\BaseUser;
  8. use yii\web\Controller;
  9. class DriverController extends Controller
  10. {
  11. public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
  12. public $enableCsrfValidation = false;
  13. /**
  14. * @return string
  15. */
  16. public function actionIndex()
  17. {
  18. $arr = Yii::$app->db->createCommand('select b.org_id,r.res_name from base_bus as b,base_resource as r where b.org_id = r.res_id GROUP BY b.org_id')->queryAll();
  19. foreach ($arr as $key => $vel) {
  20. $final[$vel['org_id']] = $vel['res_name'];
  21. }
  22. $arr = Yii::$app->db->createCommand('select d.org_id,r.res_name from base_driver as d,base_resource as r where d.org_id = r.res_id GROUP BY d.org_id')->queryAll();
  23. foreach ($arr as $key => $vel) {
  24. $final[$vel['org_id']] = $vel['res_name'];
  25. }
  26. echo '<pre>';
  27. print_r($final);
  28. die;
  29. //return $this->render('index');
  30. }
  31. /**
  32. * Function Description:司机信息列表
  33. * Function Name: actionList
  34. *
  35. * @return string
  36. *
  37. * @author 张帅
  38. */
  39. public function actionList()
  40. {
  41. $base_supplier = new BaseSupplier;
  42. $base_driver = new BaseDriver();
  43. #region 获取用户信息
  44. //获取cookies
  45. $cookies = Yii::$app->request->cookies;
  46. //账号权限
  47. $user_id = $cookies->getValue('user_id');
  48. $user_info = BaseUser::find()
  49. ->select('opera_org_id')
  50. ->where(['id' => $user_id, 'cancel_flag' => 0])
  51. ->asArray()
  52. ->one();
  53. $opera_org_id = $user_info['opera_org_id'];
  54. #endregion
  55. //创建一个数组
  56. $data = [];
  57. //1.获取所有的车队名称和车队代码
  58. $motorcade = $base_supplier->getMotorcadeCodeAndName();
  59. //2.性别
  60. $sex_array = ["男","女"];
  61. //3.司机姓名
  62. $sql_where = [
  63. 'and',
  64. ['=','cancel_flag',0]
  65. ];
  66. //用户权限
  67. if(!empty($opera_org_id)){
  68. $sql_where[] = ['in','org_id',explode(',',$opera_org_id)];
  69. }
  70. $driver_name_arr = BaseDriver::find()->select('driver_name')->where($sql_where)->groupBy('driver_name')->asArray()->all();
  71. //4.获取司机列表
  72. $driver_result = $base_driver->getDriverList();
  73. $driver_list = $driver_result['rows'];
  74. $page_arr = $driver_result['page_arr'];
  75. $page = $driver_result['page'];
  76. //把需要传递的值传送给视图
  77. $view = Yii::$app->view;
  78. $view->title = '司机信息管理';
  79. $data['sex_array'] = $sex_array;
  80. $data['motorcade'] = $motorcade;
  81. $data['driver_name_arr'] = $driver_name_arr;
  82. $data['driver_list'] = $driver_list;
  83. $data['page_arr'] = $page_arr;
  84. $data['page'] = $page;
  85. return $this->render('list', $data);
  86. }
  87. /**
  88. * Function Description:添加司机
  89. * Function Name: actionAddDriver
  90. *
  91. * @return string
  92. *
  93. * @author 张帅
  94. */
  95. public function actionAddDriver()
  96. {
  97. $base_supplier = new BaseSupplier;
  98. Yii::$app->view->title = '添加司机';
  99. //1.获取公司列表
  100. $motorcade_list = $base_supplier->getMotorcadeInfo();
  101. //2.司机状态
  102. $driver_status = ['正常','有请假'];
  103. //3.性别
  104. $sex_array = ["男","女"];
  105. //4.获取一级区域
  106. $range = BaseArea::find()->select('id as area_id,area_name')->where(['parent_id' => 0, 'cancel_flag' => 0, 'poi_type1' => 401])->asArray()->all();
  107. //5.有效期限
  108. $active_year_array = ['6'=>'6年', '10' => '10年', '20' => '20年'];
  109. $data['opera'] = 'add';
  110. $data['motorcade_list'] = $motorcade_list;
  111. $data['driver_status'] = $driver_status;
  112. $data['sex_array'] = $sex_array;
  113. $data['range'] = $range;
  114. $data['active_year_array'] = $active_year_array;
  115. return $this->render('driver-info', $data);
  116. }
  117. /**
  118. * Function Description:修改司机信息
  119. * Function Name: actionUpdateInfo
  120. *
  121. * @return string
  122. *
  123. * @author 张帅
  124. */
  125. public function actionUpdateInfo(){
  126. $base_supplier = new BaseSupplier;
  127. $base_driver = new BaseDriver();
  128. Yii::$app->view->title = '司机修改';
  129. #region 获取参数
  130. $driver_id = Yii::$app->request->get('driver_id');//司机id
  131. #endregion
  132. //1.获取公司列表
  133. $motorcade_list = $base_supplier->getMotorcadeInfo();
  134. //2.司机状态
  135. $driver_status = ['正常','有请假'];
  136. //3.性别
  137. $sex_array = ["男","女"];
  138. //4.获取一级区域
  139. $range = BaseArea::find()->select('id as area_id,area_name')->where(['parent_id' => 0, 'cancel_flag' => 0, 'poi_type1' => 401])->asArray()->all();
  140. //5.有效期限
  141. $active_year_array = ['6'=>'6年', '10' => '10年', '20' => '20年'];
  142. //6.获取司机详情
  143. $driver_info = $base_driver->getDriverInfo($driver_id);
  144. $data['opera'] = 'update';
  145. $data['motorcade_list'] = $motorcade_list;
  146. $data['driver_status'] = $driver_status;
  147. $data['sex_array'] = $sex_array;
  148. $data['range'] = $range;
  149. $data['active_year_array'] = $active_year_array;
  150. $data['driver_info'] = $driver_info;
  151. return $this->render('driver-info', $data);
  152. }
  153. /**
  154. * Function Description:展示司机详情
  155. * Function Name: actionShowInfo
  156. *
  157. * @return string
  158. *
  159. * @author 张帅
  160. */
  161. public function actionShowInfo(){
  162. $base_driver = new BaseDriver();
  163. Yii::$app->view->title = '查看司机信息';
  164. #region 1.获取参数
  165. $driver_id = Yii::$app->request->get('driver_id');//司机id
  166. #endregion
  167. //2.获取司机详情
  168. $driver_info = $base_driver->getShowDriverInfo($driver_id);
  169. $data['opera'] = 'show';
  170. $data['driver_info'] = $driver_info;
  171. return $this->render('driver-info', $data);
  172. }
  173. /*============================ajax================================ajax=================================ajax======================================*/
  174. /**
  175. * Function Description:检索车辆列表
  176. * Function Name: actionSearchList
  177. *
  178. * @return string
  179. *
  180. * @author 张帅
  181. */
  182. public function actionSearchList(){
  183. $base_driver = new BaseDriver();
  184. #region 1.获取参数
  185. $motorcade_name = Yii::$app->request->post('motorcade_name');//车队名称
  186. $motorcade_code = Yii::$app->request->post('motorcade_code');//车队代码
  187. $sex = Yii::$app->request->post('sex');//性别
  188. $driver_name = Yii::$app->request->post('driver_name');//司机名称
  189. $driver_code = Yii::$app->request->post('driver_code');//司机工号
  190. $driver_mobile = Yii::$app->request->post('driver_mobile');//司机手机号
  191. $driver_license = Yii::$app->request->post('driver_license');//司机驾驶证号
  192. $page_size = Yii::$app->request->post('page_size');//每页展示数据
  193. $current_page = Yii::$app->request->post('current_page');//当前页
  194. #endregion
  195. //2.获取数据
  196. $driver_list = $base_driver->getDriverList($motorcade_name,$motorcade_code,$sex,$driver_name,$driver_code,$driver_mobile,$driver_license,$page_size,$current_page);
  197. $json['code'] = '0';
  198. $json['info'] = '返回数据成功';
  199. $json['list'] = $driver_list;
  200. return json_encode($json);
  201. }
  202. /**
  203. * Function Description:添加司机
  204. * Function Name: actionDriverAdd
  205. *
  206. * @return string
  207. *
  208. * @author 张帅
  209. */
  210. public function actionDriverAdd(){
  211. $base_driver = new BaseDriver();
  212. #region 1.获取参数
  213. $driver_name = Yii::$app->request->post('driver_name');//司机名称
  214. $motorcade_id = Yii::$app->request->post('motorcade_id');//车队id
  215. $driver_status = Yii::$app->request->post('driver_status');//司机状态
  216. $driver_code = Yii::$app->request->post('driver_code');//司机工号
  217. $driver_license = Yii::$app->request->post('driver_license');//驾驶证号
  218. $driver_mobile = Yii::$app->request->post('driver_mobile');//手机号
  219. $driver_sex = Yii::$app->request->post('driver_sex');//司机性别
  220. $driver_birthday = Yii::$app->request->post('driver_birthday');//出生日期
  221. $first_license_date = Yii::$app->request->post('first_license_date');//初次领证日期
  222. $area_id = Yii::$app->request->post('area_id');//居住区域
  223. $driver_address = Yii::$app->request->post('driver_address');//详细住址
  224. $license_start_date = Yii::$app->request->post('license_start_date');//有效起至日期
  225. $valid_years = Yii::$app->request->post('valid_years');//有效期限
  226. #endregion
  227. $result = $base_driver->addDriver($driver_name,$motorcade_id,$driver_status,$driver_code,$driver_license,$driver_mobile,$driver_sex,$driver_birthday,$first_license_date,$area_id,$driver_address,$license_start_date,$valid_years);
  228. return json_encode($result);
  229. }
  230. /**
  231. * Function Description:修改司机信息
  232. * Function Name: actionDriverUpdate
  233. *
  234. * @return string
  235. *
  236. * @author 张帅
  237. */
  238. public function actionDriverUpdate(){
  239. $base_driver = new BaseDriver();
  240. #region 1.获取参数
  241. $driver_id = Yii::$app->request->post('driver_id');//司机id
  242. $driver_name = Yii::$app->request->post('driver_name');//司机名称
  243. $motorcade_id = Yii::$app->request->post('motorcade_id');//车队id
  244. $driver_status = Yii::$app->request->post('driver_status');//司机状态
  245. $driver_code = Yii::$app->request->post('driver_code');//司机工号
  246. $driver_license = Yii::$app->request->post('driver_license');//驾驶证号
  247. $driver_mobile = Yii::$app->request->post('driver_mobile');//手机号
  248. $driver_sex = Yii::$app->request->post('driver_sex');//司机性别
  249. $driver_birthday = Yii::$app->request->post('driver_birthday');//出生日期
  250. $first_license_date = Yii::$app->request->post('first_license_date');//初次领证日期
  251. $area_id = Yii::$app->request->post('area_id');//居住区域
  252. $driver_address = Yii::$app->request->post('driver_address');//详细住址
  253. $license_start_date = Yii::$app->request->post('license_start_date');//有效起至日期
  254. $valid_years = Yii::$app->request->post('valid_years');//有效期限
  255. #endregion
  256. $result = $base_driver->updateDriver($driver_id,$driver_name,$motorcade_id,$driver_status,$driver_code,$driver_license,$driver_mobile,$driver_sex,$driver_birthday,$first_license_date,$area_id,$driver_address,$license_start_date,$valid_years);
  257. return json_encode($result);
  258. }
  259. /**
  260. * Function Description:删除司机
  261. * Function Name: actionDeleteDriver
  262. *
  263. * @return string
  264. *
  265. * @author 张帅
  266. */
  267. public function actionDeleteDriver(){
  268. $base_driver = new BaseDriver();
  269. #region 1.获取参数
  270. $driver_id = Yii::$app->request->post('driver_id');//司机id
  271. #endregion
  272. $result = $base_driver->deleteDriver($driver_id);
  273. return json_encode($result);
  274. }
  275. }