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.

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <?php
  2. namespace backend\modules\api\models;
  3. use function GuzzleHttp\default_ca_bundle;
  4. use yii\db\ActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "bus_order".
  8. *
  9. * @property integer $id
  10. * @property integer $bus_number
  11. * @property integer $create_user_id
  12. * @property string $create_time
  13. * @property integer $update_user_id
  14. * @property string $update_time
  15. * @property integer $cancel_flag
  16. * @property integer $use_bus_org_id
  17. * @property string $run_date
  18. * @property integer $run_bus_id
  19. * @property integer $run_id
  20. * @property integer $line_id
  21. * @property string $start_time
  22. * @property integer $bus_order_id
  23. * @property integer $bus_type_res_id
  24. * @property integer $seat_count
  25. * @property integer $saled_count
  26. * @property integer $itinerary_id
  27. * @property string $itinerary_name
  28. * @property integer $line_type
  29. * @property integer $day_num
  30. * @property integer $bus_cost_type
  31. * @property string $bus_cost
  32. * @property string $remark
  33. * @property string $send_msg
  34. * @property integer $send_type
  35. * @property string $send_cost
  36. * @property integer $send_bus_res_id
  37. * @property integer $send_bus_driver_res_id
  38. * @property integer $send_status
  39. * @property integer $run_status
  40. * @property integer $finance_status
  41. * @property integer $end_status
  42. * @property integer $line_status
  43. * @property integer $safe
  44. *
  45. * @property BaseBus $sendBusRes
  46. * @property BaseDriver $sendBusDriverRes
  47. */
  48. class BusOrder extends ActiveRecord
  49. {
  50. /**
  51. * @inheritdoc
  52. */
  53. public static function tableName()
  54. {
  55. return 'bus_order';
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function rules()
  61. {
  62. return [
  63. [['bus_number', 'create_user_id', 'update_user_id', 'run_date', 'seat_count', 'saled_count', 'send_type'], 'required'],
  64. [['bus_number', 'create_user_id', 'update_user_id', 'cancel_flag', 'use_bus_org_id', 'run_bus_id', 'run_id', 'line_id', 'bus_order_id', 'bus_type_res_id', 'seat_count', 'saled_count', 'itinerary_id', 'line_type', 'day_num', 'bus_cost_type', 'send_type', 'send_bus_res_id', 'send_bus_driver_res_id', 'send_status', 'run_status', 'finance_status', 'end_status', 'line_status', 'safe'], 'integer'],
  65. [['update_time'], 'safe'],
  66. [['bus_cost', 'send_cost'], 'number'],
  67. [['create_time'], 'string', 'max' => 20],
  68. [['run_date'], 'string', 'max' => 10],
  69. [['start_time'], 'string', 'max' => 128],
  70. [['itinerary_name'], 'string', 'max' => 50],
  71. [['remark'], 'string', 'max' => 100],
  72. [['send_msg'], 'string', 'max' => 1024],
  73. [['send_bus_res_id'], 'exist', 'skipOnError' => true, 'targetClass' => BaseBus::className(), 'targetAttribute' => ['send_bus_res_id' => 'BUS_ID']],
  74. [['send_bus_driver_res_id'], 'exist', 'skipOnError' => true, 'targetClass' => BaseDriver::className(), 'targetAttribute' => ['send_bus_driver_res_id' => 'DRIVER_ID']],
  75. ];
  76. }
  77. /**
  78. * @inheritdoc
  79. */
  80. public function attributeLabels()
  81. {
  82. return [
  83. 'id' => '主键,自增',
  84. 'bus_number' => '出车单号',
  85. 'create_user_id' => 'Create User ID',
  86. 'create_time' => 'Create Time',
  87. 'update_user_id' => 'Update User ID',
  88. 'update_time' => '记录最后更新时间',
  89. 'cancel_flag' => 'Cancel Flag',
  90. 'use_bus_org_id' => '用车单位',
  91. 'run_date' => '用车日期',
  92. 'run_bus_id' => '车次ID,对应run_bus中的主键ID,用于派车时更新巴士系统车次库存',
  93. 'run_id' => '班次ID,供同步已有班次使用',
  94. 'line_id' => '线路ID,供同步数据使用',
  95. 'start_time' => 'Start Time',
  96. 'bus_order_id' => '车次号,供同步已有车次使用',
  97. 'bus_type_res_id' => '用车类型',
  98. 'seat_count' => '车座数',
  99. 'saled_count' => '乘客人数',
  100. 'itinerary_id' => '行程ID',
  101. 'itinerary_name' => '行程名称',
  102. 'line_type' => '行程类型,市内或省际 1为省际,2为市内',
  103. 'day_num' => '行程包含的行程天数',
  104. 'bus_cost_type' => '车辆计价方式 477为包车计价,478为人数计价',
  105. 'bus_cost' => '车辆计价金额',
  106. 'remark' => '用车备注',
  107. 'send_msg' => '调度原因等调度时候的信息',
  108. 'send_type' => '内部派车还是外部派车 0:内部 1:外部',
  109. 'send_cost' => '调派车辆时的价格',
  110. 'send_bus_res_id' => '调派车辆res_id',
  111. 'send_bus_driver_res_id' => '调派司机res_id',
  112. 'send_status' => '调度状态',
  113. 'run_status' => '出车状态',
  114. 'finance_status' => '报账状态',
  115. 'end_status' => '结算状态',
  116. 'line_status' => '线路牌 0为未亮起 1为亮起',
  117. 'safe' => '安检 0为未安检 1为已安检',
  118. ];
  119. }
  120. /**
  121. * @return \yii\db\ActiveQuery
  122. */
  123. public function getSendBusRes()
  124. {
  125. return $this->hasOne(BaseBus::className(), ['BUS_ID' => 'send_bus_res_id']);
  126. }
  127. /**
  128. * @return \yii\db\ActiveQuery
  129. */
  130. public function getSendBusDriverRes()
  131. {
  132. return $this->hasOne(BaseDriver::className(), ['DRIVER_ID' => 'send_bus_driver_res_id']);
  133. }
  134. /**
  135. * Function Description:获取任务列表
  136. * Function Name: getDriverTask
  137. * @param int $driver_id 司机id
  138. * @param string $run_date 日期
  139. *
  140. * @return array|\yii\db\ActiveRecord[]
  141. *
  142. * @author 张帅
  143. */
  144. public function getDriverTask($driver_id, $run_date)
  145. {
  146. #region 1.获取列表详情
  147. $task_list = self::find()
  148. ->select([
  149. 'bo.contacts',//联系人姓名
  150. 'bo.tels',//联系人号码
  151. 'bo.run_bus_id',//车次id
  152. 'bo.bus_number',//出车单号
  153. 'bo.run_id',//班次id
  154. 'bo.line_id',//线路id
  155. 'run_date',//用车日期
  156. 'run_status_id' => 'bo.run_status',
  157. 'run_status' => DictType::find()->select('type_name')->where('id = bo.run_status')->limit(1),//班次状态
  158. 'finance_status_id' => 'bo.finance_status',
  159. 'finance_status' => DictType::find()->select('type_name')->where('id = bo.finance_status')->limit(1),//报账状态
  160. 'bo.bus_order_id',//车次号
  161. 'saled_count_bo'=>'bo.saled_count',//bus_order已售座位数
  162. 'saled_count_rb'=>'rb.saled_count',//run_bus已售座位数
  163. 'send_bus_no' => BaseBus::find()->select('bus_no')->where('bus_id = bo.send_bus_res_id'),//车牌号
  164. 'itinerary_id',//行程id
  165. 'start_time' => "str_to_date(start_time,'%H:%i')",
  166. ])
  167. ->from(self::tableName() . ' as bo')
  168. ->leftJoin('run_bus as rb', 'bo.run_bus_id = rb.id')
  169. ->where([
  170. 'and',
  171. ['=', 'bo.cancel_flag', 0],
  172. ['=', 'bo.send_bus_driver_res_id', $driver_id],
  173. ['=', 'bo.run_date', $run_date],
  174. ])
  175. ->orderBy(['start_time' => SORT_ASC])
  176. ->asArray()->all();
  177. #endregion
  178. #region 2.获取上下站点及时间
  179. //行程id数组
  180. $itinerary_id = [];
  181. foreach ($task_list as $key => $vel) {
  182. $itinerary_id[] = $vel['itinerary_id'];
  183. if($vel['run_id'] != 0){ //run_id不为0时从run_bus里面取
  184. $task_list[$key]['saled_count'] = $vel['saled_count_rb'];
  185. }else{
  186. $task_list[$key]['saled_count'] = $vel['saled_count_bo'];
  187. }
  188. }
  189. //行程列表
  190. $itinerary_list = BusItinerary::find()
  191. ->select('itinerary_id,station_name,day_seq_id,start_time')
  192. ->where([
  193. 'and',
  194. ['in', 'itinerary_id', $itinerary_id],
  195. ['=', 'cancel_flag', 0],
  196. ])
  197. ->orderBy(['itinerary_id' => SORT_ASC, 'station_seq_id' => SORT_ASC])
  198. ->asArray()->all();
  199. //分车次行程
  200. $itinerary_bus_list = [];
  201. foreach ($itinerary_list as $key => $vel) {
  202. if (!isset($itinerary_bus_list[$vel['itinerary_id']])) {
  203. $itinerary_bus_list[$vel['itinerary_id']]['start_station'] = $vel['station_name'];
  204. $itinerary_bus_list[$vel['itinerary_id']]['run_time'] = $vel['start_time'];
  205. } else {
  206. $itinerary_bus_list[$vel['itinerary_id']]['end_station'] = $vel['station_name'];
  207. if( $vel["day_seq_id"] == 1 ) {
  208. $itinerary_bus_list[$vel['itinerary_id']]['arrive_time'] = $vel['start_time'];
  209. } else {
  210. $start_date_disp = "";
  211. switch( $vel["day_seq_id"] ) {
  212. case 2:
  213. $start_date_disp = "次日";
  214. break;
  215. case 3:
  216. $start_date_disp = "第三日";
  217. break;
  218. case 4:
  219. $start_date_disp = "第四日";
  220. break;
  221. default:
  222. $start_date_disp = "第{$vel["day_seq_id"]}日";
  223. break;
  224. }
  225. $itinerary_bus_list[$vel['itinerary_id']]['arrive_time'] = $start_date_disp." ".$vel['start_time'];
  226. }
  227. }
  228. }
  229. #endregion
  230. #region 3.整理任务列表
  231. foreach ($task_list as $key => $vel) {
  232. if( is_array($vel) && isset($itinerary_bus_list[$vel['itinerary_id']]) ) {
  233. $task_list[$key] = array_merge($vel, $itinerary_bus_list[$vel['itinerary_id']]);
  234. } else {
  235. $task_list[$key]['start_station'] = '未设置';
  236. $task_list[$key]['run_time'] = '未设置';
  237. $task_list[$key]['end_station'] = '未设置';
  238. $task_list[$key]['arrive_time'] = '未设置';
  239. }
  240. }
  241. #endregion
  242. return $task_list;
  243. }
  244. /**
  245. * Function Description:获取车次详情
  246. * Function Name: getBusInfo
  247. * @param int $bus_number 出车单号
  248. *
  249. * @return array|bool|null|ActiveRecord
  250. *
  251. * @author 张帅
  252. */
  253. public function getBusInfo($bus_number)
  254. {
  255. $result = self::find()
  256. ->select([
  257. 'bo.run_id',//班次id
  258. 'bo.bus_order_id',//车次id
  259. 'bo.bus_number',//出车单号
  260. 'bus_no' => BaseBus::find()->select('bus_no')->where('bus_id = bo.send_bus_res_id'),//车牌号
  261. 'bo.send_bus_res_id',
  262. 'bo.run_date',
  263. 'bo.send_bus_driver_res_id',
  264. 'bo.itinerary_id',
  265. 'order_seat_count' => 'bo.seat_count',//总座位数
  266. 'order_saled_count' => 'bo.saled_count',//售出的座位数
  267. 'bus_seat_count' => 'rb.seat_count',//总座位数
  268. 'bus_saled_count' => 'rb.saled_count',//售出的座位数
  269. 'run_status_id' => 'bo.run_status',
  270. 'bus_status' => DictType::find()->select('type_name')->where('id = bo.run_status')->limit(1),//班次状态
  271. 'finance_status_id' => 'bo.finance_status',
  272. 'finance_status' => DictType::find()->select('type_name')->where('id = bo.finance_status')->limit(1),//报账状态
  273. ])
  274. ->from(self::tableName() . ' as bo')
  275. ->leftJoin('run_bus as rb', 'bo.run_bus_id = rb.id')
  276. ->where([
  277. 'and',
  278. ['=', 'bo.cancel_flag', 0],
  279. ['=', 'bo.bus_number', $bus_number],
  280. ])
  281. ->asArray()->one();
  282. if (count($result) == 0) {
  283. return false;
  284. }
  285. //找到司机当天所有的可以开启的行程,并且正序排序
  286. $is_line_now = self::find()
  287. ->select(['bus_number','start_time'])
  288. ->where(['and',['=','cancel_flag',0],['=','run_date',$result['run_date']],['=','send_bus_driver_res_id',$result['send_bus_driver_res_id']],['or',['=','run_status',435],['=','run_status',436]]])
  289. ->orderBy(['start_time'=>SORT_ASC])
  290. ->asArray()->all();
  291. if($is_line_now){ //如果当天有结果并且当前的就是司机进入的,就返回true
  292. if($is_line_now[0]['bus_number'] == $bus_number){
  293. $result['is_right'] = true;
  294. }else{
  295. $result['is_right'] = false;
  296. }
  297. $result['right_task_time'] = $is_line_now[0]['start_time'];
  298. }
  299. if (empty($result['bus_seat_count']) && empty($result['bus_saled_count'])) {
  300. $result['seat_count'] = $result['order_seat_count'];
  301. $result['saled_count'] = $result['order_saled_count'];
  302. } else {
  303. $result['seat_count'] = $result['bus_seat_count'];
  304. $result['saled_count'] = $result['bus_saled_count'];
  305. }
  306. return $result;
  307. }
  308. /**
  309. * Function Description:获取出车详情
  310. * Function Name: getRunBusStationOrderInfo
  311. * @param $bus_info
  312. * @param $station_info
  313. * @param $order_info
  314. *
  315. * @return mixed
  316. *
  317. * @author 张帅
  318. */
  319. public function getRunBusStationOrderInfo($bus_info, $station_info, $order_info)
  320. {
  321. #region 1.获取车次信息
  322. $start = reset($station_info);
  323. $bus_info['start_station'] = $start['station_name'];
  324. $bus_info['start_time'] = $start['start_time'];
  325. $end = end($station_info);
  326. $bus_info['end_station'] = $end['station_name'];
  327. $bus_info['end_time'] = $end['start_time'];
  328. #endregion
  329. #region 2.获取每站信息
  330. $i = 0;
  331. $run_station_info = [];//站点数据
  332. foreach ($station_info as $key => $vel) {
  333. $vel['people_up_all_num'] = 0;//应上车总人数
  334. $vel['people_down_all_num'] = 0;//应下车总人数
  335. $vel['has_up_num'] = 0;//已上人数
  336. $vel['not_up_num'] = 0;//未上人数
  337. $vel['passengers'] = [];//上车乘客信息
  338. $vel['down_passengers'] = [];//下车乘客信息
  339. if ($vel['station_id'] == '') {
  340. $run_station_info[$i] = $vel;
  341. $i++;
  342. } else {
  343. $run_station_info[$vel['station_id']] = $vel;
  344. }
  345. unset($run_station_info[$vel['station_id']]['run_id']);
  346. unset($run_station_info[$vel['station_id']]['station_id']);
  347. }
  348. if (count($order_info) > 0) {
  349. foreach ($order_info as $key => $vel) {
  350. //$bus_info['saled_count'] += $vel['people_num'];//增加总乘客数
  351. $run_station_info[$vel['start_station_id']]['people_up_all_num'] += $vel['people_num'];//增加对应站应上车总人数
  352. $run_station_info[$vel['end_station_id']]['people_down_all_num'] += $vel['people_num'];//增加对应站应下车总人数
  353. if ($vel['check_status'] == 0) {
  354. $run_station_info[$vel['start_station_id']]['not_up_num'] += $vel['people_num'];//增加对应站未检票总人数
  355. } else {
  356. $run_station_info[$vel['start_station_id']]['has_up_num'] += $vel['people_num'];//增加对应站已检票总人数
  357. }
  358. $station_one = $vel;
  359. unset($station_one['start_station_id']);
  360. unset($station_one['end_station_id']);
  361. $run_station_info[$vel['start_station_id']]['passengers'][] = $station_one;//增加对应站上车订单
  362. $run_station_info[$vel['end_station_id']]['down_passengers'][] = $station_one;//增加对应站下车订单
  363. }
  364. }
  365. #endregion
  366. $result['bus_info'] = $bus_info;
  367. $result['station_info'] = array_merge($run_station_info);
  368. return $result;
  369. }
  370. /**
  371. * Function Description:获取已完成的任务数量
  372. * Function Name: getTaskComplete
  373. * @param int $driver_id 司机id
  374. *
  375. * @return int|string
  376. *
  377. * @author 张帅
  378. */
  379. public function getTaskComplete($driver_id)
  380. {
  381. $result = self::find()
  382. ->where([
  383. 'and',
  384. ['=', 'send_bus_driver_res_id', $driver_id],
  385. ['=', 'cancel_flag', 0],
  386. ['=', 'run_status', 438]
  387. ])->count();
  388. return $result;
  389. }
  390. /**
  391. * Function Description:通过司机获取报账列表
  392. * Function Name: getFinanceListByDriver
  393. * @param int $driver_id 司机id
  394. *
  395. * @return array|\yii\db\ActiveRecord[]
  396. *
  397. * @author 张帅
  398. */
  399. public function getFinanceListByDriver($driver_id)
  400. {
  401. #region 1.从数据库获取数据
  402. $finance_list = self::find()
  403. ->select([
  404. 'o.bus_number',//任务单号
  405. 'o.itinerary_name',//行程名称
  406. 'o.run_date',//行程日期
  407. 'finance_status_id' => 'o.finance_status',//报账状态代号
  408. 'finance_status' => DictType::find()->select('type_name')->where('id = o.finance_status')->limit(1),//报账状态
  409. 'finance_price' => 'e.expense_value',//报账金额
  410. 'e.expense_subject_id',
  411. 'run_status_id' => 'o.run_status',
  412. 'run_status' => DictType::find()->select('type_name')->where('id = o.run_status')->limit(1),
  413. 'finance_log' => BusOrderStatusLog::find()->select('msg')->where('bus_number = o.bus_number and type = 432 and after_status = o.finance_status')->orderBy(['id' => SORT_DESC])->limit(1),//日志
  414. ])
  415. ->from(self::tableName() . ' as o')
  416. ->innerJoin(RunBusExpenses::tableName() . ' as e', 'o.bus_number = e.bus_number')
  417. ->where([
  418. 'and',
  419. ['=', 'o.send_bus_driver_res_id', $driver_id],
  420. ['<=', 'o.run_date', date('Y-m-d', time())],
  421. ['>=', 'o.run_date', date('Y-m-d', strtotime(" -1 month "))],
  422. ['=', 'o.cancel_flag', 0],
  423. ['=', 'e.cancel_flag', 0],
  424. ['=', 'run_status', 438],
  425. ])
  426. ->orderBy(['o.run_date' => SORT_DESC, 'o.start_time' => SORT_DESC])
  427. ->asArray()->all();
  428. #endregion
  429. #region 2.整理数据
  430. $result = [];
  431. foreach ($finance_list as $key => $vel) {
  432. if (!isset($result[$vel['bus_number']])) {
  433. $result[$vel['bus_number']] = $vel;
  434. $result[$vel['bus_number']]['finance_price'] = 0;
  435. }
  436. if (in_array($vel['expense_subject_id'], [465, 466, 467])) {
  437. $result[$vel['bus_number']]['finance_price'] += $vel['finance_price'];
  438. }
  439. }
  440. $result = array_merge($result);
  441. #endregion
  442. return $result;
  443. }
  444. /**
  445. * Function Description:未报帐消息提醒
  446. * Function Name: sendFinanceMsg
  447. *
  448. * @return array
  449. *
  450. * @author 张帅
  451. */
  452. public function sendFinanceMsg()
  453. {
  454. #region 1.找出需要报账提醒的行程
  455. $itinerary_list = BusItinerary::find()
  456. ->select('itinerary_id,max(station_seq_id) as station_seq_id')
  457. ->where('cancel_flag = 0')
  458. ->groupBy('itinerary_id');
  459. $itinerary_list = BusItinerary::find()
  460. ->select('bi.itinerary_id,bi.station_seq_id,bi.start_time,bi.day_seq_id')
  461. ->from(BusItinerary::tableName() . ' as bi')
  462. ->innerJoin(['i1' => $itinerary_list], 'bi.itinerary_id = i1.itinerary_id and bi.station_seq_id = i1.station_seq_id')
  463. ->where('cancel_flag = 0');
  464. $finance_list = self::find()
  465. ->select([
  466. 'o.bus_number',
  467. 'o.finance_status',
  468. 'driver_id' => 'o.send_bus_driver_res_id',
  469. 'o.run_date',
  470. 'i.start_time',
  471. 'o.itinerary_id',
  472. 'o.itinerary_name',
  473. 'i.station_seq_id',
  474. ])
  475. ->from(self::tableName() . ' as o')
  476. ->innerJoin(['i' => $itinerary_list], 'o.itinerary_id = i.itinerary_id')
  477. ->where([
  478. 'and',
  479. ['>=', 'i.start_time', date('H') . '00'],
  480. ['<', 'i.start_time', date('H', strtotime("+1 hours")) . '00'],
  481. [
  482. 'or',
  483. [
  484. 'and',
  485. ['=', 'day_seq_id', 1],
  486. ['=', 'o.run_date', date("Y-m-d", strtotime("-1 day"))],
  487. ],
  488. [
  489. 'and',
  490. ['=', 'day_seq_id', 2],
  491. ['=', 'o.run_date', date("Y-m-d", strtotime("-2 day"))],
  492. ],
  493. ],
  494. ['=', 'o.finance_status', 444],
  495. ['!=', 'o.send_bus_driver_res_id', ''],
  496. ['=', 'o.cancel_flag', 0],
  497. ['=', 'o.run_status', 438],
  498. ])
  499. ->orderBy(['i.start_time' => SORT_ASC])
  500. ->asArray()->all();
  501. #endregion
  502. #region 2.插入信息表数据
  503. if (count($finance_list) > 0) {
  504. $msg_list = [];
  505. foreach ($finance_list as $key => $vel) {
  506. $msg_list[] = [
  507. 'CANCEL_FLAG' => 0,
  508. 'CREATE_USER_ID' => 1,
  509. 'CREATE_TIME' => date('Y-m-d H:i:s'),
  510. 'UPDATE_USER_ID' => 1,
  511. 'UPDATE_TIME' => date('Y-m-d H:i:s'),
  512. 'BUS_NUMBER' => $vel['bus_number'],
  513. 'DRIVER_ID' => $vel['driver_id'],//9181,
  514. 'MSG_TYPE' => 490,
  515. 'SEND_MESSAGE' => date('m', strtotime($vel['run_date'])) . '月' . date('d', strtotime($vel['run_date'])) . '日,(' . $vel['itinerary_name'] . ')的出车任务还未进行报账,请及时进行报账,点击进入相应任务的报账页面,该任务已报账,再次点击提示“该任务已完成报账”',
  516. 'IS_READ' => 0,
  517. ];
  518. };
  519. $res = Yii::$app->db->createCommand()->batchInsert(DriverMessage::tableName(),
  520. ['CANCEL_FLAG', 'CREATE_USER_ID', 'CREATE_TIME', 'UPDATE_USER_ID', 'UPDATE_TIME', 'BUS_NUMBER', 'DRIVER_ID', 'MSG_TYPE', 'SEND_MESSAGE', 'IS_READ'],
  521. $msg_list)->execute();
  522. if ($res) {
  523. return $msg_list;
  524. } else {
  525. return [];
  526. }
  527. } else {
  528. return [];
  529. }
  530. #endregion
  531. }
  532. public function countBusOrderFromStatus($driver_res_id, $run_date, $run_status)
  533. {
  534. $total_count = self::find()
  535. ->from(self::tableName())
  536. ->where(
  537. [
  538. 'and',
  539. ['=', 'send_bus_driver_res_id', $driver_res_id],
  540. ['=', 'run_date', $run_date],
  541. ['=', 'run_status', $run_status]
  542. ]
  543. )->count();
  544. return $total_count;
  545. }
  546. /**
  547. * 根据司机、车辆、日期等信息模糊查询出任务列表信息
  548. */
  549. public function getTaskByParam($driver_name,$bus_no,$run_date){
  550. $filter = ['and',['=','bo.cancel_flag',0]];
  551. $filter[] = ['and',['=','bb.cancel_flag',0]];
  552. $filter[] = ['and',['=','bd.cancel_flag',0]];
  553. if($driver_name != ''){
  554. //根据司机名字模糊查询出可能的司机资源id
  555. $driver_id_list = BaseDriver::find()->select(['driver_id as send_bus_driver_res_id'])->where(['and',['=','cancel_flag',0],['like','driver_name',$driver_name]])->asArray()->all();
  556. if(!$driver_id_list){ //没找到匹配的司机
  557. $filter[] = ['=','send_bus_driver_res_id','null'];
  558. }else{
  559. $filter[] = ['in','send_bus_driver_res_id',$driver_id_list];
  560. }
  561. }
  562. if($bus_no != ''){
  563. //根据车牌号查询出可能的车辆资源id
  564. $bus_id_list = BaseBus::find()->select('bus_id as send_bus_res_id')->where(['like','bus_no',$bus_no])->asArray()->all();
  565. if(!$bus_id_list){ //如果输入了车牌号,并且没有该车牌号信息
  566. $filter[] = ['=','send_bus_res_id','null'];
  567. }else{
  568. $filter[] = ['in','send_bus_res_id',$bus_id_list];
  569. }
  570. }
  571. if($run_date != ''){
  572. $filter[] = ['like','run_date',$run_date];
  573. }
  574. $task_list = self::find()
  575. ->select(['bo.run_date','bo.bus_number','bo.run_id','bo.bus_order_id','bo.start_time','bo.saled_count','bo.itinerary_name','bb.bus_no','bd.driver_name','bo.run_status'])
  576. ->from(BusOrder::tableName().' as bo')
  577. ->innerJoin(BaseBus::tableName().' as bb','bo.send_bus_res_id = bb.bus_id' )
  578. ->innerJoin(BaseDriver::tableName().' as bd','bo.send_bus_driver_res_id = bd.driver_id')
  579. ->filterWhere($filter)
  580. ->orderBy(['run_date'=>SORT_DESC])
  581. ->asArray()->all();
  582. // ->createCommand()->getRawSql();
  583. return $task_list;
  584. }
  585. public function getRunIdByBusNumber($bus_number){
  586. $result = self::find()->select("run_id,bus_order_id")->where(['bus_number' => $bus_number, 'cancel_flag' => 0])->asArray()->one();
  587. return $result;
  588. }
  589. }