| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- namespace App\Models;
- use App\Traits\Filterable;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- /**
- * App\Models\DrugReportInfo
- *
- * @property int $id
- * @property string $report_id 报告ID(来源于querydrugreport.drug_report_id)
- * @property string $report_v2_id 报告ID(来源querysealdrugreport.drug_report_v2_id)
- * @property string $report_name 报告名称
- * @property string $report_no 报告编号
- * @property string $report_date 报告日期
- * @property string $batch_no 批次号
- * @property string $drug_id 药品ID
- * @property string $drug_name 药品名称
- * @property string $prod_code 药品子类编码
- * @property string $pkg_spec 包装规格
- * @property string $prepn_spec 制剂规格
- * @property string $prepn_type_desc 剂型
- * @property array|null $pkg_ratio_list 包装比例
- * @property int $bill_type 单据类型
- * @property string $bill_id 单据ID
- * @property string $bill_detail_id 单据明细ID
- * @property string $bill_time 单据时间
- * @property string $bill_code 单据编码
- * @property string $produce_date 生产日期
- * @property string $produce_ent_id 生产企业ID
- * @property string $produce_ent_name 生产企业
- * @property string $ass_ref_ent_id 委托企业ID
- * @property string $from_ref_ent_id 发货企业ID
- * @property string $from_ent_name 发货企业
- * @property string $report_url 报告URL
- * @property string $seal_report_url 盖章报告URL
- * @property string $report_sign_status 报告签收状态(0-待发送、2-待签收、3-已签收、4-已拒绝、7-对方已签收/更正待处理、13-对方已拒绝/更正待签收)
- * @property array|null $raw_data 报告待签收原始数据(来源querydrugreport)
- * @property array|null $seal_raw_data 报告已签收原始数据(来源querysealdrugreport)
- * @property array|null $opt_raw_data 报告操作原始数据(来源drugreport.opt.history)
- * @property int $is_sign 是否签收(1-未签收、2-已签收)
- * @property int $is_seal 是否盖章(1-未盖章、2-已盖章)
- * @property Carbon $create_time 创建时间
- * @property Carbon $update_time 更新时间
- * @property-read string $is_seal_text
- * @property-read string $is_sign_text
- * @method static Builder|DrugReportInfo applyFilters(array $filters = [], array $options = [])
- * @method static Builder|DrugReportInfo newModelQuery()
- * @method static Builder|DrugReportInfo newQuery()
- * @method static Builder|DrugReportInfo query()
- * @method static Builder|DrugReportInfo whereAssRefEntId($value)
- * @method static Builder|DrugReportInfo whereBatchNo($value)
- * @method static Builder|DrugReportInfo whereBillCode($value)
- * @method static Builder|DrugReportInfo whereBillDetailId($value)
- * @method static Builder|DrugReportInfo whereBillId($value)
- * @method static Builder|DrugReportInfo whereBillTime($value)
- * @method static Builder|DrugReportInfo whereBillType($value)
- * @method static Builder|DrugReportInfo whereCreateTime($value)
- * @method static Builder|DrugReportInfo whereDrugId($value)
- * @method static Builder|DrugReportInfo whereDrugName($value)
- * @method static Builder|DrugReportInfo whereFromEntName($value)
- * @method static Builder|DrugReportInfo whereFromRefEntId($value)
- * @method static Builder|DrugReportInfo whereId($value)
- * @method static Builder|DrugReportInfo whereIsSeal($value)
- * @method static Builder|DrugReportInfo whereIsSign($value)
- * @method static Builder|DrugReportInfo whereOptRawData($value)
- * @method static Builder|DrugReportInfo wherePkgRatioList($value)
- * @method static Builder|DrugReportInfo wherePkgSpec($value)
- * @method static Builder|DrugReportInfo wherePrepnSpec($value)
- * @method static Builder|DrugReportInfo wherePrepnTypeDesc($value)
- * @method static Builder|DrugReportInfo whereProdCode($value)
- * @method static Builder|DrugReportInfo whereProduceDate($value)
- * @method static Builder|DrugReportInfo whereProduceEntId($value)
- * @method static Builder|DrugReportInfo whereProduceEntName($value)
- * @method static Builder|DrugReportInfo whereRawData($value)
- * @method static Builder|DrugReportInfo whereReportDate($value)
- * @method static Builder|DrugReportInfo whereReportId($value)
- * @method static Builder|DrugReportInfo whereReportName($value)
- * @method static Builder|DrugReportInfo whereReportNo($value)
- * @method static Builder|DrugReportInfo whereReportSignStatus($value)
- * @method static Builder|DrugReportInfo whereReportUrl($value)
- * @method static Builder|DrugReportInfo whereReportV2Id($value)
- * @method static Builder|DrugReportInfo whereSealRawData($value)
- * @method static Builder|DrugReportInfo whereSealReportUrl($value)
- * @method static Builder|DrugReportInfo whereUpdateTime($value)
- * @mixin \Eloquent
- */
- class DrugReportInfo extends Model
- {
- use HasFactory, Filterable;
- protected $table = 'drug_report_info';
- protected $guarded = [];
- const CREATED_AT = 'create_time';
- const UPDATED_AT = 'update_time';
- protected $casts = [
- 'pkg_ratio_list' => 'array',
- 'raw_data' => 'array',
- 'seal_raw_data' => 'array',
- 'opt_raw_data' => 'array',
- ];
- protected $hidden = [
- 'create_time',
- 'update_time',
- 'pkg_ratio_list',
- 'raw_data',
- 'seal_raw_data',
- 'opt_raw_data',
- ];
- /**
- * @var array|string[] 定义可搜索字段(可选,可在调用时覆盖)
- */
- public static $searchable = ['drug_id', 'drug_name', 'produce_ent_id', 'produce_ent_name'];
- /**
- * 获取「是否签收」文本
- * @return string
- */
- public function getIsSignTextAttribute(): string
- {
- $options = [
- 0 => '',
- 1 => '未签收',
- 2 => '已签收',
- ];
- return $options[$this->is_sign] ?? "未知「{$this->is_sign}」";
- }
- /**
- * 获取「是否盖章」文本
- * @return string
- */
- public function getIsSealTextAttribute(): string
- {
- $options = [
- 0 => '',
- 1 => '未盖章',
- 2 => '已盖章',
- ];
- return $options[$this->is_sign] ?? "未知「{$this->is_sign}」";
- }
- /**
- * 批量更新或插入
- * @param array $data
- * @param array $uniqueKeys
- * @return int
- * @throws \Throwable
- */
- public static function bulkUpsert(array $data, array $uniqueKeys = ['batch_no', 'drug_id']): int
- {
- if (empty($data)) {
- return 0;
- }
- return DB::transaction(function () use ($data, $uniqueKeys) {
- $count = 0;
- foreach (array_chunk($data, 100) as $chunk) {
- self::upsert(
- $chunk,
- $uniqueKeys, // 组合唯一键
- array_keys($data[0]) // 要更新的字段
- );
- $count += count($chunk);
- }
- return $count;
- });
- }
- }
|