Templates.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace App\Http\Requests\Company\DynamicQrcode;
  3. use App\Http\Requests\BaseRequest;
  4. use Illuminate\Validation\Rule;
  5. /**
  6. * 活码工具接口验证
  7. * @author 唐远望
  8. * @version 1.0
  9. * @date 2025-08-21
  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,2,3',
  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. 'qrcodes_urls' => 'required|string',
  47. 'file_names' => 'required|string',
  48. 'prioritys' => 'required|string',
  49. 'expiry_dates' => 'required|string',
  50. 'access_limits' => 'required|string',
  51. ];
  52. // 添加条件验证规则 - 使用Rule::requiredIf
  53. $rules['customer_service_qrcode'] = [
  54. Rule::requiredIf(function () {
  55. return $this->input('open_landing_page') == 1 &&
  56. $this->input('contact_event_organizer') == 1;
  57. })
  58. ];
  59. $rules['contact_phone'] = [
  60. Rule::requiredIf(function () {
  61. return $this->input('open_landing_page') == 1 &&
  62. $this->input('contact_event_organizer') == 2;
  63. })
  64. ];
  65. $rules['backup_content'] = [
  66. Rule::requiredIf(function () {
  67. return $this->input('open_advanced_config') == 1 &&
  68. $this->input('open_backup_content_display') == 1;
  69. })
  70. ];
  71. return $rules;
  72. }
  73. // 场景列表
  74. protected $scenes = [
  75. 'detail' => ['id'],
  76. 'list' => ['page', 'limit'],
  77. 'add' => [
  78. 'name',
  79. 'switching_method',
  80. 'restriction_type',
  81. 'open_repeat_addition',
  82. 'open_landing_page',
  83. 'open_safety_certification',
  84. 'open_guidance_prompt',
  85. 'activity_title',
  86. 'event_description',
  87. 'contact_event_organizer',
  88. 'customer_service_qrcode',
  89. 'contact_phone',
  90. 'open_advanced_config',
  91. 'backup_content',
  92. 'open_wechat_press_frequently_qrcode',
  93. 'open_backup_content_display',
  94. 'qrcodes_urls',
  95. 'file_names',
  96. 'prioritys',
  97. 'expiry_dates',
  98. 'access_limits',
  99. ],
  100. 'edit' => [
  101. 'id',
  102. 'name',
  103. 'switching_method',
  104. 'restriction_type',
  105. 'open_repeat_addition',
  106. 'open_landing_page',
  107. 'open_safety_certification',
  108. 'open_guidance_prompt',
  109. 'activity_title',
  110. 'event_description',
  111. 'contact_event_organizer',
  112. 'customer_service_qrcode',
  113. 'contact_phone',
  114. 'open_advanced_config',
  115. 'backup_content',
  116. 'open_wechat_press_frequently_qrcode',
  117. 'open_backup_content_display',
  118. 'status'
  119. ],
  120. 'set_status' => ['id', 'status'],
  121. 'delete' => ['id'],
  122. ];
  123. /**
  124. * 获取已定义验证规则的错误消息
  125. *
  126. * @return array
  127. */
  128. public function messages()
  129. {
  130. return [
  131. 'name.required' => '名称必填',
  132. 'id.required' => 'ID未知',
  133. 'id.integer' => 'ID格式错误',
  134. 'id.gt' => 'ID格式错误',
  135. 'status.required' => '状态未知',
  136. 'status.integer' => '状态格式错误',
  137. 'status.in' => '状态格式错误',
  138. 'page.integer' => '页码格式错误',
  139. 'page.min' => '页码格式错误',
  140. 'limit.integer' => '每页数量格式错误',
  141. 'limit.min' => '每页数量格式错误',
  142. 'sort.required' => '排序未知',
  143. 'sort.integer' => '排序格式错误',
  144. 'sort.min' => '排序格式错误',
  145. 'dynamic_qrcode_image_url.required' => '活码二维码未知',
  146. 'link_url.required' => '活码链接地址未知',
  147. 'switching_method.required' => '切换方式未知',
  148. 'switching_method.integer' => '切换方式格式错误',
  149. 'switching_method.in' => '切换方式格式错误',
  150. 'restriction_type.required' => '上限类型未知',
  151. 'restriction_type.integer' => '上限类型格式错误',
  152. 'restriction_type.in' => '上限类型格式错误',
  153. 'open_repeat_addition.required' => '重复进群/加人未知',
  154. 'open_repeat_addition.integer' => '重复进群/加人格式错误',
  155. 'open_repeat_addition.in' => '重复进群/加人格式错误',
  156. 'domain_address.required' => '域名地址未知',
  157. 'open_landing_page.required' => '落地页开关未知',
  158. 'open_landing_page.integer' => '落地页开关格式错误',
  159. 'open_landing_page.in' => '落地页开关格式错误',
  160. 'open_advanced_config.required' => '高级开关未知',
  161. 'open_advanced_config.integer' => '高级开关格式错误',
  162. 'open_advanced_config.in' => '高级开关格式错误',
  163. // 其他消息...
  164. 'open_safety_certification.required_if' => '当开启落地页时,安全认证标识必填',
  165. 'open_guidance_prompt.required_if' => '当开启落地页时,常按引导提示必填',
  166. 'activity_title.required_if' => '当开启落地页时,活动标题必填',
  167. 'event_description.required_if' => '当开启落地页时,活动描述必填',
  168. 'contact_event_organizer.required_if' => '当开启落地页时,联系活动方必填',
  169. 'customer_service_qrcode.required' => '当开启落地页并且联系活动方为客服时,客服二维码必填',
  170. 'contact_phone.required' => '当开启落地页时,联系活动方式为电话时,联系电话必填',
  171. 'open_backup_content_display.required_if' => '当开启高级配置时,备用内容显示必填',
  172. 'backup_content.required' => '当开启高级配置且备用内容显示开启时,备用内容必填',
  173. 'open_wechat_press_frequently_qrcode.required_if' => '当开启高级配置时,微信常按识别二维码必填',
  174. 'qrcodes_urls.required' =>'二维码地址集合不能为空',
  175. 'qrcodes_urls.string' =>'二维码地址集合格式错误',
  176. 'file_names.required' =>'文件名称集合不能为空',
  177. 'file_names.string' =>'文件名称集合格式错误',
  178. 'prioritys.required' =>'优先级集合不能为空',
  179. 'prioritys.string' =>'优先级集合格式错误',
  180. 'expiry_dates.required' =>'过期时间集合不能为空',
  181. 'expiry_dates.string' =>'过期时间集合格式错误',
  182. 'access_limits.required' =>'上限限制集合不能为空',
  183. 'access_limits.string' =>'上限限制集合格式错误',
  184. ];
  185. }
  186. }