20], [['SEND_BUS_NO', 'SEND_DRIVER_NAME', 'SEND_DRIVER_MOBILE', 'SEND_TOUR_GUIDE_NAME', 'SEND_TOUR_GUIDE_MOBILE'], 'string', 'max' => 100], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'ID' => 'ID', 'CANCEL_FLAG' => 'Cancel Flag', 'CREATE_USER_ID' => 'Create User ID', 'CREATE_TIME' => 'Create Time', 'UPDATE_USER_ID' => 'Update User ID', 'UPDATE_TIME' => 'Update Time', 'RUN_ID' => 'Run ID', 'BUS_ORDER_ID' => 'Bus Order ID', 'BUS_ORG_ID' => 'Bus Org ID', 'BUS_TYPE_RES_ID' => 'Bus Type Res ID', 'BUS_COST_TYPE' => 'Bus Cost Type', 'BUS_COST_BY_BUS' => 'Bus Cost By Bus', 'TOUR_ORG_ID' => 'Tour Org ID', 'TOUR_COST_TYPE' => 'Tour Cost Type', 'TOUR_COST_BY_BUS' => 'Tour Cost By Bus', 'DRIVER_SUBSIDY' => 'Driver Subsidy', 'TOUR_SUBSIDY' => 'Tour Subsidy', 'TRAVEL_SUBSIDY' => 'Travel Subsidy', 'SEND_BUS_ORG_ID' => 'Send Bus Org ID', 'SEND_BUS_RES_ID' => 'Send Bus Res ID', 'SEND_BUS_TYPE_RES_ID' => 'Send Bus Type Res ID', 'SEND_BUS_DRIVER_RES_ID' => 'Send Bus Driver Res ID', 'SEND_BUS_NO' => 'Send Bus No', 'SEND_DRIVER_NAME' => 'Send Driver Name', 'SEND_DRIVER_MOBILE' => 'Send Driver Mobile', 'SEND_BUS_USER_ID' => 'Send Bus User ID', 'SEND_BUS_TIME' => 'Send Bus Time', 'SEND_BUS_CONFIRM_USER_ID' => 'Send Bus Confirm User ID', 'SEND_BUS_CONFIRM_TIME' => 'Send Bus Confirm Time', 'SEND_TOUR_ORG_ID' => 'Send Tour Org ID', 'SEND_TOUR_GUIDE_RES_ID' => 'Send Tour Guide Res ID', 'SEND_TOUR_GUIDE_NAME' => 'Send Tour Guide Name', 'SEND_TOUR_GUIDE_MOBILE' => 'Send Tour Guide Mobile', 'SEND_TOUR_USER_ID' => 'Send Tour User ID', 'SEND_TOUR_TIME' => 'Send Tour Time', 'SEND_TOUR_CONFIRM_USER_ID' => 'Send Tour Confirm User ID', 'SEND_TOUR_CONFIRM_TIME' => 'Send Tour Confirm Time', 'SEAT_COUNT' => '座位数 ', 'SALED_COUNT' => 'Saled Count', 'ALLOW_SELECT_SEAT' => 'Allow Select Seat', 'CURRENT_ORDER_ID' => '当前已经过站点顺序ID', 'RUN_BUS_STATUS' => 'Run Bus Status', 'BRAND_RES_ID' => 'Brand Res ID', 'SEND_STATUS' => 'Send Status', 'FINANCE_STATUS' => '报账状态', 'START_ZONE_ID' => '区域res_id', 'GROUP_LINE_FLAG' => '组合线路标志 1:组合线路 0:非组合线路', 'REAL_TOTAL_COUNT' => '最终实际上车人数(该字段主要用于司机端)', 'COST_MOTORCADE_ID' => '成本id车队 对应suplier_id', 'COST_TYPE' => '结算类型 对应dict_type.id', 'COST_PRICE' => '成本单价', ]; } /** * Function Description:获取前一天的班次 * Function Name: getCostByRunBus * * @return array|\yii\db\ActiveRecord[] * * @author 张帅 */ public function getCostByRunBus() { $result = self::find() ->select([ 'rb.RUN_ID',//班次id 'rb.BUS_ORDER_ID',//车号 'BUS_ID' => 'rb.send_bus_res_id',//车资源id 'BUS_ORG_ID' => BaseBus::find()->select('org_id')->where('bus_id = rb.send_bus_res_id')->limit(1),//实际所用车车队id 'rb.COST_MOTORCADE_ID',//规定车队id 'DRIVER_ID' => 'rb.send_bus_driver_res_id',//司机id 'GUIDE_ID' => 'rb.send_tour_guide_res_id',//导游id 'rb.SEAT_COUNT',//座位数 'rb.SALED_COUNT',//已售座位数 'rb.REAL_TOTAL_COUNT',//实际上车人数 'rb.COST_TYPE',//结算类型 'rb.COST_PRICE',//结算单价 'rm.RUN_DATE', 'rm.RUN_TIME', 'LINE_ID' => 'rm.prod_id',//线路id 'ol.LINE_TYPE',//线路类型 'RUN_BUS_ID' => 'rb.id',//班次车次唯一id 'rb.SEND_BUS_TYPE_RES_ID',//车号 ]) ->from(self::tableName() . ' as rb') ->leftJoin(RunMain::tableName() . ' as rm', 'rb.run_id = rm.run_id') ->leftJoin(OperaLine::tableName() . ' as ol', 'ol.line_id = rm.prod_id') ->where([ 'and', ['=', 'rm.run_date', date('Y-m-d', strtotime("-1 day"))], ['=', 'rb.cancel_flag', 0], ['in', 'rb.run_bus_status', [138,139,141]], ])->asArray()->all(); return $result; } /** * Function Description:获取要添加的车次的基本信息 * Function Name: getBusInfoArray * @param string $bus_info_str 车次信息字符 * * @return bool * * @author 张帅 */ public function getBusInfoArray($bus_info_str) { $bus_info_str = substr($bus_info_str, 1, -1); $bus_info_arr = explode(',', $bus_info_str); $result['bus_type_res_id'] = (!isset($bus_info_arr[0]) || empty($bus_info_arr[0])) ? false : $bus_info_arr[0];//车资源类型id $result['brand_res_id'] = (!isset($bus_info_arr[1]) || empty($bus_info_arr[1])) ? false : $bus_info_arr[1];//品牌id $result['cost_motorcade_id'] = (!isset($bus_info_arr[2]) || empty($bus_info_arr[2])) ? false : $bus_info_arr[2];//承运车队id $result['cost_type'] = (!isset($bus_info_arr[3]) || empty($bus_info_arr[3])) ? false : $bus_info_arr[3];//成本类型 $result['cost_price'] = (!isset($bus_info_arr[4]) || empty($bus_info_arr[4])) ? false : $bus_info_arr[4];//成本单价 $result['allow_select_seat'] = (!isset($bus_info_arr[5]) || empty($bus_info_arr[5])) ? 156 : $bus_info_arr[5];//是否支持选座 #region 判断必要信息是否传全 foreach ($result as $key => $vel) { if ($vel === false) { return false; } } #endregion return $result; } /** * Function Description:获取车号 * Function Name: getBusNoByLineDate * @param int $line_id 线路id * @param string $run_date 出发日期 * * @return array|int|mixed|null|ActiveRecord * * @author 张帅 */ public function getBusNoByLineDate($line_id, $run_date) { $result = self::find() ->select('max(rb.bus_order_id) as bus_order_id') ->from(self::tableName() . ' as rb') ->leftJoin(RunMain::tableName() . ' as rm', 'rb.run_id = rm.run_id') ->where([ 'and', ['=', 'rm.prod_id', $line_id], ['=', 'rm.run_date', $run_date], ['=', 'rm.run_status', 138], ]) ->asArray()->one(); #region 判断该班次是否有车 if (count($result) == 0) { return 1; } #endregion $result = $result['bus_order_id'] + 1; return $result; } /** * Function Description:为班次添加车次 * Function Name: addBusForRun * @param array $run_info * @param array /bool $bus_info * @param array $bus_res_info * @param array $matrix_arr * @param array $run_station_info * @param int $bus_order_id * @param int $user_id * * @return mixed * * @author 张帅 */ public function addBusForRun($run_info, $bus_info, $bus_res_info, $matrix_arr, $run_station_info, $bus_order_id, $user_id) { #region run_bus新增数据 $run_bus_val = [ 'CANCEL_FLAG' => 0, 'CREATE_USER_ID' => $user_id, 'CREATE_TIME' => date('Y-m-d H:i:s'), 'UPDATE_USER_ID' => $user_id, 'UPDATE_TIME' => date('Y-m-d H:i:s'), 'RUN_ID' => $run_info['run_id'], 'BUS_ORDER_ID' => $bus_order_id, 'BUS_TYPE_RES_ID' => $bus_info['bus_type_res_id'], 'SEAT_COUNT' => $bus_res_info['total_count'], 'ALLOW_SELECT_SEAT' => $bus_info['allow_select_seat'], 'BRAND_RES_ID' => $bus_info['brand_res_id'], 'COST_MOTORCADE_ID' => $bus_info['cost_motorcade_id'], 'RUN_BUS_STATUS' => $run_info['run_status'], 'COST_TYPE' => $bus_info['cost_type'], 'COST_PRICE' => $bus_info['cost_price'], ]; #endregion #region run_x新增数据 $run_date = $run_info['run_date']; $x_date = explode('-', $run_date); $run_x_name = 'run_' . $x_date[0] . $x_date[1];//run_x表名 $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 $run_x_key = []; foreach ($run_station_info as $station_key => $station_vel) { foreach ($matrix_arr as $matrix_key => $matrix_vel) { #region run_x每条数据 $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 '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 'RUN_LOCK_TYPE' => 121, 'RUN_DATE' => $run_date, 'LOCK_COUNT' => 1, 'ORDER_ID' => $station_vel['station_order_id'], 'STATION_RES_ID' => $station_vel['station_res_id'], 'STATION_INOUT_TYPE' => $station_vel['station_inout_type'], 'BUS_ORDER_ID' => $bus_order_id, 'BUS_RES_ID' => $bus_info['bus_type_res_id'], 'SEAT_X' => $matrix_vel['pos_x'], 'SEAT_Y' => $matrix_vel['pos_y'], 'SEAT_TYPE' => $matrix_vel['pos_type'], 'SEAT_SEQ_ID' => $matrix_vel['pos_seq_id'], 'SEAT_NAME' => $matrix_vel['pos_name'], 'SEAT_STATUS' => 0, 'CREATE_USER_ID' => $user_id, 'CREATE_TIME' => date('Y-m-d H:i:s'), 'ORDER_MAIN_ID' => 0, 'ORDER_MAIN_PROD_ID' => 0, 'ORDER_PROD_ID' => 0, 'ORDER_SEQ_ID' => 0, 'ORDER_LOCK_USER_ID' => 0, 'ORDER_LOCK_TIME' => date('Y-m-d H:i:s'), 'ORDER_LOCK_END_TIME' => date('Y-m-d H:i:s'), 'HUMAN_TYPE' => 0, 'AREA_ID' => $station_vel['area_id'], 'ALLOW_SELECT_SEAT' => $bus_info['allow_select_seat'], 'CHECK_USER_ID' => 0, 'CHECK_TIME' => '', 'CANCEL_FLAG' => 0, ]; #endregion #region run_x添加时的键值 if (count($run_x_key) == 0) { $run_x_key = array_keys($run_x_one); } #endregion #region 将数据加入$run_x_val $run_x_val[] = $run_x_one; #endregion } } #endregion $transaction = Yii::$app->db->beginTransaction(); try { #region 在run_bus表中添加数据 $this->attributes = $run_bus_val; $run_bus_id = $this->insert(); if (!$run_bus_id) { throw new Exception('run_bus添加失败'); } #endregion #region 修改run_stock数据 $update_value = [ 'UPDATE_USER_ID' => $user_id, 'UPDATE_TIME' => date('Y-m-d H:i:s'), 'TOTAL_COUNT' => new Expression('TOTAL_COUNT+' . $bus_res_info['total_count']), ]; $update_where = [ 'and', ['=', 'run_id', $run_info['run_id']], ['=', 'seat_type', 72], ['=', 'cancel_flag', 0], ]; $res = RunStock::updateAll($update_value, $update_where); if (!$res) { throw new Exception('更新run_stock失败'); } #endregion #region 添加run_x数据 $res = Yii::$app->db->createCommand()->batchInsert($run_x_name, $run_x_key, $run_x_val)->execute(); if (!$res) { throw new Exception('添加座位图失败'); } #endregion $transaction->commit(); $result['code'] = '0'; $result['info'] = '加车成功'; $result['data'] = [ 'bus_order_id' => $bus_order_id, 'run_bus_id' => $this->ID, 'seat_count' => $bus_res_info['total_count'] ]; } catch (Exception $e) { # 回滚事务 $result['code'] = '1'; $result['info'] = '加车失败'; $result['error'] = $e->getMessage(); } return $result; } /** * Function Description:获取车次信息 * Function Name: getBusInfo * @param $run_id * * @return array|ActiveRecord[] * * @author 李健 */ public function getBusInfo($run_id) { $select = [ 'res.res_name as property', 'run.bus_order_id', 'allow_select_seat'=>new Expression('if(run.allow_select_seat>0,"支持","不支持")'), 'send_bus_res_id'=>new Expression('if(run.send_bus_res_id>0,"已派","未派")'), 'send_bus_driver_res_id'=>new Expression('if(run.send_bus_driver_res_id>0,"已派","未派")'), 'bus_brand'=>new Expression('if(res1.res_name is null,"",res1.res_name)') ]; $where = ['and']; $where[] = ['=', 'run.run_id', $run_id]; $where[] = ['=', 'run.cancel_flag', 0]; $res = self::find() ->select($select) ->from(self::tableName() . ' run') ->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)')) ->leftJoin(BaseResource::tableName().' res1','res1.res_id=run.brand_res_id and res1.res_type_id=134') ->where($where) ->asArray() ->all(); return $res; } /** * Function Description:根据RUN_ID获取车辆数及选座状态 * Function Name: getRunHasCar * @param $run_id * * @return array|ActiveRecord[] * * @author 李健 */ public function getRunHasCar($run_id) { $select = [ 'id'=>new Expression('if(b.send_bus_type_res_id=0,b.bus_type_res_id,b.send_bus_type_res_id)'), 'b.allow_select_seat as selectseat', 'b.id as run_bus_id', 'b.bus_order_id as carnum', 'b.brand_res_id', 'b.cost_motorcade_id', 'b.cost_type', 'b.cost_price', 'bus_brand'=>new Expression('if(base.res_name is null,"",base.res_name)'), 'b.send_bus_res_id' ]; $where = ['and']; $where[] = ['=','b.run_id',$run_id]; $where[] = ['=','b.cancel_flag',0]; $res = self::find() ->select($select) ->from(self::tableName(). ' b') ->leftJoin(BaseResource::tableName().' base','base.res_id=b.brand_res_id and res_type_id=134') ->where($where) ->orderBy('b.bus_order_id') ->asArray() ->all(); return $res; } /** * Function Description:根据runid获取当前run_bus记录中最大record的记录 * Function Name: GetMaxOrderId * @param $runid * * @return mixed * * @author 冒炎 */ public function GetMaxOrderId($runid){ $res=self::find() ->select(['max'=>new Expression("ifnull(max(bus_order_id), 0)")]) ->from(self::tableName()) ->where(['=','run_id',$runid]) ->asArray() ->one(); return $res['max']; } /** * Function Description:获得特定run_bus记录的状态值 * Function Name: getOneBusStatus * @param $run_id * @param $bus_order_id * * @return array|null|ActiveRecord * * @author 冒炎 */ public function getOneBusStatus($run_id,$bus_order_id){ $where = ['and']; $where[] = ['=','run_id',$run_id]; $where[] = ['=','bus_order_id',$bus_order_id]; $res = self::find() ->select(['run_bus_status']) ->from(self::tableName()) ->where($where) ->asArray() ->one(); return $res; } /** * Function Description:筛选出车次组中不可以停运的车次 * Function Name: getCanNotStopRunBus * @param $bus_arr * * @return array * * @author 冒炎 */ public function getCanNotStopRunBus($bus_arr){ $select = [ 'l.line_code as prod_code', 'l.line_name as prod_name', 'a.run_id as run_id', 'a.send_bus_no as bus_no', 'a.run_bus_status as status', 'o.order_id as order_id' ]; $list =[]; foreach ($bus_arr as $val){ $run_bus = self::find() ->select($select) ->from(self::tableName() . ' a') ->leftJoin('run_main m','m.run_id=a.run_id') ->leftJoin('opera_line l','l.line_id=m.prod_id and l.cancel_flag=0') ->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)') ->where(['=','a.cancel_flag',0]) ->andWhere("a.run_id = {$val['run_id']}") ->andWhere("a.bus_order_id = {$val['bus_order_id']}") ->asArray() ->one(); if(!in_array($run_bus['status'],[137,138,139])||!empty($run_bus['bus_no'])||!empty($run_bus['order_id'])){ $list[] = $run_bus['prod_code'] . $run_bus['prod_name']; } } if(empty($list)){ return []; }else{ return $list; } } }