Award.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 lake_log_lst()
  70. {
  71. [$page, $limit] = $this->getPage();
  72. $where = $this->request->params(['type','pm']);
  73. return app('json')->success($this->repository->getLakeList($where, $page, $limit));
  74. }
  75. /**
  76. * 列表
  77. * @return \think\response\Json
  78. * @author Qinii
  79. * @day 2023/9/24
  80. */
  81. public function oil_lst(OilLevelValidate $validate,OilLevelRepository $repository)
  82. {
  83. [$page, $limit] = $this->getPage();
  84. $where = $this->request->params(['']);
  85. return app('json')->success($repository->getList($where, $page, $limit));
  86. }
  87. /**
  88. * 添加
  89. * @param OilLevelValidate $validate
  90. * @return mixed
  91. * @author Qinii
  92. */
  93. public function oil_create(OilLevelValidate $validate,OilLevelRepository $repository)
  94. {
  95. $data = $this->oil_checkParams($validate);
  96. $grade = app()->make(OilLevelRepository::class)->getSearch([])->where('grade', $data['grade'])->find();
  97. if ($grade){
  98. return app('json')->fail('等级已存在');
  99. }
  100. $data['update_time'] = time();
  101. $repository->create($data);
  102. return app('json')->success('添加成功');
  103. }
  104. /**
  105. * 文章详情
  106. * @param $id
  107. */
  108. public function oil_detail($id,OilLevelRepository $repository)
  109. {
  110. // if (!$this->repository->merExists($this->request->merId(), $id))
  111. // return app('json')->fail('数据不存在');
  112. return app('json')->success($repository->getWith($id));
  113. }
  114. /**
  115. * 更新
  116. * @param $id
  117. */
  118. public function oil_update($id, OilLevelValidate $validate,OilLevelRepository $repository)
  119. {
  120. $data = $this->oil_checkParams($validate);
  121. // if (!$this->repository->merExists($this->request->merId(), $id))
  122. // return app('json')->fail('数据不存在');
  123. $grade = app()->make(OilLevelRepository::class)->getSearch([])->whereNotIn('id',[$id])->where('grade', $data['grade'])->find();
  124. if ($grade){
  125. return app('json')->fail('等级已存在');
  126. }
  127. $repository->update($id, $data);
  128. return app('json')->success('编辑成功');
  129. }
  130. /**
  131. * 删除
  132. */
  133. public function oil_delete($id,OilLevelRepository $repository)
  134. {
  135. // if (!$this->repository->merExists($this->request->merId(), $id))
  136. // return app('json')->fail('数据不存在');
  137. $repository->delete($id);
  138. return app('json')->success('删除成功');
  139. }
  140. /**
  141. * 验证数据
  142. * @param OilLevelValidate $validate
  143. * @return array
  144. * @author Qinii
  145. */
  146. public function oil_checkParams(OilLevelValidate $validate)
  147. {
  148. $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
  149. $validate->check($data);
  150. return $data;
  151. }
  152. /**
  153. * 列表
  154. * @return \think\response\Json
  155. * @author Qinii
  156. * @day 2023/9/24
  157. */
  158. public function gift_lst(GiftLevelValidate $validate,GiftLevelRepository $repository)
  159. {
  160. [$page, $limit] = $this->getPage();
  161. $where = $this->request->params(['']);
  162. return app('json')->success($repository->getList($where, $page, $limit));
  163. }
  164. /**
  165. * 添加
  166. * @param GiftLevelValidate $validate
  167. * @return mixed
  168. * @author Qinii
  169. */
  170. public function gift_create(GiftLevelValidate $validate,GiftLevelRepository $repository)
  171. {
  172. $data = $this->gift_checkParams($validate);
  173. $grade = app()->make(GiftLevelRepository::class)->getSearch([])->where('grade', $data['grade'])->find();
  174. if ($grade){
  175. return app('json')->fail('等级已存在');
  176. }
  177. $data['update_time'] = time();
  178. $repository->create($data);
  179. return app('json')->success('添加成功');
  180. }
  181. /**
  182. * 更新
  183. * @param $id
  184. */
  185. public function gift_update($id, GiftLevelValidate $validate,GiftLevelRepository $repository)
  186. {
  187. $data = $this->gift_checkParams($validate);
  188. // if (!$this->repository->merExists($this->request->merId(), $id))
  189. // return app('json')->fail('数据不存在');
  190. $grade = app()->make(GiftLevelRepository::class)->getSearch([])->whereNotIn('id',[$id])->where('grade', $data['grade'])->find();
  191. if ($grade){
  192. return app('json')->fail('等级已存在');
  193. }
  194. $repository->update($id, $data);
  195. return app('json')->success('编辑成功');
  196. }
  197. /**
  198. * 删除
  199. */
  200. public function gift_delete($id,GiftLevelRepository $repository)
  201. {
  202. // if (!$this->repository->merExists($this->request->merId(), $id))
  203. // return app('json')->fail('数据不存在');
  204. $repository->delete($id);
  205. return app('json')->success('删除成功');
  206. }
  207. /**
  208. * 验证数据
  209. * @param GiftLevelValidate $validate
  210. * @return array
  211. * @author Qinii
  212. */
  213. public function gift_checkParams(GiftLevelValidate $validate)
  214. {
  215. $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
  216. $validate->check($data);
  217. return $data;
  218. }
  219. }