<?php


namespace app\api\controller\shopro;


use app\admin\model\users\Users;
use app\common\controller\Api;
use app\admin\model\shopro\goods\Goods as GoodsModel;

class Goods extends Api
{

    protected $noNeedLogin = ['goodswholelist','goodsdetails'];
    protected $noNeedRight = ['*'];


    /**
     * 全品区商品列表
     */
    public function goodsWholeList(){
        $banner=['/applet/imgs/goodsbanner.png'];
        $page = $this->request->param('page', 1);
        $skeyword = $this->request->param('skeyword', '');
        $map['closed']=0;
        //$map['activity_list']=null;
        if (!empty($skeyword)) {
            $map['title|intro'] = array('LIKE', '%' . $skeyword . '%');
        }
        $list=GoodsModel::where($map)->where('!FIND_IN_SET(2,activity_list)')->order("orderby desc")->limit($this->pageSize)->page($page)->select();
        return $this->success("",['banner'=>$banner,'list'=>$list]);
    }

    /**
     * 抵扣区商品列表
     */
    public function goodsDeductionList(){
        $banner=['/applet/imgs/dikouqubanner.png'];
        $page = $this->request->param('page', 1);
        $skeyword = $this->request->param('skeyword', '');
        $map['closed']=0;
        if (!empty($skeyword)) {
            $map['title|intro'] = array('LIKE', '%' . $skeyword . '%');
        }
        $list=GoodsModel::where($map)->where('FIND_IN_SET(2,activity_list)')->order("orderby desc")->limit($this->pageSize)->page($page)->select();
        $users['shopping_money']=Users::where(['id'=>$this->auth->id])->value("shopping_money");
        $this->success("",['banner'=>$banner,'list'=>$list,'users'=>$users]);
    }

    /**
     * 订单详情
     */
    public function goodsDetails(){
        $goods_id = $this->request->param('goods_id');
        if(empty($goods_id)){
            $this->error("商品id有误");
        }
        $goodsDetails=GoodsModel::where(['goods_id'=>$goods_id])->find();
        $this->success("",['goodsDetails'=>$goodsDetails]);
    }


}