添加退款处理流程

main
fengxinyhyl 9 months ago
parent c2f55f5726
commit 2cca063da1
  1. 13
      app/common/dao/user/UserAssetsLogDao.php
  2. 104
      app/common/repositories/user/UserAssetsLogRepository.php
  3. 10
      app/common/repositories/user/UserAssetsRepository.php
  4. 8
      app/controller/api/Auth.php
  5. 1
      app/event.php
  6. 12
      crmeb/listens/pay/CustomizeRefundAll.php
  7. 22
      crmeb/listens/pay/CustomizeTake.php

@ -37,10 +37,21 @@ class UserAssetsLogDao extends BaseDao
}
public function search(int $uid, array $where){
public function search(int $uid, array $where)
{
$query = UserAssetsLog::getDB()->where('uid', $uid)->where($where);
return $query;
}
public function orderData(int $orderId, array $where)
{
return UserAssetsLog::getDB()->where('order_id', $orderId)->where($where)->group('uid, asset_type')->field('uid,asset_type, sum(count) as count')->select();
}
public function updateOrderStatus($orderId, $status){
return UserAssetsLog::where('order_id', $orderId)->update(array('status' => $status));
}
}

@ -50,6 +50,7 @@ class UserAssetsLogRepository extends BaseRepository
const STATUS_FROZEN = 0; // 冻结
const STATUS_SUCCESS = 1; // 成功
const STATUS_REFUND = 2; // 退款
const STATUS_USED = 3; // 使用积分
public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository, GroupDataRepository $groupRepository)
{
@ -554,6 +555,101 @@ class UserAssetsLogRepository extends BaseRepository
}
$this->addLog($logList);
$this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
// 5. 本人使用的福利积分
if ($orderItem['integral']) {
$consume = $welfare = $huitong = $contribution = 0;
$log = array('uid' => $orderItem['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER,
'status' => self::STATUS_USED,
'order_id' => $orderItem['order_id'],
'count' => $orderItem['integral'],
);
$this->addLog([$log]);
$this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_USED, compact('consume', 'welfare', 'huitong', 'contribution'));
}
}
public function userTakeEvent()
{
}
/**
* notes 订单退款事件处理
* @param $orderItem
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/19 11:01
* @update 2024/3/19 11:01
* @author zhangkxiang
* @editor
*/
public function userRefundEvent($orderItem)
{
// 订单发送冻结资产收回
$refundList = $this->_getOrderData($orderItem['order_id'], self::STATUS_FROZEN);
if ($refundList) {
foreach ($refundList as $refund) {
$this->userAssetsRepository->orderEvent($refund['uid'], self::STATUS_REFUND, $refund);
}
}
// 返回用户支付的福利积分
$usedList = $this->_getOrderData($orderItem['order_id'], self::STATUS_USED);
if ($usedList) {
foreach ($usedList as $used) {
if($used['welfare'] > 0){
$info = $this->userAssetsRepository->get($used['uid']);
$this->userAssetsRepository->update($used['uid'], array('welfare' => $info['welfare'] + $used['welfare']));
}
}
}
// 更新该订单的所有数据为退款状态
$this->dao->updateOrderStatus($orderItem['order_id'], self::STATUS_REFUND);
}
private function _getOrderData($orderId, $status)
{
$data = $this->dao->orderData($orderId, ['status' => $status]);
// 订单发送冻结资产收回
if (!$data->isEmpty()) {
$list = array();
foreach ($data as $item) {
if (!isset($list[$item['uid']])) {
$list[$item['uid']] = array(
'uid' => $item['uid'],
'consume' => 0,
'welfare' => 0,
'huitong' => 0,
'contribution' => 0,
);
}
switch ($item['asset_type']) {
case self::ASSET_TYPE_CONSUME:
$list[$item['uid']]['consume'] += $item['count'];
break;
case self::ASSET_TYPE_WELFARE:
$list[$item['uid']]['welfare'] += $item['count'];
break;
case self::ASSET_TYPE_HUITONG:
$list[$item['uid']]['huitong'] += $item['count'];
break;
case self::ASSET_TYPE_CONTRIBUTION:
$list[$item['uid']]['contribution'] += $item['count'];
break;
}
}
return $list;
}
return array();
}
@ -602,7 +698,7 @@ class UserAssetsLogRepository extends BaseRepository
{
$query = $this->dao->search($uid, $where);
$count = $query->count();
$data = $query->page($page, $limit)->select();
$data = $query->page($page, $limit)->order('id desc')->select();
$list = array();
$changeType = $this->getChangeType();
foreach ($data as $item) {
@ -611,10 +707,4 @@ class UserAssetsLogRepository extends BaseRepository
}
return compact('count', 'list');
}
public function userRefund()
{
}
}

