CardController.php 2.6 KB

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