DiyViewEdit.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. declare (strict_types = 1);
  12. namespace app\event;
  13. use app\Controller;
  14. use app\model\web\DiyView as DiyViewModel;
  15. use think\View;
  16. /**
  17. * 自定义页面编辑
  18. */
  19. class DiyViewEdit extends Controller
  20. {
  21. // 行为扩展的执行入口必须是run
  22. public function handle($data)
  23. {
  24. $diy_view = new DiyViewModel();
  25. // 自定义模板组件集合
  26. $utils = $diy_view->getDiyViewUtilList($data['condition']);
  27. $diy_view_info = [];
  28. // 推广码
  29. $qrcode_info = [];
  30. if (!empty($data['id'])) {
  31. $diy_view_info = $diy_view->getSiteDiyViewDetail([
  32. [ 'sdv.site_id', '=', $data['site_id'] ],
  33. [ 'sdv.id', '=', $data['id'] ]
  34. ]);
  35. $qrcode_info = $diy_view->qrcode([
  36. [ 'site_id', '=', $data['site_id'] ],
  37. [ 'id', '=', $data['id'] ]
  38. ]);
  39. } elseif (!empty($data['name'])) {
  40. $condition = [
  41. [ 'sdv.site_id', '=', $data['site_id'] ],
  42. [ 'sdv.name', '=', $data['name'] ]
  43. ];
  44. $qrcode_info = $diy_view->qrcode([
  45. [ 'site_id', '=', $data['site_id'] ],
  46. [ 'name', '=', $data['name'] ]
  47. ]);
  48. $diy_view_info = $diy_view->getSiteDiyViewDetail($condition);
  49. }
  50. if (!empty($diy_view_info) && !empty($diy_view_info['data'])) {
  51. $diy_view_info = $diy_view_info['data'];
  52. }
  53. if (!empty($qrcode_info)) {
  54. $qrcode_info = $qrcode_info['data'];
  55. // 目前只支持H5
  56. if ($qrcode_info['path']['h5']['status'] != 1) {
  57. $qrcode_info = [];
  58. }
  59. }
  60. $diy_view_utils = array();
  61. if (!empty($utils['data'])) {
  62. // 先遍历,组件分类
  63. foreach ($utils['data'] as $k => $v) {
  64. $value = array();
  65. $value['type'] = $v['type'];
  66. $value['type_name'] = $diy_view->getTypeName($v['type']);
  67. $value['list'] = [];
  68. if (!in_array($value, $diy_view_utils)) {
  69. array_push($diy_view_utils, $value);
  70. }
  71. }
  72. // 遍历每一个组件,将其添加到对应的分类中
  73. foreach ($utils['data'] as $k => $v) {
  74. foreach ($diy_view_utils as $diy_k => $diy_v) {
  75. if ($diy_v['type'] == $v['type']) {
  76. array_push($diy_view_utils[ $diy_k ]['list'], $v);
  77. }
  78. }
  79. }
  80. }
  81. $this->assign("time", time());
  82. $this->assign("name", isset($data['name']) ? $data['name'] : '');
  83. $this->assign("qrcode_info", $qrcode_info);
  84. $this->assign('diy_view_utils', $diy_view_utils);
  85. $this->assign("diy_view_info", $diy_view_info);
  86. $this->assign("app_module", $data['app_module']);
  87. $request_url = $data['app_module'] . '/diy/edit';
  88. $this->assign("request_url", $request_url);
  89. $this->assign("extend_base", 'app/' . $data['app_module'] . '/view/base.html');
  90. $template = dirname(realpath(__DIR__)) . '/admin/view/diy/edit.html';
  91. return $this->fetch($template);
  92. }
  93. }