LangCountryServices.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\services\system\lang;
  3. use app\dao\system\lang\LangCountryDao;
  4. use app\services\BaseServices;
  5. use crmeb\exceptions\AdminException;
  6. use crmeb\services\FormBuilder as Form;
  7. use think\facade\Route as Url;
  8. class LangCountryServices extends BaseServices
  9. {
  10. /**
  11. * @param LangCountryDao $dao
  12. */
  13. public function __construct(LangCountryDao $dao)
  14. {
  15. $this->dao = $dao;
  16. }
  17. /**
  18. * 国家语言列表
  19. * @param array $where
  20. * @return array
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\DbException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. */
  25. public function LangCountryList(array $where = []): array
  26. {
  27. [$page, $limit] = $this->getPageValue();
  28. $list = $this->dao->selectList($where, '*', $page, $limit, 'id desc', true)->toArray();
  29. $count = $this->dao->count($where);
  30. return compact('list', 'count');
  31. }
  32. /**
  33. * 设置国家语言类型表单
  34. * @param $id
  35. * @return array
  36. * @throws \FormBuilder\Exception\FormBuilderException
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function LangCountryTypeForm($id)
  42. {
  43. if (!$id) throw new AdminException(100100);
  44. $info = $this->dao->get($id);
  45. if (!$info) throw new AdminException(100026);
  46. /** @var LangTypeServices $typeServices */
  47. $typeServices = app()->make(LangTypeServices::class);
  48. $typeList = $typeServices->getColumn(['status' => 1, 'is_del' => 0], 'language_name,file_name', 'id');
  49. $options[] = ['value' => 0, 'label' => '未定义'];
  50. foreach ($typeList as $item) {
  51. $options[] = ['value' => $item['id'], 'label' => $item['language_name'] . '(' . $item['file_name'] . ')'];
  52. }
  53. $field[] = Form::select('type', '选择语言类型', $info->type_id)->setOptions($options)->filterable(1);
  54. return create_form('设置语言类型', $field, Url::buildUrl('/setting/lang_country/save/' . $id), 'POST');
  55. }
  56. /**
  57. * 国家语言修改
  58. * @param $id
  59. * @param $typeId
  60. * @return bool
  61. */
  62. public function LangCountrySave($id, $typeId)
  63. {
  64. $res = $this->dao->update(['id' => $id], ['type_id' => $typeId]);
  65. if (!$res) throw new AdminException(100007);
  66. return true;
  67. }
  68. }