StoreServiceSpeechcraftCateServices.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\message\service;
  12. use app\dao\other\CategoryDao;
  13. use app\services\other\CategoryServices;
  14. use crmeb\services\FormBuilder;
  15. use think\exception\ValidateException;
  16. /**
  17. * Class StoreServiceSpeechcraftCateServices
  18. * @package app\services\message\service
  19. * @property CategoryDao dao
  20. */
  21. class StoreServiceSpeechcraftCateServices extends CategoryServices
  22. {
  23. /**
  24. * 获取分类表单
  25. * @param array $data
  26. * @return mixed
  27. */
  28. public function serviceSpeechcraftCateForm(array $data = [])
  29. {
  30. $f[] = FormBuilder::input('name', '分类名称', $data['name'] ?? '')->required();
  31. $f[] = FormBuilder::number('sort', '排序', (int)($data['sort'] ?? 0))->min(0);
  32. return $f;
  33. }
  34. /**
  35. * 获取创建表单
  36. * @return array
  37. * @throws \FormBuilder\Exception\FormBuilderException
  38. */
  39. public function createForm()
  40. {
  41. return create_form('添加分类', $this->serviceSpeechcraftCateForm(), $this->url('/app/wechat/speechcraftcate'), 'POST');
  42. }
  43. /**
  44. * 获取编辑表单
  45. * @param int $id
  46. * @return array
  47. * @throws \FormBuilder\Exception\FormBuilderException
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function editForm(int $id)
  53. {
  54. $cateInfo = $this->dao->get($id);
  55. if (!$cateInfo) {
  56. throw new ValidateException('分类没有查询到');
  57. }
  58. return create_form('修改分类', $this->serviceSpeechcraftCateForm($cateInfo->toArray()), $this->url('/app/wechat/speechcraftcate/' . $id), 'PUT');
  59. }
  60. }