<?php
namespace app\admin\controller\medical;

use app\admin\controller\BaseController;
use app\admin\server\medical\MedicalCarePostageServer;
use app\admin\server\medical\MedicalCareProductServer;
use app\admin\server\medical\NewsCategoryServer;
use app\admin\server\package\PackageGoodsServer;

class NewsCategory extends BaseController
{
    /**
     * Notes:文章分类
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/28
     */
    public function getCategoryList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = NewsCategoryServer::getCategoryList($page, $limit,$keywords);
        return json_success($result, '成功');
    }
    /**
     * Notes:添加运费模板
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/28
     *
     */
    public function addPostage()
    {
        $param     = $this->request->post();
        $this->validateCheck('medical\MedicalCarePostagetValidate',
            [
                'postage_name'          => $param['postage_name'],
                'postage_type_id'       => $param['postage_type_id'],
                'postage_first_weight'  => $param['postage_first_weight'],
                'postage_first_price'   => $param['postage_first_price'],
                'postage_extend_weight' => $param['postage_extend_weight'],
                'postage_extend_price'   => $param['postage_extend_price'],
            ],
            'add');
        $result         = MedicalCarePostageServer::insertPostage($param);
        return json_success($result, '添加成功');
    }
    /**
     * Notes:修改产品
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/23
     */
    public function updatePostage()
    {
        $param      = $this->request->post();
        $this->validateCheck('medical\MedicalCarePostagetValidate',
            [
                'postage_id'            => $param['postage_id'],
                'postage_name'          => $param['postage_name'],
                'postage_type_id'       => $param['postage_type_id'],
                'postage_first_weight'  => $param['postage_first_weight'],
                'postage_first_price'   => $param['postage_first_price'],
                'postage_extend_weight' => $param['postage_extend_weight'],
                'postage_extend_price'  => $param['postage_extend_price'],
            ], 'update');
         $result         = MedicalCarePostageServer::updatePostage($param);
        return json_success($result, '修改成功');
    }

    /**
     * Notes:删除权益包
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/23
     */
    public function delPostage()
    {
        $postage_id = $this->request->get('postage_id');
        $this->validateCheck('medical\MedicalCarePostagetValidate', ['postage_id' => $postage_id], 'del');
        $result         = MedicalCarePostageServer::delPostage($postage_id);
        if ($result){
            return json_success($result, '删除成功');
        }else{
            throw new \Exception('删除失败！');
        }

    }
    /**
     * Notes:查看模板详情
     * @return \support\Response
     * User: QJF
     * Date: 2022/9/28
     */
    public function infoPostage()
    {
        $postage_id = $this->request->get('postage_id');
        $this->validateCheck('medical\MedicalCarePostagetValidate', ['postage_id' => $postage_id], 'info');
        $result         = MedicalCarePostageServer::infoPostage($postage_id);
        if ($result){
            return json_success($result, '获取成功');
        }else{
            throw new \Exception('获取失败！');
        }

    }
    //产品上下架
    public function showPostage(){

        $postage_id = $this->request->get('postage_id');
        $postage_status= $this->request->get('postage_status');
        $this->validateCheck('medical\MedicalCarePostagetValidate', ['postage_id' => $postage_id], 'del');
        $result         = MedicalCarePostageServer::showPostage($postage_id,$postage_status);
        if ($result){
            return json_success($result, '成功');
        }else{
            throw new \Exception('失败！');
        }
    }
}
