'int', 'code_module_category_guid' => 'string', 'code_module_category_name' => 'string', 'code_module_category_ps' => 'string', 'code_module_category_parent_guid' => 'string', 'code_module_category_sort' => 'int', 'code_module_category_global_mode' => 'int', 'code_module_category_library_type' => 'int', 'customer_guid' => 'string', 'code_module_category_audit' => 'int', 'code_module_category_create_time' => 'datetime', 'code_module_category_create_user_guid' => 'string', 'code_module_category_update_time' => 'datetime', 'code_module_category_update_user_guid' => 'string', 'code_module_category_delete_time' => 'datetime', 'code_module_category_delete_user_guid' => 'string', ]; // 设置json类型字段 protected $json = ['']; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = 'datetime'; // 创建时间 protected $createTime = 'code_module_category_create_time'; // 修改时间 protected $updateTime = 'code_module_category_update_time'; // 字典 public static $dictionaryMap = [ 'code_module_category_audit' => [ self::AUDIT_UNAUDITED => '未审核', self::AUDIT_PASS => '审核通过', self::AUDIT_FAILED => '审核未通过' ], 'code_module_category_library_type' => [ self::LIBRARY_DEFAULT => '默认', self::LIBRARY_COMMON => '公共', self::LIBRARY_PRIVATE => '私人' ], ]; // 审核状态 未审核 const AUDIT_UNAUDITED = 1; // 审核状态 审核通过 const AUDIT_PASS = 2; // 审核状态 审核未通过 const AUDIT_FAILED = 3; //库类型 默认 const LIBRARY_DEFAULT = 1; //库类型 公共 const LIBRARY_COMMON = 2; //库类型 私人 const LIBRARY_PRIVATE = 3; //主级类目guid默认值 const MASTER_DEFAULT = '0'; //父级主键字段 public $parent_guid_field = 'code_module_category_parent_guid'; //父子类目共用信息字段 const COMMON_INFO_FIELDS = [ 'code_module_category_global_mode', 'code_module_category_library_type', 'customer_guid' ]; /** * 新增前 */ public static function onBeforeInsert(self $model): void { CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model); CommonLogicCodeModuleCategory::validateCategoryInfo($model); $model->completeCreateField(); } /** * 更新前 */ public static function onBeforeUpdate(self $model): void { CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model); CommonLogicCodeModuleCategory::validateCategoryInfo($model); $model->completeUpdateField(); } /** * 删除前 */ public static function onBeforeDelete(self $model): void { $model->completeDeleteField(); } /** * 设置全局模式 * * @param $value * @return string * @date 2023-06-28 * @author xjh * @since 1.0.0 */ public function setCodeModuleCategoryGlobalModeAttr($value): string { return is_array($value) ? implode(',', $value) : $value; } /** * 获取全局模式 * * @param string $value * @return array * @date 2023-06-28 * @author xjh * @since 1.0.0 */ public function getCodeModuleCategoryGlobalModeAttr($value): array { return explode(',', $value); } /** * 查询范围-主级类目 * * @param $query * @return void * @date 2023-06-29 * @author xjh * @since 1.0.0 */ public function scopeMaster($query): void { $query->where('code_module_category.code_module_category_parent_guid', self::MASTER_DEFAULT); } /** * 查询范围-非主级类目(子类目) * * @param $query * @return void * @date 2023-07-01 * @author xjh * @since 1.0.0 */ public function scopeNotMaster($query): void { $query->where('code_module_category.code_module_category_parent_guid', '<>', self::MASTER_DEFAULT); } /** * 查询范围-过审代码块类目 * * @param $query * @return void * @date 2023-07-01 * @author xjh * @since 1.0.0 */ public function scopeAuditPass($query): void { $query->where('code_module_category.code_module_category_audit', self::AUDIT_PASS); } /** * 查询范围-未审核代码块类目 * * @param $query * @return void * @date 2023-07-05 * @author xjh * @since 1.0.0 */ public function scopeAuditUnaudited($query): void { $query->where('code_module_category.code_module_category_audit', self::AUDIT_UNAUDITED); } /** * 获取全局模式名称 * * @param string $value * @return array * @date 2023-07-01 * @author lwh * @since 1.0.0 */ public function getLangHitAttr($value, $data) { $mode = $data['code_module_category_global_mode']; $mode_arr = explode(',', $mode); $mode_name_arr = []; foreach ($mode_arr as $key => $value) { $global_mode = ModelDictionary::getDictionaryData('global_mode'); $mode_name_arr[] = ModelDictionary::getDataDictionaryName($global_mode, $value); } return $mode_name_arr; } /** * 获取库类型名称 * * @param string $value * @return string * @date 2023-07-01 * @author lwh * @since 1.0.0 */ public function getLibraryTypeAttr($value, $data) { return ModelDictionary::getDataDictionaryName(ModelDictionary::getDictionaryData('library_type'), $data['code_module_category_library_type']); } }