<?php
/*
 本代码由 焕岱科技 创建
 技术支持 WX：15285007200
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace app\admin\controller\bbfxshop\goods;

use app\admin\controller\bbfxshop\Base;
use think\Db;


class Collection extends Base
{

    public function _initialize(){
        parent::_initialize();
    }

    public function getList(){
        $params = $this->param();
        $page = $params["page"] ?? 1;
        $limit = $params["limit"] ?? 10;
        $type = intval($params['type']);
        $keyword = $params['keyword'];

        $where = ['a.uniacid'=>UNIACID,'a.id'=>['>',0],'b.id'=>['>',0]];

        if(!empty($keyword)){
            if($type == 1){
                $where['a.user_id'] = intval($keyword);
            }
            else if($type == 2){
                $where['a.goods_id'] = intval($keyword);
            }
            else if($type == 3){
                $where['c.nickname'] = ['like','%'.$keyword.'%'];
            }
            else if($type == 4){
                $where['b.title'] = ['like','%'.$keyword.'%'];
            }
        }

        $list = Db::name("bbfx_goods_collection")
            ->alias("a")
            ->join("bbfx_goods b","a.goods_id=b.id","LEFT")
            ->join("bbfx_user c","a.user_id=c.id","LEFT")
            ->where($where)
            ->order("a.id desc")
            ->field("a.*,b.title as goods_name,b.thumb as goods_image,c.nickname,c.avatar")
            ->limit(($page-1)*$limit,$limit)
            ->select();

        $total = Db::name("bbfx_goods_collection")
            ->alias("a")
            ->join("bbfx_goods b","a.goods_id=b.id","LEFT")
            ->join("bbfx_user c","a.user_id=c.id","LEFT")
            ->where($where)
            ->count();

        foreach($list as $key=>&$val){
            $val['goods_image'] = cdnurl($val['goods_image']);
            $val['avatar'] = cdnurl($val['avatar']);
            $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
        }
        unset($val);
            
            
        __success("操作成功",['list'=>$list,'total'=>$total]);
    }
}