Award.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. $data['update_time']=time();
  128. $repository->update($id, $data);
  129. return app('json')->success('编辑成功');
  130. }
  131. /**
  132. * 删除
  133. */
  134. public function oil_delete($id,OilLevelRepository $repository)
  135. {
  136. // if (!$this->repository->merExists($this->request->merId(), $id))
  137. // return app('json')->fail('数据不存在');
  138. $repository->delete($id);
  139. return app('json')->success('删除成功');
  140. }
  141. /**
  142. * 验证数据
  143. * @param OilLevelValidate $validate
  144. * @return array
  145. * @author Qinii
  146. */
  147. public function oil_checkParams(OilLevelValidate $validate)
  148. {
  149. $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
  150. $validate->check($data);
  151. return $data;
  152. }
  153. /**
  154. * 列表
  155. * @return \think\response\Json
  156. * @author Qinii
  157. * @day 2023/9/24
  158. */
  159. public function gift_lst(GiftLevelValidate $validate,GiftLevelRepository $repository)
  160. {
  161. [$page, $limit] = $this->getPage();
  162. $where = $this->request->params(['']);
  163. return app('json')->success($repository->getList($where, $page, $limit));
  164. }
  165. /**
  166. * 添加
  167. * @param GiftLevelValidate $validate
  168. * @return mixed
  169. * @author Qinii
  170. */
  171. public function gift_create(GiftLevelValidate $validate,GiftLevelRepository $repository)
  172. {
  173. $data = $this->gift_checkParams($validate);
  174. $grade = app()->make(GiftLevelRepository::class)->getSearch([])->where('grade', $data['grade'])->find();
  175. if ($grade){
  176. return app('json')->fail('等级已存在');
  177. }
  178. $data['update_time'] = time();
  179. $repository->create($data);
  180. return app('json')->success('添加成功');
  181. }
  182. /**
  183. * 更新
  184. * @param $id
  185. */
  186. public function gift_update($id, GiftLevelValidate $validate,GiftLevelRepository $repository)
  187. {
  188. $data = $this->gift_checkParams($validate);
  189. // if (!$this->repository->merExists($this->request->merId(), $id))
  190. // return app('json')->fail('数据不存在');
  191. $grade = app()->make(GiftLevelRepository::class)->getSearch([])->whereNotIn('id',[$id])->where('grade', $data['grade'])->find();
  192. if ($grade){
  193. return app('json')->fail('等级已存在');
  194. }
  195. $data['update_time']=time();
  196. $repository->update($id, $data);
  197. return app('json')->success('编辑成功');
  198. }
  199. /**
  200. * 删除
  201. */
  202. public function gift_delete($id,GiftLevelRepository $repository)
  203. {
  204. // if (!$this->repository->merExists($this->request->merId(), $id))
  205. // return app('json')->fail('数据不存在');
  206. $repository->delete($id);
  207. return app('json')->success('删除成功');
  208. }
  209. /**
  210. * 验证数据
  211. * @param GiftLevelValidate $validate
  212. * @return array
  213. * @author Qinii
  214. */
  215. public function gift_checkParams(GiftLevelValidate $validate)
  216. {
  217. $data = $this->request->params(['name', 'grade', 'achievement','award_ratio']);
  218. $validate->check($data);
  219. return $data;
  220. }
  221. }