CardBatchController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * CardBatchController.php
  4. * User: ZhouBenXu
  5. * Date: 2024/6/27
  6. * Time: 上午9:36
  7. * Notes: 卡批次管理
  8. */
  9. namespace app\admin\controller\card;
  10. use support\Request;
  11. use support\Response;
  12. use app\admin\validate\card\CardBatchValidate;
  13. use app\admin\service\card\CardBatchService;
  14. use Tinywan\Jwt\JwtToken;
  15. class CardBatchController
  16. {
  17. /**
  18. * Notes: 添加卡批次
  19. * User: ZhouBenXu
  20. * DateTime: 2024/6/27 上午9:44
  21. */
  22. public function insert(Request $request)
  23. {
  24. $params = $request->post();
  25. $params['join_card_batch_user_id'] = JwtToken::getCurrentId();
  26. // 验证器
  27. $validate = new CardBatchValidate();
  28. if (!$validate->scene('add')->check($params)) {
  29. return json_fail($validate->getError());
  30. }
  31. return CardBatchService::insert($params);
  32. }
  33. /**
  34. * Notes: 修改卡批次 仅修改名称 状态 有效期
  35. * User: ZhouBenXu
  36. * DateTime: 2024/6/27 上午9:44
  37. */
  38. public function save(Request $request)
  39. {
  40. $params = $request->post();
  41. $params['join_card_batch_user_id'] = JwtToken::getCurrentId();
  42. // 验证器
  43. $validate = new CardBatchValidate();
  44. if (!$validate->scene('save')->check($params)) {
  45. return json_fail($validate->getError());
  46. }
  47. // 校验有效期 0 永久 1增加 2 减少
  48. return CardBatchService::save($params);
  49. }
  50. /**
  51. * Notes: 删除 支持批量
  52. * User: ZhouBenXu
  53. * DateTime: 2024/6/27 下午5:41
  54. * @param Request $request
  55. * @return Response
  56. */
  57. public function delete(Request $request)
  58. {
  59. // 验证器
  60. $validate = new CardBatchValidate();
  61. if (!$validate->scene('delete')->check($request->post())) {
  62. return json_fail($validate->getError());
  63. }
  64. $card_batch_ids = $request->post('card_batch_ids');
  65. return CardBatchService::delete($card_batch_ids);
  66. }
  67. /**
  68. * Notes: 批次列表
  69. * User: ZhouBenXu
  70. * DateTime: 2024/6/28 上午9:51
  71. * @param Request $request
  72. * @return Response
  73. */
  74. public function list(Request $request)
  75. {
  76. $params = $request->get();
  77. $params['page'] = $params['page'] ?? 1;
  78. $params['pageSize'] = $params['pageSize'] ?? 20;
  79. $params['join_card_batch_user_id'] = JwtToken::getCurrentId();
  80. // 验证器
  81. $validate = new CardBatchValidate();
  82. if (!$validate->scene('list')->check($params)) {
  83. return json_fail($validate->getError());
  84. }
  85. return CardBatchService::getList($params);
  86. }
  87. /**
  88. * Notes: 卡批次详情
  89. * User: ZhouBenXu
  90. * DateTime: 2024/6/28 上午10:51
  91. * @param Request $request
  92. * @return Response
  93. */
  94. public function info(Request $request)
  95. {
  96. $params = $request->get();
  97. // 验证器
  98. $validate = new CardBatchValidate();
  99. if (!$validate->scene('info')->check($params)) {
  100. return json_fail($validate->getError());
  101. }
  102. return CardBatchService::getInfo($params['card_batch_id']);
  103. }
  104. }