<?php
namespace app\api\controller\v1;
use app\api\controller\Base;
use app\hander\HelpHander;
use think\App;
use think\Db;

class ShopDay extends Base
{
    public function __construct(App $app = null) {
        parent::__construct($app);
        $this->model = new \app\common\model\ShopDay();
    }
    public function date(){
        $ret = $this->model->shopDate();
        HelpHander::success($ret);
    }

    public function cate(){
//        $type = input('type/d',0);
        $ret = $this->model->cate($this->orgId);
        HelpHander::success($ret);
    }

    public function goods(){
//        $type = input('type/d',0);
        $cate_id = input('cate_id/d',0);
        $ret = $this->model->goods($cate_id,$this->orgId);
        HelpHander::success($ret);
    }

    // 获取类型
    public function types(){
        $day = input('day','','trim');
        if(!$day){
            $this->error('参数错误');
        }
        $lists = Db::name('shop_day')
            ->where('org_id',$this->orgId)
            ->where('day',$day)
            ->field('id,cate')
            ->order('cate asc')
            ->select();
        $lists = $lists?$lists:[];
        foreach ($lists as $k=>$v){
            if($v['cate'] == 1){
                $lists[$k]['name'] = "早餐";
            }else if($v['cate'] == 2){
                $lists[$k]['name'] = "午餐";
            }else if($v['cate'] == 3){
                $lists[$k]['name'] = "晚餐";
            }else if($v['cate'] == 4){
                $lists[$k]['name'] = "当日餐";
            }
        }
        HelpHander::success($lists);
    }

}