StoreServiceSpeechcraftCate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\kefu;
  12. use app\Request;
  13. use think\facade\App;
  14. use app\adminapi\controller\AuthController;
  15. use app\services\kefu\service\StoreServiceSpeechcraftCateServices;
  16. /**
  17. * Class StoreServiceSpeechcraftCate
  18. * @package app\adminapi\controller\v1\application\wechat
  19. */
  20. class StoreServiceSpeechcraftCate extends AuthController
  21. {
  22. /**
  23. * StoreServiceSpeechcraftCate constructor.
  24. * @param App $app
  25. * @param StoreServiceSpeechcraftCateServices $services
  26. */
  27. public function __construct(App $app, StoreServiceSpeechcraftCateServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 获取列表
  34. * @return mixed
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['name', '']
  43. ]);
  44. $where['owner_id'] = 0;
  45. $where['type'] = 1;
  46. return app('json')->success($this->services->getCateList($where));
  47. }
  48. /**
  49. * 获取创建表单
  50. * @return mixed
  51. * @throws \FormBuilder\Exception\FormBuilderException
  52. */
  53. public function create()
  54. {
  55. return app('json')->success($this->services->createForm());
  56. }
  57. /**
  58. * 保存数据
  59. * @return mixed
  60. */
  61. public function save()
  62. {
  63. $data = $this->request->postMore([
  64. ['name', ''],
  65. ['sort', 0],
  66. ]);
  67. if (!$data['name']) {
  68. return app('json')->fail(400100);
  69. }
  70. if ($this->services->count(['name' => $data['name'], 'type' => 1, 'owner_id' => 0])) {
  71. return app('json')->fail(400101);
  72. }
  73. $data['add_time'] = time();
  74. $data['type'] = 1;
  75. $this->services->save($data);
  76. return app('json')->success(100021);
  77. }
  78. /**
  79. * 获取修改表单
  80. * @param $id
  81. * @return mixed
  82. * @throws \FormBuilder\Exception\FormBuilderException
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function edit($id)
  88. {
  89. return app('json')->success($this->services->editForm((int)$id));
  90. }
  91. /**
  92. * 修改保存
  93. * @param Request $request
  94. * @param $id
  95. * @return mixed
  96. */
  97. public function update(Request $request, $id)
  98. {
  99. $data = $request->postMore([
  100. ['name', ''],
  101. [['sort', 'd'], 0],
  102. ]);
  103. if (!$data['name']) {
  104. return app('json')->fail(400100);
  105. }
  106. $cateInfo = $this->services->get($id);
  107. if (!$cateInfo) {
  108. return app('json')->fail(400103);
  109. }
  110. $cateInfo->name = $data['name'];
  111. $cateInfo->sort = $data['sort'];
  112. $cateInfo->save();
  113. return app('json')->success(100001);
  114. }
  115. /**
  116. * 删除
  117. * @param $id
  118. * @return mixed
  119. */
  120. public function delete($id)
  121. {
  122. if ($id == 0) return app('json')->fail(400273);
  123. $cateInfo = $this->services->get($id);
  124. if (!$cateInfo) {
  125. return app('json')->fail(400103);
  126. }
  127. $cateInfo->delete();
  128. return app('json')->success(100002);
  129. }
  130. }