Files
xk-api-yii/common/models/DrugStoreDrug.php
2024-11-13 15:16:20 +08:00

50 lines
1.2 KiB
PHP

<?php
namespace common\models;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
class DrugStoreDrug extends \common\modelsgii\DrugStoreDrug
{
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']);
}
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'];
$result[$k]['drug_name'] = $v['drug']['drug_name'];
$result[$k]['market_price'] = $v['market_price'];
$result[$k]['price'] = $v['price'];
}
return $result;
}
}