Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

560 řádky
22 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use yii\base\Exception;
  4. use yii\db\ActiveRecord;
  5. use Yii;
  6. use yii\db\Expression;
  7. /**
  8. * This is the model class for table "run_bus".
  9. *
  10. * @property integer $ID
  11. * @property integer $CANCEL_FLAG
  12. * @property integer $CREATE_USER_ID
  13. * @property string $CREATE_TIME
  14. * @property integer $UPDATE_USER_ID
  15. * @property string $UPDATE_TIME
  16. * @property integer $RUN_ID
  17. * @property integer $BUS_ORDER_ID
  18. * @property integer $BUS_ORG_ID
  19. * @property integer $BUS_TYPE_RES_ID
  20. * @property integer $BUS_COST_TYPE
  21. * @property string $BUS_COST_BY_BUS
  22. * @property integer $TOUR_ORG_ID
  23. * @property integer $TOUR_COST_TYPE
  24. * @property string $TOUR_COST_BY_BUS
  25. * @property string $DRIVER_SUBSIDY
  26. * @property string $TOUR_SUBSIDY
  27. * @property string $TRAVEL_SUBSIDY
  28. * @property integer $SEND_BUS_ORG_ID
  29. * @property integer $SEND_BUS_RES_ID
  30. * @property integer $SEND_BUS_TYPE_RES_ID
  31. * @property integer $SEND_BUS_DRIVER_RES_ID
  32. * @property string $SEND_BUS_NO
  33. * @property string $SEND_DRIVER_NAME
  34. * @property string $SEND_DRIVER_MOBILE
  35. * @property integer $SEND_BUS_USER_ID
  36. * @property string $SEND_BUS_TIME
  37. * @property integer $SEND_BUS_CONFIRM_USER_ID
  38. * @property string $SEND_BUS_CONFIRM_TIME
  39. * @property integer $SEND_TOUR_ORG_ID
  40. * @property integer $SEND_TOUR_GUIDE_RES_ID
  41. * @property string $SEND_TOUR_GUIDE_NAME
  42. * @property string $SEND_TOUR_GUIDE_MOBILE
  43. * @property integer $SEND_TOUR_USER_ID
  44. * @property string $SEND_TOUR_TIME
  45. * @property integer $SEND_TOUR_CONFIRM_USER_ID
  46. * @property string $SEND_TOUR_CONFIRM_TIME
  47. * @property integer $SEAT_COUNT
  48. * @property integer $SALED_COUNT
  49. * @property integer $ALLOW_SELECT_SEAT
  50. * @property integer $CURRENT_ORDER_ID
  51. * @property integer $RUN_BUS_STATUS
  52. * @property string $BRAND_RES_ID
  53. * @property integer $SEND_STATUS
  54. * @property integer $FINANCE_STATUS
  55. * @property integer $START_ZONE_ID
  56. * @property integer $GROUP_LINE_FLAG
  57. * @property integer $REAL_TOTAL_COUNT
  58. * @property integer $COST_MOTORCADE_ID
  59. * @property integer $COST_TYPE
  60. * @property string $COST_PRICE
  61. */
  62. class RunBus extends ActiveRecord
  63. {
  64. /**
  65. * @inheritdoc
  66. */
  67. public static function tableName()
  68. {
  69. return 'run_bus';
  70. }
  71. /**
  72. * @inheritdoc
  73. */
  74. public function rules()
  75. {
  76. return [
  77. [['CANCEL_FLAG', 'CREATE_USER_ID', 'UPDATE_USER_ID', 'RUN_ID', 'BUS_ORDER_ID', 'BUS_ORG_ID', 'BUS_TYPE_RES_ID', 'BUS_COST_TYPE', 'TOUR_ORG_ID', 'TOUR_COST_TYPE', 'SEND_BUS_ORG_ID', 'SEND_BUS_RES_ID', 'SEND_BUS_TYPE_RES_ID', 'SEND_BUS_DRIVER_RES_ID', 'SEND_BUS_USER_ID', 'SEND_BUS_CONFIRM_USER_ID', 'SEND_TOUR_ORG_ID', 'SEND_TOUR_GUIDE_RES_ID', 'SEND_TOUR_USER_ID', 'SEND_TOUR_CONFIRM_USER_ID', 'SEAT_COUNT', 'SALED_COUNT', 'ALLOW_SELECT_SEAT', 'CURRENT_ORDER_ID', 'RUN_BUS_STATUS', 'BRAND_RES_ID', 'SEND_STATUS', 'FINANCE_STATUS', 'START_ZONE_ID', 'GROUP_LINE_FLAG', 'REAL_TOTAL_COUNT', 'COST_MOTORCADE_ID', 'COST_TYPE'], 'integer'],
  78. [['BUS_COST_BY_BUS', 'TOUR_COST_BY_BUS', 'DRIVER_SUBSIDY', 'TOUR_SUBSIDY', 'TRAVEL_SUBSIDY', 'COST_PRICE'], 'number'],
  79. [['CREATE_TIME', 'UPDATE_TIME', 'SEND_BUS_TIME', 'SEND_BUS_CONFIRM_TIME', 'SEND_TOUR_TIME', 'SEND_TOUR_CONFIRM_TIME'], 'string', 'max' => 20],
  80. [['SEND_BUS_NO', 'SEND_DRIVER_NAME', 'SEND_DRIVER_MOBILE', 'SEND_TOUR_GUIDE_NAME', 'SEND_TOUR_GUIDE_MOBILE'], 'string', 'max' => 100],
  81. ];
  82. }
  83. /**
  84. * @inheritdoc
  85. */
  86. public function attributeLabels()
  87. {
  88. return [
  89. 'ID' => 'ID',
  90. 'CANCEL_FLAG' => 'Cancel Flag',
  91. 'CREATE_USER_ID' => 'Create User ID',
  92. 'CREATE_TIME' => 'Create Time',
  93. 'UPDATE_USER_ID' => 'Update User ID',
  94. 'UPDATE_TIME' => 'Update Time',
  95. 'RUN_ID' => 'Run ID',
  96. 'BUS_ORDER_ID' => 'Bus Order ID',
  97. 'BUS_ORG_ID' => 'Bus Org ID',
  98. 'BUS_TYPE_RES_ID' => 'Bus Type Res ID',
  99. 'BUS_COST_TYPE' => 'Bus Cost Type',
  100. 'BUS_COST_BY_BUS' => 'Bus Cost By Bus',
  101. 'TOUR_ORG_ID' => 'Tour Org ID',
  102. 'TOUR_COST_TYPE' => 'Tour Cost Type',
  103. 'TOUR_COST_BY_BUS' => 'Tour Cost By Bus',
  104. 'DRIVER_SUBSIDY' => 'Driver Subsidy',
  105. 'TOUR_SUBSIDY' => 'Tour Subsidy',
  106. 'TRAVEL_SUBSIDY' => 'Travel Subsidy',
  107. 'SEND_BUS_ORG_ID' => 'Send Bus Org ID',
  108. 'SEND_BUS_RES_ID' => 'Send Bus Res ID',
  109. 'SEND_BUS_TYPE_RES_ID' => 'Send Bus Type Res ID',
  110. 'SEND_BUS_DRIVER_RES_ID' => 'Send Bus Driver Res ID',
  111. 'SEND_BUS_NO' => 'Send Bus No',
  112. 'SEND_DRIVER_NAME' => 'Send Driver Name',
  113. 'SEND_DRIVER_MOBILE' => 'Send Driver Mobile',
  114. 'SEND_BUS_USER_ID' => 'Send Bus User ID',
  115. 'SEND_BUS_TIME' => 'Send Bus Time',
  116. 'SEND_BUS_CONFIRM_USER_ID' => 'Send Bus Confirm User ID',
  117. 'SEND_BUS_CONFIRM_TIME' => 'Send Bus Confirm Time',
  118. 'SEND_TOUR_ORG_ID' => 'Send Tour Org ID',
  119. 'SEND_TOUR_GUIDE_RES_ID' => 'Send Tour Guide Res ID',
  120. 'SEND_TOUR_GUIDE_NAME' => 'Send Tour Guide Name',
  121. 'SEND_TOUR_GUIDE_MOBILE' => 'Send Tour Guide Mobile',
  122. 'SEND_TOUR_USER_ID' => 'Send Tour User ID',
  123. 'SEND_TOUR_TIME' => 'Send Tour Time',
  124. 'SEND_TOUR_CONFIRM_USER_ID' => 'Send Tour Confirm User ID',
  125. 'SEND_TOUR_CONFIRM_TIME' => 'Send Tour Confirm Time',
  126. 'SEAT_COUNT' => '座位数 ',
  127. 'SALED_COUNT' => 'Saled Count',
  128. 'ALLOW_SELECT_SEAT' => 'Allow Select Seat',
  129. 'CURRENT_ORDER_ID' => '当前已经过站点顺序ID',
  130. 'RUN_BUS_STATUS' => 'Run Bus Status',
  131. 'BRAND_RES_ID' => 'Brand Res ID',
  132. 'SEND_STATUS' => 'Send Status',
  133. 'FINANCE_STATUS' => '报账状态',
  134. 'START_ZONE_ID' => '区域res_id',
  135. 'GROUP_LINE_FLAG' => '组合线路标志 1:组合线路 0:非组合线路',
  136. 'REAL_TOTAL_COUNT' => '最终实际上车人数(该字段主要用于司机端)',
  137. 'COST_MOTORCADE_ID' => '成本id车队 对应suplier_id',
  138. 'COST_TYPE' => '结算类型 对应dict_type.id',
  139. 'COST_PRICE' => '成本单价',
  140. ];
  141. }
  142. /**
  143. * Function Description:获取前一天的班次
  144. * Function Name: getCostByRunBus
  145. *
  146. * @return array|\yii\db\ActiveRecord[]
  147. *
  148. * @author 张帅
  149. */
  150. public function getCostByRunBus()
  151. {
  152. $result = self::find()
  153. ->select([
  154. 'rb.RUN_ID',//班次id
  155. 'rb.BUS_ORDER_ID',//车号
  156. 'BUS_ID' => 'rb.send_bus_res_id',//车资源id
  157. 'BUS_ORG_ID' => BaseBus::find()->select('org_id')->where('bus_id = rb.send_bus_res_id')->limit(1),//实际所用车车队id
  158. 'rb.COST_MOTORCADE_ID',//规定车队id
  159. 'DRIVER_ID' => 'rb.send_bus_driver_res_id',//司机id
  160. 'GUIDE_ID' => 'rb.send_tour_guide_res_id',//导游id
  161. 'rb.SEAT_COUNT',//座位数
  162. 'rb.SALED_COUNT',//已售座位数
  163. 'rb.REAL_TOTAL_COUNT',//实际上车人数
  164. 'rb.COST_TYPE',//结算类型
  165. 'rb.COST_PRICE',//结算单价
  166. 'rm.RUN_DATE',
  167. 'rm.RUN_TIME',
  168. 'LINE_ID' => 'rm.prod_id',//线路id
  169. 'ol.LINE_TYPE',//线路类型
  170. 'RUN_BUS_ID' => 'rb.id',//班次车次唯一id
  171. 'rb.SEND_BUS_TYPE_RES_ID',//车号
  172. ])
  173. ->from(self::tableName() . ' as rb')
  174. ->leftJoin(RunMain::tableName() . ' as rm', 'rb.run_id = rm.run_id')
  175. ->leftJoin(OperaLine::tableName() . ' as ol', 'ol.line_id = rm.prod_id')
  176. ->where([
  177. 'and',
  178. ['=', 'rm.run_date', date('Y-m-d', strtotime("-1 day"))],
  179. ['=', 'rb.cancel_flag', 0],
  180. ['in', 'rb.run_bus_status', [138,139,141]],
  181. ])->asArray()->all();
  182. return $result;
  183. }
  184. /**
  185. * Function Description:获取要添加的车次的基本信息
  186. * Function Name: getBusInfoArray
  187. * @param string $bus_info_str 车次信息字符
  188. *
  189. * @return bool
  190. *
  191. * @author 张帅
  192. */
  193. public function getBusInfoArray($bus_info_str)
  194. {
  195. $bus_info_str = substr($bus_info_str, 1, -1);
  196. $bus_info_arr = explode(',', $bus_info_str);
  197. $result['bus_type_res_id'] = (!isset($bus_info_arr[0]) || empty($bus_info_arr[0])) ? false : $bus_info_arr[0];//车资源类型id
  198. $result['brand_res_id'] = (!isset($bus_info_arr[1]) || empty($bus_info_arr[1])) ? false : $bus_info_arr[1];//品牌id
  199. $result['cost_motorcade_id'] = (!isset($bus_info_arr[2]) || empty($bus_info_arr[2])) ? false : $bus_info_arr[2];//承运车队id
  200. $result['cost_type'] = (!isset($bus_info_arr[3]) || empty($bus_info_arr[3])) ? false : $bus_info_arr[3];//成本类型
  201. $result['cost_price'] = (!isset($bus_info_arr[4]) || empty($bus_info_arr[4])) ? false : $bus_info_arr[4];//成本单价
  202. $result['allow_select_seat'] = (!isset($bus_info_arr[5]) || empty($bus_info_arr[5])) ? 156 : $bus_info_arr[5];//是否支持选座
  203. #region 判断必要信息是否传全
  204. foreach ($result as $key => $vel) {
  205. if ($vel === false) {
  206. return false;
  207. }
  208. }
  209. #endregion
  210. return $result;
  211. }
  212. /**
  213. * Function Description:获取车号
  214. * Function Name: getBusNoByLineDate
  215. * @param int $line_id 线路id
  216. * @param string $run_date 出发日期
  217. *
  218. * @return array|int|mixed|null|ActiveRecord
  219. *
  220. * @author 张帅
  221. */
  222. public function getBusNoByLineDate($line_id, $run_date)
  223. {
  224. $result = self::find()
  225. ->select('max(rb.bus_order_id) as bus_order_id')
  226. ->from(self::tableName() . ' as rb')
  227. ->leftJoin(RunMain::tableName() . ' as rm', 'rb.run_id = rm.run_id')
  228. ->where([
  229. 'and',
  230. ['=', 'rm.prod_id', $line_id],
  231. ['=', 'rm.run_date', $run_date],
  232. ['=', 'rm.run_status', 138],
  233. ])
  234. ->asArray()->one();
  235. #region 判断该班次是否有车
  236. if (count($result) == 0) {
  237. return 1;
  238. }
  239. #endregion
  240. $result = $result['bus_order_id'] + 1;
  241. return $result;
  242. }
  243. /**
  244. * Function Description:为班次添加车次
  245. * Function Name: addBusForRun
  246. * @param array $run_info
  247. * @param array /bool $bus_info
  248. * @param array $bus_res_info
  249. * @param array $matrix_arr
  250. * @param array $run_station_info
  251. * @param int $bus_order_id
  252. * @param int $user_id
  253. *
  254. * @return mixed
  255. *
  256. * @author 张帅
  257. */
  258. public function addBusForRun($run_info, $bus_info, $bus_res_info, $matrix_arr, $run_station_info, $bus_order_id, $user_id)
  259. {
  260. #region run_bus新增数据
  261. $run_bus_val = [
  262. 'CANCEL_FLAG' => 0,
  263. 'CREATE_USER_ID' => $user_id,
  264. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  265. 'UPDATE_USER_ID' => $user_id,
  266. 'UPDATE_TIME' => date('Y-m-d H:i:s'),
  267. 'RUN_ID' => $run_info['run_id'],
  268. 'BUS_ORDER_ID' => $bus_order_id,
  269. 'BUS_TYPE_RES_ID' => $bus_info['bus_type_res_id'],
  270. 'SEAT_COUNT' => $bus_res_info['total_count'],
  271. 'ALLOW_SELECT_SEAT' => $bus_info['allow_select_seat'],
  272. 'BRAND_RES_ID' => $bus_info['brand_res_id'],
  273. 'COST_MOTORCADE_ID' => $bus_info['cost_motorcade_id'],
  274. 'RUN_BUS_STATUS' => $run_info['run_status'],
  275. 'COST_TYPE' => $bus_info['cost_type'],
  276. 'COST_PRICE' => $bus_info['cost_price'],
  277. ];
  278. #endregion
  279. #region run_x新增数据
  280. $run_date = $run_info['run_date'];
  281. $x_date = explode('-', $run_date);
  282. $run_x_name = 'run_' . $x_date[0] . $x_date[1];//run_x表名
  283. $run_x_val = [];//RUN_ID,RUN_LOCK_TYPE,RUN_DATE,LOCK_COUNT,ORDER_ID,STATION_RES_ID,STATION_INOUT_TYPE,BUS_ORDER_ID,BUS_RES_ID,SEAT_X,SEAT_Y,SEAT_TYPE,SEAT_SEQ_ID,SEAT_NAME,SEAT_STATUS,CREATE_USER_ID,CREATE_TIME,ORDER_MAIN_ID,ORDER_MAIN_PROD_ID,ORDER_PROD_ID,ORDER_SEQ_ID,ORDER_LOCK_USER_ID,ORDER_LOCK_TIME,ORDER_LOCK_END_TIME,HUMAN_TYPE,AREA_ID,ALLOW_SELECT_SEAT,CHECK_USER_ID,CHECK_TIME
  284. $run_x_key = [];
  285. foreach ($run_station_info as $station_key => $station_vel) {
  286. foreach ($matrix_arr as $matrix_key => $matrix_vel) {
  287. #region run_x每条数据
  288. $run_x_one = [//SEAT_STATUS,CREATE_USER_ID,CREATE_TIME,ORDER_MAIN_ID,ORDER_MAIN_PROD_ID,ORDER_PROD_ID,ORDER_SEQ_ID,ORDER_LOCK_USER_ID,ORDER_LOCK_TIME,ORDER_LOCK_END_TIME,HUMAN_TYPE,AREA_ID,ALLOW_SELECT_SEAT,CHECK_USER_ID,CHECK_TIME
  289. 'RUN_ID' => $run_info['run_id'],//ORDER_LOCK_TIME,ORDER_LOCK_END_TIME,HUMAN_TYPE,AREA_ID,ALLOW_SELECT_SEAT,CHECK_USER_ID,CHECK_TIME
  290. 'RUN_LOCK_TYPE' => 121,
  291. 'RUN_DATE' => $run_date,
  292. 'LOCK_COUNT' => 1,
  293. 'ORDER_ID' => $station_vel['station_order_id'],
  294. 'STATION_RES_ID' => $station_vel['station_res_id'],
  295. 'STATION_INOUT_TYPE' => $station_vel['station_inout_type'],
  296. 'BUS_ORDER_ID' => $bus_order_id,
  297. 'BUS_RES_ID' => $bus_info['bus_type_res_id'],
  298. 'SEAT_X' => $matrix_vel['pos_x'],
  299. 'SEAT_Y' => $matrix_vel['pos_y'],
  300. 'SEAT_TYPE' => $matrix_vel['pos_type'],
  301. 'SEAT_SEQ_ID' => $matrix_vel['pos_seq_id'],
  302. 'SEAT_NAME' => $matrix_vel['pos_name'],
  303. 'SEAT_STATUS' => 0,
  304. 'CREATE_USER_ID' => $user_id,
  305. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  306. 'ORDER_MAIN_ID' => 0,
  307. 'ORDER_MAIN_PROD_ID' => 0,
  308. 'ORDER_PROD_ID' => 0,
  309. 'ORDER_SEQ_ID' => 0,
  310. 'ORDER_LOCK_USER_ID' => 0,
  311. 'ORDER_LOCK_TIME' => date('Y-m-d H:i:s'),
  312. 'ORDER_LOCK_END_TIME' => date('Y-m-d H:i:s'),
  313. 'HUMAN_TYPE' => 0,
  314. 'AREA_ID' => $station_vel['area_id'],
  315. 'ALLOW_SELECT_SEAT' => $bus_info['allow_select_seat'],
  316. 'CHECK_USER_ID' => 0,
  317. 'CHECK_TIME' => '',
  318. 'CANCEL_FLAG' => 0,
  319. ];
  320. #endregion
  321. #region run_x添加时的键值
  322. if (count($run_x_key) == 0) {
  323. $run_x_key = array_keys($run_x_one);
  324. }
  325. #endregion
  326. #region 将数据加入$run_x_val
  327. $run_x_val[] = $run_x_one;
  328. #endregion
  329. }
  330. }
  331. #endregion
  332. $transaction = Yii::$app->db->beginTransaction();
  333. try {
  334. #region 在run_bus表中添加数据
  335. $this->attributes = $run_bus_val;
  336. $run_bus_id = $this->insert();
  337. if (!$run_bus_id) {
  338. throw new Exception('run_bus添加失败');
  339. }
  340. #endregion
  341. #region 修改run_stock数据
  342. $update_value = [
  343. 'UPDATE_USER_ID' => $user_id,
  344. 'UPDATE_TIME' => date('Y-m-d H:i:s'),
  345. 'TOTAL_COUNT' => new Expression('TOTAL_COUNT+' . $bus_res_info['total_count']),
  346. ];
  347. $update_where = [
  348. 'and',
  349. ['=', 'run_id', $run_info['run_id']],
  350. ['=', 'seat_type', 72],
  351. ['=', 'cancel_flag', 0],
  352. ];
  353. $res = RunStock::updateAll($update_value, $update_where);
  354. if (!$res) {
  355. throw new Exception('更新run_stock失败');
  356. }
  357. #endregion
  358. #region 添加run_x数据
  359. $res = Yii::$app->db->createCommand()->batchInsert($run_x_name, $run_x_key, $run_x_val)->execute();
  360. if (!$res) {
  361. throw new Exception('添加座位图失败');
  362. }
  363. #endregion
  364. $transaction->commit();
  365. $result['code'] = '0';
  366. $result['info'] = '加车成功';
  367. $result['data'] = [
  368. 'bus_order_id' => $bus_order_id,
  369. 'run_bus_id' => $this->ID,
  370. 'seat_count' => $bus_res_info['total_count']
  371. ];
  372. } catch (Exception $e) {
  373. # 回滚事务
  374. $result['code'] = '1';
  375. $result['info'] = '加车失败';
  376. $result['error'] = $e->getMessage();
  377. }
  378. return $result;
  379. }
  380. /**
  381. * Function Description:获取车次信息
  382. * Function Name: getBusInfo
  383. * @param $run_id
  384. *
  385. * @return array|ActiveRecord[]
  386. *
  387. * @author 李健
  388. */
  389. public function getBusInfo($run_id)
  390. {
  391. $select = [
  392. 'res.res_name as property',
  393. 'run.bus_order_id',
  394. 'allow_select_seat'=>new Expression('if(run.allow_select_seat>0,"支持","不支持")'),
  395. 'send_bus_res_id'=>new Expression('if(run.send_bus_res_id>0,"已派","未派")'),
  396. 'send_bus_driver_res_id'=>new Expression('if(run.send_bus_driver_res_id>0,"已派","未派")'),
  397. 'bus_brand'=>new Expression('if(res1.res_name is null,"",res1.res_name)')
  398. ];
  399. $where = ['and'];
  400. $where[] = ['=', 'run.run_id', $run_id];
  401. $where[] = ['=', 'run.cancel_flag', 0];
  402. $res = self::find()
  403. ->select($select)
  404. ->from(self::tableName() . ' run')
  405. ->leftJoin(BaseResource::tableName() . ' res', 'res.cancel_flag=0 and '.new Expression('if(run.send_bus_type_res_id=0,res.res_id=run.bus_type_res_id,res.res_id=run.send_bus_type_res_id)'))
  406. ->leftJoin(BaseResource::tableName().' res1','res1.res_id=run.brand_res_id and res1.res_type_id=134')
  407. ->where($where)
  408. ->asArray()
  409. ->all();
  410. return $res;
  411. }
  412. /**
  413. * Function Description:根据RUN_ID获取车辆数及选座状态
  414. * Function Name: getRunHasCar
  415. * @param $run_id
  416. *
  417. * @return array|ActiveRecord[]
  418. *
  419. * @author 李健
  420. */
  421. public function getRunHasCar($run_id)
  422. {
  423. $select = [
  424. 'id'=>new Expression('if(b.send_bus_type_res_id=0,b.bus_type_res_id,b.send_bus_type_res_id)'),
  425. 'b.allow_select_seat as selectseat',
  426. 'b.id as run_bus_id',
  427. 'b.bus_order_id as carnum',
  428. 'b.brand_res_id',
  429. 'b.cost_motorcade_id',
  430. 'b.cost_type',
  431. 'b.cost_price',
  432. 'bus_brand'=>new Expression('if(base.res_name is null,"",base.res_name)'),
  433. 'b.send_bus_res_id'
  434. ];
  435. $where = ['and'];
  436. $where[] = ['=','b.run_id',$run_id];
  437. $where[] = ['=','b.cancel_flag',0];
  438. $res = self::find()
  439. ->select($select)
  440. ->from(self::tableName(). ' b')
  441. ->leftJoin(BaseResource::tableName().' base','base.res_id=b.brand_res_id and res_type_id=134')
  442. ->where($where)
  443. ->orderBy('b.bus_order_id')
  444. ->asArray()
  445. ->all();
  446. return $res;
  447. }
  448. /**
  449. * Function Description:根据runid获取当前run_bus记录中最大record的记录
  450. * Function Name: GetMaxOrderId
  451. * @param $runid
  452. *
  453. * @return mixed
  454. *
  455. * @author 冒炎
  456. */
  457. public function GetMaxOrderId($runid){
  458. $res=self::find()
  459. ->select(['max'=>new Expression("ifnull(max(bus_order_id), 0)")])
  460. ->from(self::tableName())
  461. ->where(['=','run_id',$runid])
  462. ->asArray()
  463. ->one();
  464. return $res['max'];
  465. }
  466. /**
  467. * Function Description:获得特定run_bus记录的状态值
  468. * Function Name: getOneBusStatus
  469. * @param $run_id
  470. * @param $bus_order_id
  471. *
  472. * @return array|null|ActiveRecord
  473. *
  474. * @author 冒炎
  475. */
  476. public function getOneBusStatus($run_id,$bus_order_id){
  477. $where = ['and'];
  478. $where[] = ['=','run_id',$run_id];
  479. $where[] = ['=','bus_order_id',$bus_order_id];
  480. $res = self::find()
  481. ->select(['run_bus_status'])
  482. ->from(self::tableName())
  483. ->where($where)
  484. ->asArray()
  485. ->one();
  486. return $res;
  487. }
  488. /**
  489. * Function Description:筛选出车次组中不可以停运的车次
  490. * Function Name: getCanNotStopRunBus
  491. * @param $bus_arr
  492. *
  493. * @return array
  494. *
  495. * @author 冒炎
  496. */
  497. public function getCanNotStopRunBus($bus_arr){
  498. $select = [
  499. 'l.line_code as prod_code',
  500. 'l.line_name as prod_name',
  501. 'a.run_id as run_id',
  502. 'a.send_bus_no as bus_no',
  503. 'a.run_bus_status as status',
  504. 'o.order_id as order_id'
  505. ];
  506. $list =[];
  507. foreach ($bus_arr as $val){
  508. $run_bus = self::find()
  509. ->select($select)
  510. ->from(self::tableName() . ' a')
  511. ->leftJoin('run_main m','m.run_id=a.run_id')
  512. ->leftJoin('opera_line l','l.line_id=m.prod_id and l.cancel_flag=0')
  513. ->leftJoin('order_main o','o.run_id=a.run_id and o.run_bus_order_id=a.bus_order_id and o.ORDER_VALID_STATUS = 1 and o.cancel_flag = 0 and a.run_bus_status in (137,138,139)')
  514. ->where(['=','a.cancel_flag',0])
  515. ->andWhere("a.run_id = {$val['run_id']}")
  516. ->andWhere("a.bus_order_id = {$val['bus_order_id']}")
  517. ->asArray()
  518. ->one();
  519. if(!in_array($run_bus['status'],[137,138,139])||!empty($run_bus['bus_no'])||!empty($run_bus['order_id'])){
  520. $list[] = $run_bus['prod_code'] . $run_bus['prod_name'];
  521. }
  522. }
  523. if(empty($list)){
  524. return [];
  525. }else{
  526. return $list;
  527. }
  528. }
  529. }