<?php

namespace app\ros\controller;

use app\ros\model\Product as ProductModel;
use app\ros\model\Buyer as BuyerModel;
use fastphp\base\Controller;

class Product extends Controller
{
    //获取产品列表
    public function getList() {
        $product_model = new ProductModel();

        $list = $product_model->getList([],'*','id asc');
        $info = [
            'Code' => 10000,
            'TotalCount' => count($list),
            'Data' => $list
        ];
        echo json_encode($info);
    }

    /**
     * @description: 修改状态
     * @param {*}
     * @return {*}
     */    
    public function setStatus() {
        $data = json_decode(file_get_contents("php://input"),true);
        $product_model = new ProductModel();
        $product_model->updateOne(['id'=>$data['id']],['status'=>$data['status']]);

        $info = [
            'Code' => 10000,
        ];
        echo json_encode($info);
    }

    /**
     * @description: 修改产品信息
     * @param {*}
     * @return {*}
     */    
    public function setInfo() {
        $data = json_decode(file_get_contents("php://input"),true);
        $product_model = new ProductModel();
        $update_data = $data;
        unset($update_data['id']);
        $product_model->updateOne(['id'=>$data['id']],$update_data);

        $info = [
            'Code' => 10000,
        ];
        echo json_encode($info);
    }
}