DtalkRobot.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\setting;
  10. use app\common\enum\dtalk\RobotSence;
  11. use app\store\controller\Controller;
  12. use app\store\model\DtalkRobot as DtalkRobotModel;
  13. /**
  14. * Class DtalkRobot
  15. * 钉钉机器人
  16. *
  17. * @Author: Yeshihao
  18. * @DateTime: 2024/8/9 17:28
  19. * @package app\store\controller\setting
  20. */
  21. class DtalkRobot extends Controller
  22. {
  23. /**
  24. * [index]
  25. *
  26. * @Author: Yeshihao
  27. * @DateTime: 2024/8/9 17:28
  28. * @return mixed
  29. */
  30. public function index()
  31. {
  32. $model = new DtalkRobotModel;
  33. $list = $model->getList();
  34. $robotSence = RobotSence::data();
  35. return $this->fetch('index', compact('list', 'robotSence'));
  36. }
  37. /**
  38. * [delete]
  39. * 删除
  40. *
  41. * @Author: Yeshihao
  42. * @DateTime: 2024/8/9 18:24
  43. * @param $id
  44. * @return array|bool
  45. * @throws \think\exception\DbException
  46. */
  47. public function delete($id)
  48. {
  49. $model = DtalkRobotModel::detail($id);
  50. if (!$model->setDelete()) {
  51. return $this->renderError($model->getError() ?: '删除失败');
  52. }
  53. return $this->renderSuccess('删除成功');
  54. }
  55. /**
  56. * 添加配送模板
  57. *
  58. * @return array|mixed
  59. * @throws \think\Exception
  60. * @throws \think\exception\PDOException
  61. */
  62. public function add()
  63. {
  64. if (!$this->request->isAjax()) {
  65. $robotSence = RobotSence::data();
  66. return $this->fetch('add', compact('robotSence'));
  67. }
  68. // 新增记录
  69. $model = new DtalkRobotModel;
  70. if ($model->add($this->postData())) {
  71. return $this->renderSuccess('添加成功', url('setting.dtalk_robot/index'));
  72. }
  73. return $this->renderError($model->getError() ?: '添加失败');
  74. }
  75. /**
  76. * 编辑配送模板
  77. *
  78. * @param $delivery_id
  79. * @return array|mixed
  80. * @throws \think\Exception
  81. * @throws \think\exception\DbException
  82. * @throws \think\exception\PDOException
  83. */
  84. public function edit($id)
  85. {
  86. // 模板详情
  87. $model = DtalkRobotModel::detail($id);
  88. if (!$this->request->isAjax()) {
  89. $robotSence = RobotSence::data();
  90. return $this->fetch('edit', compact('model', 'robotSence'));
  91. }
  92. // 更新记录
  93. if ($model->edit($this->postData())) {
  94. return $this->renderSuccess('更新成功');
  95. }
  96. return $this->renderError($model->getError() ?: '更新失败');
  97. }
  98. }