分账更新购药订单分账

This commit is contained in:
2025-10-20 08:21:50 +08:00
parent 11718a4479
commit daea14dbdb

View File

@@ -5,6 +5,7 @@ namespace common\forms;
use common\core\BaseModel;
use common\models\newDb\AccountBalanceModel;
use common\models\newDb\MonthlyPaymentModel;
use common\models\newDb\RegisterInfoModel;
use common\models\oldDb\CashAccount;
use common\models\oldDb\Ledger;
use common\models\oldDb\LedgerLog;
@@ -103,6 +104,130 @@ class LedgerForm extends BaseModel
$time = time();
$ledgerData = [];
if ($productOrder->order_type === 2) {
if($productOrder->decoct_price > 0){
$ledgerData[] = [
'order_id' => $this->order_id,
'user_id' => 0,
'user_type' => 2, //平台
'order_type' => 1,//产品订单
'fee_type' => 4,//代煎费用
'su_id' => $productOrder->su_id,
'drugstore_id' => $productOrder->store_id,
'drug_id' => 0,
'xd_time' => $productOrder->created_at,
'number' => 1,
'money' => $productOrder->decoct_price,
'status' => 0,
'created_at' => $time,
'updated_at' => $time
];
}
if($productOrder->process_price > 0){
$ledgerData[] = [
'order_id' => $this->order_id,
'user_id' => 0,
'user_type' => 3, //供应商
'order_type' => 1,//产品订单
'fee_type' => 5,//加工费用
'su_id' => $productOrder->su_id,
'drugstore_id' => $productOrder->store_id,
'drug_id' => 0,
'xd_time' => $productOrder->created_at,
'number' => 1,
'money' => $productOrder->process_price,
'status' => 0,
'created_at' => $time,
'updated_at' => $time
];
}
if($productOrder->treatement_price > 0){
$ledgerData[] = [
'order_id' => $this->order_id,
'user_id' => $store->id,
'user_type' => 1, //门店
'order_type' => 1,//产品订单
'fee_type' => 6,//诊疗费用
'su_id' => $productOrder->su_id,
'drugstore_id' => $productOrder->store_id,
'drug_id' => 0,
'xd_time' => $productOrder->created_at,
'number' => 1,
'money' => $productOrder->treatement_price,
'status' => 0,
'created_at' => $time,
'updated_at' => $time
];
}
if($productOrder->trans_expenses > 0){
$ledgerData[] = [
'order_id' => $this->order_id,
'user_id' => 0,
'user_type' => 2, //平台
'order_type' => 1,//产品订单
'fee_type' => 3,//快递费用
'su_id' => $productOrder->su_id,
'drugstore_id' => $productOrder->store_id,
'drug_id' => 0,
'xd_time' => $productOrder->created_at,
'number' => 1,
'money' => $productOrder->trans_expenses,
'status' => 0,
'created_at' => $time,
'updated_at' => $time
];
}
if(!empty($ledgerData)){
\Yii::$app->db->createCommand()->batchInsert(Ledger::tableName(), [
'order_id', 'user_id', 'user_type', 'order_type', 'fee_type', 'su_id', 'drugstore_id',
'drug_id', 'xd_time','number','money', 'status', 'created_at', 'updated_at'
], $ledgerData)->execute();
}
$productOrderItems = ProductOrderItems::find()->where(['product_order_id' => $productOrder->id])->all();
$ledger = [];
foreach($productOrderItems as $v){
$totalPrice = round($v['number'] * $v['price'], 4);
$totalBuyPrice = round($v['number'] * $v['buy_price'], 4);
$ledger[] = [
'order_id' => $this->order_id,
'user_id' => $store->id,
'user_type' => 1, //门店
'order_type' => 1,//产品订单
'fee_type' => 1,//药品费用
'su_id' => $productOrder->su_id,
'drugstore_id' => $productOrder->store_id,
'xd_time' => $productOrder->created_at,
'drug_id' => $v['drug_id'],
'number' => $v['number'],
'money' => bcsub($totalPrice, $totalBuyPrice, 2),
'status' => 0,
'created_at' => $time,
'updated_at' => $time
];
$ledger[] = [
'order_id' => $this->order_id,
'user_id' => 0,
'user_type' => 2, //平台
'order_type' => 1,//产品订单
'fee_type' => 1,//药品费用
'su_id' => $productOrder->su_id,
'drugstore_id' => $productOrder->store_id,
'drug_id' => $v['drug_id'],
'xd_time' => $productOrder->created_at,
'number' => $v['number'],
'money' => $totalBuyPrice,
'status' => 0,
'created_at' => $time,
'updated_at' => $time
];
\Yii::$app->db->createCommand()->batchInsert(Ledger::tableName(), [
'order_id', 'user_id', 'user_type', 'order_type', 'fee_type', 'su_id', 'drugstore_id',
'drug_id','xd_time', 'number','money', 'status', 'created_at', 'updated_at'
], $ledger)->execute();
}
} else {
if($productOrder->decoct_price > 0){
$ledgerData[] = [
'order_id' => $this->order_id,
@@ -376,6 +501,8 @@ class LedgerForm extends BaseModel
throw new Exception('错误的处方类型');
break;
}
}
$t->commit();
$ledgerForm = new LedgerForm();