LangCountryServices.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 langCountryForm($id)
  42. {
  43. if ($id) $info = $this->dao->get($id);
  44. $field = [];
  45. $field[] = Form::input('name', '所属地区', $info['name'] ?? '')->required('请填写所属地区');
  46. $field[] = Form::input('code', '语言码', $info['code'] ?? '')->required('请填写语言码');
  47. return create_form($id ? '修改语言地区' : '新增语言地区', $field, Url::buildUrl('/setting/lang_country/save/' . $id), 'POST');
  48. }
  49. /**
  50. * 保存语言地区
  51. * @param $id
  52. * @param $typeId
  53. * @return bool
  54. */
  55. public function LangCountrySave($id, $data)
  56. {
  57. if ($id) {
  58. $res = $this->dao->update(['id' => $id], $data);
  59. } else {
  60. $res = $this->dao->save($data);
  61. }
  62. if (!$res) throw new AdminException(100007);
  63. return true;
  64. }
  65. /**
  66. * 删除语言地区
  67. * @param $id
  68. * @return bool
  69. */
  70. public function langCountryDel($id)
  71. {
  72. $res = $this->dao->delete($id);
  73. if (!$res) throw new AdminException(100008);
  74. return true;
  75. }
  76. }