Templates.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace App\Http\Requests\Api\DynamicQrcode;
  3. use App\Http\Requests\BaseRequest;
  4. use Illuminate\Validation\Rule;
  5. /**
  6. * 活码工具接口验证
  7. * @author 唐远望
  8. * @version 1.0
  9. * @date 2025-08-22
  10. *
  11. */
  12. class Templates extends BaseRequest
  13. {
  14. /**
  15. * 获取应用于请求的规则
  16. *
  17. * @return array
  18. */
  19. public function rules()
  20. {
  21. // 返回结果
  22. $rules= [
  23. 'name' => 'required',
  24. 'id' => 'required|integer|gt:0',
  25. 'status' => 'required|integer|in:0,1',
  26. 'page' => 'integer|min:1',
  27. 'limit' => 'integer|min:1',
  28. 'sort' => 'required|integer|min:0',
  29. 'dynamic_qrcode_image_url' => 'required',
  30. 'link_url' => 'required',
  31. 'switching_method' => 'required|integer|in:1,2,3,4',
  32. 'restriction_type' => 'required|integer|in:1,2',
  33. 'open_repeat_addition' => 'required|integer|in:0,1',
  34. 'domain_address' => 'required',
  35. 'open_landing_page' => 'required|integer|in:0,1',
  36. 'open_advanced_config' => 'required|integer|in:0,1',
  37. // 落地页条件规则
  38. 'open_safety_certification' => 'required_if:open_landing_page,1',
  39. 'open_guidance_prompt' => 'required_if:open_landing_page,1',
  40. 'activity_title' => 'required_if:open_landing_page,1',
  41. 'event_description' => 'required_if:open_landing_page,1',
  42. 'contact_event_organizer' => 'required_if:open_landing_page,1',
  43. // 高级配置条件规则
  44. 'open_backup_content_display' => 'required_if:open_advanced_config,1',
  45. 'open_wechat_press_frequently_qrcode' => 'required_if:open_advanced_config,1',
  46. ];
  47. // 添加条件验证规则 - 使用Rule::requiredIf
  48. $rules['customer_service_qrcode'] = [
  49. Rule::requiredIf(function () {
  50. return $this->input('open_landing_page') == 1 &&
  51. $this->input('contact_event_organizer') == 1;
  52. })
  53. ];
  54. $rules['contact_phone'] = [
  55. Rule::requiredIf(function () {
  56. return $this->input('open_landing_page') == 1 &&
  57. $this->input('contact_event_organizer') == 2;
  58. })
  59. ];
  60. $rules['backup_content'] = [
  61. Rule::requiredIf(function () {
  62. return $this->input('open_advanced_config') == 1 &&
  63. $this->input('open_backup_content_display') == 1;
  64. })
  65. ];
  66. return $rules;
  67. }
  68. // 场景列表
  69. protected $scenes = [
  70. 'detail' => ['id'],
  71. 'list' => ['page', 'limit'],
  72. 'add' => [
  73. 'name',
  74. 'switching_method',
  75. 'restriction_type',
  76. 'open_repeat_addition',
  77. 'domain_address',
  78. 'open_landing_page',
  79. 'open_safety_certification',
  80. 'open_guidance_prompt',
  81. 'activity_title',
  82. 'event_description',
  83. 'contact_event_organizer',
  84. 'customer_service_qrcode',
  85. 'contact_phone',
  86. 'open_advanced_config',
  87. 'backup_content',
  88. 'open_wechat_press_frequently_qrcode',
  89. 'open_backup_content_display',
  90. 'status'
  91. ],
  92. 'edit' => [
  93. 'id',
  94. 'name',
  95. 'switching_method',
  96. 'restriction_type',
  97. 'open_repeat_addition',
  98. 'domain_address',
  99. 'open_landing_page',
  100. 'open_safety_certification',
  101. 'open_guidance_prompt',
  102. 'activity_title',
  103. 'event_description',
  104. 'contact_event_organizer',
  105. 'customer_service_qrcode',
  106. 'contact_phone',
  107. 'open_advanced_config',
  108. 'backup_content',
  109. 'open_wechat_press_frequently_qrcode',
  110. 'open_backup_content_display',
  111. 'status'
  112. ],
  113. 'set_status' => ['id', 'status'],
  114. 'delete' => ['id'],
  115. ];
  116. /**
  117. * 获取已定义验证规则的错误消息
  118. *
  119. * @return array
  120. */
  121. public function messages()
  122. {
  123. return [
  124. 'name.required' => '名称必填',
  125. 'id.required' => 'ID未知',
  126. 'id.integer' => 'ID格式错误',
  127. 'id.gt' => 'ID格式错误',
  128. 'status.required' => '状态未知',
  129. 'status.integer' => '状态格式错误',
  130. 'status.in' => '状态格式错误',
  131. 'page.integer' => '页码格式错误',
  132. 'page.min' => '页码格式错误',
  133. 'limit.integer' => '每页数量格式错误',
  134. 'limit.min' => '每页数量格式错误',
  135. 'sort.required' => '排序未知',
  136. 'sort.integer' => '排序格式错误',
  137. 'sort.min' => '排序格式错误',
  138. 'dynamic_qrcode_image_url.required' => '活码二维码未知',
  139. 'link_url.required' => '活码链接地址未知',
  140. 'switching_method.required' => '切换方式未知',
  141. 'switching_method.integer' => '切换方式格式错误',
  142. 'switching_method.in' => '切换方式格式错误',
  143. 'restriction_type.required' => '上限类型未知',
  144. 'restriction_type.integer' => '上限类型格式错误',
  145. 'restriction_type.in' => '上限类型格式错误',
  146. 'open_repeat_addition.required' => '重复进群/加人未知',
  147. 'open_repeat_addition.integer' => '重复进群/加人格式错误',
  148. 'open_repeat_addition.in' => '重复进群/加人格式错误',
  149. 'domain_address.required' => '域名地址未知',
  150. 'open_landing_page.required' => '落地页开关未知',
  151. 'open_landing_page.integer' => '落地页开关格式错误',
  152. 'open_landing_page.in' => '落地页开关格式错误',
  153. 'open_advanced_config.required' => '高级开关未知',
  154. 'open_advanced_config.integer' => '高级开关格式错误',
  155. 'open_advanced_config.in' => '高级开关格式错误',
  156. // 其他消息...
  157. 'open_safety_certification.required_if' => '当开启落地页时,安全认证标识必填',
  158. 'open_guidance_prompt.required_if' => '当开启落地页时,常按引导提示必填',
  159. 'activity_title.required_if' => '当开启落地页时,活动标题必填',
  160. 'event_description.required_if' => '当开启落地页时,活动描述必填',
  161. 'contact_event_organizer.required_if' => '当开启落地页时,联系活动方必填',
  162. 'customer_service_qrcode.required' => '当开启落地页并且联系活动方为客服时,客服二维码必填',
  163. 'contact_phone.required' => '当开启落地页时,联系活动方式为电话时,联系电话必填',
  164. 'open_backup_content_display.required_if' => '当开启高级配置时,备用内容显示必填',
  165. 'backup_content.required' => '当开启高级配置且备用内容显示开启时,备用内容必填',
  166. 'open_wechat_press_frequently_qrcode.required_if' => '当开启高级配置时,微信常按识别二维码必填',
  167. ];
  168. }
  169. }