123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace App\Http\Controllers\Admin\TCM;
- use App\Exports\PatientExport;
- use App\Exports\StudentExport;
- use App\Http\Controllers\Controller;
- use App\Repositories\Criteria\TCM\PatientCriteria;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Models\TCM\Patient;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- use Jiannei\Response\Laravel\Support\Facades\Response;
- use Overtrue\LaravelPinyin\Facades\Pinyin;
- use Prettus\Validator\Contracts\ValidatorInterface;
- use Prettus\Validator\Exceptions\ValidatorException;
- use App\Contracts\Repositories\TCM\PatientRepository;
- use App\Repositories\Validators\TCM\PatientValidator;
- /**
- * Class PatientsController.
- *
- * @package namespace App\Http\Controllers\TCM;
- */
- class PatientController extends Controller
- {
- /**
- * @var PatientRepository
- */
- protected $repository;
- /**
- * @var PatientValidator
- */
- protected $validator;
- /**
- * PatientsController constructor.
- *
- * @param PatientRepository $repository
- * @param PatientValidator $validator
- */
- public function __construct(PatientRepository $repository, PatientValidator $validator)
- {
- $this->repository = $repository;
- $this->validator = $validator;
- }
- public function index()
- {
- $this->repository->pushCriteria(PatientCriteria::class);
- $lists = $this->repository->paginate(request('per_page', self::PAGE_NUM));
- return Response::success($lists);
- }
- public function store(Request $request)
- {
- $this->validate($request, $this->validator->getRules(ValidatorInterface::RULE_CREATE));
- try {
- $data = $request->only(array_keys($this->validator->getRules(ValidatorInterface::RULE_CREATE)));
- $data['admin_id'] = login_user_id();
- $patient = Patient::query()->create($data);
- return Response::success($patient);
- } catch (\Exception $e) {
- return $this->errorStore($e);
- }
- }
- public function show($id)
- {
- $patient = $this->repository->find($id);
- return Response::success($patient);
- }
- public function update(Request $request, $id)
- {
- $this->validate($request, $this->validator->getRules(ValidatorInterface::RULE_UPDATE));
- try {
- $data = $request->only(array_keys($this->validator->getRules(ValidatorInterface::RULE_UPDATE)));
- $patient = Patient::query()->where('id', $id)->first();
- $patient->fill($data);
- $patient->save();
- return Response::success($patient);
- } catch (\Exception $e) {
- $this->errorStore($e);
- }
- }
- public function destroy($id)
- {
- try {
- $re = $this->repository->delete($id);
- if ($re) {
- return Response::success(null, T('successfully delete.'));
- }
- return Response::fail(T('Delete failed.'), ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
- } catch (\Exception $exception) {
- return Response::fail(T('Delete failed.'), ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
- }
- }
- public function lists(Request $request)
- {
- $this->repository->pushCriteria(PatientCriteria::class);
- $lists = $this->repository->get();
- return Response::success($lists);
- }
- /**
- * 导出
- * Author: Mead
- */
- public function export(Request $request)
- {
- $this->validate($request, [
- 'ids' => 'required|array',
- 'fields' => 'sometimes|array',
- 'type' => 'required'
- ]);
- $ids = $request->get('ids');
- $name = time();
- return (new PatientExport($request->get('fields', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]), (int)$request->get('type', 0)))->forIds($ids)->download($name . '.xlsx', null, [
- 'Access-Control-Allow-Origin' => '*',
- 'Access-Control-Allow-Methods' => '*',
- 'Access-Control-Allow-Headers' => 'Content-Type, Authorization, X-Requested-With',
- 'Access-Control-Expose-Headers' => 'Content-Disposition',
- 'Content-type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment; filename=' . $name . '.xlsx',
- ]);
- }
- }
|