优化代码

main
home.fengxinyhyl 8 months ago
parent fc5d0a9b12
commit 15f8c50b74
  1. 34
      app/common/repositories/user/UserAssetsLogRepository.php
  2. 2
      app/event.php
  3. 32
      crmeb/listens/pay/CustomizePaySuccess.php
  4. 32
      crmeb/listens/pay/CustomizeRefundAll.php

@ -16,6 +16,7 @@ namespace app\common\repositories\user;
use app\common\dao\user\UserAssetsLogDao; use app\common\dao\user\UserAssetsLogDao;
use app\common\model\store\StoreOrderHot; use app\common\model\store\StoreOrderHot;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderBaseRepository;
use app\common\repositories\store\order\StoreOrderHotRepository; use app\common\repositories\store\order\StoreOrderHotRepository;
use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\ProductRepository;
@ -135,6 +136,39 @@ class UserAssetsLogRepository extends BaseRepository
} }
public function userRefundEvent($orderItem)
{
// 更新该订单的所有数据为退款状态
$this->dao->updateOrderStatus($orderItem['order_id'], self::STATUS_REFUND);
$item = $this->dao->getWhere(array('id' => $orderItem));
if($item){
$item->status = self::STATUS_REFUND;
$item->save();
}
$this->userAssetsRepository->updateAssets($orderItem['uid'], array('integral_buy' => -1 * $item['count']));
}
public function userPayEvent($groupOrder){
foreach ($groupOrder['orderList'] as $orderItem) {
// 5. 本人使用的福利积分
if ($orderItem['integral']) {
$log = array('uid' => $orderItem['uid'],
'asset_type' => self::ASSET_INTEGRAL,
'type' => self::INTEGRAL_BUY,
'status' => self::STATUS_BUY,
'order_id' => $orderItem['order_id'],
'count' => -$orderItem['integral'],
);
$this->addLog([$log]);
$this->userAssetsRepository->updateAssets($orderItem['uid'], array('integral_buy' => -$orderItem['integral']));
}
}
}
/** /**
* notes 订单收货事件处理 * notes 订单收货事件处理
* @param $orderItem * @param $orderItem

@ -68,6 +68,8 @@ return [
'create_operate_log' => [\crmeb\listens\CreateOperateLogListen::class], // 操作日志事件 'create_operate_log' => [\crmeb\listens\CreateOperateLogListen::class], // 操作日志事件
'mini_order_shipping' => [\crmeb\listens\MiniOrderShippingListen::class], // 小程序发货管理事件 'mini_order_shipping' => [\crmeb\listens\MiniOrderShippingListen::class], // 小程序发货管理事件
'order.take' => [\crmeb\listens\pay\CustomizeTake::class], 'order.take' => [\crmeb\listens\pay\CustomizeTake::class],
'order.paySuccess' => [\crmeb\listens\pay\CustomizePaySuccess::class],
'order.refundAll' => [\crmeb\listens\pay\CustomizeRefundAll::class],
], ],
'subscribe' => [], 'subscribe' => [],

@ -0,0 +1,32 @@
<?php
/**
* CustomizePaySuccess.php
* 文件描述
* Created on 2024/3/13 23:02
* Created by zhangkaixiang
*/
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 CustomizePaySuccess implements ListenerInterface
{
public function handle($data): void
{
Log::info('支付成功' . json_encode($data));
if(isset($data['groupOrder']) and $data['groupOrder']){
/**
* @var UserAssetsLogRepository $repository
*/
$repository = app()->make(UserAssetsLogRepository::class);
$repository->userPayEvent($data['groupOrder']);
}
}
}

@ -0,0 +1,32 @@
<?php
/**
* CustomizePaySuccess.php
* 文件描述
* Created on 2024/3/13 23:02
* Created by zhangkaixiang
*/
namespace crmeb\listens\pay;
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']);
}
}
}
Loading…
Cancel
Save