RecycleController.php 8.6 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/12
 * Time: 18:21
 */

namespace api\index\controller;


use cmf\controller\RestBaseController;
use think\Db;
use think\Request;


/**
 * @title 回收首页
 * @description
 */
class RecycleController extends RestBaseController
{
    /**
     * @title 可回收物类型
     * @description
     * @author GuoSheng
     * @url /index/Recycle/index
     * @method GET
     *
     * @return id:可回收物分类ID
     * @return recycle_name:类型名称
     * @return thumbnail:图片
     * @return price:价格
     *
     */
    public function index(){
        $where['delete_time'] = ['eq',0];
        $data = Db::name('recycletype')
            ->where($where)
            ->field('id,recycle_name,thumbnail,price')
            ->select()
            ->toArray();
        $this->success('SUCCESS',$data);

    }

    /**
     * @title 可回收物品
     * @description
     * @author GuoSheng
     * @url /index/Recycle/rgoods
     * @method GET
     *
     * @param name:recycletype_id type:int require:0 other: desc:所属分类ID
     *
     * @return id:可回收物品id
     * @return recycletype_id:所属分类id
     * @return name:名称
     * @return thumbnail:图片
     *
     */
    public function rgoods(){
        $recycletype_id = $this->request->param('recycletype_id');
        if(empty($recycletype_id)){
            $data = Db::name('recyclegoods')
                ->where('recycletype_id',1)
                ->select();
            $this->success('SUCCESS',$data);
        }else{
            $data = Db::name('recyclegoods')
                ->where('recycletype_id',$recycletype_id)
                ->select();
            $this->success('SUCCESS',$data);
        }
    }

    /**
     * @title 不可回收物类型
     * @description
     * @author GuoSheng
     * @url /index/Recycle/noRecycle
     * @method GET
     *
     * @return id:不可回收物分类ID
     * @return recycle_name:类型名称
     * @return thumbnail:图片
     * @return price:价格
     *
     */
    public function noRecycle()
    {
        $where['delete_time'] = ['eq',0];
        $data = Db::name('norecycletype')
            ->where($where)
            ->field('id,recycle_name,thumbnail')
            ->select()
            ->toArray();
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 不可回收物品
     * @description
     * @author GuoSheng
     * @url /index/Recycle/norgoods
     * @method GET
     *
     * @param name:recycletype_id type:int require:0 other: desc:所属分类ID
     *
     * @return id:不可回收物品id
     * @return recycletype_id:所属分类id
     * @return name:名称
     * @return thumbnail:图片
     *
     */
    public function norgoods(){
        $recycletype_id = $this->request->param('recycletype_id');
        if(empty($recycletype_id)){
            $data = Db::name('norecyclegoods')
                ->where('recycletype_id',1)
                ->select();
            $this->success('SUCCESS',$data);
        }else{
            $data = Db::name('norecyclegoods')
                ->where('recycletype_id',$recycletype_id)
                ->select();
            $this->success('SUCCESS',$data);
        }
    }

    /**
     * @title 回收首页轮播图
     * @description
     * @author GuoSheng
     * @url /index/Recycle/photo
     * @method GET
     *
     * @return id:ID
     * @return thumbnail:图片
     * @return url:链接地址
     *
     */
    public function photo(){
        $where['delete_time'] = ['eq',0];
        $data = Db::name('pic')
            ->where($where)
            ->field('id,thumbnail,url')
            ->select()
            ->toArray();
        foreach ($data as &$v){
            $v['thumbnail'] = cmf_get_image_url($v['thumbnail']);
        }
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 回收站点列表
     * @description
     * @author GuoSheng
     * @url /index/Recycle/point
     * @method GET
     *
     * @return id:ID
     * @return point_name:站点名称
     * @return thumbnail:图片
     * @return address:详细地址
     * @return lng:站点所在经度
     * @return lat:站点所在纬度
     *
     */
    public function point()
    {
        $where['delete_time'] = ['eq',0];
        $data = Db::name('point')
            ->where($where)
            ->field('id,point_name,address,thumbnail,lng,lat')
            ->select()
            ->toArray();
        foreach ($data as &$v){
            $v['thumbnail'] = cmf_get_image_url($v['thumbnail']);
        }
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 回收首页装修材料logo
     * @description
     * @author GuoSheng
     * @url /index/Recycle/build
     * @method GET
     *
     * @return id:ID
     * @return thumbnail:图片
     *
     */
    public function build(){
        $data = Db::name('pic')
            ->where('id',1)
            ->field('id,thumbnail')
            ->find();
        $data['thumbnail'] = cmf_get_image_url($data['thumbnail']);
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 回收首页服务评价列表
     * @description
     * @author GuoSheng
     * @url /index/Recycle/rgoods
     * @method GET
     *
     * @param name:page type:int require:0 other: desc:当前页(默认1)
     * @param name:pageNum type:int require:0 other: desc:每页显示数据个数(默认10)
     *
     * @return id:评价id
     * @return user_id:用户ID
     * @return user_nickname:用户名
     * @return num:评价星数
     * @return content:评价内容
     *
     */
    public function comment()
    {
        $page = $this->request->param('page',1,'intval');
        $pageNum = $this->request->param('pageNum',10,'intval');
        $res = Db::name('recyclecomment')
            ->alias('a')
            ->join('user b','a.user_id = b.id')
            ->field('a.*,b.user_nickname')
            ->page($page,$pageNum)
            ->select()
            ->toArray();
        foreach ($res as &$v){
            $v['num'] = ceil(($v['speed']+$v['service']+$v['recycle'])/3);
        }
        $this->success('SUCCESS',$res);
    }

    /**
     * @title 回收首页我的积分
     * @description
     * @author GuoSheng
     * @url /index/Recycle/integral
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @return status:状态   (1没有注册过   2注册过)
     * @return after_wallet:当前积分
     * @return num:参与次数
     * @return add_total:累计积分
     *
     */
    public function integral()
    {
        $user_id = $this->getUserId();
        $data = Db::name('integral')
            ->where('user_id',$user_id)
            ->find();
        if(empty($data)){
            $res['status'] = 1;
        }else{
            $res['status'] = 2;
            $res['after_wallet'] = $data['after_wallet'];
            $res['num'] = $data['num'];
            $res['add_total'] = $data['add_total'];
        }
        $this->success('SUCCESS',$res);
    }

    /**
     * @title 上门回收地址列表
     * @description
     * @author GuoSheng
     * @url /index/Recycle/recycleList
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @return status:是否选中   (0不选中   1选中)
     * @return name:姓名
     * @return phone:电话
     * @return address:详细地址
     *
     */
    public function recycleList()
    {
        $user_id = $this->getUserId();
        $where['user_id'] = ['eq',$user_id];
        $where['delete_time'] = ['eq',0];
        $data = Db::name('recycle')
            ->where($where)
            ->order('status desc')
            ->select()
            ->toArray();
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 上传文件
     * @description 接口说明
     * @author 开发者
     * @url /index/Resource/uploadFile
     * @method POST
     * @header name:XX-Token require:1 default: desc:token
     * @param name:image type:file require:1 default: other: desc:文件
     * @return image_url:图片路径
     */
    public function uploadFile(){
        $files = request()->file('image');
        if (empty($files)) {
            $this->error('未检出文件上传');
        }
        if($files){
            $info = $files->move(ROOT_PATH . 'public' . DS . 'uploads');
            if($info){
                $request = Request::instance();
                $a = $request->domain().'/'.'uploads/'.$info->getSaveName();
                $this->success('SUCCESS',$a);
            }else{
                $this->error($files->getError());
            }
        }
    }
}