DiyViewCreate.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +---------------------------------------------------------------------+
  3. // | NiuCloud | [ WE CAN DO IT JUST NiuCloud ]  |
  4. // +---------------------------------------------------------------------+
  5. // | Copy right 2019-2029 www.niucloud.com  |
  6. // +---------------------------------------------------------------------+
  7. // | Author | NiuCloud <niucloud@outlook.com>  |
  8. // +---------------------------------------------------------------------+
  9. // | Repository | https://github.com/niucloud/framework.git  |
  10. // +---------------------------------------------------------------------+
  11. namespace app\event;
  12. use app\Controller;
  13. use app\model\system\DiyTemplate;
  14. use app\model\web\DiyView as DiyViewModel;
  15. /**
  16. * 自定义页面创建(根据内置模板)
  17. */
  18. class DiyViewCreate extends Controller
  19. {
  20. // 行为扩展的执行入口必须是run
  21. public function handle($data)
  22. {
  23. $diy_view = new DiyViewModel();
  24. $div_template = new DiyTemplate();
  25. // 获取系统模板数据
  26. $diy_view_info = $div_template->getTemplateInfo([ [ 'id', '=', $data[ 'template_id' ] ] ]);
  27. if (empty($diy_view_info[ 'data' ])) return error(-1, '未获取到模板数据');
  28. $diy_view_info = $diy_view_info[ 'data' ];
  29. // 自定义模板组件集合
  30. $condition = [
  31. [ 'support_diy_view', 'like', [ $diy_view_info[ 'type' ], '%' . $diy_view_info[ 'type' ] . ',%', '%' . $diy_view_info[ 'type' ], '%,' . $diy_view_info[ 'type' ] . ',%', 'DIY_VIEW_SHOP', '' ], 'or' ]
  32. ];
  33. $utils = $diy_view->getDiyViewUtilList($condition);
  34. // 推广码
  35. $qrcode_info = [];
  36. $diy_view_utils = array ();
  37. if (!empty($utils[ 'data' ])) {
  38. // 先遍历,组件分类
  39. foreach ($utils[ 'data' ] as $k => $v) {
  40. $value = array ();
  41. $value[ 'type' ] = $v[ 'type' ];
  42. $value[ 'type_name' ] = $diy_view->getTypeName($v[ 'type' ]);
  43. $value[ 'list' ] = [];
  44. if (!in_array($value, $diy_view_utils)) {
  45. array_push($diy_view_utils, $value);
  46. }
  47. }
  48. // 遍历每一个组件,将其添加到对应的分类中
  49. foreach ($utils[ 'data' ] as $k => $v) {
  50. foreach ($diy_view_utils as $diy_k => $diy_v) {
  51. if ($diy_v[ 'type' ] == $v[ 'type' ]) {
  52. array_push($diy_view_utils[ $diy_k ][ 'list' ], $v);
  53. }
  54. }
  55. }
  56. }
  57. $this->assign("extend_base", 'app/' . $data[ 'app_module' ] . '/view/base.html');
  58. $this->assign("time", time());
  59. $this->assign("name", $diy_view_info[ 'type' ]);
  60. $this->assign("qrcode_info", $qrcode_info);
  61. $this->assign('diy_view_utils', $diy_view_utils);
  62. $this->assign("diy_view_info", $diy_view_info);
  63. $request_url = $data[ 'app_module' ] . '/diy/create';
  64. $this->assign("app_module", $data[ 'app_module' ]);
  65. $this->assign("request_url", $request_url);
  66. $replace = [];
  67. $template = dirname(realpath(__DIR__)) . '/shop/view/diy/edit.html';
  68. return $this->fetch($template, [], $replace);
  69. }
  70. }