Award.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\user;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\user\AwardIntegralPriceRepository;
  14. use app\common\repositories\user\GiftLevelRepository;
  15. use app\common\repositories\user\OilLevelRepository;
  16. use app\common\repositories\user\UserInfoRepository;
  17. use app\validate\admin\GiftLevelValidate;
  18. use app\validate\admin\OilLevelValidate;
  19. use crmeb\basic\BaseController;
  20. use app\common\repositories\user\UserBillRepository;
  21. use crmeb\services\ExcelService;
  22. use think\App;
  23. use think\db\exception\DataNotFoundException;
  24. use think\db\exception\DbException;
  25. use think\db\exception\ModelNotFoundException;
  26. /**
  27. * Class Award
  28. * app\controller\admin\user
  29. * 用户扩展字段设置
  30. */
  31. class Award extends BaseController
  32. {
  33. protected $repository;
  34. public function __construct(App $app, AwardIntegralPriceRepository $repository)
  35. {
  36. parent::__construct($app);
  37. $this->repository = $repository;
  38. }
  39. /**
  40. * 列表
  41. * @return \think\response\Json
  42. * @author Qinii
  43. * @day 2023/9/24
  44. */
  45. public function lst()
  46. {
  47. [$page, $limit] = $this->getPage();
  48. $where = $this->request->params(['day']);
  49. return app('json')->success($this->repository->getList($where, $page, $limit));
  50. }
  51. /**
  52. * 奖池列表
  53. * @return \think\response\Json
  54. * @author Qinii
  55. * @day 2023/9/24
  56. */
  57. public function lake_lst()
  58. {
  59. [$page, $limit] = $this->getPage();
  60. $where = $this->request->params(['type']);
  61. return app('json')->success($this->repository->getLakeList($where, $page, $limit));
  62. }
  63. /**
  64. * 列表
  65. * @return \think\response\Json
  66. * @author Qinii
  67. * @day 2023/9/24
  68. */
  69. public function oil_lst(OilLevelValidate $validate,OilLevelRepository $repository)
  70. {
  71. [$page, $limit] = $this->getPage();
  72. $where = $this->request->params(['']);
  73. return app('json')->success($repository->getList($where, $page, $limit));
  74. }
  75. /**
  76. * 添加
  77. * @param OilLevelValidate $validate
  78. * @return mixed
  79. * @author Qinii
  80. */
  81. public function oil_create(OilLevelValidate $validate,OilLevelRepository $repository)
  82. {
  83. $data = $this->oil_checkParams($validate);
  84. $grade = app()->make(OilLevelRepository::class)->getSearch([])->where('grade', $data['grade'])->find();
  85. if ($grade){
  86. return app('json')->fail('等级已存在');
  87. }
  88. $data['update_time'] = time();
  89. $repository->create($data);
  90. return app('json')->success('添加成功');
  91. }
  92. /**
  93. * 文章详情
  94. * @param $id
  95. */
  96. public function oil_detail($id,OilLevelRepository $repository)
  97. {
  98. // if (!$this->repository->merExists($this->request->merId(), $id))
  99. // return app('json')->fail('数据不存在');
  100. return app('json')->success($repository->getWith($id));
  101. }
  102. /**
  103. * 更新
  104. * @param $id
  105. */
  106. public function oil_update($id, OilLevelValidate $validate,OilLevelRepository $repository)
  107. {
  108. $data = $this->oil_checkParams($validate);
  109. // if (!$this->repository->merExists($this->request->merId(), $id))
  110. // return app('json')->fail('数据不存在');
  111. $grade = app()->make(OilLevelRepository::class)->getSearch([])->whereNotIn('id',[$id])->where('grade', $data['grade'])->find();
  112. if ($grade){
  113. return app('json')->fail('等级已存在');
  114. }
  115. $repository->update($id, $data);
  116. return app('json')->success('编辑成功');
  117. }
  118. /**
  119. * 删除
  120. */
  121. public function oil_delete($id,OilLevelRepository $repository)
  122. {
  123. // if (!$this->repository->merExists($this->request->merId(), $id))
  124. // return app('json')->fail('数据不存在');
  125. $repository->delete($id);
  126. return app('json')->success('删除成功');
  127. }
  128. /**
  129. * 验证数据
  130. * @param OilLevelValidate $validate
  131. * @return array
  132. * @author Qinii
  133. */
  134. public function oil_checkParams(OilLevelValidate $validate)
  135. {
  136. $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
  137. $validate->check($data);
  138. return $data;
  139. }
  140. /**
  141. * 列表
  142. * @return \think\response\Json
  143. * @author Qinii
  144. * @day 2023/9/24
  145. */
  146. public function gift_lst(GiftLevelValidate $validate,GiftLevelRepository $repository)
  147. {
  148. [$page, $limit] = $this->getPage();
  149. $where = $this->request->params(['']);
  150. return app('json')->success($repository->getList($where, $page, $limit));
  151. }
  152. /**
  153. * 添加
  154. * @param GiftLevelValidate $validate
  155. * @return mixed
  156. * @author Qinii
  157. */
  158. public function gift_create(GiftLevelValidate $validate,GiftLevelRepository $repository)
  159. {
  160. $data = $this->gift_checkParams($validate);
  161. $grade = app()->make(GiftLevelRepository::class)->getSearch([])->where('grade', $data['grade'])->find();
  162. if ($grade){
  163. return app('json')->fail('等级已存在');
  164. }
  165. $data['update_time'] = time();
  166. $repository->create($data);
  167. return app('json')->success('添加成功');
  168. }
  169. /**
  170. * 更新
  171. * @param $id
  172. */
  173. public function gift_update($id, GiftLevelValidate $validate,GiftLevelRepository $repository)
  174. {
  175. $data = $this->gift_checkParams($validate);
  176. // if (!$this->repository->merExists($this->request->merId(), $id))
  177. // return app('json')->fail('数据不存在');
  178. $grade = app()->make(GiftLevelRepository::class)->getSearch([])->whereNotIn('id',[$id])->where('grade', $data['grade'])->find();
  179. if ($grade){
  180. return app('json')->fail('等级已存在');
  181. }
  182. $repository->update($id, $data);
  183. return app('json')->success('编辑成功');
  184. }
  185. /**
  186. * 删除
  187. */
  188. public function gift_delete($id,GiftLevelRepository $repository)
  189. {
  190. // if (!$this->repository->merExists($this->request->merId(), $id))
  191. // return app('json')->fail('数据不存在');
  192. $repository->delete($id);
  193. return app('json')->success('删除成功');
  194. }
  195. /**
  196. * 验证数据
  197. * @param GiftLevelValidate $validate
  198. * @return array
  199. * @author Qinii
  200. */
  201. public function gift_checkParams(GiftLevelValidate $validate)
  202. {
  203. $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
  204. $validate->check($data);
  205. return $data;
  206. }
  207. }