Award.php 7.7 KB

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