SystemDictDataLogic.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\logic\system;
  8. use plugin\saiadmin\basic\think\BaseLogic;
  9. use plugin\saiadmin\exception\ApiException;
  10. use plugin\saiadmin\app\model\system\SystemDictData;
  11. use plugin\saiadmin\app\model\system\SystemDictType;
  12. use plugin\saiadmin\app\cache\DictCache;
  13. use plugin\saiadmin\utils\Helper;
  14. /**
  15. * 字典类型逻辑层
  16. */
  17. class SystemDictDataLogic extends BaseLogic
  18. {
  19. /**
  20. * 构造函数
  21. */
  22. public function __construct()
  23. {
  24. $this->model = new SystemDictData();
  25. }
  26. /**
  27. * 添加数据
  28. * @param $data
  29. * @return mixed
  30. */
  31. public function add($data): mixed
  32. {
  33. $type = SystemDictType::where('id', $data['type_id'])->findOrEmpty();
  34. if ($type->isEmpty()) {
  35. throw new ApiException('字典类型不存在');
  36. }
  37. $data['code'] = $type->code;
  38. $model = $this->model->create($data);
  39. DictCache::clear();
  40. return $model->getKey();
  41. }
  42. }