Files
2024-12-23 12:11:29 +08:00

139 lines
4.4 KiB
PHP

<?php
namespace common\models\oldDb;
use common\models\newDb\SupplierModel;
class Drug extends \common\modelsgii\oldDb\Drug
{
public $number;
public function getCommon()
{
return $this->hasMany(DoctorCommon::class,['id'=>'drug_id'])->with(['su_id'=>\Yii::$app->user->identity->id]);
}
public function getDrugStoreDrug()
{
return $this->hasOne(DrugStoreDrug::class,['drug_id'=>'id']);
}
public function getDrugStoreRelation()
{
return $this->hasOne(DrugStoreRelations::class,['drug_id'=>'id']);
}
//关联门店
public function getStore(){
return $this->hasOne(Store::class,['id'=>'store_id']);
}
//关联单位
public function getUnit()
{
return $this->hasOne(WestUnit::class,['id'=>'unit_id']);
}
public function getDrugStoreRelationes()
{
return $this->hasOne(DrugStoreRelations::class,['drug_id'=>'id']);
}
//关联使用频率
public function getDrugUseFrequency()
{
return $this->hasOne(DrugUseFrequency::class,['id'=>'frequency_id']);
}
//关联
public function getDrugUseType()
{
return $this->hasOne(DrugUseType::class,['id'=>'type_id']);
}
//关联使用时间
public function getDrugUseTime()
{
return $this->hasOne(DrugUseTime::class,['id'=>'time_id']);
}
//关联使用时间
public function getSupplier()
{
return $this->hasOne(SupplierModel::class,['id'=>'source']);
}
//关联煎法
public function getDrugUseWay()
{
return $this->hasOne(DrugUseWay::class,['id'=>'decotion']);
}
//导出药品
public static function inventory($params)
{
$su_id=\Yii::$app->user->id;
//统计时间范围
if (!empty($params['date_max']) && !empty($params['date_min'])) {
$params['date_max'] = strtotime($params['date_max']);
$params['date_min'] = strtotime($params['date_min']);
}
else{
$date_max = date('Y-m-d');
$date_min = date('Y-m-d',strtotime("-31 day"));
}
$data = [
'and',
['between', 'created_at', $params['date_min'], $params['date_max']],
['type' => $params['type']],
];
//查询数据
$list=Drug::find()->filterWhere($data)->asArray()->all();
//把结果按照显示顺序存到返回的数组中
if(!empty($list)){
foreach ($list as $key => $value){
$inventory[$key]['id'] = $value['id'];
$inventory[$key]['drug_name'] = $value['drug_name'];
$inventory[$key]['pinyin_simple'] = $value['pinyin_simple'];
$inventory[$key]['source'] = $value['source'];
if ($value['type']==1){
$inventory[$key]['type']='中药';
}elseif ($value['type']==2){
$inventory[$key]['type']='西药';
}elseif ($value['type']==3){
$inventory[$key]['type']='颗粒配方';
}elseif ($value['type']==4){
$inventory[$key]['type']='中成药';
}else{
$inventory[$key]['type']='其他';
}
$inventory[$key]['is_otc'] = $value['is_otc'];
$inventory[$key]['content'] = $value['content'];
$inventory[$key]['usage'] = $value['usage'];
$inventory[$key]['function'] = $value['function'];
$inventory[$key]['specification'] = $value['specification'];
$inventory[$key]['drug_number'] = $value['drug_number'];
$inventory[$key]['bar_code'] = $value['specification'];
$inventory[$key]['guozi_no'] = $value['guozi_no'];
$inventory[$key]['drug_alias'] = $value['drug_alias'];
if ($value['status']==1){
$inventory[$key]['status']='草稿';
}elseif ($value['status']==2){
$inventory[$key]['status']='下架';
}elseif ($value['status']==3){
$inventory[$key]['status']='上架';
}else{
$inventory[$key]['status']='其他';
}
}
}else{
$inventory[0]['prescription_no']= '无数据导出';
}
return $inventory;
}
}