Page.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model;
  13. use cores\BaseModel;
  14. use app\common\library\helper;
  15. use app\common\enum\page\PageType as PageTypeEnum;
  16. /**
  17. * 店铺页面模型
  18. * Class Page
  19. * @package app\common\model
  20. */
  21. class Page extends BaseModel
  22. {
  23. // 定义表名
  24. protected $name = 'page';
  25. // 定义主键
  26. protected $pk = 'page_id';
  27. /**
  28. * 获取器:格式化页面数据
  29. * @param string $json
  30. * @return array
  31. */
  32. public function getPageDataAttr(string $json): array
  33. {
  34. // 数据转义
  35. $array = helper::jsonDecode(htmlspecialchars_decode($json));
  36. // 合并默认数据
  37. return $this->_mergeDefaultData($array);
  38. }
  39. /**
  40. * 修改器:自动转换data为json格式
  41. * @param array $value
  42. * @return string
  43. */
  44. public function setPageDataAttr(array $value): string
  45. {
  46. return helper::jsonEncode($value ?: ['items' => []]);
  47. }
  48. /**
  49. * 页面标题栏默认数据
  50. * @return array
  51. */
  52. public function getDefaultPage(): array
  53. {
  54. return [
  55. 'params' => [
  56. 'name' => '页面名称',
  57. 'title' => '页面标题',
  58. 'shareTitle' => '分享标题'
  59. ],
  60. 'style' => [
  61. 'titleTextColor' => 'black',
  62. 'titleBackgroundColor' => '#ffffff',
  63. ]
  64. ];
  65. }
  66. /**
  67. * 页面diy元素默认数据
  68. * @return array
  69. */
  70. public function getDefaultItems(): array
  71. {
  72. return [
  73. 'search' => [
  74. 'name' => '搜索框',
  75. 'type' => 'search',
  76. 'params' => ['placeholder' => '请输入关键字进行搜索', 'sticky' => false],
  77. 'style' => [
  78. 'textAlign' => 'left',
  79. 'searchStyle' => 'square'
  80. ]
  81. ],
  82. 'banner' => [
  83. 'name' => '图片轮播',
  84. 'type' => 'banner',
  85. 'style' => [
  86. 'btnColor' => '#ffffff',
  87. 'btnShape' => 'round',
  88. 'interval' => 2.5
  89. ],
  90. 'data' => [
  91. [
  92. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  93. 'imgName' => 'image-1.jpg',
  94. 'link' => null
  95. ],
  96. [
  97. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  98. 'imgName' => 'image-1.jpg',
  99. 'link' => null
  100. ]
  101. ]
  102. ],
  103. 'image' => [
  104. 'name' => '图片',
  105. 'type' => 'image',
  106. 'style' => [
  107. 'paddingTop' => 0,
  108. 'paddingLeft' => 0,
  109. 'background' => '#ffffff'
  110. ],
  111. 'data' => [
  112. [
  113. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  114. 'imgName' => 'image-1.jpg',
  115. 'link' => null
  116. ]
  117. ]
  118. ],
  119. 'navBar' => [
  120. 'name' => '导航组',
  121. 'type' => 'navBar',
  122. 'style' => ['rowsNum' => 4, 'background' => '#ffffff', 'paddingTop' => 0, 'textColor' => '#666666'],
  123. 'data' => [
  124. [
  125. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  126. 'imgName' => 'icon-1.png',
  127. 'link' => null,
  128. 'text' => '按钮文字1'
  129. ],
  130. [
  131. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  132. 'imgName' => 'icon-2.jpg',
  133. 'link' => null,
  134. 'text' => '按钮文字2'
  135. ],
  136. [
  137. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  138. 'imgName' => 'icon-3.jpg',
  139. 'link' => null,
  140. 'text' => '按钮文字3'
  141. ],
  142. [
  143. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  144. 'imgName' => 'icon-4.jpg',
  145. 'link' => null,
  146. 'text' => '按钮文字4'
  147. ]
  148. ]
  149. ],
  150. 'blank' => [
  151. 'name' => '辅助空白',
  152. 'type' => 'blank',
  153. 'style' => [
  154. 'height' => 20,
  155. 'background' => '#ffffff'
  156. ]
  157. ],
  158. 'guide' => [
  159. 'name' => '辅助线',
  160. 'type' => 'guide',
  161. 'style' => [
  162. 'background' => '#ffffff',
  163. 'lineStyle' => 'solid',
  164. 'lineHeight' => 1,
  165. 'lineColor' => "#000000",
  166. 'paddingTop' => 10
  167. ]
  168. ],
  169. 'video' => [
  170. 'name' => '视频组',
  171. 'type' => 'video',
  172. 'params' => [
  173. 'videoUrl' => 'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400.mp4',
  174. 'poster' => base_url() . 'assets/store/img/diy/video_poster.png',
  175. 'autoplay' => 0
  176. ],
  177. 'style' => [
  178. 'paddingTop' => 0,
  179. 'height' => 190
  180. ]
  181. ],
  182. 'article' => [
  183. 'name' => '文章组',
  184. 'type' => 'article',
  185. 'params' => [
  186. 'source' => 'auto', // 数据来源 (choice手动选择 auto自动获取)
  187. 'auto' => [
  188. 'category' => -1, // -1全部
  189. 'showNum' => 6
  190. ]
  191. ],
  192. // '自动获取' => 默认数据
  193. 'defaultData' => [
  194. [
  195. 'title' => '此处显示文章标题',
  196. 'show_type' => 10,
  197. 'image' => base_url() . 'assets/store/img/diy/article/01.png',
  198. 'views_num' => 309
  199. ],
  200. [
  201. 'title' => '此处显示文章标题',
  202. 'show_type' => 10,
  203. 'image' => base_url() . 'assets/store/img/diy/article/01.png',
  204. 'views_num' => 309
  205. ]
  206. ],
  207. // '手动选择' => 默认数据
  208. 'data' => []
  209. ],
  210. 'notice' => [
  211. 'name' => '店铺公告',
  212. 'type' => 'notice',
  213. 'params' => [
  214. 'text' => '这里是第一条自定义公告的标题', // 公告内容
  215. // 'icon' => base_url() . 'assets/store/img/diy/notice.png',
  216. 'link' => null, // 链接
  217. 'showIcon' => true, // 是否显示图标
  218. 'scrollable' => true // 是否滚动
  219. ],
  220. 'style' => [
  221. 'paddingTop' => 0,
  222. 'background' => '#fffbe8',
  223. 'textColor' => '#de8c17'
  224. ]
  225. ],
  226. 'richText' => [
  227. 'name' => '富文本',
  228. 'type' => 'richText',
  229. 'params' => [
  230. 'content' => '<p>这里是文本的内容</p>'
  231. ],
  232. 'style' => [
  233. 'paddingTop' => 0,
  234. 'paddingLeft' => 0,
  235. 'background' => '#ffffff'
  236. ]
  237. ],
  238. 'window' => [
  239. 'name' => '图片橱窗',
  240. 'type' => 'window',
  241. 'style' => [
  242. 'paddingTop' => 0,
  243. 'paddingLeft' => 0,
  244. 'background' => '#ffffff',
  245. 'layout' => 2 // 布局方式: -1橱窗
  246. ],
  247. 'data' => [
  248. [
  249. 'imgUrl' => base_url() . 'assets/store/img/diy/window/01.jpg',
  250. 'link' => null
  251. ],
  252. [
  253. 'imgUrl' => base_url() . 'assets/store/img/diy/window/02.jpg',
  254. 'link' => null
  255. ],
  256. [
  257. 'imgUrl' => base_url() . 'assets/store/img/diy/window/03.jpg',
  258. 'link' => null
  259. ],
  260. [
  261. 'imgUrl' => base_url() . 'assets/store/img/diy/window/04.jpg',
  262. 'link' => null
  263. ]
  264. ],
  265. 'dataNum' => 4
  266. ],
  267. 'hotZone' => [
  268. 'name' => '热区',
  269. 'type' => 'hotZone',
  270. 'style' => [
  271. 'paddingTop' => 0,
  272. 'paddingLeft' => 0,
  273. 'background' => '#ffffff'
  274. ],
  275. 'data' => [
  276. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  277. 'imgName' => 'image-1.jpg',
  278. 'maps' => [
  279. [
  280. 'width' => 300,
  281. 'height' => 100,
  282. 'left' => 0,
  283. 'top' => 0,
  284. 'link' => null,
  285. 'key' => 1
  286. ],
  287. ]
  288. ]
  289. ],
  290. 'goods' => [
  291. 'name' => '商品组',
  292. 'type' => 'goods',
  293. 'params' => [
  294. 'source' => 'auto', // 数据来源 (choice手动选择 auto自动获取)
  295. 'auto' => [
  296. 'category' => 0, // 商品分类 0为全部
  297. 'goodsSort' => 'all', // 商品排序 (all默认 sales销量 price价格)
  298. 'showNum' => 6 // 显示数量
  299. ]
  300. ],
  301. 'style' => [
  302. 'display' => 'list', // 显示类型 (list列表平铺 slide横向滑动)
  303. 'column' => 2, // 分列数量
  304. 'show' => [ // 显示内容
  305. 'goodsName', 'goodsPrice', 'linePrice', 'sellingPoint', 'goodsSales', 'cartBtn'
  306. ],
  307. 'priceColor' => '#ff1051', // 商品价格颜色
  308. 'sellingColor' => '#e3771f', // 商品卖点颜色
  309. 'goodsNameRows' => 'two', // 商品名称行数 (one单行 two双行)
  310. 'btnCartStyle' => 1, // 购物车按钮风格
  311. 'btnCartColor' => '#27c29a', // 购物车按钮颜色
  312. // 'btnFontColor' => '#ffffff', // 购物车按钮文字颜色
  313. 'cardType' => 'card', // 卡片样式:flat扁平 card卡片
  314. 'borderRadius' => 10, // 圆角尺寸
  315. 'itemMargin' => 10, // 商品间距
  316. 'background' => '#f6f6f6', // 背景颜色
  317. 'paddingY' => 12, // 上下边距
  318. 'paddingX' => 12, // 左右边距
  319. ],
  320. // '自动获取' => 默认数据
  321. 'defaultData' => [
  322. [
  323. 'goods_name' => '此处显示商品名称',
  324. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  325. 'goods_price_min' => '99.00',
  326. 'line_price_min' => '139.00',
  327. 'selling_point' => '此款商品美观大方 不容错过',
  328. 'goods_sales' => 100,
  329. ],
  330. [
  331. 'goods_name' => '此处显示商品名称',
  332. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  333. 'goods_price_min' => '99.00',
  334. 'line_price_min' => '139.00',
  335. 'selling_point' => '此款商品美观大方 不容错过',
  336. 'goods_sales' => 100,
  337. ],
  338. [
  339. 'goods_name' => '此处显示商品名称',
  340. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  341. 'goods_price_min' => '99.00',
  342. 'line_price_min' => '139.00',
  343. 'selling_point' => '此款商品美观大方 不容错过',
  344. 'goods_sales' => 100,
  345. ],
  346. [
  347. 'goods_name' => '此处显示商品名称',
  348. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  349. 'goods_price_min' => '99.00',
  350. 'line_price_min' => '139.00',
  351. 'selling_point' => '此款商品美观大方 不容错过',
  352. 'goods_sales' => 100,
  353. ]
  354. ],
  355. // '手动选择' => 默认数据
  356. 'data' => [
  357. [
  358. 'goods_name' => '此处显示商品名称',
  359. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  360. 'goods_price_min' => '99.00',
  361. 'line_price_min' => '139.00',
  362. 'selling_point' => '此款商品美观大方 不容错过',
  363. 'goods_sales' => 100
  364. ],
  365. [
  366. 'goods_name' => '此处显示商品名称',
  367. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  368. 'goods_price_min' => '99.00',
  369. 'line_price_min' => '139.00',
  370. 'selling_point' => '此款商品美观大方 不容错过',
  371. 'goods_sales' => 100
  372. ]
  373. ]
  374. ],
  375. 'service' => [
  376. 'name' => '在线客服',
  377. 'type' => 'service',
  378. 'params' => [
  379. 'type' => 'chat', // '客服类型' => chat在线聊天,phone拨打电话
  380. 'image' => base_url() . 'assets/store/img/diy/service.png',
  381. 'tel' => '' // 电话号吗
  382. ],
  383. 'style' => [
  384. 'right' => 1,
  385. 'bottom' => 10,
  386. 'opacity' => 100
  387. ]
  388. ],
  389. 'officialAccount' => [
  390. 'name' => '关注公众号',
  391. 'type' => 'officialAccount',
  392. 'params' => [],
  393. 'style' => []
  394. ],
  395. 'coupon' => [
  396. 'name' => '优惠券组',
  397. 'type' => 'coupon',
  398. 'style' => [
  399. 'paddingTop' => 10,
  400. 'background' => '#ffffff',
  401. 'marginRight' => 20, // 左右间距
  402. 'couponBgColor' => '#ffa708', // 优惠券背景颜色
  403. 'couponTextColor' => '#ffffff', // 优惠券文字颜色
  404. 'receiveBgColor' => '#717070', // 领取按钮颜色
  405. 'receiveTextColor' => '#ffffff', // 领取文字颜色
  406. ],
  407. 'params' => [
  408. 'source' => 'auto', // 数据来源 (choice手动选择 auto自动获取)
  409. 'showNum' => 5
  410. ],
  411. // '自动获取' => 默认数据
  412. 'defaultData' => [
  413. [
  414. 'min_price' => '100.00',
  415. 'coupon_type' => 10,
  416. 'reduce_price' => '10',
  417. ],
  418. [
  419. 'min_price' => '200.00',
  420. 'coupon_type' => 10,
  421. 'reduce_price' => '20',
  422. ],
  423. [
  424. 'min_price' => '300.00',
  425. 'coupon_type' => 10,
  426. 'reduce_price' => '30',
  427. ]
  428. ],
  429. // '手动选择' => 默认数据
  430. 'data' => []
  431. ],
  432. 'special' => [
  433. 'name' => '头条快报',
  434. 'type' => 'special',
  435. 'params' => [
  436. 'source' => 'auto',
  437. 'auto' => [
  438. 'category' => -1, // 文章分类ID -1为全部
  439. 'showNum' => 6
  440. ],
  441. 'display' => 1, // 显示行数
  442. 'image' => base_url() . 'assets/store/img/diy/special.png',
  443. ],
  444. 'style' => [
  445. 'background' => '#ffffff', // 背景颜色
  446. 'textColor' => '#141414', // 文字颜色
  447. 'paddingTop' => 0, // 上下边距
  448. ],
  449. // '自动获取' => 默认数据
  450. 'defaultData' => [
  451. ['title' => '张小龙4小时演讲:你和高手之间,隔着“简单”二字'],
  452. ['title' => '张小龙4小时演讲:你和高手之间,隔着“简单”二字']
  453. ],
  454. // '手动选择' => 默认数据
  455. 'data' => []
  456. ],
  457. 'ICPLicense' => [
  458. 'name' => '备案号',
  459. 'type' => 'ICPLicense',
  460. 'params' => [
  461. 'text' => '网站备案号:粤ICP备10000000号-1',
  462. 'link' => 'https://beian.miit.gov.cn/',
  463. ],
  464. 'style' => [
  465. 'fontSize' => '13', // 文字大小
  466. 'textAlign' => 'center', // 文字对齐
  467. 'textColor' => '#696969', // 文字颜色
  468. 'paddingTop' => 6, // 上下边距
  469. 'paddingLeft' => 0, // 左右边距
  470. 'background' => '#ffffff', // 背景颜色
  471. ]
  472. ],
  473. 'title' => [
  474. 'name' => '标题文本',
  475. 'type' => 'title',
  476. 'params' => [
  477. 'title' => '这是标题', // 标题文字内容
  478. 'desc' => '这里是描述', // 描述文字内容
  479. 'titleFontSize' => 15, // 标题大小: 12px-18px
  480. 'titleFontWeight' => 'bold', // 标题字体: normal常规 bold加粗
  481. 'descFontSize' => 12, // 描述大小: 12px-16px
  482. 'descFontWeight' => 'normal', // 描述字体: normal常规 bold加粗
  483. 'more' => [
  484. 'enable' => true, // 是否显示查看更多
  485. 'text' => '查看更多', // 文字内容
  486. 'enableIcon' => true, // 是否显示箭头图标
  487. 'link' => null, // 跳转链接
  488. ]
  489. ],
  490. 'style' => [
  491. // 'textAlign' => 'left', // 显示位置: left居左、center居中
  492. 'titleTextColor' => '#323233', // 标题文字颜色
  493. 'descTextColor' => '#969799', // 描述文字颜色
  494. 'moreTextColor' => '#969799', // 更多文字颜色
  495. 'background' => '#ffffff', // 背景颜色
  496. 'paddingY' => 8, // 上下边距
  497. ]
  498. ],
  499. ];
  500. }
  501. /**
  502. * diy页面详情
  503. * @param int $pageId
  504. * @return static|array|null
  505. */
  506. public static function detail(int $pageId)
  507. {
  508. return static::get(['page_id' => $pageId]);
  509. }
  510. /**
  511. * diy页面详情
  512. * @return static|array|null
  513. */
  514. public static function getHomePage()
  515. {
  516. return static::get(['page_type' => PageTypeEnum::HOME]);
  517. }
  518. /**
  519. * 合并默认数据
  520. * @param $array
  521. * @return mixed
  522. */
  523. private function _mergeDefaultData($array)
  524. {
  525. $array['page'] = \resetOptions($this->getDefaultPage(), $array['page']);
  526. $defaultItems = $this->getDefaultItems();
  527. foreach ($array['items'] as &$item) {
  528. if (isset($defaultItems[$item['type']])) {
  529. array_key_exists('data', $item) && $defaultItems[$item['type']]['data'] = [];
  530. $item = \resetOptions($defaultItems[$item['type']], $item);
  531. }
  532. }
  533. return $array;
  534. }
  535. }