新增获取合作公司检测项目列表接口
This commit is contained in:
parent
98b442ca61
commit
d7adc01b84
28
app/Controller/DetectionController.php
Normal file
28
app/Controller/DetectionController.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Request\DetectionRequest;
|
||||
use App\Services\DetectionService;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class DetectionController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 获取合作公司检测项目列表
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getDetectionProjectList(): ResponseInterface
|
||||
{
|
||||
$request = $this->container->get(DetectionRequest::class);
|
||||
$request->scene('getDetectionProjectList')->validateResolved();
|
||||
|
||||
$detectionService = new DetectionService();
|
||||
$data = $detectionService->getDetectionProjectList();
|
||||
return $this->response->json($data);
|
||||
}
|
||||
}
|
||||
73
app/Model/BasicCompany.php
Normal file
73
app/Model/BasicCompany.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Hyperf\Database\Model\Collection;
|
||||
|
||||
/**
|
||||
* @property int $company_id 主键id
|
||||
* @property string $company_name 公司名称
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
*/
|
||||
class BasicCompany extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'basic_company';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['company_id', 'company_name', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "company_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增-批量
|
||||
* @param array $data 新增数据
|
||||
* @return \Hyperf\Database\Model\Model|BasicCompany
|
||||
*/
|
||||
public static function addBasicCompany(array $data): \Hyperf\Database\Model\Model|BasicCompany
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改-批量
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function editBasicCompany(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
76
app/Model/DetectionProject.php
Normal file
76
app/Model/DetectionProject.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Hyperf\Database\Model\Collection;
|
||||
|
||||
/**
|
||||
* @property int $detection_project_id 主键id
|
||||
* @property string $detection_project_name 检测项目名称
|
||||
* @property int $company_id 合作公司id
|
||||
* @property string $detection_project_price 检测价格
|
||||
* @property string $img_path 内容图片地址
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
*/
|
||||
class DetectionProject extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'detection_project';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['detection_project_id', 'detection_project_name', 'company_id', 'detection_project_price', 'img_path', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "detection_project_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增-批量
|
||||
* @param array $data 新增数据
|
||||
* @return \Hyperf\Database\Model\Model|DetectionProject
|
||||
*/
|
||||
public static function addBasicCompany(array $data): \Hyperf\Database\Model\Model|DetectionProject
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改-批量
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function editBasicCompany(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
46
app/Request/DetectionRequest.php
Normal file
46
app/Request/DetectionRequest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class DetectionRequest extends FormRequest
|
||||
{
|
||||
protected array $scenes = [
|
||||
'getDetectionProjectList' => [ // 获取合作公司检测项目列表
|
||||
'company_id',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'company_id' => 'required',
|
||||
'detection_project_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已定义验证规则的错误消息.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'company_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Services/DetectionService.php
Normal file
42
app/Services/DetectionService.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Model\BasicCompany;
|
||||
use App\Model\DetectionProject;
|
||||
|
||||
class DetectionService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 获取合作公司检测项目列表
|
||||
* @return array
|
||||
*/
|
||||
public function getDetectionProjectList(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$company_id = $this->request->input("company_id",1);
|
||||
// $detection_project_id = $this->request->input("detection_project_id",1);
|
||||
|
||||
// 获取合作公司数据
|
||||
$params = array();
|
||||
$params['company_id'] = $company_id;
|
||||
$basic_company = BasicCompany::getOne($params);
|
||||
if (empty($basic_company)){
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 获取项目数据
|
||||
$params = array();
|
||||
$params['company_id'] = $company_id;
|
||||
$detection_project = DetectionProject::getList($params);
|
||||
if (empty($detection_project)){
|
||||
return fail();
|
||||
}
|
||||
|
||||
foreach ($detection_project as &$value){
|
||||
$value['img_path'] = addAliyunOssWebsite($value['img_path']);
|
||||
}
|
||||
|
||||
return success($detection_project->toArray());
|
||||
}
|
||||
}
|
||||
@ -13,6 +13,7 @@ declare(strict_types=1);
|
||||
use App\Controller\AreaController;
|
||||
use App\Controller\BasicDataController;
|
||||
use App\Controller\CallBackController;
|
||||
use App\Controller\DetectionController;
|
||||
use App\Controller\DoctorAccountController;
|
||||
use App\Controller\DoctorAuthController;
|
||||
use App\Controller\IndexController;
|
||||
@ -272,6 +273,9 @@ Router::addGroup('/patient', function () {
|
||||
|
||||
// 获取检测机构合作医生列表
|
||||
Router::get('/doctor', [InquiryController::class, 'getDetectionDoctor']);
|
||||
|
||||
// 获取合作公司检测项目列表
|
||||
Router::get('/project', [DetectionController::class, 'getDetectionProjectList']);
|
||||
});
|
||||
|
||||
// 医生数据
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user