AgentLevelTask.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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\agent;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\agent\AgentLevelTaskServices;
  14. use think\facade\App;
  15. /**
  16. * 分销等级任务控制器
  17. * Class AgentLevelTask
  18. * @package app\controller\admin\v1\agent
  19. */
  20. class AgentLevelTask extends AuthController
  21. {
  22. /**
  23. * AgentLevelTask constructor.
  24. * @param App $app
  25. * @param AgentLevelTaskServices $services
  26. */
  27. public function __construct(App $app, AgentLevelTaskServices $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. ['id', 0],
  43. ['status', ''],
  44. ['keyword', '']
  45. ]);
  46. if (!$where['id']) {
  47. return app('json')->fail(100100);
  48. }
  49. $where['level_id'] = $where['id'];
  50. unset($where['id']);
  51. return app('json')->success($this->services->getLevelTaskList($where));
  52. }
  53. /**
  54. * 等级任务添加表单
  55. * @return mixed
  56. * @throws \FormBuilder\Exception\FormBuilderException
  57. */
  58. public function create()
  59. {
  60. [$level_id] = $this->request->postMore([
  61. ['level_id', 0]], true);
  62. if (!$level_id) {
  63. return app('json')->fail(100100);
  64. }
  65. return app('json')->success($this->services->createForm((int)$level_id));
  66. }
  67. /**
  68. * 保存等级任务
  69. * @return mixed
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function save()
  75. {
  76. $data = $this->request->postMore([
  77. ['level_id', 0],
  78. ['name', ''],
  79. ['type', ''],
  80. ['number', 0],
  81. ['desc', 0],
  82. ['sort', 0],
  83. ['status', 0]]);
  84. if (!$data['level_id']) return app('json')->fail(100100);
  85. if (!$data['name']) return app('json')->fail(400207);
  86. if (!$data['type']) return app('json')->fail(400208);
  87. if (!$data['number']) return app('json')->fail(400209);
  88. $this->services->checkTypeTask(0, $data);
  89. $data['add_time'] = time();
  90. $this->services->save($data);
  91. return app('json')->success(400210);
  92. }
  93. /**
  94. * 显示指定的资源
  95. * @param $id
  96. */
  97. public function read($id)
  98. {
  99. }
  100. /**
  101. * 等级任务修改表单
  102. * @param $id
  103. * @return mixed
  104. * @throws \FormBuilder\Exception\FormBuilderException
  105. */
  106. public function edit($id)
  107. {
  108. return app('json')->success($this->services->editForm((int)$id));
  109. }
  110. /**
  111. * 修改等级任务
  112. * @param $id
  113. * @return mixed
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\DbException
  116. * @throws \think\db\exception\ModelNotFoundException
  117. */
  118. public function update($id)
  119. {
  120. $data = $this->request->postMore([
  121. ['name', ''],
  122. ['type', ''],
  123. ['number', 0],
  124. ['desc', 0],
  125. ['sort', 0],
  126. ['status', 0]]);
  127. if (!$data['name']) return app('json')->fail(400207);
  128. if (!$data['type']) return app('json')->fail(400208);
  129. if (!$data['number']) return app('json')->fail(400209);
  130. if (!$levelTaskInfo = $this->services->getLevelTaskInfo((int)$id)) return app('json')->fail(400211);
  131. $this->services->checkTypeTask((int)$id, $data);
  132. $levelTaskInfo->name = $data['name'];
  133. $levelTaskInfo->type = $data['type'];
  134. $levelTaskInfo->number = $data['number'];
  135. $levelTaskInfo->desc = $data['desc'];
  136. $levelTaskInfo->sort = $data['sort'];
  137. $levelTaskInfo->status = $data['status'];
  138. $levelTaskInfo->save();
  139. return app('json')->success(100001);
  140. }
  141. /**
  142. * 删除等级任务
  143. * @param $id
  144. * @return mixed
  145. * @throws \think\db\exception\DataNotFoundException
  146. * @throws \think\db\exception\DbException
  147. * @throws \think\db\exception\ModelNotFoundException
  148. */
  149. public function delete($id)
  150. {
  151. if (!$id) return app('json')->fail(100100);
  152. $levelTaskInfo = $this->services->getLevelTaskInfo((int)$id);
  153. if ($levelTaskInfo) {
  154. $res = $this->services->update($id, ['is_del' => 1]);
  155. if (!$res)
  156. return app('json')->fail(100008);
  157. }
  158. return app('json')->success(100002);
  159. }
  160. /**
  161. * 修改状态
  162. * @param int $id
  163. * @param string $status
  164. * @return mixed
  165. */
  166. public function set_status($id = 0, $status = '')
  167. {
  168. if ($status == '' || $id == 0) return app('json')->fail(100100);
  169. $this->services->update($id, ['status' => $status]);
  170. return app('json')->success(100014);
  171. }
  172. }