Commit 263aa722 by lujunyi

药品导入

parent 50432b60
......@@ -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
{
/**
......@@ -32,6 +36,9 @@ public function handle(array $input): JsonResponse
return is_string($value) ? trim($value) : $value;
}, $row);
$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['商品名'];
......@@ -45,7 +52,6 @@ public function handle(array $input): JsonResponse
$drugModel->standard_code = $item['本位码'];
$drugModel->category_code = $item['分类码'];
$drugModel->category_name = $item['分类名称'];
$drugModel->code = '';
$drugModel->is_foreign = self::toBool($item['是否进口药']);
$drugModel->is_rx = self::toBool($item['是否处方药']);
$drugModel->is_si = self::toBool($item['是否医保药']);
......@@ -71,12 +77,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');
......
......@@ -50,9 +50,9 @@ class DrugModel extends Model
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
$pinyin = new Pinyin();
$abbr = $pinyin->abbr($value)->join(''); // 获取拼音首字母
// echo $abbr;exit;
$this->attributes['code'] = strtoupper($abbr);
}
......
......@@ -12,7 +12,7 @@
public function up(): void
{
Schema::table('drug', function (Blueprint $table) {
$table->string('preparation_pec', 128)->default('')->comment('制剂规格');
$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('分类码');
......
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