CardBatchValidate.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * CardBatchValidate.php
  4. * User: ZhouBenXu
  5. * Date: 2024/6/27
  6. * Time: 上午9:54
  7. * Notes:
  8. */
  9. namespace app\admin\validate\card;
  10. use support\Validate;
  11. use app\model\CardBatch;
  12. class CardBatchValidate extends Validate
  13. {
  14. protected $rule = [
  15. 'card_batch_id' => 'require', // 批次id
  16. 'join_card_batch_user_id' => 'require', // 批次创建用户 user_id
  17. 'join_card_batch_category_id' => 'require', // 批次卡分类ID
  18. 'card_batch_status' => 'require', // 批次状态 CREATE=已创建|PRODUCTED=制作完成|ENABLED=启用|DISABLED=禁用
  19. 'card_batch_name' => 'require', // 卡批次名称
  20. 'card_batch_prefix' => 'require', // 卡批次前缀
  21. 'card_batch_suffix' => 'require', // 卡批次后缀
  22. 'card_batch_serial_begin' => 'require', // 卡批次序号起始
  23. 'card_batch_serial_end' => 'require', // 卡批次序号结束
  24. 'card_batch_amount' => 'require', // 卡批次面额
  25. 'card_batch_validtimes' => 'require', // 卡批次有效期时间戳 0=永久 天
  26. 'validtimes_status' => 'require', // 修改时有效期状态 0 永久 1增加 2减少
  27. 'page' => 'require', // 页码
  28. 'pageSize' => 'require', // 分页条数
  29. 'card_batch_ids' => 'require', // 批次ids
  30. ];
  31. protected $message = [];
  32. protected $scene = [
  33. 'add' => ['join_card_batch_user_id', 'join_card_batch_category_id', 'card_batch_status', 'card_batch_name', 'card_batch_prefix', 'card_batch_suffix', 'card_batch_serial_begin', 'card_batch_serial_end', 'card_batch_amount', 'card_batch_validtimes'],
  34. 'save' => ['join_card_batch_user_id', 'card_batch_id', 'validtimes_status', 'card_batch_name'],
  35. 'delete' => ['card_batch_ids'],
  36. 'list' => ['page', 'pageSize'],
  37. 'info' => ['card_batch_id']
  38. ];
  39. /**
  40. * Notes: 卡号区间校验不能存在交集
  41. * User: ZhouBenXu
  42. * DateTime: 2024/7/1 上午11:30
  43. * @param $params
  44. * @return bool
  45. */
  46. public function checkCardSort($params)
  47. {
  48. if ($params['card_batch_serial_begin'] > $params['card_batch_serial_end']) {
  49. return false;
  50. }
  51. // 查询是否存在相同前缀后缀信息
  52. $cardBatchInfo = CardBatch::where('card_batch_prefix', $params['card_batch_prefix'])
  53. ->where('card_batch_suffix', $params['card_batch_prefix'])
  54. ->select()
  55. ->get()
  56. ->toArray();
  57. if (!empty($cardBatchInfo)) {
  58. foreach ($cardBatchInfo as $key => $value) {
  59. // 校验序号是否存在交集信息
  60. if ($value['card_batch_serial_begin'] <= $params['card_batch_serial_end'] && $value['card_batch_serial_end'] >= $params['card_batch_serial_begin']) {
  61. return false;
  62. }
  63. }
  64. }
  65. return true;
  66. }
  67. }