<?php

namespace App\Api\Controllers;

use App\Http\Controllers\BaseApiController;
use App\Models\DrugModel;
use Illuminate\Http\Request;

// 药品控制器
class DrugController extends BaseApiController
{
    public function test()
    {
        return $this->success(['a' => 1, 'b' => 2, 'c' => 3]);
    }

    // 药品列表
    public function drugList(Request $request)
    {
        // $code = $request->input('code');
        //  TODO 通过药店编号筛选药品列表
        // pharmacy_id = $request->input('code');
        $data = DrugModel::query()->paginate(10);

        // $total = DrugModel::query()->count();
        // $data = [
        //     'data'=>$drugList,
        //     'total'=>$total
        // ];
        return $this->success($data);
    }

    // 药品7日内限购
    public function drugLimit(Request $request)
    {
        $drug_id = $request->input('drug_id');
        // 判断当前药品有没有设置7日内限购
        $drug = DrugModel::query()->find($drug_id);
        // 当前药品未设置则使用全局的7日内限购
        $limit_num = 0;
        if ($drug->limit_num == 0) {

        }

        return $this->success($limit_num);

    }
}
