RecycleController.php 1.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;


/**
 * @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')
            ->order('id desc')
            ->select()
            ->toArray();
        $this->success('SUCCESS',$data);

    }

    //不可回收物
    public function noRecycle()
    {
        $where['delete_time'] = ['eq',0];
        $recycleModel = new NorecycletypeModel();
        $data = $recycleModel->selectData($where)->toArray();
        $recycleGoodsModel = new NorecyclegoodsModel();
        $tiao = [];
        $res = $recycleGoodsModel->selectData($tiao)->toArray();
        foreach ($data as &$v){
            $v['norecyclegoods'] = [];
            foreach ($res as $key=>$val){
                if($val['recycletype_id'] == $v['id']){
                    array_push($v['norecyclegoods'],$val);
                }
            }
        }
        $this->assign('data',$data);
        return $this->fetch();
    }
}