MarketController.php 8.5 KB
<?php
namespace api\portal\controller;
use think\Controller;
use think\Db;

/**
 * @title 后台营销业务
 * @description 营销业务相关接口
 */
class MarketController extends Controller
{
    /**
     * @title 添加分类
     * @description
     * @author panhaowen
     * @url /portal/market/marketAdd
     * @param name:type type:int require:1 desc:字段类型
     * @param name:selected type:varchar require:1 desc:所选字段id(,隔开)
     * @param name:name type:varchar require:1 desc:分类名称
     * @method POST
     */
    public function marketAdd()
    {
        $param=$this->request->param();
//        $param['selected']=json_encode(explode(',',$param['selected']));
        $re=Db::name('market')->insert($param);
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 分类(列表)
     * @description
     * @author panhaowen
     * @url /portal/market/market
     * @method POST
     */
    public function market()
    {
        $data=Db::name('market')->select();
        $this->success('获取信息成功',$data);
    }

    /**
     * @title 编辑分类
     * @description
     * @author panhaowen
     * @url /portal/market/marketEdit
     * @param name:id type:int require:1 desc:分类id
     * @method POST
     */
    public function marketEdit()
    {
        $param=$this->request->param();
        $data=Db::name('market')->where('id',$param['id'])->find();
        $data['selected']=Db::name('classify')->where('id','in',explode(',', $data['selected']))->select();
        $type=Db::name('type')->where('id',$data['type'])->find()['classify'];
        $data['classify']=Db::name('classify')->where('id','in',explode(',', $type))->select();
        $this->success('获取信息成功',$data);
    }


    /**
     * @title 编辑分类提交
     * @description
     * @author panhaowen
     * @url /portal/market/marketEditPost
     * @param name:id type:int require:1 desc:分类id
     * @param name:selected type:varchar require:1 desc:所选字段id(,隔开)
     * @param name:name type:varchar require:1 desc:分类名称
     * @method POST
     */
    public function marketEditPost()
    {
        $param=$this->request->param();
        $re=Db::name('market')->where('id',$param['id'])->update($param);
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 删除分类
     * @description
     * @author panhaowen
     * @url /portal/market/marketDelete
     * @param name:id type:int require:1 desc:分类id
     * @method POST
     */
    public function marketDelete()
    {
        $param=$this->request->param();
        $re=Db::name('market')->where('id',$param['id'])->delete();
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 筛选条件(添加)
     * @description
     * @author panhaowen
     * @url /portal/market/classify
     * @method POST
     * @param name:type type:int require:1 desc:字段类型
     */
    public function classify()
    {
        $param=$this->request->param();
        $classify=Db::name('type')->where('id',$param['type'])->find()['classify'];
        $classify=explode(',',$classify);
        $data=Db::name('classify')->where('id','in',$classify)->select();
        $this->success('获取信息成功',$data);
    }


    /**
     * @title 筛选条件(列表)
     * @description
     * @author panhaowen
     * @url /portal/market/classifyIndex
     * @method POST
     * @param name:id type:int require:1 desc:分类id
     */
    public function classifyIndex()
    {
        $param=$this->request->param();
        $classify=explode(',',Db::name('market')->where('id',$param['id'])->find()['selected']);
        $data=Db::name('classify')->where('id','in',$classify)->select()->toArray();
        $arr=[];
//        $arr['id']=$classify;
        foreach ($data as $k=>$v){
            $arr[$v['name']]=Db::name('classify_value')->where(['market_id'=>$param['id'],'classify_id'=>$v['id']])->select();
        }
        $this->success('获取信息成功',$arr);
    }

    /**
     * @title 添加筛选字段
     * @description
     * @author panhaowen
     * @url /portal/market/classifyAdd
     * @method POST
     * @param name:id type:int require:1 desc:筛选字段id
     * @param name:category_id type:int require:1 desc:分类id
     * @param name:name type:varchar require:1 desc:筛选名称
     */
    public function classifyAdd()
    {
        $param=$this->request->param();
        $re=Db::name('classify_value')->insert(['market_id'=>$param['category_id'],'create_time'=>time(),'classify_id'=>$param['id'],'value'=>$param['name']]);
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }


    /**
     * @title 删除筛选字段
     * @description
     * @author panhaowen
     * @url /portal/market/classifyDelete
     * @param name:id type:int require:1 desc:筛选字段值id
     * @method POST
     */
    public function classifyDelete()
    {
        $param=$this->request->param();
        $re=Db::name('classify_value')->where('id',$param['id'])->delete();
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 添加营销
     * @description
     * @author panhaowen
     * @url /portal/market/marketBusinessAdd
     * @method POST
     * @param name:market_id type:int require:1 desc:上级分类id
     */
    public function marketBusinessAdd()
    {
        $param=$this->request->param();
        $type=Db::name('market')->where('id',$param['market_id'])->find()['type'];
        $classify=Db::name('type')->where('id',$type)->find()['classify'];
        $data=Db::name('classify')->where('id','in',explode(',',$classify))->select();
        $this->success('获取信息成功',$data);
    }

    /**
     * @title 添加营销提交
     * @description 添加营销提交
     * @author panhaowen
     * @url /portal/market/marketBusinessAddPost
     * @method POST
     * @param name:market_id type:int require:1 desc:上级分类id
     */
    public function marketBusinessAddPost()
    {
        $param=$this->request->param();
        $param['create_time']=time();
        $re=Db::name('market_business')->insert($param);
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 编辑营销
     * @description
     * @author panhaowen
     * @url /portal/market/marketBusinessEdit
     * @method POST
     * @param name:id type:int require:1 desc:媒体id
     */
    public function marketBusinessEdit()
    {
        $param=$this->request->param();
        $data=Db::name('market_business')->where('id',$param['id'])->find();
        $this->success('获取信息成功',$data);
    }

    /**
     * @title 编辑营销提交
     * @description
     * @author panhaowen
     * @url /portal/market/marketBusinessEditPost
     * @method POST
     * @param name:id type:int require:1 desc:媒体id
     */
    public function marketBusinessEditPost()
    {
        $param=$this->request->param();
        $re=Db::name('market_business')->where('id',$param['id'])->update($param);
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 删除营销
     * @description
     * @author panhaowen
     * @url /portal/market/marketBusinessDelete
     * @param name:id type:int require:1 desc:媒体id
     * @method POST
     */
    public function marketBusinessDelete()
    {
        $param=$this->request->param();
        $re=Db::name('market_business')->where('id',$param['id'])->delete();
        if ($re){
            $this->success('操作成功');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * @title 营销(列表)
     * @description
     * @author panhaowen
     * @url /portal/market/marketBusiness
     * @param name:market_id type:int require:1 desc:分类id
     * @method POST
     */
    public function marketBusiness()
    {
        $param=$this->request->param();
        $data=Db::name('market_business')->where('market_id',$param['market_id'])->paginate(10);
        $this->success('获取信息成功',$data);
    }

}