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


use app\admin\model\Appointment;
use app\admin\model\MedicalCareOrder;
use app\admin\model\MedicalCareOrderProduct;
use app\admin\model\MedicalCarePostage;
use app\admin\model\PackageOrderDetail;
use app\admin\model\SystemAdmin;
use app\admin\model\SystemMenu;
use app\admin\model\SystemRole;

class AppointmentServer
{
    /**
     * Notes:获取订单列表
     * @param string $keywords
     * @param int $page
     * @param int $limit
     * @return array
     * User: QJF
     * Date: 2022/9/17
     */
    public static function getMentList(int $page, int $limit, string $keywords)
    {
        [$list, $count] =  Appointment::geMentList($page, $limit,$keywords);

        return compact('list', 'page', 'limit', 'count');
    }

    /**
     * Notes: 添加m模板
     * @param array $param
     * @return int
     * User: QJF
     * Date: 2022/9/28
     */
    public static function insertMent(array $param)
    {
        SystemRole::affairBegin();
        try {
            $param['appointment_create_time'] = time();
            $param['appointment_auto'] = 1;
            $result = Appointment ::insertGetId($param);
            if (!empty($result)){
                SystemRole::affairCommit();
                return $result;
            }
            throw new \Exception('操作失败！');
        }catch (\Exception $exception){
            SystemRole::affairRollback();
            throw new \Exception($exception->getMessage(), 500);
        }
    }


    /**
     * Notes:修改产品
     * @param array $param
     * @return int
     * User: QJF
     * Date: 2022/9/23
     */
    public static function updateMent($param)
    {
        SystemRole::affairBegin();
        try {
            $where = [];
            $where['appointment_id'] = $param['appointment_id'];
            $result = Appointment::where($where)->update($param);
            if ($result !== false){
                SystemRole::affairCommit();
                return true;
            }
            throw new \Exception('操作失败！');
        }catch (\Exception $exception){
            SystemRole::affairRollback();
            throw new \Exception($exception->getMessage(), 500);
        }
    }
    /**
     * Notes:删除产品
     * @param int $role_id
     * @return int
     * User: QJF
     * Date: 2022/9/23
     */
    public static function delMent($appointment_id)
    {
        SystemRole::affairBegin();
        try {
            $where = [];
            $where['appointment_id']         = $appointment_id;
            $data['appointment_del']      = 1;
            $result = Appointment::where($where)->update($data);
            if (!empty($result)){
                SystemRole::affairCommit();
                return true;
            }else{
                return false;
            }
        }catch (\Exception $exception){
            SystemRole::affairRollback();
            throw new \Exception($exception->getMessage(), 500);
        }
    }
    /**
     * Notes:上/下架
     * @param int $role_id
     * @return int
     * User: QJF
     * Date: 2022/9/28
     */
    public static function showMent($appointment_id,$appointment_status)
    {
        $where = [];
        $where['appointment_id']         = $appointment_id;
        $data['appointment_status']      = $appointment_status;
        $result = Appointment::where($where)->update($data);
        if (!empty($result)){
            return true;
        }else{
            return false;
        }
    }
    /**
     * Notes:产品详情
     * @param int $package_id
     * @return int
     * User: QJF
     * Date: 2022/9/23
     */
    public static function infoMent($appointment_id)
    {
        SystemRole::affairBegin();
        try {
            $where = [];
            $where['appointment_id'] = $appointment_id;

            $result = Appointment::with(['Category','Shop'])->where($where)->first();
            if (!empty($result)){
                SystemRole::affairCommit();
                return $result;
            }else{
                return false;
            }
        }catch (\Exception $exception){
            SystemRole::affairRollback();
            throw new \Exception($exception->getMessage(), 500);
        }
    }
}
