Page.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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' => '请输入关键字进行搜索'],
  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. 'link' => null
  94. ],
  95. [
  96. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  97. 'link' => null
  98. ]
  99. ]
  100. ],
  101. 'image' => [
  102. 'name' => '图片',
  103. 'type' => 'image',
  104. 'style' => [
  105. 'paddingTop' => 0,
  106. 'paddingLeft' => 0,
  107. 'background' => '#ffffff'
  108. ],
  109. 'data' => [
  110. [
  111. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  112. 'imgName' => 'image-1.jpg',
  113. 'link' => null
  114. ]
  115. ]
  116. ],
  117. 'navBar' => [
  118. 'name' => '导航组',
  119. 'type' => 'navBar',
  120. 'style' => ['rowsNum' => 4, 'background' => '#ffffff', 'paddingTop' => 0, 'textColor' => '#666666'],
  121. 'data' => [
  122. [
  123. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  124. 'imgName' => 'icon-1.png',
  125. 'link' => null,
  126. 'text' => '按钮文字1'
  127. ],
  128. [
  129. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  130. 'imgName' => 'icon-2.jpg',
  131. 'link' => null,
  132. 'text' => '按钮文字2'
  133. ],
  134. [
  135. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  136. 'imgName' => 'icon-3.jpg',
  137. 'link' => null,
  138. 'text' => '按钮文字3'
  139. ],
  140. [
  141. 'imgUrl' => base_url() . 'assets/store/img/diy/navbar/01.png',
  142. 'imgName' => 'icon-4.jpg',
  143. 'link' => null,
  144. 'text' => '按钮文字4'
  145. ]
  146. ]
  147. ],
  148. 'blank' => [
  149. 'name' => '辅助空白',
  150. 'type' => 'blank',
  151. 'style' => [
  152. 'height' => 20,
  153. 'background' => '#ffffff'
  154. ]
  155. ],
  156. 'guide' => [
  157. 'name' => '辅助线',
  158. 'type' => 'guide',
  159. 'style' => [
  160. 'background' => '#ffffff',
  161. 'lineStyle' => 'solid',
  162. 'lineHeight' => 1,
  163. 'lineColor' => "#000000",
  164. 'paddingTop' => 10
  165. ]
  166. ],
  167. 'video' => [
  168. 'name' => '视频组',
  169. 'type' => 'video',
  170. 'params' => [
  171. 'videoUrl' => 'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400.mp4',
  172. 'poster' => base_url() . 'assets/store/img/diy/video_poster.png',
  173. 'autoplay' => 0
  174. ],
  175. 'style' => [
  176. 'paddingTop' => 0,
  177. 'height' => 190
  178. ]
  179. ],
  180. 'article' => [
  181. 'name' => '文章组',
  182. 'type' => 'article',
  183. 'params' => [
  184. 'source' => 'auto', // 数据来源 (choice指定 auto自动获取)
  185. 'auto' => [
  186. 'category' => -1, // -1全部
  187. 'showNum' => 6
  188. ]
  189. ],
  190. // '自动获取' => 默认数据
  191. 'defaultData' => [
  192. [
  193. 'title' => '此处显示文章标题',
  194. 'show_type' => 10,
  195. 'image' => base_url() . 'assets/store/img/diy/article/01.png',
  196. 'views_num' => 309
  197. ],
  198. [
  199. 'title' => '此处显示文章标题',
  200. 'show_type' => 10,
  201. 'image' => base_url() . 'assets/store/img/diy/article/01.png',
  202. 'views_num' => 309
  203. ]
  204. ],
  205. // '手动选择' => 默认数据
  206. 'data' => []
  207. ],
  208. 'notice' => [
  209. 'name' => '店铺公告',
  210. 'type' => 'notice',
  211. 'params' => [
  212. 'text' => '这里是第一条自定义公告的标题', // 公告内容
  213. // 'icon' => base_url() . 'assets/store/img/diy/notice.png',
  214. 'link' => null, // 链接
  215. 'showIcon' => true, // 是否显示图标
  216. 'scrollable' => true // 是否滚动
  217. ],
  218. 'style' => [
  219. 'paddingTop' => 0,
  220. 'background' => '#fffbe8',
  221. 'textColor' => '#de8c17'
  222. ]
  223. ],
  224. 'richText' => [
  225. 'name' => '富文本',
  226. 'type' => 'richText',
  227. 'params' => [
  228. 'content' => '<p>这里是文本的内容</p>'
  229. ],
  230. 'style' => [
  231. 'paddingTop' => 0,
  232. 'paddingLeft' => 0,
  233. 'background' => '#ffffff'
  234. ]
  235. ],
  236. 'window' => [
  237. 'name' => '图片橱窗',
  238. 'type' => 'window',
  239. 'style' => [
  240. 'paddingTop' => 0,
  241. 'paddingLeft' => 0,
  242. 'background' => '#ffffff',
  243. 'layout' => 2 // 布局方式: -1橱窗
  244. ],
  245. 'data' => [
  246. [
  247. 'imgUrl' => base_url() . 'assets/store/img/diy/window/01.jpg',
  248. 'link' => null
  249. ],
  250. [
  251. 'imgUrl' => base_url() . 'assets/store/img/diy/window/02.jpg',
  252. 'link' => null
  253. ],
  254. [
  255. 'imgUrl' => base_url() . 'assets/store/img/diy/window/03.jpg',
  256. 'link' => null
  257. ],
  258. [
  259. 'imgUrl' => base_url() . 'assets/store/img/diy/window/04.jpg',
  260. 'link' => null
  261. ]
  262. ],
  263. 'dataNum' => 4
  264. ],
  265. 'hotZone' => [
  266. 'name' => '热区',
  267. 'type' => 'hotZone',
  268. 'style' => [
  269. 'paddingTop' => 0,
  270. 'paddingLeft' => 0,
  271. 'background' => '#ffffff'
  272. ],
  273. 'data' => [
  274. 'imgUrl' => base_url() . 'assets/store/img/diy/banner/01.png',
  275. 'imgName' => 'image-1.jpg',
  276. 'maps' => [
  277. [
  278. 'width' => 300,
  279. 'height' => 100,
  280. 'left' => 0,
  281. 'top' => 0,
  282. 'link' => null,
  283. 'key' => 1
  284. ],
  285. ]
  286. ]
  287. ],
  288. 'goods' => [
  289. 'name' => '商品组',
  290. 'type' => 'goods',
  291. 'params' => [
  292. 'source' => 'auto', // 数据来源 (choice手动选择 auto自动获取)
  293. 'auto' => [
  294. 'category' => 0, // 商品分类 0为全部
  295. 'goodsSort' => 'all', // 商品排序 (all默认 sales销量 price价格)
  296. 'showNum' => 6 // 显示数量
  297. ]
  298. ],
  299. 'style' => [
  300. 'background' => '#F6F6F6',
  301. 'display' => 'list', // 显示类型 (list列表平铺 slide横向滑动)
  302. 'column' => 2, // 分列数量
  303. 'show' => [ // 显示内容
  304. 'goodsName', 'goodsPrice', 'linePrice', 'sellingPoint', 'goodsSales'
  305. ]
  306. ],
  307. // '自动获取' => 默认数据
  308. 'defaultData' => [
  309. [
  310. 'goods_name' => '此处显示商品名称',
  311. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  312. 'goods_price_min' => '99.00',
  313. 'line_price_min' => '139.00',
  314. 'selling_point' => '此款商品美观大方 不容错过',
  315. 'goods_sales' => 100,
  316. ],
  317. [
  318. 'goods_name' => '此处显示商品名称',
  319. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  320. 'goods_price_min' => '99.00',
  321. 'line_price_min' => '139.00',
  322. 'selling_point' => '此款商品美观大方 不容错过',
  323. 'goods_sales' => 100,
  324. ],
  325. [
  326. 'goods_name' => '此处显示商品名称',
  327. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  328. 'goods_price_min' => '99.00',
  329. 'line_price_min' => '139.00',
  330. 'selling_point' => '此款商品美观大方 不容错过',
  331. 'goods_sales' => 100,
  332. ],
  333. [
  334. 'goods_name' => '此处显示商品名称',
  335. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  336. 'goods_price_min' => '99.00',
  337. 'line_price_min' => '139.00',
  338. 'selling_point' => '此款商品美观大方 不容错过',
  339. 'goods_sales' => 100,
  340. ]
  341. ],
  342. // '手动选择' => 默认数据
  343. 'data' => [
  344. [
  345. 'goods_name' => '此处显示商品名称',
  346. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  347. 'goods_price_min' => '99.00',
  348. 'line_price_min' => '139.00',
  349. 'selling_point' => '此款商品美观大方 不容错过',
  350. 'goods_sales' => 100
  351. ],
  352. [
  353. 'goods_name' => '此处显示商品名称',
  354. 'goods_image' => base_url() . 'assets/store/img/diy/goods/01.png',
  355. 'goods_price_min' => '99.00',
  356. 'line_price_min' => '139.00',
  357. 'selling_point' => '此款商品美观大方 不容错过',
  358. 'goods_sales' => 100
  359. ]
  360. ]
  361. ],
  362. 'service' => [
  363. 'name' => '在线客服',
  364. 'type' => 'service',
  365. 'params' => [
  366. 'type' => 'chat', // '客服类型' => chat在线聊天,phone拨打电话
  367. 'image' => base_url() . 'assets/store/img/diy/service.png',
  368. 'tel' => '' // 电话号吗
  369. ],
  370. 'style' => [
  371. 'right' => 1,
  372. 'bottom' => 10,
  373. 'opacity' => 100
  374. ]
  375. ],
  376. 'officialAccount' => [
  377. 'name' => '关注公众号',
  378. 'type' => 'officialAccount',
  379. 'params' => [],
  380. 'style' => []
  381. ],
  382. 'coupon' => [
  383. 'name' => '优惠券组',
  384. 'type' => 'coupon',
  385. 'style' => [
  386. 'paddingTop' => 10,
  387. 'background' => '#ffffff',
  388. 'marginRight' => 20,
  389. 'couponBgColor' => '#ffa708',
  390. 'receiveBgColor' => '#717070'
  391. ],
  392. 'params' => ['showNum' => 5],
  393. 'data' => [
  394. [
  395. 'reduce_price' => '10',
  396. 'min_price' => '100.00'
  397. ],
  398. [
  399. 'reduce_price' => '10',
  400. 'min_price' => '100.00'
  401. ],
  402. [
  403. 'reduce_price' => '10',
  404. 'min_price' => '100.00'
  405. ]
  406. ]
  407. ],
  408. 'special' => [
  409. 'name' => '头条快报',
  410. 'type' => 'special',
  411. 'params' => [
  412. 'source' => 'auto',
  413. 'auto' => [
  414. 'category' => -1, // 文章分类ID -1为全部
  415. 'showNum' => 6
  416. ],
  417. 'display' => 1, // 显示行数
  418. 'image' => base_url() . 'assets/store/img/diy/special.png',
  419. ],
  420. 'style' => [
  421. 'background' => '#ffffff', // 背景颜色
  422. 'textColor' => '#141414', // 文字颜色
  423. 'paddingTop' => 0, // 上下边距
  424. ],
  425. // '自动获取' => 默认数据
  426. 'defaultData' => [
  427. ['title' => '张小龙4小时演讲:你和高手之间,隔着“简单”二字'],
  428. ['title' => '张小龙4小时演讲:你和高手之间,隔着“简单”二字']
  429. ],
  430. // '手动选择' => 默认数据
  431. 'data' => []
  432. ],
  433. 'ICPLicense' => [
  434. 'name' => '备案号',
  435. 'type' => 'ICPLicense',
  436. 'params' => [
  437. 'text' => '网站备案号:粤ICP备10000000号-1',
  438. 'link' => 'https://beian.miit.gov.cn/',
  439. ],
  440. 'style' => [
  441. 'fontSize' => '13', // 文字大小
  442. 'textAlign' => 'center', // 文字对齐
  443. 'textColor' => '#696969', // 文字颜色
  444. 'paddingTop' => 6, // 上下边距
  445. 'paddingLeft' => 0, // 左右边距
  446. 'background' => '#ffffff', // 背景颜色
  447. ]
  448. ],
  449. ];
  450. }
  451. /**
  452. * diy页面详情
  453. * @param int $pageId
  454. * @return static|array|null
  455. */
  456. public static function detail(int $pageId)
  457. {
  458. return static::get(['page_id' => $pageId]);
  459. }
  460. /**
  461. * diy页面详情
  462. * @return static|array|null
  463. */
  464. public static function getHomePage()
  465. {
  466. return static::get(['page_type' => PageTypeEnum::HOME]);
  467. }
  468. /**
  469. * 合并默认数据
  470. * @param $array
  471. * @return mixed
  472. */
  473. private function _mergeDefaultData($array)
  474. {
  475. $array['page'] = \resetOptions($this->getDefaultPage(), $array['page']);
  476. $defaultItems = $this->getDefaultItems();
  477. foreach ($array['items'] as &$item) {
  478. if (isset($defaultItems[$item['type']])) {
  479. array_key_exists('data', $item) && $defaultItems[$item['type']]['data'] = [];
  480. $item = \resetOptions($defaultItems[$item['type']], $item);
  481. }
  482. }
  483. return $array;
  484. }
  485. }