门店仓库药品管理
This commit is contained in:
@@ -196,6 +196,7 @@ class WareController extends BaseAdminController
|
||||
public function actionIsSale()
|
||||
{
|
||||
$post = \Yii::$app->request->post();
|
||||
$isStore = $post['isStore']?? false;
|
||||
$this->requestValidate($post, [
|
||||
[['drug_id', 'type', 'status'], 'required']
|
||||
]);
|
||||
@@ -209,13 +210,24 @@ class WareController extends BaseAdminController
|
||||
}
|
||||
$t = \Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
$DrugStoreDrug->status= $post['status'];
|
||||
$DrugStoreDrug->saveOrFail();
|
||||
|
||||
$ids = DrugStoreRelations::find()->select(['id'])->where([
|
||||
'drug_id' => $post['drug_id']
|
||||
])->column();
|
||||
DrugStoreRelations::updateAll(['status' => $post['status']], ['id' => $ids]);//修改门店
|
||||
if (!$isStore) {
|
||||
// 有争议
|
||||
$DrugStoreDrug->status= $post['status'];
|
||||
$DrugStoreDrug->saveOrFail();
|
||||
$ids = DrugStoreRelations::find()->select(['id'])->where([
|
||||
'drug_id' => $post['drug_id']
|
||||
])->column();
|
||||
} else {
|
||||
$storeId = \Yii::$app->user->identity->store_id;
|
||||
if (empty($storeId)) throw new Exception('门店获取失败');
|
||||
$ids = DrugStoreRelations::find()->select(['id'])->where([
|
||||
'drug_id' => $post['drug_id'],
|
||||
'store_id' => $storeId
|
||||
])->column();
|
||||
}
|
||||
if (!empty($ids)) {
|
||||
DrugStoreRelations::updateAll(['status' => $post['status']], ['id' => $ids]);//修改门店
|
||||
}
|
||||
|
||||
$t->commit();
|
||||
return ['success'];
|
||||
@@ -255,6 +267,7 @@ class WareController extends BaseAdminController
|
||||
$DrugStoreDrug->market_price = $post['market_price'] ?? $DrugStoreDrug->market_price;
|
||||
$DrugStoreDrug->saveOrFail();
|
||||
|
||||
// TODO 2024-10-31 删除了修改门店售价的操作,门店售价由门店自己设置
|
||||
switch ($post['type']) {
|
||||
case 1://中药
|
||||
$DrugStoreRelations = DrugStoreRelations::find()->where(['drug_id' => $post['drug_id']])->asArray()->all();
|
||||
@@ -263,9 +276,8 @@ class WareController extends BaseAdminController
|
||||
$store = Store::find()->where(['id' => $val['store_id']])->one();
|
||||
|
||||
\Yii::$app->db->createCommand()->update('yii_drug_store_relations',
|
||||
['price' =>bcdiv(bcmul($store['z_sale_percent']??100,$DrugStoreDrug->price,4),100,4),
|
||||
'buy_price' =>bcdiv(bcmul($store['z_buy_percent']??100,$DrugStoreDrug->market_price,4),100,4)],
|
||||
['drug_id' => $val['drug_id'], 'store_id' => $val['store_id']])->execute();
|
||||
[ 'buy_price' =>bcdiv(bcmul($store['z_buy_percent']??100,$DrugStoreDrug->market_price,4),100,4) ],
|
||||
[ 'drug_id' => $val['drug_id'], 'store_id' => $val['store_id'] ])->execute();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -276,12 +288,10 @@ class WareController extends BaseAdminController
|
||||
if ($DrugStoreRelations) {
|
||||
foreach ($DrugStoreRelations as $val) {
|
||||
\Yii::$app->db->createCommand()->update('yii_drug_store_relations',
|
||||
['price' =>$DrugStoreDrug->price,
|
||||
'buy_price' => $DrugStoreDrug->market_price??0],
|
||||
[ 'buy_price' => $DrugStoreDrug->market_price??0 ],
|
||||
['drug_id' => $val['drug_id'], 'store_id' => $val['store_id']])->execute();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 3://配方颗粒
|
||||
|
||||
@@ -290,8 +300,7 @@ class WareController extends BaseAdminController
|
||||
foreach ($DrugStoreRelations as $val) {
|
||||
$store = Store::find()->where(['id' => $val['store_id']])->one();
|
||||
\Yii::$app->db->createCommand()->update('yii_drug_store_relations',
|
||||
['price' =>bcdiv(bcmul($store['g_sale_percent']??100,$DrugStoreDrug->price,4),100,4),
|
||||
'buy_price' =>bcdiv(bcmul($store['g_buy_percent']??100,$DrugStoreDrug->market_price,4),100,4)],
|
||||
['buy_price' =>bcdiv(bcmul($store['g_buy_percent']??100,$DrugStoreDrug->market_price,4),100,4)],
|
||||
['drug_id' => $val['drug_id'], 'store_id' => $val['store_id']])->execute();
|
||||
}
|
||||
}
|
||||
@@ -302,8 +311,7 @@ class WareController extends BaseAdminController
|
||||
foreach ($DrugStoreRelations as $val) {
|
||||
|
||||
\Yii::$app->db->createCommand()->update('yii_drug_store_relations',
|
||||
['price' =>$DrugStoreDrug->price,
|
||||
'buy_price' => $DrugStoreDrug->market_price??$DrugStoreDrug->price],
|
||||
[ 'buy_price' => $DrugStoreDrug->market_price??$DrugStoreDrug->price],
|
||||
['drug_id' => $val['drug_id'], 'store_id' => $val['store_id']])->execute();
|
||||
}
|
||||
}
|
||||
@@ -323,15 +331,6 @@ class WareController extends BaseAdminController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Excel修改仓库价格
|
||||
* @return void
|
||||
*/
|
||||
public function actionUpdateDrugstorePriceByExcel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 仓库修改门店西药价格
|
||||
* @doc-param int store_id 门店id
|
||||
@@ -369,6 +368,7 @@ class WareController extends BaseAdminController
|
||||
* @doc-return string z_sale_percent 中药销售比例 / optional
|
||||
* @doc-return string g_bug_percent 配方颗粒采购比例 / optional
|
||||
* @doc-return string g_sale_percent 配方颗粒销售比例 / optional
|
||||
* @throws Exception
|
||||
*/
|
||||
public function actionEditPercent()
|
||||
{
|
||||
@@ -674,6 +674,9 @@ class WareController extends BaseAdminController
|
||||
|
||||
$ImportForm = new ImportForm();
|
||||
$ImportForm->attributes = $post;
|
||||
if ($request->post('is_store') == true) {
|
||||
return $ImportForm->ExportUpdateDrugPriceByStore($data, $storeId);
|
||||
}
|
||||
return $ImportForm->ExportUpdateDrugPrice($data, $storeId);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -691,4 +694,219 @@ class WareController extends BaseAdminController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @doc-name 仓库药品列表 - 门店
|
||||
* @doc-param int status 状态1下架2上架 / optional
|
||||
* @doc-param string name 搜索别名,拼音首拼,药名 / optional
|
||||
* @doc-param int type 类型1中药2西药3颗粒配方4中成药 / optional
|
||||
* @doc-return mixed @List{id,drug_id,type-int-类型1中药2西药3颗粒配方,stock-int-库存,price-int-销售价格,market_price-int-采购价,status-int-状态1下架2上架,name-string-药名,pinyin_simple-string-拼音首拼,is_otc-int-是否处方} 药品信息
|
||||
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
||||
*/
|
||||
public function actionWareGoodListByStore()
|
||||
{
|
||||
$get = \Yii::$app->request->get();
|
||||
$admin = \Yii::$app->user->identity;
|
||||
$storeId = $admin->store_id;
|
||||
$name = $get['name'];
|
||||
|
||||
// 获取门店信息
|
||||
$store = Store::find()->where(['id' => $storeId])->one();
|
||||
if (!$store) throw new Exception('门店信息不存在');
|
||||
$query = DrugStoreRelations::find()->alias('dsr')->with(['drugStoreDrug', 'drug']);
|
||||
|
||||
$query->andWhere(['dsr.store_id' => $storeId]);
|
||||
|
||||
$query->joinWith(['drug' => function ($d) use ($name) {
|
||||
if (!empty($name)) {
|
||||
$d->andWhere([
|
||||
'or',
|
||||
['like', 'drug_name', $name],
|
||||
['like', 'pinyin_simple', $name],
|
||||
['like', 'pinyin_simple', $name],
|
||||
]);
|
||||
}
|
||||
}]);
|
||||
$query->joinWith(['drugStoreDrug' => function ($drugStoreDrug) use ($get) {
|
||||
if (!empty($get['type'])) {
|
||||
$drugStoreDrug->alias('dsd')->where(['dsd.type' => $get['type']]);
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
if (!empty($get['status'])) {
|
||||
$query->andWhere(['dsr.status' => $get['status']]);
|
||||
}
|
||||
|
||||
$this->field = [
|
||||
DrugStoreRelations::class => [
|
||||
'id',
|
||||
'drug_id',
|
||||
'type' => 'drugStoreDrug.type',
|
||||
'stock',
|
||||
'price',
|
||||
'market_price' => 'drugStoreDrug.market_price',
|
||||
'status',
|
||||
'name' => 'drug.drug_name',
|
||||
'image' => 'drug.image',
|
||||
'pinyin_simple' => 'drug.pinyin_simple',
|
||||
'is_otc' => 'drug.is_otc','drug_number'=>'drug.drug_number',
|
||||
'drug_alias'=>'drug.drug_alias',
|
||||
]
|
||||
];
|
||||
return $this->create($query, $get);
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 添加仓库商品 - 门店
|
||||
* @doc-param int drug_id 药id
|
||||
* @doc-param int type 药品类型 1中药 2西药 3颗粒药 4中成药
|
||||
* @doc-param float price 销售价格
|
||||
* @doc-param float market_price 市场价格
|
||||
* @doc-param int stock 库存
|
||||
*/
|
||||
public function actionSaveWareDrugByStore()
|
||||
{
|
||||
// TODO 未做,等确认需求
|
||||
$post = \Yii::$app->request->post();
|
||||
$this->requestValidate($post, [
|
||||
[['drug_id', 'type', 'price', 'stock'], 'required']
|
||||
]);
|
||||
|
||||
$DrugStoreDrug = DrugStoreDrug::find()->where([
|
||||
'drugstore_id' => 1,
|
||||
'drug_id' => $post['drug_id'],
|
||||
])->one();
|
||||
if ($DrugStoreDrug) throw new Exception('已存在,请勿重复添加');
|
||||
|
||||
if ($post['type']==1 || $post['type']==3 ){
|
||||
if (empty($post['market_price'])){
|
||||
throw new Exception('市场价格不能为空');
|
||||
}
|
||||
}
|
||||
|
||||
$t = \Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
$drug = new DrugStoreDrug();
|
||||
$drug->drugstore_id = 1;//仓库默认为1
|
||||
$drug->drug_id = $post['drug_id'];
|
||||
$drug->type = $post['type'];
|
||||
$drug->price = $post['price'];
|
||||
$drug->market_price = $post['market_price']??0;
|
||||
$drug->stock = $post['stock'];
|
||||
$drug->saveOrFail();
|
||||
|
||||
$Store = Store::find()->select(['id','z_buy_percent','z_sale_percent','g_bug_percent','g_sale_percent','store_set_sale_z','store_set_sale_g'])->where(['is_delete' => 0])->all();
|
||||
|
||||
if ($post['type']==1){
|
||||
foreach ($Store as $val) {
|
||||
if (!empty($val['store_set_sale_z'])){
|
||||
$DrugStoreRelations = new DrugStoreRelations();
|
||||
$DrugStoreRelations->drug_id = $post['drug_id'];
|
||||
$DrugStoreRelations->store_id = $val['id'];
|
||||
$DrugStoreRelations->price =bcdiv(bcmul($post['price'], $val['store_set_sale_z']??100, 4), 100, 4);//销售价
|
||||
$DrugStoreRelations->buy_price = bcdiv(bcmul($post['market_price'], $val['z_buy_percent']??100, 4), 100, 4);//进货(采购)价
|
||||
$DrugStoreRelations->status = 2;//上架
|
||||
$DrugStoreRelations->created_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->updated_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->saveOrFail();
|
||||
}else{
|
||||
$DrugStoreRelations = new DrugStoreRelations();
|
||||
$DrugStoreRelations->drug_id = $post['drug_id'];
|
||||
$DrugStoreRelations->store_id = $val['id'];
|
||||
$DrugStoreRelations->price =bcdiv(bcmul($post['price'], $val['z_sale_percent']??100, 4), 100, 4);//销售价
|
||||
$DrugStoreRelations->buy_price = bcdiv(bcmul($post['market_price'], $val['z_buy_percent']??100, 4), 100, 2);//进货(采购)价
|
||||
$DrugStoreRelations->status = 2;//上架
|
||||
$DrugStoreRelations->created_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->updated_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->saveOrFail();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($post['type']==3){
|
||||
foreach ($Store as $val){
|
||||
if (!empty($val['store_set_sale_g'])){
|
||||
$DrugStoreRelations = new DrugStoreRelations();
|
||||
$DrugStoreRelations->drug_id = $post['drug_id'];
|
||||
$DrugStoreRelations->store_id = $val['id'];
|
||||
$DrugStoreRelations->price =bcdiv(bcmul($post['price'], $val['store_set_sale_g']??100, 4), 100, 4);//销售价
|
||||
$DrugStoreRelations->buy_price = bcdiv(bcmul($post['market_price'], $val['g_bug_percent']??100, 4), 100, 4);//进货(采购)价
|
||||
$DrugStoreRelations->status = 2;//上架
|
||||
$DrugStoreRelations->created_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->updated_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->saveOrFail();
|
||||
}else{
|
||||
$DrugStoreRelations = new DrugStoreRelations();
|
||||
$DrugStoreRelations->drug_id = $post['drug_id'];
|
||||
$DrugStoreRelations->store_id = $val['id'];
|
||||
|
||||
$DrugStoreRelations->price =bcdiv(bcmul($post['price'], $val['g_sale_percent']??100, 4), 100, 4);//销售价
|
||||
$DrugStoreRelations->buy_price = bcdiv(bcmul($post['market_price'], $val['g_bug_percent']??100, 4), 100, 4);//进货(采购)价
|
||||
$DrugStoreRelations->status = 2;//上架
|
||||
$DrugStoreRelations->created_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->updated_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->saveOrFail();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ($post['type']==2|| $post['type']==4){
|
||||
foreach ($Store as $val) {
|
||||
$DrugStoreRelations = new DrugStoreRelations();
|
||||
$DrugStoreRelations->drug_id = $post['drug_id'];
|
||||
$DrugStoreRelations->store_id = $val['id'];
|
||||
$DrugStoreRelations->price =$post['price'];//销售价
|
||||
$DrugStoreRelations->buy_price = $post['market_price']??$post['price'];//进货(采购)价
|
||||
$DrugStoreRelations->status = 2;//上架
|
||||
$DrugStoreRelations->created_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->updated_at = date('Y-m-d H:i:s', time());
|
||||
$DrugStoreRelations->saveOrFail();
|
||||
}
|
||||
}
|
||||
|
||||
$t->commit();
|
||||
return ['添加成功'];
|
||||
} catch (\Exception $e) {
|
||||
$t->rollBack();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 修改仓库价格 - 门店
|
||||
* @doc-param int drug_id 药品ID
|
||||
* @doc-param int type 类型1中药2西药3颗粒配方4中成药
|
||||
* @doc-param float price 销售价 / optional
|
||||
* @doc-param int stock 库存 / optional
|
||||
* @doc-param float market_price 市场价 / optional
|
||||
*/
|
||||
public function actionUpdateDrugstorePriceByStore()
|
||||
{
|
||||
// TODO 开始修改这部分
|
||||
$post = \Yii::$app->request->post();
|
||||
$admin = \Yii::$app->user->identity;
|
||||
$storeId = $admin->store_id;
|
||||
if (empty($storeId)) throw new Exception('门店信息获取失败');
|
||||
$this->requestValidate($post, [
|
||||
[['drug_id', 'type'], 'required']
|
||||
]);
|
||||
|
||||
$DrugStoreRelations = DrugStoreRelations::find()->where([
|
||||
'store_id' => $storeId,
|
||||
'drug_id' => $post['drug_id'],
|
||||
])->one();
|
||||
if (!$DrugStoreRelations) throw new Exception('药品不存在');
|
||||
|
||||
try {
|
||||
$DrugStoreRelations->price = $post['price'] ?? $DrugStoreRelations->price;
|
||||
$DrugStoreRelations->stock = $post['stock'] ?? $DrugStoreRelations->stock;
|
||||
$DrugStoreRelations->saveOrFail();
|
||||
|
||||
return ['修改成功'];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -350,6 +350,48 @@ class ImportForm extends BaseModel
|
||||
}
|
||||
|
||||
public function ExportUpdateDrugPrice($data, $storeId)
|
||||
{
|
||||
if (empty($data)) {
|
||||
throw new Exception('导入数据为空');
|
||||
} else {
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
foreach ($data as $item) {
|
||||
if (empty(trim($item['药品ID']))) {
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:药品ID为空';
|
||||
continue;
|
||||
}
|
||||
if (empty(trim($item['销售价格']))) {
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:药品价格为空【'. $item['销售价格'].'】';
|
||||
continue;
|
||||
}
|
||||
$DrugStoreDrug = DrugStoreDrug::find()->where(['drug_id' => trim($item['药品ID']), 'store_id' => $storeId])->one();
|
||||
|
||||
if ($DrugStoreDrug) {
|
||||
$DrugStoreDrug->setAttribute('drug_id', trim($item['药品ID']));
|
||||
$DrugStoreDrug->setAttribute('market_price', trim($item['销售价格']));
|
||||
$DrugStoreDrug->updated_at = date('Y-m-d H:i:s');
|
||||
|
||||
if (!$DrugStoreDrug->save()) {
|
||||
$errorsMsg = array_values($DrugStoreDrug->getFirstErrors());
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:保存失败;'.$errorsMsg[0];
|
||||
}else{
|
||||
$success[] = $item['药品ID'] . '导入成功!';
|
||||
}
|
||||
} else {
|
||||
$errors[] = $item['药品ID'] . '导入失败,原因:未找到对应药品';
|
||||
}
|
||||
}
|
||||
$t->commit();
|
||||
} catch (\Exception $e) {
|
||||
$t->rollBack();
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
return ['success' => $success, 'error' => $errors];
|
||||
}
|
||||
}
|
||||
|
||||
public function ExportUpdateDrugPriceByStore($data, $storeId)
|
||||
{
|
||||
if (empty($data)) {
|
||||
throw new Exception('导入数据为空');
|
||||
|
||||
Reference in New Issue
Block a user