/** * @param string $url * @param int $id * @return array */ private static function _get_flow_data($url, $id = null) { $data = []; $name = Lib_Request::post_var('name'); $main = Lib_Request::post_var('main'); $stuff = Lib_Request::post_var('stuff'); $config = Lib_Request::post_var('config'); $name = trim($name); $main = trim($main); $stuff = trim($stuff); $config = trim($config); $flow_model = new Model_FlowInfo(); $flash_error = function ($msg, $url) { Lib_Request::flash('error', $msg); Module_HttpRequest_Router::redirect_to($url); }; if (empty($name)) { $flash_error('流程名称不能为空', $url); } if (!empty($id)) { $cond = ['name' => $name, '_id' => ['$ne' => intval($id)]]; } else { $cond = ['name' => $name]; } $flow_info = $flow_model->get_flow_by_cond($cond); if ($flow_info['errno'] == Const_Err_Base::ERR_OK && !empty($flow_info['data'])) { $flash_error('流程名称存在', $url); } if (empty($main)) { $flash_error('主流程不能为空', $url); } $mains = self::_get_array_by_str($main); $stuffs = self::_get_array_by_str($stuff); $configs = self::_get_array_by_str($config); $data = ['name' => $name, 'flow' => [Module_FlowManager_Main::FLOW_TYPE_MAIN => $mains, Module_FlowManager_Main::FLOW_TYPE_STUFF => $stuffs, Module_FlowManager_Main::FLOW_TYPE_CONFIG => $configs]]; return $data; }
/** * @return array */ public function save() { if (empty($this->id)) { $id_gen = new Model_IdGen(); $id = $id_gen->gen_inc_id_by_key(Const_DataAccess::ID_FLOW); if ($id['errno'] != Const_Err_Base::ERR_OK) { return $id; } $id = $id['data']; if (empty($id)) { return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_GET_ID_FAILD, '获取ID失败', __FILE__, __LINE__); } $this->id = $id; } if (empty($this->flow) || empty($this->id)) { return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_FLOW_EMPTY_FLOW, '[空流程] 未设置流程', __FILE__, __LINE__); } $data = [Model_FlowInfo::FIELD_FLOW_ID => $this->id, Model_FlowInfo::FIELD_FLOW_NAME => $this->name, Model_FlowInfo::FIELD_FLOW_FLOW => $this->flow, Model_FlowInfo::FIELD_FLOW_OPTIONS => $this->options]; $flow_model = new Model_FlowInfo(); $save = $flow_model->save($data); if ($save['errno'] !== Const_Err_Base::ERR_OK) { Lib_Log::error(__METHOD__ . ' faild! cause: ' . json_encode($save['data'])); return Lib_Helper::get_err_struct(Const_Err_Db::ERR_SAVE_DATA_FAIL, __METHOD__ . '数据保存失败', __FILE__, __LINE__); } return Lib_Helper::get_return_struct($this->id); }
/** * @return array */ static function all_flow() { $flow_model = new Model_FlowInfo(); return $flow_model->get_all(); }