支付方式修改

This commit is contained in:
2025-03-11 14:32:18 +08:00
parent 50bd6ae12a
commit 4fe7b503d1
3 changed files with 171 additions and 76 deletions

View File

@@ -4,6 +4,7 @@ namespace common\forms;
use common\core\BaseModel;
use common\models\newDb\AccountBalanceModel;
use common\models\newDb\MonthlyPaymentModel;
use common\models\oldDb\CashAccount;
use common\models\oldDb\Ledger;
use common\models\oldDb\LedgerLog;
@@ -30,6 +31,12 @@ class LedgerForm extends BaseModel
];
}
/**
* 订单分账
* @param $type
* @return void
* @throws Exception
*/
public function create($type = 'productorder'){
switch ($type) {
case 'register':
@@ -81,7 +88,7 @@ class LedgerForm extends BaseModel
ProductOrderLog::saveLog($this->order_id, '产品订单增加待结算记录开始');
$t = \Yii::$app->db->beginTransaction();
try {
$productOrder = ProductOrder::find()->where(['id' => $this->order_id])->one();
$productOrder = ProductOrder::find()->with(['prescription'])->where(['id' => $this->order_id])->one();
if(!$productOrder){
throw new Exception('产品订单不存在');
}
@@ -95,6 +102,7 @@ class LedgerForm extends BaseModel
}
$time = time();
$ledgerData = [];
if($productOrder->decoct_price > 0){
$ledgerData[] = [
'order_id' => $this->order_id,
@@ -182,44 +190,54 @@ class LedgerForm extends BaseModel
$number = $v['number'];
$totalPrice = round($number * $v['price'], 4);
$totalBuyPrice = round($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,
'drug_id' => $v['drug_id'],
'xd_time' => $productOrder->created_at,
'number' => $number,
'money' => $totalPrice - $totalBuyPrice,
'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' => $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();
if ($productOrder['prescription']['category'] == 2) {
(new MonthlyPaymentModel)->save([
'store_id' => $productOrder->store_id,
'order_id' => $productOrder->id,
'amount' => $totalBuyPrice,
'created_at' => $time,
]);
} else {
$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,
'drug_id' => $v['drug_id'],
'xd_time' => $productOrder->created_at,
'number' => $number,
'money' => $totalPrice - $totalBuyPrice,
'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' => $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();
}
}
break;
case '2': //西药分佣
@@ -227,43 +245,52 @@ class LedgerForm extends BaseModel
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' => $totalPrice - $totalBuyPrice,
'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();
if ($productOrder['prescription']['category'] == 2) {
(new MonthlyPaymentModel)->save([
'store_id' => $productOrder->store_id,
'order_id' => $productOrder->id,
'amount' => $totalBuyPrice,
'created_at' => $time,
]);
} else {
$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' => $totalPrice - $totalBuyPrice,
'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();
}
}
break;