12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\common\model\base\dic;
- /**
- * @title : 字典模型模型
- * @desc :
- * @Author : Rock
- * @Date : 2021-12-04 09:58:38
- * @LastEditTime : 2022-06-28 10:21:38
- */
- use app\common\model\Common;
- class Dic extends Common{
- protected $name = "system_dic";
- protected $append = [
- 'group_name',
- 'status_txt'
- ];
- static public function statusList()
- {
- return [1=>'启用',2=>'禁用'];
- }
- public function getStatusTxtAttr($value,$data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : 0);
- $statusList = $this->statusList();
- return isset($statusList[$value])?$statusList[$value]:'';
- }
- public function getGroupNameAttr($value,$data)
- {
- $value = isset($data['group_code'])?$data['group_code']:'';
- $DicGroupList = cache('DIC_GROUP_'.$value);
- if(empty($DicGroupList)){
- $DicGroupList = DicGroup::where('group_code',$value)->column('group_name','group_code');
- cache('DIC_GROUP_'.$value,$DicGroupList,7200);
- }
- return isset($DicGroupList[$value])?$DicGroupList[$value]:'';
- }
- /**
- * @title: 重置排序号
- * @desc:
- * @param {int} {group_id} {} {分组ID}
- * @return {*}
- * @Author: Rock
- * @Date: 2021-12-04 10:06:46
- * @LastEditTime: Do not edit
- */
- static public function resetSort($group_id)
- {
- $list = self::where('group_id',$group_id)->order('sort ASC')->select();
- foreach($list as $key=>$val){
- $val->sort = $key+1;
- $val->save();
- }
- }
- /**
- * @title:取得最大的排序号
- * @desc:
- * @param {int} {group_id} {} {分组ID}
- * @return {*}
- * @Author: Rock
- * @Date: 2021-12-04 10:07:43
- * @LastEditTime: Do not edit
- */
- static public function getMaxSort($group_id)
- {
- $max = self::where('group_id',$group_id)->max('sort');
- return $max + 1;
- }
- /**
- * @title: 创建字典
- * @desc:
- * @param {array} {data} {} {字典数据}
- * @return {*}
- * @Author: Rock
- * @Date: 2021-12-13 18:41:39
- * @LastEditTime: Do not edit
- */
- static public function createDic($data)
- {
- $code = !empty($data['code'])?$data['code']:getStrFirstChar($data['title']);
- $sort = self::where('group_code',$data['group_code'])->max('sort');
- if(empty($data['sort'])){
- $sort +=1;
- }else{
- $sort = $data['sort'];
- }
- $info = self::where('code',$code)->where('group_code',$data['group_code'])->find();
- if(empty($info)){
- $data['code'] = $code;
- }else{
- $data['code'] = $code.$sort;
- }
- return self::create($data);
- }
- }
|