Files
xk-api-yii/common/models/oldDb/DrugStoreDrug.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2024-09-19 11:32:39 +08:00
<?php
2024-12-19 19:20:27 +08:00
namespace common\models\oldDb;
2024-09-19 11:32:39 +08:00
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
2024-12-19 19:20:27 +08:00
class DrugStoreDrug extends \common\modelsgii\oldDb\DrugStoreDrug
2024-09-19 11:32:39 +08:00
{
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at','updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
],
];
}
//关联门店
public function getStore()
{
return $this->hasOne(Store::class,['drugstore_id' => 'drugstore_id']);
}
//关联基础商品
public function getDrug()
{
return $this->hasOne(Drug::class,['id' => 'drug_id']);
}
2024-11-13 15:16:20 +08:00
public static function inventory($params, $storeId)
{
$list = self::find()->with(['drug'])->asArray()->all();
$result = [];
foreach ($list as $k => $v) {
$result[$k]['drug_id'] = $v['drug_id'];
2025-04-29 09:58:06 +08:00
$result[$k]['drug_name'] = array_key_exists('drug_name', $v['drug'] ?? [])? $v['drug']['drug_name']: '获取失败';
2024-11-13 15:16:20 +08:00
$result[$k]['market_price'] = $v['market_price'];
$result[$k]['price'] = $v['price'];
}
return $result;
}
2024-09-19 11:32:39 +08:00
}