<?php
// +----------------------------------------------------------------------
// | [ WE CAN DO IT MORE SIMPLE  ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2020 rights reserved.
// +----------------------------------------------------------------------
// | Author: TABLE ME
// +----------------------------------------------------------------------
// | Date: 2020-08-31 20:43
// +----------------------------------------------------------------------

namespace app\admin\controller\v1;


use app\BaseController;
use app\model\admin\ExpCost;
use app\model\admin\MemberLevel;
use app\model\admin\Site as SiteModel;
use app\Request;
use library\services\UtilService;

class Site extends  BaseController
{

    public function list(Request $request) {
        $pageSize = 50;
        $post =  UtilService::getMore(
            [
                ['page',1],
                ['name',''],
                ['artType','all']
            ],$request
        );
        $where = [];
        $where['tj_sassid'] =$request->site['sassid'];
        //获取自己模板
        $expCost = new ExpCost;
        $expData = $expCost
            ->where('sassid',$request->site['sassid'])
            ->where('level_id','>',-1)
            ->select();
        $level = (new MemberLevel)->select();
        list($pageCount,$data) = (new SiteModel)
            ->getList($post['page'],$where,$pageSize,'id desc');
        //特殊数据
        foreach ($data as $k=>$v) {
            $data[$k]['warehouse'] = $expCost->expSite($v['sassid'],$expData);
            $data[$k]['_time'] = date("Y-m-d H:i:s",$data[$k]['time']);
        }

        return app('json')->success([
            'list'      => $data,
            'pageCount' => $pageCount,
            'pageSize'  => $pageSize,
            'page'      => $post['page'],
            'level'     => $level
        ]);
    }
}