<?php

namespace plugin\admin\app\controller;

use plugin\admin\app\controller\Base;
use plugin\admin\app\controller\Crud;
use app\model\ProductOrder;
use support\exception\BusinessException;
use support\Request;
use support\Response;
use Throwable;

/**
 * 工作室
 */
class ProductOrderController extends Crud
{
    
    /**
     * @var ProductOrder
     */
    protected $model = null;
    protected $relationSearch = ['user','product'];

    /**
     * 构造函数
     * @return void
     */
    function __construct()
    {
        $this->model = new ProductOrder(); 
        $statusList = $this->model->getStatusList();
        $this->assign("statusList", $statusList);
        $this->assignconfig("statusList", $statusList);
    }
    public function team(Request $request): Response
    {
        return view();
    }
    /**
     * 浏览
     * @return Response
     * @throws Throwable
     */
    public function index(Request $request): Response
    {
        return view('productorder/index');
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException|Throwable
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::insert($request);
        }
        return view('productorder/update',[
            'row'   => \plugin\admin\app\model\User::findOrEmpty(0)
        ]);
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException|Throwable
     */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            [$id, $data] = $this->updateInput($request);
            $this->doUpdate($id, $data);
            $ret =  $this->success('操作成功');
            return $ret;
        }
        $ids = Request()->get('ids');
        $user = $this->model->where('id',$ids)->find();
        return view('productorder/update',[
            'row'   => $user
        ]);
    }
}
