AgentLevelTask.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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\controller\admin\v1\agent;
  12. use app\controller\admin\AuthController;
  13. use app\services\agent\AgentLevelTaskServices;
  14. use think\facade\App;
  15. /**
  16. * Class AgentLevelTask
  17. * @package app\controller\admin\v1\agent
  18. */
  19. class AgentLevelTask extends AuthController
  20. {
  21. /**
  22. * AgentLevelTask constructor.
  23. * @param App $app
  24. * @param AgentLevelTaskServices $services
  25. */
  26. public function __construct(App $app, AgentLevelTaskServices $services)
  27. {
  28. parent::__construct($app);
  29. $this->services = $services;
  30. }
  31. /**
  32. * 显示资源列表
  33. *
  34. * @return \think\Response
  35. */
  36. public function index()
  37. {
  38. $where = $this->request->getMore([
  39. ['id', 0],
  40. ['status', ''],
  41. ['keyword', '']
  42. ]);
  43. if (!$where['id']) {
  44. return $this->fail('缺少参数ID');
  45. }
  46. $where['level_id'] = $where['id'];
  47. unset($where['id']);
  48. return $this->success($this->services->getLevelTaskList($where));
  49. }
  50. /**
  51. * 显示创建资源表单页.
  52. *
  53. * @return \think\Response
  54. */
  55. public function create()
  56. {
  57. [$level_id] = $this->request->postMore([
  58. ['level_id', 0]], true);
  59. if (!$level_id) {
  60. return $this->fail('缺少等级ID');
  61. }
  62. return $this->success($this->services->createForm((int)$level_id));
  63. }
  64. /**
  65. * 保存新建的资源
  66. *
  67. * @return \think\Response
  68. */
  69. public function save()
  70. {
  71. $data = $this->request->postMore([
  72. ['level_id', 0],
  73. ['name', ''],
  74. ['type', ''],
  75. ['number', 0],
  76. ['desc', 0],
  77. ['sort', 0],
  78. ['status', 0]]);
  79. if (!$data['level_id']) return $this->fail('缺少等级ID');
  80. if (!$data['name']) return $this->fail('请输入等级名称');
  81. if (!$data['type']) return $this->fail('请选择任务类型');
  82. if (!$data['number']) return $this->fail('请输入限定数量');
  83. $this->services->checkTypeTask(0, $data);
  84. $data['add_time'] = time();
  85. $this->services->save($data);
  86. return $this->success('添加等级任务成功!');
  87. }
  88. /**
  89. * 显示指定的资源
  90. *
  91. * @param int $id
  92. * @return \think\Response
  93. */
  94. public function read($id)
  95. {
  96. //
  97. }
  98. /**
  99. * 显示编辑资源表单页.
  100. *
  101. * @param int $id
  102. * @return \think\Response
  103. */
  104. public function edit($id)
  105. {
  106. return $this->success($this->services->editForm((int)$id));
  107. }
  108. /**
  109. * 保存更新的资源
  110. *
  111. * @param int $id
  112. * @return \think\Response
  113. */
  114. public function update($id)
  115. {
  116. $data = $this->request->postMore([
  117. ['name', ''],
  118. ['type', ''],
  119. ['number', 0],
  120. ['desc', 0],
  121. ['sort', 0],
  122. ['status', 0]]);
  123. if (!$data['name']) return $this->fail('请输入等级名称');
  124. if (!$data['type']) return $this->fail('请选择任务类型');
  125. if (!$data['number']) return $this->fail('请输入限定数量');
  126. if (!$levelTaskInfo = $this->services->getLevelTaskInfo((int)$id)) return $this->fail('编辑的任务不存在!');
  127. $this->services->checkTypeTask((int)$id, $data);
  128. $levelTaskInfo->name = $data['name'];
  129. $levelTaskInfo->type = $data['type'];
  130. $levelTaskInfo->number = $data['number'];
  131. $levelTaskInfo->desc = $data['desc'];
  132. $levelTaskInfo->sort = $data['sort'];
  133. $levelTaskInfo->status = $data['status'];
  134. $levelTaskInfo->save();
  135. return $this->success('修改成功!');
  136. }
  137. /**
  138. * 删除指定资源
  139. * @param $id
  140. * @return mixed
  141. * @throws \think\db\exception\DataNotFoundException
  142. * @throws \think\db\exception\DbException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. */
  145. public function delete($id)
  146. {
  147. if (!$id) return $this->fail('参数错误,请重新打开');
  148. $levelTaskInfo = $this->services->getLevelTaskInfo((int)$id);
  149. if ($levelTaskInfo) {
  150. $res = $this->services->update($id, ['is_del' => 1]);
  151. if (!$res)
  152. return $this->fail('删除失败,请稍候再试!');
  153. }
  154. return $this->success('删除成功!');
  155. }
  156. /**
  157. * 修改状态
  158. * @param int $id
  159. * @param string $status
  160. * @return mixed
  161. */
  162. public function set_status($id = 0, $status = '')
  163. {
  164. if ($status == '' || $id == 0) return $this->fail('参数错误');
  165. $this->services->update($id, ['status' => $status]);
  166. return $this->success($status == 0 ? '隐藏成功' : '显示成功');
  167. }
  168. }