Tpl.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 模板管理
  7. */
  8. namespace app\citys\controller;
  9. use app\citys\controller\Common;
  10. use app\citys\model\CitysTpl;
  11. use app\citys\model\CitysCate;
  12. class Tpl extends Common{
  13. public function initialize() {
  14. parent::initialize();
  15. $this->assign('pathMaps',[['name'=>'模板库','url'=>url("citys/tpl/index")]]);
  16. }
  17. //商品规格
  18. public function index(){
  19. $view['lists'] = CitysTpl::where($this->mini_program)->order('id asc')->paginate(20);
  20. $view['tabs'] = [
  21. ['name' => '主题管理','url' => url('citys/cate/index')],
  22. ['name' => '模板库','url' => url('citys/tpl/index'),'action' => 1],
  23. ['name' => '应用配置','url' => url('citys/setting/info')],
  24. ];
  25. return view('index',$view);
  26. }
  27. //规格编辑
  28. public function edit(){
  29. if(request()->isAjax()){
  30. $data = [
  31. 'id' => $this->request->param('id/d',0),
  32. 'name' => $this->request->param('name/s'),
  33. 'note' => $this->request->param('note/s'),
  34. 'title' => $this->request->param('title/a'),
  35. 'types' => $this->request->param('types/a'),
  36. 'values' => $this->request->param('values/a'),
  37. 'placeholder' => $this->request->param('placeholder/a'),
  38. 'member_miniapp_id' => $this->member_miniapp_id,
  39. ];
  40. $validate = $this->validate($data,'Infotpl.edit');
  41. if(true !== $validate){
  42. return json(['code'=>0,'msg'=>$validate]);
  43. }
  44. return CitysTpl::edit($data);
  45. }else{
  46. $id = $this->request->param('id/d',0);
  47. if($id){
  48. $info = CitysTpl::where($this->mini_program)->where(['id' => $id])->find();
  49. $fields = json_decode($info->fields,true);
  50. foreach ($fields as $key => $value) {
  51. if($value['types'] == 'selector'){
  52. $fields[$key]['values'] = implode('|',$value['values']);
  53. }
  54. }
  55. $info->fields = $fields;
  56. $view['info'] = $info;
  57. return view()->assign($view);
  58. }else{
  59. return view('add');
  60. }
  61. }
  62. }
  63. //规格编辑
  64. public function users(){
  65. if(request()->isAjax()){
  66. $data = [
  67. 'id' => $this->request->param('id/d',0),
  68. 'is_shop' => $this->request->param('is_shop/d',0),
  69. 'name' => $this->request->param('button_name/s','下单'),
  70. 'tips' => $this->request->param('tips/s','下单'),
  71. 'title' => $this->request->param('title/a'),
  72. 'types' => $this->request->param('types/a'),
  73. 'values' => $this->request->param('values/a'),
  74. 'placeholder' => $this->request->param('placeholder/a'),
  75. 'member_miniapp_id' => $this->member_miniapp_id,
  76. ];
  77. $validate = $this->validate($data,'Infotpl.edit');
  78. if(true !== $validate){
  79. return json(['code'=>0,'msg'=>$validate]);
  80. }
  81. return CitysTpl::usersEdit($data);
  82. }else{
  83. $id = $this->request->param('id/d',0);
  84. $info = CitysTpl::where($this->mini_program)->where(['id' => $id])->find();
  85. $users = json_decode($info->users,true);
  86. foreach ($users as $key => $value) {
  87. if($value['types'] == 'selector'){
  88. $users[$key]['values'] = implode('|',$value['values']);
  89. }
  90. }
  91. $info->users = $users;
  92. $view['info'] = $info;
  93. return view()->assign($view);
  94. }
  95. }
  96. //规格模板
  97. public function delete(int $id){
  98. $rel = CitysCate::where(['tpl_id' => $id])->find();
  99. if($rel){
  100. return enjson(0,'模板在【'.$rel->name.'】的信息类别中启用,禁止删除');
  101. }
  102. $result = CitysTpl::destroy(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id]);
  103. if($result){
  104. return enjson(200,'操作成功');
  105. }
  106. return enjson(0);
  107. }
  108. }