Award.php 7.7 KB

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