产品服务包,分账
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace common\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\newDb\AccountBalanceModel;
|
||||
use common\models\oldDb\CashAccount;
|
||||
use common\models\oldDb\Ledger;
|
||||
use common\models\oldDb\LedgerLog;
|
||||
@@ -116,7 +117,7 @@ class LedgerForm extends BaseModel
|
||||
$ledgerData[] = [
|
||||
'order_id' => $this->order_id,
|
||||
'user_id' => 0,
|
||||
'user_type' => 2, //平台
|
||||
'user_type' => 3, //供应商
|
||||
'order_type' => 1,//产品订单
|
||||
'fee_type' => 5,//加工费用
|
||||
'su_id' => $productOrder->su_id,
|
||||
@@ -265,6 +266,72 @@ class LedgerForm extends BaseModel
|
||||
], $ledger)->execute();
|
||||
}
|
||||
|
||||
break;
|
||||
case '5':
|
||||
|
||||
//产品服务包分成
|
||||
$ledger = [];
|
||||
foreach ($productOrderItems as $v) {
|
||||
$totalPrice = bcmul($v['number'], $v['price'], 4);
|
||||
$platformMoney = bcmul($totalPrice, $v['drug']['platform_ledger'] / 100, 4);
|
||||
$storeMoney = bcmul($totalPrice, $v['drug']['store_ledger'] / 100, 4);
|
||||
$supplierMoney = bcmul($totalPrice, $v['drug']['supplier_ledger'] / 100, 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' => $storeMoney,
|
||||
'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' => $platformMoney,
|
||||
'status' => 0,
|
||||
'created_at' => $time,
|
||||
'updated_at' => $time
|
||||
];
|
||||
|
||||
$ledger[] = [
|
||||
'order_id' => $this->order_id,
|
||||
'user_id' => $v['drug']['supplier']['id'],
|
||||
'user_type' => 3, //平台
|
||||
'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' => $supplierMoney,
|
||||
'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;
|
||||
default:
|
||||
throw new Exception('错误的处方类型');
|
||||
@@ -416,6 +483,34 @@ class LedgerForm extends BaseModel
|
||||
$item->created_at = $time;
|
||||
$item->updated_at = $time;
|
||||
$item->saveOrFail();
|
||||
|
||||
|
||||
|
||||
/******************************************** 供应商 ********************************************** */
|
||||
$storeTotal = Ledger::find()->where(['order_id' => $this->order_id, 'user_id' => $v->drug->source, 'user_type' => 3, 'order_type' => 1, 'fee_type' => 1])->sum('money'); // 该订单供应商分佣总金额
|
||||
$storeTotal = round($storeTotal, 6);//4舍5入
|
||||
//增加供应商分佣
|
||||
$log = clone $model;
|
||||
$log->order_id = $this->order_id;
|
||||
$log->user_id = $v->drug->source;
|
||||
$log->user_type = 3;// 供应商
|
||||
$log->order_type = 1; //产品订单
|
||||
$log->fee_type = 1; //药品费用
|
||||
$log->type = 1;// 增加
|
||||
$log->amount = $storeTotal;
|
||||
$log->content = '订单结算后增加供应商佣金额';
|
||||
$log->created_at = $time;
|
||||
$log->updated_at = $time;
|
||||
$log->saveOrFail();
|
||||
|
||||
//供应商冻结金额及累计金额更新
|
||||
AccountBalanceModel::updateAllCounters([
|
||||
'total' => $storeTotal,
|
||||
'frozen' => $storeTotal,
|
||||
], [
|
||||
'user_id' => $v->drug->source,
|
||||
'type' => 3
|
||||
]);
|
||||
}
|
||||
|
||||
//分账表批量更新状态为已结算
|
||||
@@ -541,21 +636,47 @@ class LedgerForm extends BaseModel
|
||||
|
||||
$ledgerLog = LedgerLog::find()->where(['order_id' => $this->order_id])->asArray()->all();
|
||||
foreach($ledgerLog as $v){
|
||||
$log = clone $model;
|
||||
$log->order_id = $v['order_id'];
|
||||
$log->user_id = $v['user_id'];
|
||||
$log->user_type = $v['user_type'];
|
||||
$log->order_type = $v['order_type'];
|
||||
$log->fee_type = $v['fee_type'];
|
||||
$log->type = 2;// 扣减
|
||||
$log->amount = $v['amount'];
|
||||
$log->content = '订单结算后用户退货退款,扣减金额';
|
||||
$log->created_at = $time;
|
||||
$log->updated_at = $time;
|
||||
$log->saveOrFail();
|
||||
|
||||
//可提现及累计金额更新
|
||||
CashAccount::updateAllCounters(['able_cash' => $v['amount'] * -1, 'total_cash' => $v['amount'] * -1],['user_type' => $v['user_type'], 'user_id' => $v['user_id']]);
|
||||
if ($v['user_type'] === 3) {
|
||||
/******************************************** 供应商 ********************************************** */
|
||||
//增加供应商分佣
|
||||
$log = clone $model;
|
||||
$log->order_id = $v['order_id'];
|
||||
$log->user_id = $v['user_id'];
|
||||
$log->user_type = $v['user_type'];// 供应商
|
||||
$log->order_type = $v['order_type']; //产品订单
|
||||
$log->fee_type = $v['fee_type']; //药品费用
|
||||
$log->type = 2;// 增加
|
||||
$log->amount = $v['amount'];
|
||||
$log->content = '订单结算后用户退货退款,扣减供应商金额';
|
||||
$log->created_at = $time;
|
||||
$log->updated_at = $time;
|
||||
$log->saveOrFail();
|
||||
|
||||
//供应商冻结金额及累计金额更新
|
||||
AccountBalanceModel::updateAllCounters([
|
||||
'total' => bcmul($v['amount'], -1, 6),
|
||||
'frozen' => bcmul($v['amount'], -1, 6),
|
||||
], [
|
||||
'user_id' => $v->drug->source,
|
||||
'type' => 3
|
||||
]);
|
||||
} else {
|
||||
$log = clone $model;
|
||||
$log->order_id = $v['order_id'];
|
||||
$log->user_id = $v['user_id'];
|
||||
$log->user_type = $v['user_type'];
|
||||
$log->order_type = $v['order_type'];
|
||||
$log->fee_type = $v['fee_type'];
|
||||
$log->type = 2;// 扣减
|
||||
$log->amount = $v['amount'];
|
||||
$log->content = '订单结算后用户退货退款,扣减金额';
|
||||
$log->created_at = $time;
|
||||
$log->updated_at = $time;
|
||||
$log->saveOrFail();
|
||||
|
||||
//可提现及累计金额更新
|
||||
CashAccount::updateAllCounters(['able_cash' => $v['amount'] * -1, 'total_cash' => $v['amount'] * -1],['user_type' => $v['user_type'], 'user_id' => $v['user_id']]);
|
||||
}
|
||||
}
|
||||
} else { // 未结算
|
||||
Ledger::updateAll(['status' => 2, 'updated_at' => $time], ['order_id' => $this->order_id, 'order_type' => 1]);//order_type 1产品订单 2挂号订单
|
||||
|
||||
Reference in New Issue
Block a user