截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClosureValidate.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <?php
  2. namespace app\shop\validate\content;
  3. use app\common\model\content\Closure as ClosureModel;
  4. use app\common\basics\Validate;
  5. class ClosureValidate extends Validate
  6. {
  7. protected $rule = [
  8. 'id' => 'require|number',
  9. 'cid' => 'require|number',
  10. 'title' => 'require',
  11. // 'version' => 'require|checkVersion',
  12. 'a2' => 'require|number|checkPost',
  13. 'a3' => 'require|number',
  14. ];
  15. protected $message = [
  16. 'id.require' => 'id不可为空',
  17. 'id.number' => 'id必须为数字',
  18. 'cid.require' => '请选择分类',
  19. 'cid.number' => '分类选择异常',
  20. 'title.require' => '请填写文章标题',
  21. 'version.require' => '请填写版本号',
  22. 'a2.require' => '运行时长不可为空',
  23. 'a2.number' => '运行时长必须为数字',
  24. 'a3.require' => '操作总数不可为空',
  25. 'a3.number' => '操作总数必须为数字',
  26. ];
  27. protected $scene = [
  28. 'id' => ['id'],
  29. 'add' => [
  30. 'cid', 'title',
  31. 'a2',
  32. 'a3'
  33. ],
  34. 'edit' => [
  35. 'id', 'cid', 'title',
  36. 'a2',
  37. 'a3'
  38. ],
  39. ];
  40. /*
  41. * 检查版本号
  42. */
  43. protected function checkVersion($value,$rule,$data){
  44. $where[] = ['shop_id','=',$data['shop_id']];
  45. $where[] = ['del','=',0];
  46. // 如果有id代表是编辑校验分类名称
  47. if(isset($data['id'])){
  48. $where[] = ['id','<>',$data['id']];
  49. }
  50. $where[] = ['version','=',$data['version']];
  51. $where[] = ['cid','=',$data['cid']];
  52. $where[] = ['yid','=',$data['yid']];
  53. $name = ClosureModel::where($where)->value('version');
  54. if($name){
  55. return '版本号已存在';
  56. }
  57. return true;
  58. }
  59. /*
  60. * 验证所有post 参数
  61. * 通过a1字段 触发函数
  62. */
  63. protected function checkPost($value,$rule,$data){
  64. if((int)$data['a2'] < 900){
  65. return "运行时长不能小于900秒!";
  66. }
  67. if((int)$data['a3'] < 100){
  68. return "操作总数不能小于100个!";
  69. }
  70. if((int)$data['a4'] === 1){
  71. //组合模式
  72. if($data['a1'] == '推荐'){
  73. if((int)$data['a5'][0] < 120){
  74. return "推荐时长不能小于120秒";
  75. }
  76. if((int)$data['a5'][1] < 120){
  77. return "搜索时长不能小于120秒!";
  78. }
  79. }else if($data['a1'] == '搜索') {
  80. if ((int)$data['a6'][0] < 120) {
  81. return "搜索时长不能小于120秒";
  82. }
  83. if ((int)$data['a6'][1] < 120) {
  84. return "推荐时长不能小于120秒!";
  85. }
  86. }else{
  87. }
  88. }
  89. //搜索词
  90. if(empty($data['a7'])){
  91. return "启动设置-搜索词-不能为空!";
  92. }
  93. //过滤词
  94. if (strpos($data['b3'], "|") === false) {
  95. return "列表设置-过滤词格式不正确!";
  96. }
  97. //分类规则
  98. foreach ($data['b2_1'] as $k => $v) {
  99. if(empty($v) && $k !== 1){
  100. return "列表设置-分类规则-匹配词不能为空!";
  101. }
  102. }
  103. foreach ($data['b2_2'] as $k => $v) {
  104. if(empty($v) && $k !== 1){
  105. return "列表设置-分类规则-每[]个不能为空!";
  106. }
  107. }
  108. foreach ($data['b2_3'] as $k => $v) {
  109. if(empty($v) && $k !== 1){
  110. return "列表设置-分类规则-点击[]个不能为空!";
  111. }
  112. if($v > $data['b2_4'][$k] && $k !== 1){
  113. return "列表设置-分类规则-点击范围大小错误";
  114. }
  115. }
  116. foreach ($data['b2_4'] as $k => $v) {
  117. if(empty($v) && $k !== 1){
  118. return "列表设置-分类规则-到[]个不能为空!";
  119. }
  120. }
  121. //列表操作 滑动操作
  122. if(empty($data['b4'])){
  123. return "列表设置-滑动操作-随机滑动-不能为空!";
  124. }
  125. if((int)$data['b4'][0] > (int)$data['b4'][1]){
  126. return "列表设置-滑动操作-随机滑动-范围大小错误";
  127. }
  128. if(empty($data['b5'])){
  129. return "列表设置-滑动操作-返回滑动-不能为空!";
  130. }
  131. if((int)$data['b5'][0] > (int)$data['b5'][1]){
  132. return "列表设置-滑动操作-返回滑动-范围大小错误";
  133. }
  134. if(empty($data['b6'])){
  135. return "列表设置-滑动操作-列表滑动-不能为空!";
  136. }
  137. //浏览笔记
  138. foreach ($data['c1_1'] as $k => $v) {
  139. if(empty($v) && $k > 1){
  140. return "浏览笔记-观看时长-评论数-不能为空!";
  141. }else if(strpos($v, "-") === false && $k > 1) {
  142. return "浏览笔记-观看时长-评论数规则格式不正确!";
  143. }else{
  144. if($k !== 1){
  145. if(empty($data['c1_2'][$k]) || $data['c1_2'][$k] == 0){
  146. return "浏览笔记-观看时长-观看秒数不能为空或等于0!";
  147. }else if(empty($data['c1_3'][$k]) || $data['c1_3'][$k] == 0){
  148. return "浏览笔记-观看时长-观看秒数不能为空或等于0!";
  149. }else if((int)$data['c1_2'][$k] > (int)$data['c1_3'][$k]){
  150. return "浏览笔记-观看时长-观看时间大小有误!";
  151. }
  152. }
  153. }
  154. }
  155. //随机滑动
  156. if(empty($data['c2'][0]) || $data['c2'][0] == 0){
  157. return "浏览笔记-随机滑动-次数不能为空或等于0!";
  158. }else if(empty($data['c2'][1]) || $data['c2'][1] == 0){
  159. return "浏览笔记-随机滑动-次数不能为空或等于0!";
  160. }else if((int)$data['c2'][0] > (int)$data['c2'][1]){
  161. return "浏览笔记-随机滑动-次数大小有误!";
  162. }
  163. //滑动等待
  164. if(empty($data['c3'][0]) || $data['c3'][0] == 0){
  165. return "浏览笔记-滑动等待-次数不能为空或等于0!";
  166. }else if(empty($data['c3'][1]) || $data['c3'][1] == 0){
  167. return "浏览笔记-滑动等待-次数不能为空或等于0!";
  168. }else if((int)$data['c3'][0] > (int)$data['c3'][1]){
  169. return "浏览笔记-滑动等待-次数大小有误!";
  170. }
  171. //评论区
  172. if(empty($data['c4'])){
  173. return "浏览笔记-评论区-滑动比例-不能为空!";
  174. }
  175. //展开回复
  176. if(empty($data['c5'][0]) || $data['c5'][0] == 0){
  177. return "浏览笔记-展开回复-次数不能为空或等于0!";
  178. }else if(empty($data['c5'][1]) || $data['c5'][1] == 0){
  179. return "浏览笔记-展开回复-次数不能为空或等于0!";
  180. }else if((int)$data['c5'][0] > (int)$data['c5'][1]){
  181. return "浏览笔记-展开回复-次数大小有误!";
  182. }
  183. //展开概率
  184. if(empty($data['c6'][0]) || $data['c6'][0] == 0){
  185. return "浏览笔记-展开概率-最小数不能为空或等于0!";
  186. }else if(empty($data['c6'][1]) || $data['c6'][1] == 0){
  187. return "浏览笔记-展开概率-最大数不能为空或等于0!";
  188. }else if((int)$data['c6'][0] > (int)$data['c6'][1]){
  189. return "浏览笔记-展开概率-数大小有误!";
  190. }
  191. //更多回复
  192. if(empty($data['c7'][0]) || $data['c7'][0] == 0){
  193. return "浏览笔记-更多回复-最小数不能为空或等于0!";
  194. }else if(empty($data['c7'][1]) || $data['c7'][1] == 0){
  195. return "浏览笔记-更多回复-最大数不能为空或等于0!";
  196. }else if((int)$data['c7'][0] > (int)$data['c7'][1]){
  197. return "浏览笔记-更多回复-大小有误!";
  198. }
  199. //来回观看
  200. if(empty($data['c8'][0]) || $data['c8'][0] == 0){
  201. return "浏览笔记-来回观看-最小数不能为空或等于0!";
  202. }else if(empty($data['c8'][1]) || $data['c8'][1] == 0){
  203. return "浏览笔记-来回观看-最大数不能为空或等于0!";
  204. }else if((int)$data['c8'][0] > (int)$data['c8'][1]){
  205. return "浏览笔记-来回观看-大小有误!";
  206. }
  207. //向上滑动
  208. if(empty($data['c9'][0]) || $data['c9'][0] == 0){
  209. return "浏览笔记-向上滑动-次数不能为空或等于0!";
  210. }else if(empty($data['c9'][1]) || $data['c9'][1] == 0){
  211. return "浏览笔记-向上滑动-次数不能为空或等于0!";
  212. }else if((int)$data['c9'][0] > (int)$data['c9'][1]){
  213. return "浏览笔记-向上滑动-次数大小有误!";
  214. }
  215. //向下滑动
  216. if(empty($data['c10'][0]) || $data['c10'][0] == 0){
  217. return "浏览笔记-向下滑动-次数不能为空或等于0!";
  218. }else if(empty($data['c10'][1]) || $data['c10'][1] == 0){
  219. return "浏览笔记-向下滑动-次数不能为空或等于0!";
  220. }else if((int)$data['c10'][0] > (int)$data['c10'][1]){
  221. return "浏览笔记-向下滑动-次数大小有误!";
  222. }
  223. //浏览视频
  224. foreach ($data['d1_1'] as $k => $v) {
  225. if(empty($v) && $k > 1){
  226. return "浏览视频-观看时长-评论数-不能为空!";
  227. }else if(strpos($v, "-") === false && $k > 1) {
  228. return "浏览视频-观看时长-评论数规则格式不正确!";
  229. }else{
  230. if($k !== 1){
  231. if(empty($data['d1_2'][$k]) || $data['d1_2'][$k] == 0){
  232. return "浏览视频-观看时长-观看秒数不能为空或等于0!";
  233. }else if(empty($data['d1_3'][$k]) || $data['d1_3'][$k] == 0){
  234. return "浏览视频-观看时长-观看秒数不能为空或等于0!";
  235. }else if((int)$data['d1_2'][$k] > (int)$data['d1_3'][$k]){
  236. return "浏览视频-观看时长-观看时间大小有误!";
  237. }
  238. }
  239. }
  240. }
  241. //非列表视频操作 - 观看时长
  242. if(empty($data['d2'][0]) || $data['d2'][0] == 0){
  243. return "浏览视频-非列表视频操作-观看时长-秒数不能为空或等于0!";
  244. }else if(empty($data['d2'][1]) || $data['d2'][1] == 0){
  245. return "浏览视频-非列表视频操作-观看时长-秒数不能为空或等于0!";
  246. }else if((int)$data['d2'][0] > (int)$data['d2'][1]){
  247. return "浏览视频-非列表视频操作-观看时长-秒数大小有误!";
  248. }
  249. //往下浏览
  250. if(empty($data['d3'][0]) || $data['d3'][0] == 0){
  251. return "浏览视频-非列表视频操作-往下浏览-个数不能为空或等于0!";
  252. }else if(empty($data['d3'][1]) || $data['d3'][1] == 0){
  253. return "浏览视频-非列表视频操作-往下浏览-个数不能为空或等于0!";
  254. }else if((int)$data['d3'][0] > (int)$data['d3'][1]){
  255. return "浏览视频-非列表视频操作-往下浏览-个数大小有误!";
  256. }
  257. //滑动次数
  258. if(empty($data['d4'][0]) || $data['d4'][0] == 0){
  259. return "浏览视频-评论区操作-滑动次数-次数不能为空或等于0!";
  260. }else if(empty($data['d4'][1]) || $data['d4'][1] == 0){
  261. return "浏览视频-评论区操作-滑动次数-次数不能为空或等于0!";
  262. }else if((int)$data['d4'][0] > (int)$data['d4'][1]){
  263. return "浏览视频-评论区操作-滑动次数-次数大小有误!";
  264. }
  265. //展开回复
  266. if(empty($data['d5'][0]) || $data['d5'][0] == 0){
  267. return "浏览视频-评论区操作-展开回复-次数不能为空或等于0!";
  268. }else if(empty($data['d5'][1]) || $data['d5'][1] == 0){
  269. return "浏览视频-评论区操作-展开回复-次数不能为空或等于0!";
  270. }else if((int)$data['d5'][0] > (int)$data['d5'][1]){
  271. return "浏览视频-评论区操作-展开回复-次数大小有误!";
  272. }
  273. //展开概率
  274. if(empty($data['d6'][0]) || $data['d6'][0] == 0){
  275. return "浏览视频-评论区操作-展开概率-次数不能为空或等于0!";
  276. }else if(empty($data['d6'][1]) || $data['d6'][1] == 0){
  277. return "浏览视频-评论区操作-展开概率-次数不能为空或等于0!";
  278. }else if((int)$data['d6'][0] > (int)$data['d6'][1]){
  279. return "浏览视频-评论区操作-展开概率-次数大小有误!";
  280. }
  281. //列表视频 是否完整观看以及观看时长
  282. if(empty($data['d7'][0])){
  283. return "浏览视频-是否完整观看-列表视频-每[]个不能为空!";
  284. }
  285. if(empty($data['d7'][1])){
  286. return "浏览视频-是否完整观看-列表视频-点击[]个不能为空!";
  287. }
  288. if($data['d7'][1] > $data['d7'][2]){
  289. return "浏览视频-是否完整观看-列表视频-点击范围大小错误";
  290. }
  291. //浏览视频-是否完整观看-列表视频-到[]个不能为空
  292. if(empty($data['d7'][2])){
  293. return "浏览视频-是否完整观看-列表视频-到[]个不能为空!";
  294. }
  295. //列表视频 是否完整观看以及观看时长
  296. if(empty($data['d8'][0])){
  297. return "浏览视频-是否完整观看-用户视频-每[]个不能为空!";
  298. }
  299. if(empty($data['d8'][1])){
  300. return "浏览视频-是否完整观看-用户视频-点击[]个不能为空!";
  301. }
  302. if($data['d8'][1] > $data['d8'][2]){
  303. return "浏览视频-是否完整观看-用户视频-点击范围大小错误";
  304. }
  305. if(empty($data['d8'][2])){
  306. return "浏览视频-是否完整观看-用户视频-到[]个不能为空!";
  307. }
  308. //列表视频 是否完整观看以及观看时长
  309. if(empty($data['d9'][0])){
  310. return "浏览视频-是否完整观看-截流视频-每[]个不能为空!";
  311. }
  312. if(empty($data['d9'][1])){
  313. return "浏览视频-是否完整观看-截流视频-点击[]个不能为空!";
  314. }
  315. if($data['d9'][1] > $data['d9'][2]){
  316. return "浏览视频-是否完整观看-截流视频-点击范围大小错误";
  317. }
  318. if(empty($data['d9'][2])){
  319. return "浏览视频-是否完整观看-截流视频-到[]个不能为空!";
  320. }
  321. //互动设置
  322. if((int)$data['e1'] === 1){
  323. if($data['e2'] == '场景1_是否开启全局默认互动'){
  324. $ks = ['e5_1','e5_2','e5_3','e5_4','e5_5','e5_6'];
  325. foreach ($ks as $k => $v) {
  326. //只验证默认参数
  327. if(empty($data[$v][0])){
  328. return "互动设置-默认互动-第".$k."行-每[]个不能为空!";
  329. }
  330. if(empty($data[$v][1])){
  331. return "互动设置-默认互动-第".$k."行-点击[]个不能为空!";
  332. }
  333. if($data[$v][1] > $data[$v][2]){
  334. return "互动设置-默认互动-第".$k."行-点击范围大小错误";
  335. }
  336. if(empty($data[$v][2])){
  337. return "互动设置-默认互动-第".$k."行-到[]个不能为空!";
  338. }
  339. }
  340. }else{
  341. //验证 截流和非截流
  342. $ks = ['e3_1','e3_2','e3_3','e3_4','e3_5','e3_6'];
  343. foreach ($ks as $k => $v) {
  344. //只验证默认参数
  345. if(empty($data[$v][0])){
  346. return "互动设置-截流互动-第".$k."行-每[]个不能为空!";
  347. }
  348. if(empty($data[$v][1])){
  349. return "互动设置-截流互动-第".$k."行-点击[]个不能为空!";
  350. }
  351. if($data[$v][1] > $data[$v][2]){
  352. return "互动设置-截流互动-第".$k."行-点击范围大小错误";
  353. }
  354. if(empty($data[$v][2])){
  355. return "互动设置-截流互动-第".$k."行-到[]个不能为空!";
  356. }
  357. }
  358. $ks = ['e4_1','e4_2','e4_3','e4_4','e4_5','e4_6'];
  359. foreach ($ks as $k => $v) {
  360. //只验证默认参数
  361. if(empty($data[$v][0])){
  362. return "互动设置-非截流互动-第".$k."行-每[]个不能为空!";
  363. }
  364. if(empty($data[$v][1])){
  365. return "互动设置-非截流互动-第".$k."行-点击[]个不能为空!";
  366. }
  367. if($data[$v][1] > $data[$v][2]){
  368. return "互动设置-非截流互动-第".$k."行-点击范围大小错误";
  369. }
  370. if(empty($data[$v][2])){
  371. return "互动设置-非截流互动-第".$k."行-到[]个不能为空!";
  372. }
  373. }
  374. }
  375. }
  376. //用户作品
  377. if(empty($data['e6'])){
  378. return "互动设置-其他-用户作品-不能为空!";
  379. }
  380. //截流设置
  381. if(empty($data['f4'])){
  382. return "截流设置-截流相关互动设置-关注概率-不能为空!";
  383. }
  384. //内容评论区截流
  385. if(empty($data['f5']) || $data['f5'] == 0){
  386. return "截流设置-内容评论区截流-笔记滑动-不能为空或者不能等于0!";
  387. }
  388. //内容评论区截流
  389. if(empty($data['f6']) || $data['f6'] == 0){
  390. return "截流设置-内容评论区截流-视频滑动-不能为空或者不能等于0!";
  391. }
  392. //截流总数
  393. if(empty($data['f7']) || $data['f7'] == 0){
  394. return "截流设置-内容评论区截流-截流总数-不能为空或者不能等于0!";
  395. }
  396. //笔记匹配
  397. if(empty($data['f8'][0]) || $data['f8'][0] == 0){
  398. return "截流设置-内容评论区截流-笔记匹配-个数不能为空或等于0!";
  399. }else if(empty($data['f8'][1]) || $data['f8'][1] == 0){
  400. return "截流设置-内容评论区截流-笔记匹配-个数不能为空或等于0!";
  401. }else if((int)$data['f8'][0] > (int)$data['f8'][1]){
  402. return "截流设置-内容评论区截流-笔记匹配-个数大小有误!";
  403. }
  404. //视频匹配
  405. if(empty($data['f9'][0]) || $data['f9'][0] == 0){
  406. return "截流设置-内容评论区截流-视频匹配-个数不能为空或等于0!";
  407. }else if(empty($data['f9'][1]) || $data['f9'][1] == 0){
  408. return "截流设置-内容评论区截流-视频匹配-个数不能为空或等于0!";
  409. }else if((int)$data['f9'][0] > (int)$data['f9'][1]){
  410. return "截流设置-内容评论区截流-视频匹配-个数大小有误!";
  411. }
  412. //评论内容
  413. foreach ($data['f21_1'] as $k => $v) {
  414. if($k !== 1) {
  415. if (empty($v)) {
  416. return "截流设置-评论内容-关键词-请填写关键词";
  417. }
  418. }
  419. }
  420. foreach ($data['f21_2'] as $k => $v) {
  421. if($k !== 1) {
  422. if (empty($v)) {
  423. return "截流设置-评论内容-评论语句-请填写评论语句";
  424. }
  425. }
  426. }
  427. //私信内容
  428. foreach ($data['f25_1'] as $k => $v) {
  429. if($k !== 1) {
  430. if (empty($v)) {
  431. return "截流设置-私信内容-关键词-请填写关键词";
  432. }
  433. }
  434. }
  435. foreach ($data['f25_2'] as $k => $v) {
  436. if($k !== 1) {
  437. if (empty($v)) {
  438. return "截流设置-私信内容-私信语句-请填写私信语句";
  439. }
  440. }
  441. }
  442. //评论钩子设置
  443. if((int)$data['k3'] < 0){
  444. return "其他设置-评论钩子设置-点赞数不能小于0";
  445. }
  446. if((int)$data['k4'] < 0){
  447. return "其他设置-评论钩子设置-点赞数不能小于0";
  448. }
  449. if((int)$data['k5'] < 0){
  450. return "其他设置-评论钩子设置-点赞数不能小于0";
  451. }
  452. if(empty($data['k6'])) {
  453. return "请输入评论内容!";
  454. }
  455. return true;
  456. }
  457. }