订单退款,供应链订单同步退款
This commit is contained in:
parent
5dbf9b0e81
commit
31349fc1ef
@ -331,8 +331,8 @@ class StoreConsumptionUserDao extends BaseDao
|
||||
$rate = bcdiv($productPrice, $orderTotalPrice, 5);
|
||||
$realPrice = $this->isLast ? bcsub($orderPayPrice, $realPriceTotal, 2) : ceil(bcmul($orderPayPrice, $rate, 5));
|
||||
$consumptionAmount = $productPrice - $realPrice;
|
||||
$realPriceTotal += $realPrice;
|
||||
}
|
||||
$realPriceTotal += $realPrice;
|
||||
$realPrice = bcdiv($realPrice, 100, 2);
|
||||
$consumptionAmount = bcdiv($consumptionAmount, 100, 2);
|
||||
$realPriceTotal = bcdiv($realPriceTotal, 100, 2);
|
||||
|
@ -19,6 +19,9 @@ use app\common\model\store\order\StoreGroupOrderOther;
|
||||
use app\common\model\store\order\StoreOrderOther;
|
||||
use app\common\model\store\order\StoreOrderProductOther;
|
||||
use app\common\model\store\order\StoreOrderStatusOther;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\store\order\StoreRefundOrderOther;
|
||||
use app\common\model\store\order\StoreRefundProductOther;
|
||||
use app\common\repositories\store\order\StoreOrderStatusRepository;
|
||||
use app\common\repositories\store\product\ProductAssistSetRepository;
|
||||
use app\common\repositories\store\product\ProductGroupBuyingRepository;
|
||||
@ -27,6 +30,7 @@ use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
@ -764,4 +768,54 @@ class StoreOrderOtherDao extends BaseDao
|
||||
});
|
||||
})->where('StoreOrderOther.uid', $uid)->count();
|
||||
}
|
||||
|
||||
public function refund($id)
|
||||
{
|
||||
$refundOrder = StoreRefundOrder::where('refund_order_id', $id)->with(['refundProduct.product', 'order'])->find();
|
||||
$refundProducts = [];
|
||||
foreach ($refundOrder->refundProduct->toArray() as $item) {
|
||||
$refundProducts[$item['product']['product_id']] = ['num' => $item['refund_num']];
|
||||
}
|
||||
$order = StoreOrderOther::where('order_sn', $refundOrder->order['order_sn'])->find();
|
||||
$refundOrderArray = $refundOrder->toArray();
|
||||
unset($refundOrderArray['return_order_id']);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$model = new StoreRefundOrderOther();
|
||||
$model->setAttrs($refundOrderArray);
|
||||
$model->order_sn = $refundOrderArray['refund_order_sn'];
|
||||
$model->order_id = $order['order_id'];
|
||||
$model->uid = $order['uid'];
|
||||
$model->mer_id = $order['mer_id'];
|
||||
$model->save();
|
||||
$products = [];
|
||||
$orderProducts = StoreOrderProductOther::where('order_id', $order['order_id'])->select();
|
||||
foreach ($orderProducts as $orderProduct) {
|
||||
$refundProduct = $refundProducts[$orderProduct['product_id']] ?? [];
|
||||
if (!empty($refundProduct)) {
|
||||
$products[] = [
|
||||
'refund_order_id' => $model->refund_order_id,
|
||||
'order_product_id' => $orderProduct['order_product_id'],
|
||||
'refund_price' => $orderProduct['total_price'],
|
||||
'refund_consumption' => 0,
|
||||
'platform_refund_price' => 0,
|
||||
'refund_postage' => 0,
|
||||
'refund_integral' => 0,
|
||||
'refund_num' => $refundProduct['num'],
|
||||
];
|
||||
$orderProduct->refund_num -= $refundProduct['num'];
|
||||
$orderProduct->is_refund = 1;
|
||||
$orderProduct->save();
|
||||
}
|
||||
}
|
||||
if (count($products) > 0) {
|
||||
StoreRefundProductOther::getDB()->insertAll($products);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new ValidateException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
41
app/common/model/store/order/StoreRefundOrderOther.php
Normal file
41
app/common/model/store/order/StoreRefundOrderOther.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store\order;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\model\user\User;
|
||||
|
||||
class StoreRefundOrderOther extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'refund_order_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'store_refund_order_other';
|
||||
}
|
||||
|
||||
public function refundProduct()
|
||||
{
|
||||
return $this->hasMany(StoreRefundProductOther::class, 'refund_order_id', 'refund_order_id');
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasOne(StoreOrderOther::class, 'order_id', 'order_id');
|
||||
}
|
||||
}
|
30
app/common/model/store/order/StoreRefundProductOther.php
Normal file
30
app/common/model/store/order/StoreRefundProductOther.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store\order;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class StoreRefundProductOther extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'refund_product_id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'store_refund_product_other';
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(StoreOrderProductOther::class,'order_product_id','order_product_id');
|
||||
}
|
||||
|
||||
public function refundOrder()
|
||||
{
|
||||
return $this->hasOne(StoreRefundOrderOther::class,'refund_order_id','refund_order_id');
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\dao\store\consumption\CommissionDao;
|
||||
use app\common\dao\store\consumption\StoreConsumptionUserDao;
|
||||
use app\common\dao\store\order\StoreOrderOtherDao;
|
||||
use app\common\dao\store\order\StoreRefundOrderDao;
|
||||
use app\common\dao\store\StoreActivityOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
@ -922,6 +923,7 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
if ($refund['refund_type'] == 1) {
|
||||
//TODO 退款单同意退款
|
||||
$refund = $this->doRefundPrice($id, $_refund_price);
|
||||
(new StoreOrderOtherDao())->refund($id);
|
||||
$data['status'] = 3;
|
||||
$orderStatus['change_message'] = '退款成功';
|
||||
$orderStatus['change_type'] = $storeOrderStatusRepository::ORDER_STATUS_CREATE;
|
||||
@ -1382,7 +1384,8 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
'number' => $refundRate,
|
||||
], $res->mer_id);
|
||||
|
||||
event('refund.after', compact('id', 'res'));
|
||||
// 业务流程调整,暂时注释
|
||||
// event('refund.after', compact('id', 'res'));
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user