@ -79,6 +79,12 @@ class UserAssetsRepository extends BaseRepository
{
$assets = array();
$info = $this->dao->get($uid);
$data['consume'] = $data['consume'] ?? 0;
$data['welfare'] = $data['welfare'] ?? 0;
$data['huitong'] = $data['huitong'] ?? 0;
$data['contribution'] = $data['contribution'] ?? 0;
if ($info) {
// 购买订单获得冻结资产
if ($status == UserAssetsLogRepository::STATUS_FROZEN) {
@ -106,6 +112,10 @@ class UserAssetsRepository extends BaseRepository
'huitong_frozen' => $info['huitong_frozen'] - $data['huitong'],
'contribution_frozen' => $info['contribution_frozen'] - $data['contribution'],
);
} elseif ($status == UserAssetsLogRepository::STATUS_USED) {
$assets = array(
'welfare' => $info['welfare'] - $data['welfare'],
);
}
$this->dao->update($uid, $assets);
} else {

File diff suppressed because one or more lines are too long

@ -62,6 +62,7 @@ return [
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
'order.paySuccess' => [\crmeb\listens\pay\CustomizePaySuccess::class],
'order.take' => [\crmeb\listens\pay\CustomizeTake::class],
'order.refundAll' => [\crmeb\listens\pay\CustomizeRefundAll::class],
],

@ -9,16 +9,24 @@
namespace crmeb\listens\pay;
use app\common\repositories\store\order\StoreGroupOrderRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\user\UserAssetsLogRepository;
use crmeb\interfaces\ListenerInterface;
use think\facade\Log;
class CustomizeRefundAll implements ListenerInterface
{
// {"order":{"order_id":28,"main_id":0,"group_order_id":27,"order_sn":"wxo1710646722542760291","uid":3,"spread_uid":0,"top_uid":0,"district_id":3378,"real_name":"\u5f20\u51ef\u7fd4","user_phone":"18362705640","user_address":"\u6c5f\u82cf\u5357\u4eac\u5e02\u6816\u971e\u533a\u5c27\u5316\u8857\u9053\u4e1c\u57ce\u4e16\u5bb6(\u5357\u4eac\u5e02\u6816\u971e\u533a\u5c27\u8fb0\u8def3\u53f7)24\u680b501","cart_id":"69","total_num":1,"total_price":"180.00","total_postage":"0.00","pay_price":"180.00","pay_postage":"0.00","is_selfbuy":0,"extension_one":"0.00","extension_two":"0.00","commission_rate":"5.0000","integral":0,"integral_price":"0.00","give_integral":180,"coupon_id":"","coupon_price":"0.00","platform_coupon_price":"0.00","svip_discount":"0.00","order_type":0,"paid":1,"pay_time":"2024-03-17 11:38:42","pay_type":0,"create_time":"2024-03-17 11:38:43","status":-1,"delivery_type":null,"is_virtual":0,"delivery_name":null,"delivery_id":null,"mark":"","remark":null,"admin_mark":null,"verify_code":null,"verify_time":null,"verify_service_id":null,"transaction_id":null,"activity_type":0,"order_extend":null,"mer_id":6,"reconciliation_id":0,"cost":"200.00","is_del":0,"is_system_del":0,"verify_status":0,"orderProduct":[{"order_product_id":28,"order_id":28,"uid":3,"cart_id":69,"product_id":6,"extension_one":"0.00","extension_two":"0.00","integral":0,"integral_price":"0.00","integral_total":0,"coupon_price":"0.00","platform_coupon_price":null,"svip_discount":"0.00","postage_price":"0.00","product_sku":"167ac3990130","is_refund":3,"product_num":1,"product_type":0,"activity_id":6,"refund_num":0,"is_reply":0,"cost":"200.00","product_price":"180.00","total_price":"180.00","cart_info":{"product":{"product_id":6,"cate_id":14,"image":"https:\/\/mer.crmeb.net\/uploads\/attach\/2022\/04\/24\/8113054bdc3753c2f4f479e5b04f11d1.png","store_name":"Prada\/\u666e\u62c9\u8fbe\u5973\u58eb\u53d1\u5939\u5934\u9970","is_show":1,"status":1,"is_del":0,"unit_name":"\u4ef6","price":"180.00","mer_status":1,"temp_id":0,"give_coupon_ids":[],"is_gift_bag":0,"is_used":1,"product_type":0,"old_product_id":0,"integral_rate":0,"delivery_way":"2","delivery_free":1,"type":0,"extend":"","pay_limit":0,"once_max_count":0,"once_min_count":0,"mer_svip_status":1,"svip_price_type":0,"temp":null},"productAttr":{"image":"https:\/\/img.alicdn.com\/imgextra\/i2\/2207289125344\/O1CN010XEeaY1pLbHpe8KwV_!!2-item_pic.png","extension_one":"0.00","extension_two":"0.00","product_id":6,"stock":999,"price":"180.00","unique":"167ac3990130","sku":"\u767e\u5408\u8272","volume":"0.00","weight":"0.00","ot_price":"200.00","cost":"200.00","svip_price":"0.00","show_svip_price":false,"bc_extension_one":3.6,"bc_extension_two":1.8},"product_type":0},"create_time":"2024-03-17 11:38:42"}],"presellOrder":null,"groupOrder":{"group_order_id":27,"group_order_sn":"wxo1710646722542760291","uid":3,"total_postage":"0.00","total_price":"180.00","total_num":1,"integral":0,"integral_price":"0.00","give_integral":180,"coupon_price":"0.00","real_name":"\u5f20\u51ef\u7fd4","user_phone":"18362705640","user_address":"\u6c5f\u82cf\u5357\u4eac\u5e02\u6816\u971e\u533a\u5c27\u5316\u8857\u9053\u4e1c\u57ce\u4e16\u5bb6(\u5357\u4eac\u5e02\u6816\u971e\u533a\u5c27\u8fb0\u8def3\u53f7)24\u680b501","pay_price":"180.00","pay_postage":"0.00","cost":"200.00","coupon_id":"","give_coupon_ids":[],"paid":1,"pay_time":"2024-03-17 11:38:42","pay_type":0,"create_time":"2024-03-17 11:38:43","is_remind":0,"is_del":0,"is_combine":0}}}
public function handle($data): void
{
Log::info('退款' . json_encode($data));
if(isset($data['order']) and $data['order']){
/**
* @var UserAssetsLogRepository $repository
*/
$repository = app()->make(UserAssetsLogRepository::class);
$repository->userRefundEvent($data['order']);
}
}
}

@ -0,0 +1,22 @@
<?php
/**
* CustomizePaySuccess.php
* 文件描述
* Created on 2024/3/13 23:02
* Created by zhangkaixiang
*/
namespace crmeb\listens\pay;
use crmeb\interfaces\ListenerInterface;
use think\facade\Log;
class CustomizeTake implements ListenerInterface
{
public function handle($data): void
{
Log::info('收货' . json_encode($data));
}
}
Loading…
Cancel
Save