DiypageController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\DiyPage;
  5. use app\model\DomainReplace;
  6. use think\db\Where;
  7. class DiypageController extends Base
  8. {
  9. function index()
  10. {
  11. $weid = weid();
  12. $keyword = input('post.keyword', '', 'serach_in');
  13. $query = DiyPage::where(['weid' => $weid]);
  14. if (!empty($keyword)) {
  15. $query->where('title', 'like', '%' . $keyword . '%');
  16. }
  17. $res = $query->order('id asc')
  18. ->paginate(getpage())
  19. ->toArray();
  20. $data['data'] = $res;
  21. return $this->json($data);
  22. }
  23. public function add()
  24. {
  25. $weid = weid();
  26. $data['weid'] = $weid;
  27. $data['title'] = '自定义页面';
  28. $data['version'] = 2;
  29. $data['pagebase'] = serialize(input('post.pagebase'));
  30. $res = DiyPage::create($data);
  31. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  32. }
  33. public function update()
  34. {
  35. $id = $this->request->post('id');
  36. $weid = weid();
  37. $postdata = input('post.');
  38. unset($data['create_time']);
  39. if (!empty($postdata['pageList'])) {
  40. foreach ($postdata['pageList'] as $vo) {
  41. $dp = DiyPage::where(['weid' => $weid, 'id' => $vo['id'], 'version' => 2])->find();
  42. $data['weid'] = $weid;
  43. $data['title'] = $vo['pagebase'][0]['params']['title'];
  44. $data['pagebase'] = serialize($vo['pagebase']);
  45. $data['modulelist'] = serialize($vo['modulelist']);
  46. $data['version'] = 2;
  47. $data['status'] = 1;
  48. if (empty($dp)) {
  49. try {
  50. $res = DiyPage::create($data);
  51. } catch (\Exception $e) {
  52. throw new ValidateException($e->getMessage());
  53. }
  54. } else {
  55. $data['id'] = $vo['id'];
  56. try {
  57. DiyPage::update($data);
  58. } catch (\Exception $e) {
  59. throw new ValidateException($e->getMessage());
  60. }
  61. }
  62. }
  63. return $this->json(['msg' => '保存成功']);
  64. } else {
  65. if (empty($id)) {
  66. $data['weid'] = $weid;
  67. $data['title'] = $postdata['title'];
  68. $data['is_index'] = $postdata['is_index'];
  69. $data['status'] = $postdata['status'];
  70. try {
  71. $res = DiyPage::create($data);
  72. } catch (\Exception $e) {
  73. throw new ValidateException($e->getMessage());
  74. }
  75. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  76. } else {
  77. try {
  78. DiyPage::update($data);
  79. } catch (\Exception $e) {
  80. throw new ValidateException($e->getMessage());
  81. }
  82. return $this->json(['msg' => '修改成功']);
  83. }
  84. }
  85. }
  86. public function listUpdate()
  87. {
  88. $data = only('id,status,is_submitaudit,is_index');
  89. if (!$data['id']) throw new ValidateException('参数错误');
  90. DiyPage::update($data);
  91. return $this->json(['msg' => '操作成功']);
  92. }
  93. public function setaudit()
  94. {
  95. $id = input('post.id');
  96. DiyPage::where('id', '>', 0)->where(['weid' => weid()])->where(['version' => 2])->where(['version' => 2])->update(['is_submitaudit' => 0]);
  97. DiyPage::where('id', '=', $id)->update(['is_submitaudit' => 1]);
  98. return $this->json(['msg' => '设为审核成功']);
  99. }
  100. public function setindex()
  101. {
  102. $id = input('post.id');
  103. DiyPage::where('id', '>', 0)->where(['weid' => weid()])->update(['is_index' => 0]);
  104. DiyPage::where('id', '=', $id)->update(['is_index' => 1]);
  105. return $this->json(['msg' => '设置首页成功']);
  106. }
  107. function getInfo()
  108. {
  109. $id = $this->request->post('id', '', 'serach_in');
  110. if (!$id) throw new ValidateException('参数错误');
  111. $data = DiyPage::field('*')->find($id)->toArray();
  112. return $this->json(['data' => $data]);
  113. }
  114. function getpageInfo()
  115. {
  116. $text = [
  117. 'subtitle' => '',
  118. 'miaoshu' => '',
  119. 'show' => false,
  120. 'defaultstyle' => false,
  121. 'fontsize' => 14,
  122. 'color' => '#333333',
  123. 'bold' => false,
  124. 'italics' => false,
  125. 'underline' => false
  126. ];
  127. $link = [
  128. 'ptype' => '',
  129. 'miaoshu' => '',
  130. 'id' => '',
  131. 'path' => ''
  132. ];
  133. $base = [
  134. 'style' => 0,
  135. 'margin' => true,
  136. 'bg' => 1,
  137. 'bt' => 1,
  138. 'bc' => '#ffffff',
  139. 'bi' => '',
  140. 'fc' => ''
  141. ];
  142. $data = DiyPage::where(['weid' => weid(), 'version' => 2])->select()->toArray();
  143. if (!empty($data)) {
  144. foreach ($data as &$vo) {
  145. $vo['title'] = $vo['title'];
  146. $vo['pagebase'] = iunserializer($vo['pagebase']);
  147. if (empty($vo['pagebase'][0]['base']['titleBackground'])) {
  148. $vo['pagebase'][0]['base']['titleBackground'] = $base;
  149. }
  150. $vo['modulelist'] = iunserializer($vo['modulelist']);
  151. foreach ($vo['modulelist'] as &$movo) {
  152. if ($movo['type'] == 'goods') {
  153. if (empty($movo['title']['title'])) {
  154. $movo['title']['title'] = $text;
  155. $movo['title']['title']['prompt'] = '模块标题';
  156. $movo['title']['title']['txt'] = '商品模块标题';
  157. $movo['title']['more'] = $text;
  158. $movo['title']['more']['prompt'] = '更多文字';
  159. $movo['title']['more']['txt'] = '更多';
  160. $movo['title']['link'] = $link;
  161. }
  162. if(empty($movo['base']['auto']['ptype'])){
  163. $movo['base']['auto']['ptype'] = 0;
  164. }
  165. }
  166. if ($movo['type'] == 'tuan') {
  167. if (empty($movo['title']['title'])) {
  168. $movo['title']['title'] = $text;
  169. $movo['title']['title']['prompt'] = '模块标题';
  170. $movo['title']['title']['txt'] = '超值拼团';
  171. $movo['title']['title']['show'] = true;
  172. $movo['title']['more'] = $text;
  173. $movo['title']['more']['prompt'] = '更多文字';
  174. $movo['title']['more']['txt'] = '更多';
  175. $movo['title']['more']['show'] = true;
  176. }
  177. }
  178. if ($movo['type'] == 'miaosha') {
  179. if (empty($movo['title']['title'])) {
  180. $movo['title']['title'] = $text;
  181. $movo['title']['title']['prompt'] = '模块标题';
  182. $movo['title']['title']['txt'] = '限时秒杀';
  183. $movo['title']['title']['show'] = true;
  184. $movo['title']['more'] = $text;
  185. $movo['title']['more']['prompt'] = '更多文字';
  186. $movo['title']['more']['txt'] = '更多';
  187. $movo['title']['more']['show'] = true;
  188. }
  189. }
  190. if ($movo['type'] == 'window') {
  191. if (empty($movo['base']['style'])) {
  192. $movo['base']['style'] = 'style1';
  193. }
  194. foreach ($movo['list'] as &$wlistvo) {
  195. if (empty($wlistvo['type'])) {
  196. $wlistvo['type'] = "";
  197. }
  198. if (empty($wlistvo['windowbody'])) {
  199. $wlistvo['windowbody'] = [];
  200. }
  201. }
  202. }
  203. }
  204. }
  205. } else {
  206. $data = '';
  207. }
  208. $data = DomainReplace::setreplace($data);
  209. return $this->json(['data' => $data]);
  210. }
  211. function delete()
  212. {
  213. return $this->del(new DiyPage());
  214. }
  215. }