RoutineTemplate.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\adminapi\controller\v1\application\routine;
  3. use think\Request;
  4. use think\facade\Route as Url;
  5. use app\adminapi\controller\AuthController;
  6. use crmeb\services\{FormBuilder as Form, UtilService as Util};
  7. use app\models\routine\RoutineTemplate as RoutineTemplateModel;
  8. class RoutineTemplate extends AuthController
  9. {
  10. /**
  11. * 显示资源列表
  12. *
  13. * @return \think\Response
  14. */
  15. public function index()
  16. {
  17. $where = Util::getMore([
  18. ['page', 1],
  19. ['limit', 20],
  20. ['name', ''],
  21. ['status', '']
  22. ], $this->request);
  23. $list = RoutineTemplateModel::SystemPage($where);
  24. return $this->success($list);
  25. }
  26. /**
  27. * 显示创建资源表单页.
  28. *
  29. * @return \think\Response
  30. */
  31. public function create()
  32. {
  33. $f = array();
  34. $f[] = Form::input('tempkey', '模板编号');
  35. $f[] = Form::input('tempid', '模板ID');
  36. $f[] = Form::input('name', '模板名');
  37. $f[] = Form::input('content', '回复内容')->type('textarea');
  38. $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  39. return $this->makePostForm('添加模板消息', $f, Url::buildUrl('/app/routine'), 'POST');
  40. }
  41. /**
  42. * 保存新建的资源
  43. *
  44. * @param \think\Request $request
  45. * @return \think\Response
  46. */
  47. public function save(Request $request)
  48. {
  49. $data = Util::postMore([
  50. 'tempkey',
  51. 'tempid',
  52. 'name',
  53. 'content',
  54. ['status', 0]
  55. ]);
  56. if ($data['tempkey'] == '') return $this->fail('请输入模板编号');
  57. if ($data['tempkey'] != '' && RoutineTemplateModel::be($data['tempkey'], 'tempkey'))
  58. return $this->fail('请输入模板编号已存在,请重新输入');
  59. if ($data['tempid'] == '') return $this->fail('请输入模板ID');
  60. if ($data['name'] == '') return $this->fail('请输入模板名');
  61. if ($data['content'] == '') return $this->fail('请输入回复内容');
  62. $data['add_time'] = time();
  63. RoutineTemplateModel::create($data);
  64. return $this->success('添加模板消息成功!');
  65. }
  66. /**
  67. * 显示指定的资源
  68. *
  69. * @param int $id
  70. * @return \think\Response
  71. */
  72. public function read($id)
  73. {
  74. //
  75. }
  76. /**
  77. * 显示编辑资源表单页.
  78. *
  79. * @param int $id
  80. * @return \think\Response
  81. */
  82. public function edit($id)
  83. {
  84. if (!$id) return $this->fail('数据不存在');
  85. $product = RoutineTemplateModel::get($id);
  86. if (!$product) return $this->fail('数据不存在!');
  87. $f = array();
  88. $f[] = Form::input('tempkey', '模板编号', $product->getData('tempkey'))->disabled(1);
  89. $f[] = Form::input('name', '模板名', $product->getData('name'))->disabled(1);
  90. $f[] = Form::input('tempid', '模板ID', $product->getData('tempid'));
  91. $f[] = Form::radio('status', '状态', $product->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  92. return $this->makePostForm('编辑模板消息', $f, Url::buildUrl('/app/routine/' . $id), 'PUT');
  93. }
  94. /**
  95. * 保存更新的资源
  96. *
  97. * @param \think\Request $request
  98. * @param int $id
  99. * @return \think\Response
  100. */
  101. public function update(Request $request, $id)
  102. {
  103. $data = Util::postMore([
  104. 'tempid',
  105. ['status', 0]
  106. ]);
  107. if ($data['tempid'] == '') return $this->fail('请输入模板ID');
  108. if (!$id) return $this->fail('数据不存在');
  109. $product = RoutineTemplateModel::get($id);
  110. if (!$product) return $this->fail('数据不存在!');
  111. RoutineTemplateModel::edit($data, $id);
  112. return $this->success('修改成功!');
  113. }
  114. /**
  115. * 删除指定资源
  116. *
  117. * @param int $id
  118. * @return \think\Response
  119. */
  120. public function delete($id)
  121. {
  122. if (!$id) return $this->fail('数据不存在!');
  123. if (!RoutineTemplateModel::del($id))
  124. return $this->fail(RoutineTemplateModel::getErrorInfo('删除失败,请稍候再试!'));
  125. else
  126. return $this->success('删除成功!');
  127. }
  128. /**
  129. * 修改状态
  130. * @param $id
  131. * @param $status
  132. * @return mixed
  133. */
  134. public function set_status($id, $status)
  135. {
  136. if ($status == '' || $id == 0) return $this->fail('参数错误');
  137. RoutineTemplateModel::where(['id' => $id])->update(['status' => $status]);
  138. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  139. }
  140. }