Treasured.php 5.2 KB
<?php


namespace app\api\controller;

/**
 * 墨宝档案
 * @package app\api\controller
 */
class Treasured extends BaseApi
{
    protected $noNeedLogin = '';
    protected $noNeedRight = '*';

    /**
     * 获取墨宝档案尺寸
     * @ApiTitle    (获取墨宝档案尺寸)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/treasured/getTreasuredSize)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "获取数据成功",
        "time": "1609298080",
        "data": [
            {
                "id": "尺寸id",
                "name": "尺寸名称",
                "createtime": "2020-12-29 09:18:49"
            }
        ]
        })
     */
    public function getTreasuredSize(){
        $TreasuredSize = model('TreasuredSize')->order('weigh','desc')->field('id,name,createtime')->select();
        $this->success('获取数据成功',$TreasuredSize);
    }
    /**
     * 增加墨宝档案
     * @ApiTitle    (增加墨宝档案)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/treasured/addTreasured)
     * @ApiParams   (name="author", type="string", required=true, description="墨宝作者")
     * @ApiParams   (name="title", type="string", required=true, description="墨宝标题")
     * @ApiParams   (name="content", type="string", required=true, description="墨宝内容")
     * @ApiParams   (name="images", type="string", required=true, description="图片数组{不带域名}")
     * @ApiParams   (name="production_typeface_id", type="integer", required=true, description="字体ID")
     * @ApiParams   (name="treasured_size_id", type="integer", required=true, description="尺寸ID")
     * @ApiParams   (name="production_format_id", type="integer", required=true, description="格式ID")
     * @ApiParams   (name="status", type="integer", required=true, description="状态:0=待出售,1=已出售,2=非卖品")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "增加墨宝档案成功",
        "time": "1609306718",
        "data": {
        "id": 1,
        "user_id": "用户ID",
        "avatar": "用户头像",
        "nickname": "用户昵称",
        "title": "我是文章标题",
        "number": "墨宝编号",
        "author": "作者",
        "images": "墨宝图片",
        "content": "墨宝内容",
        "production_typeface": "书体名称",
        "production_typeface_id": "书体id{用的作品里面的书体}",
        "production_format": "格式名称",
        "production_format_id": "用的作品里面的格式",
        "treasured_size": "尺寸名称",
        "treasured_size_id": "尺寸id",
        "status": "状态:0=待出售,1=已出售,2=非卖品",
        "zan_num": "点赞数量",
        "createtime": "2020-12-30 13:38:38",
        "updatetime": "2020-12-30 13:38:38",
        "deletetime": null,
        "message": null
        }
        })
     */
    public function addTreasured(){
        //1.验证用户权限
        if ($this->auth->authlist == '' || $this->auth->authlist == ','){
            $this->error('请您先实名认证');
        }
        //2.获取数据
        $data = $this->get_data_array([
            ['title','作品标题不能为空'],
            ['content','内容不存在'],
            ['images','图片必须上传'],
            ['production_typeface_id','字体ID必须传入'],
            ['treasured_size_id','尺寸ID必须传入'],
            ['production_format_id','格式ID必须传入'],
            ['status','状态必须填写 0=待出售,1=已出售,2=非卖品'],
        ]);
        //3.获取图片数据
        $files = str_replace('&quot;','"',$data['images']);
        $images = implode(',',json_decode($files,true));
        //4.查询数据
        $typeface = model('production_typeface')->where('id',$data['production_typeface_id'])->find();
        $treasured_size = model('treasured_size')->where('id',$data['treasured_size_id'])->find();
        $format = model('production_format')->where('id',$data['production_format_id'])->find();
        if (!$typeface || !$treasured_size || !$format){
            $this->error('数据不存在');
        }
        $data['production_typeface'] = $typeface['name'];
        $data['treasured_size'] = $treasured_size['name'];
        $data['production_format'] = $format['name'];
        $data['user_id'] = $this->auth->id;
        $data['avatar'] = $this->auth->avatar;
        $data['nickname'] = $this->auth->nickname;
        $data['images'] = $images;
        //5.增加墨宝
        $treasured = model('treasured')->create($data);
        //6.查询数据
        $treasured = model('treasured')->where('id',$treasured['id'])->find();
        //7.返回结果
        $this->success('增加墨宝档案成功',$treasured);
    }

}