Commit 5543cc99 by 赵增煜
parents 03463ec0 308136a6
......@@ -33,20 +33,28 @@ protected function grid()
$grid->column('id')->sortable();
$grid->column('name');
$grid->column('code');
$grid->column('unit');
$grid->column('is_rx', '处方药')->using(DrugModel::RX_MAP);
$grid->column('is_si', '医保')->using(DrugModel::SI_MAP);
$grid->column('product_name');
$grid->column('spec');
$grid->column('preparation_pec');
$grid->column('dosage_form');
$grid->column('unit');
$grid->column('factory');
$grid->column('approval_no');
$grid->column('mnemonic');
$grid->column('standard_code');
$grid->column('category_code');
$grid->column('category_name');
$grid->column('is_foreign')->using(DrugModel::FOREIGN_MAP);
$grid->column('is_rx')->using(DrugModel::RX_MAP);
$grid->column('is_si')->using(DrugModel::SI_MAP);
$grid->column('limit_buy_7');
$grid->column('tag')->display(function ($tags) {
return collect($tags)->map(function ($tag) {
return "<span class='label' style='background:#6d8be6'>{$tag->tag_name}</span>";
})->implode('&nbsp;');
});
$grid->column('standard_code');
$grid->column('product_id');
// $grid->column('created_at');
// $grid->column('updated_at')->sortable();
......@@ -87,29 +95,7 @@ protected function grid()
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new DrugRepository(), function (Show $show) {
$show->field('id')->width(4);
$show->field('name')->width(4);
$show->field('code')->width(4);
$show->field('unit')->width(4);
$show->field('spec')->width(4);
$show->field('dosage_form')->width(4);
$show->field('factory')->width(4);
$show->field('approval_no')->width(4);
$show->field('limit_buy_7')->width(4);
$show->field('is_rx')->using(DrugModel::RX_MAP)->width(4);
$show->field('tag')->width(4);
$show->field('standard_code')->width(4);
$show->field('created_at')->width(4);
$show->field('updated_at')->width(4);
$show->panel()->tools(function ($tools) {
$tools->disableDelete(); // 禁止删除按钮
});
});
}
protected function detail($id) {}
/**
* Make a form builder.
......@@ -119,35 +105,45 @@ protected function detail($id)
protected function form()
{
return Form::make(new DrugRepository('tag'), function (Form $form) {
$form->display('id')->width(4);
$form->text('name')->width(4)->required()->maxLength(64, '最多输入64个字符');
$form->display('code')->width(4);
$form->select('unit')->options(DrugUnitModel::all()->pluck('name', 'name'))->width(4);
$form->text('spec')->width(4)->required()->maxLength(128, '最多输入128个字符');
$form->text('dosage_form')->width(4)->required()->maxLength(128, '最多输入128个字符');
$form->text('factory')->width(4)->required()->maxLength(128, '最多输入128个字符');
$form->text('approval_no')->width(4)->required()->maxLength(64, '最多输入64个字符');
$array = range(1, 10);
$limitOption = array_combine($array, $array);
$form->select('limit_buy_7')->placeholder('请选择限购数量')->width(4)->options($limitOption)->help('限购数量')->required();
$form->switch('is_rx')->width(4);
$form->text('standard_code')->width(4)->required()->rules(function (Form $form) {
// 如果不是编辑状态,则添加字段唯一验证
if (! $id = $form->model()->id) {
return 'unique:App\Models\DrugModel,standard_code';
}
$form->column(6, function (Form $form) {
$form->display('id');
$form->display('code');
$form->text('name')->required()->maxLength(64);
$form->text('product_name')->maxLength(64);
$form->text('spec')->required()->maxLength(128);
$form->text('preparation_pec')->maxLength(128);
$form->text('dosage_form')->required()->maxLength(128);
$form->select('unit')->options(DrugUnitModel::all()->pluck('name', 'name'));
$form->text('factory')->required()->maxLength(128);
$form->text('approval_no')->required()->maxLength(64);
$form->text('mnemonic')->maxLength(64);
});
$form->column(6, function (Form $form) {
$form->text('standard_code')->required()->rules(function (Form $form) {
// 如果不是编辑状态,则添加字段唯一验证
if (! $id = $form->model()->id) {
return 'unique:App\Models\DrugModel,standard_code';
}
});
$form->text('category_code')->maxLength(32);
$form->text('category_name')->maxLength(32);
$form->switch('is_foreign');
$form->switch('is_rx');
$form->switch('is_si');
$array = range(1, 10);
$limitOption = array_combine($array, $array);
$form->select('limit_buy_7')->placeholder('请选择限购数量')->options($limitOption)->help('限购数量')->required();
$form->multipleSelect('tag', '标签')
->options(function () {
return DrugTagModel::all()->pluck('tag_name', 'id');
})
->customFormat(function ($v) {
return array_column($v, 'id');
});
$form->display('created_at');
$form->display('updated_at');
});
$form->multipleSelect('tag', '标签')
->options(function () {
return DrugTagModel::all()->pluck('tag_name', 'id');
})
->customFormat(function ($v) {
return array_column($v, 'id');
})->width(4);
$form->display('created_at')->width(4);
$form->display('updated_at')->width(4);
// 右上角按钮控制
$form->disableDeleteButton(); // 去掉删除按钮
$form->disableViewButton(); // 去掉跳转详情页按钮
......@@ -161,8 +157,8 @@ protected function form()
*/
public function exportDrugTemplate(Request $request)
{
$sheet1Head = ['药品名称', '本位码', '单位', '规格', '剂型', '生产厂家', '批准文号', '是否处方药', '是否医保药品', '君元ID'];
$sheet1Data = [['加味天麻胶囊', '86903692001013', '粒', '36s', '每粒装0.25g', '葵花药业集团(佳木斯)有限公司', '国药准字Z23020970', '是', '是', '8000']];
$sheet1Head = ['君元ID', '通用名', '商品名', '包装规格', '制剂规格', '剂型', '计量单位', '生产厂家', '批准文号', '助记码', '本位码', '分类码', '分类名称', '是否进口药', '是否处方药', '是否医保药'];
$sheet1Data = [['8045', '重组人干扰素α2b软膏(假单胞菌)', '里亚美', '5g', '5.0g/支', '软膏剂', '支', '哈药集团生物工程有限公司', '国药准字S20020020', 'zzrgrs2brg(jdbj)/lym', '86903708000436', '001S00000', '生物制品', 'N', 'Y', 'Y']];
$sheet1 = Excel::createSheet($sheet1Data, '药品信息', $sheet1Head)->row(function (array $row) {
$style = (new StyleBuilder)
......
......@@ -43,7 +43,7 @@ protected function grid()
$answerMap = [1 => '是', 0 => '否'];
return array_map(function ($item) {
return $item['drug_name'].' : '.$item['spec'].' : '.$item['num'].$item['unit'].' : '.$item['dosage_desc'];
return $item['drug_name'].' : '.($item['spec'] ?? '').' : '.$item['num'].($item['unit'] ?? '').' : '.($item['dosage_desc'] ?? '');
}, $drugInfo);
})->label();
$grid->column('pharmacy_name');
......
......@@ -9,6 +9,10 @@
use Dcat\EasyExcel\Support\SheetCollection;
use Exception;
set_time_limit(600);
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 600);
ini_set('max_input_time', 600);
class DrugImportForm extends Form
{
/**
......@@ -24,25 +28,36 @@ public function handle(array $input): JsonResponse
$chunkSize = 10;
$successNum = 0;
$failNum = 0;
Excel::import($filePath)->first()->chunk($chunkSize, function (SheetCollection $collection) use ($successNum) {
Excel::import($filePath)->first()->chunk($chunkSize, function (SheetCollection $collection) use (&$successNum) {
// 此处的数组下标依然是excel表中数据行的行号
$rows = $collection->toArray();
foreach ($rows as $row) {
$item = array_map(function ($value) {
return is_string($value) ? trim($value) : $value;
}, $row);
$drugModel = DrugModel::where('product_id', $item['君元ID'])->first();
$drugModel->name = $item['药品名称'];
$drugModel->code = '';
$drugModel->standard_code = $item['本位码'];
$drugModel->unit = $item['单位'];
$drugModel->spec = $item['规格'];
$drugModel = null;
if (isset($item['君元ID']) && $item['君元ID']) {
$drugModel = DrugModel::where('product_id', $item['君元ID'])->first();
}
if (! $drugModel) {
$drugModel = new DrugModel;
}
$drugModel->product_id = $item['君元ID'] ?? 0;
$drugModel->name = $item['通用名'];
$drugModel->product_name = $item['商品名'];
$drugModel->spec = $item['包装规格'];
$drugModel->preparation_pec = $item['制剂规格'];
$drugModel->dosage_form = $item['剂型'];
$drugModel->factory = $item['生产厂家'];
$drugModel->unit = $item['计量单位'];
$drugModel->factory = $item['生产企业'];
$drugModel->approval_no = $item['批准文号'];
$drugModel->mnemonic = $item['助记码'];
$drugModel->standard_code = $item['本位码'];
$drugModel->category_code = $item['分类码'];
$drugModel->category_name = $item['分类名称'];
$drugModel->is_foreign = self::toBool($item['是否进口药']);
$drugModel->is_rx = self::toBool($item['是否处方药']);
$drugModel->is_si = self::toBool($item['是否医保药品']);
$drugModel->product_id = $item['君元ID'] ?? 0;
$drugModel->is_si = self::toBool($item['是否医保药']);
if ($drugModel->save()) {
$successNum++;
}
......@@ -65,12 +80,13 @@ public function form()
$this->file('import_file', '文件')
->disk('local')
->accept('xls,xlsx,csv')
->maxSize(1024 * 30)
->autoUpload()
->uniqueName()
->required()
->help("导入要求:<br />
<span style='color:red;'>
1、支持xls、xlsx、csv三种格式\n
1、支持xls、xlsx、csv三种格式<br \>
2、更新的时候根据本位码唯一更新药品信息
</span>");
$downloadUrl = admin_url('drug-template');
......
......@@ -14,7 +14,7 @@ class DrugModel extends Model
protected $table = 'drug';
// 是否处方药[0=不是,1=是]
// 是否处方药[0=,1=是]
const RX_TRUE = 0;
const RX_FALSE = 1;
......@@ -25,7 +25,7 @@ class DrugModel extends Model
self::RX_FALSE => '否',
];
// 是否医保药品[0=不是,1=是]
// 是否医保药品[0=,1=是]
const SI_TRUE = 0;
const SI_FALSE = 1;
......@@ -36,12 +36,23 @@ class DrugModel extends Model
self::RX_FALSE => '否',
];
// 是否进口药[0=否,1=是]
const FOREIGN_TRUE = 0;
const FOREIGN_FALSE = 1;
// 是否进口药-文字映射
const FOREIGN_MAP = [
self::FOREIGN_TRUE => '是',
self::FOREIGN_FALSE => '否',
];
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
$pinyin = new Pinyin();
$abbr = $pinyin->abbr($value)->join(''); // 获取拼音首字母
// echo $abbr;exit;
$this->attributes['code'] = strtoupper($abbr);
}
......
......@@ -19,7 +19,7 @@ public function up(): void
$table->string('code', 64)->index('idx_code')->comment('简码');
$table->string('standard_code', 64)->unique('uk_standardcode')->comment('本位码');
$table->string('unit', 20)->nullable()->comment('单位');
$table->string('spec', 128)->comment('规格');
$table->string('spec', 128)->comment('包装规格');
$table->string('dosage_form', 128)->comment('剂型');
$table->string('factory', 128)->index('idx_factory')->comment('生产厂家');
$table->string('approval_no', 64)->comment('批准文号');
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('drug', function (Blueprint $table) {
$table->string('preparation_pec')->default('')->comment('制剂规格');
$table->string('product_name', 64)->default('')->comment('商品名');
$table->string('mnemonic', 64)->default('')->comment('助记码');
$table->string('category_code', 32)->default('')->comment('分类码');
$table->string('category_name', 32)->default('')->comment('分类名称');
$table->boolean('is_foreign')->default(false)->comment('是否进口药');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('drug', function (Blueprint $table) {
//
});
}
};
......@@ -5,17 +5,25 @@
'drug' => '药品',
],
'fields' => [
'name' => '药品名称',
'product_id' => '君元ID',
'name' => '通用名',
'product_name' => '商品名',
'code' => '简码',
'unit' => '单位',
'spec' => '规格',
'spec' => '包装规格',
'preparation_pec' => '制剂规格',
'dosage_form' => '剂型',
'factory' => '生产厂家',
'unit' => '计量单位',
'factory' => '生产企业',
'approval_no' => '批准文号',
'limit_buy_7' => '7天限购',
'mnemonic' => '助记码',
'standard_code' => '本位码',
'category_code' => '分类码',
'category_name' => '分类名称',
'is_foreign' => '是否进口药',
'is_rx' => '是否处方药',
'is_si' => '是否医保药',
'limit_buy_7' => '7天限购',
'tag' => '标签',
'standard_code' => '本位码',
],
'options' => [
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment