123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- /**
- * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
- * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
- * @author pillar<ltmn@qq.com>
- * 模板管理
- */
- namespace app\citys\controller;
- use app\citys\controller\Common;
- use app\citys\model\CitysTpl;
- use app\citys\model\CitysCate;
- class Tpl extends Common{
- public function initialize() {
- parent::initialize();
- $this->assign('pathMaps',[['name'=>'模板库','url'=>url("citys/tpl/index")]]);
- }
- //商品规格
- public function index(){
- $view['lists'] = CitysTpl::where($this->mini_program)->order('id asc')->paginate(20);
- $view['tabs'] = [
- ['name' => '主题管理','url' => url('citys/cate/index')],
- ['name' => '模板库','url' => url('citys/tpl/index'),'action' => 1],
- ['name' => '应用配置','url' => url('citys/setting/info')],
- ];
- return view('index',$view);
- }
- //规格编辑
- public function edit(){
- if(request()->isAjax()){
- $data = [
- 'id' => $this->request->param('id/d',0),
- 'name' => $this->request->param('name/s'),
- 'note' => $this->request->param('note/s'),
- 'title' => $this->request->param('title/a'),
- 'types' => $this->request->param('types/a'),
- 'values' => $this->request->param('values/a'),
- 'placeholder' => $this->request->param('placeholder/a'),
- 'member_miniapp_id' => $this->member_miniapp_id,
- ];
- $validate = $this->validate($data,'Infotpl.edit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- return CitysTpl::edit($data);
- }else{
-
- $id = $this->request->param('id/d',0);
- if($id){
- $info = CitysTpl::where($this->mini_program)->where(['id' => $id])->find();
- $fields = json_decode($info->fields,true);
- foreach ($fields as $key => $value) {
- if($value['types'] == 'selector'){
- $fields[$key]['values'] = implode('|',$value['values']);
- }
- }
- $info->fields = $fields;
- $view['info'] = $info;
- return view()->assign($view);
- }else{
- return view('add');
- }
- }
- }
- //规格编辑
- public function users(){
- if(request()->isAjax()){
- $data = [
- 'id' => $this->request->param('id/d',0),
- 'is_shop' => $this->request->param('is_shop/d',0),
- 'name' => $this->request->param('button_name/s','下单'),
- 'tips' => $this->request->param('tips/s','下单'),
- 'title' => $this->request->param('title/a'),
- 'types' => $this->request->param('types/a'),
- 'values' => $this->request->param('values/a'),
- 'placeholder' => $this->request->param('placeholder/a'),
- 'member_miniapp_id' => $this->member_miniapp_id,
- ];
- $validate = $this->validate($data,'Infotpl.edit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- return CitysTpl::usersEdit($data);
- }else{
- $id = $this->request->param('id/d',0);
- $info = CitysTpl::where($this->mini_program)->where(['id' => $id])->find();
- $users = json_decode($info->users,true);
- foreach ($users as $key => $value) {
- if($value['types'] == 'selector'){
- $users[$key]['values'] = implode('|',$value['values']);
- }
- }
- $info->users = $users;
- $view['info'] = $info;
- return view()->assign($view);
- }
- }
- //规格模板
- public function delete(int $id){
- $rel = CitysCate::where(['tpl_id' => $id])->find();
- if($rel){
- return enjson(0,'模板在【'.$rel->name.'】的信息类别中启用,禁止删除');
- }
- $result = CitysTpl::destroy(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id]);
- if($result){
- return enjson(200,'操作成功');
- }
- return enjson(0);
- }
- }
|