feat: 修改订单和支付逻辑,增加用户等级判断和积分计算

This commit is contained in:
mkm 2024-07-02 17:02:21 +08:00
parent 23bf1ecee8
commit d6aaceb425
4 changed files with 91 additions and 69 deletions

View File

@ -534,7 +534,11 @@ class OrderLogic extends BaseLogic
$money = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 2])->value('number') ?? 0;
$financeFlowLogic->updateStatusStore($order['id'], $order['store_id'], $money, $deposit);
//积分结算
if($order['is_storage']==0&&$order['source']==0){
$user_ship=-1;
if($order['uid']){
$user_ship=User::where('id',$order['uid'])->value('user_ship');
}
if($order['is_storage']==0&&$order['source']==0&&in_array($user_ship,[0,4])){
UserSignLogic::WriteOff($order);
}
Db::commit();

View File

@ -435,7 +435,6 @@ class PayNotifyLogic extends BaseLogic
self::addNewUserSing($order, 8, $total_vip, 1, 1);
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
}
}
if (!empty($extra['payer']['openid']) && $order->pay_type == 7) {
Redis::send('push-delivery', ['order_id' => $order['order_id'], 'openid' => $extra['payer']['openid']], 4);
@ -795,7 +794,6 @@ class PayNotifyLogic extends BaseLogic
public static function afterPay($order, $transaction_id = 0)
{
$financeLogic = new StoreFinanceFlowLogic();
$user_sing = new UserSign();
$off_activity = Config::where('name', 'off_activity')->value('value');
$village_uid = 0;
$brigade_uid = 0;
@ -806,8 +804,17 @@ class PayNotifyLogic extends BaseLogic
Log::error('订单推送失败:' . $e->getMessage());
// 异常处理代码,例如记录日志或发送通知等。
}
if ($order['uid'] > 0) {
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
//用户下单该用户等级为1得时候才处理冻结金额
$user = User::where('id', $order['uid'])->find();
$user_ship = $user['user_ship'];
}
//积分写入
if(in_array($user_ship,[0,4])){
UserSignLogic::OrderWrite($order);
}
if ($off_activity == 1) {
//-----活动价结算更改
$financeLogic->order = $order;
@ -818,20 +825,14 @@ class PayNotifyLogic extends BaseLogic
$financeLogic->save();
return false;
}
if ($order['uid'] > 0) {
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
//用户下单该用户等级为1得时候才处理冻结金额
$user = User::where('id', $order['uid'])->find();
$user_ship = $user['user_ship'];
//纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额)
if ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) {
if ($user_ship== 1 && $order['pay_type'] != PayEnum::CASH_PAY) {
$vipFrozenAmount = self::dealFrozenPrice($order['id']);
//为1的时候要去减活动价
$order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2);
self::dealVipAmount($order, $order['pay_type']);
}
}
if ($order['spread_uid'] > 0 || $user_ship > 0) {
if ($order['spread_uid'] > 0 && $user_ship == 0) {
$user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
@ -1107,7 +1108,6 @@ class PayNotifyLogic extends BaseLogic
$value['create_time'] = time();
}
Db::name('store_product_miss')->insertAll($format);
}

View File

@ -73,16 +73,17 @@ class UserSignLogic extends BaseLogic
/**
* 储存商品积分结算
*/
public static function storage($order)
public static function storage($order_id,$price)
{
$find = UserSign::where(['order_id' => $order['order_id'], 'status' => 0, 'financial_pm' => 1, 'order_type' => 1])->find();
$find = UserSign::where(['order_id' => $order_id, 'status' => 0, 'financial_pm' => 1, 'order_type' => 1])->find();
if ($find) {
// if($or)
// $find->status=1;
// $find->save();
// User::where('id', $order->uid)->inc('integral', $find['number'])->update();
// self::write_log($find,$find['number'], 1);
self::write_log($find, $price, 1, 2,0);
self::write_log($find, $price, 1, 2,1);
if($price>$find['number']){
$find->status = 1;
$find->save();
}
User::where('id', $find['uid'])->inc('integral', $price)->update();
}
}

View File

@ -3,7 +3,10 @@
namespace app\common\logic\user_product_storage;
use app\common\logic\BaseLogic;
use app\common\logic\UserSignLogic;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\user\User;
use app\common\model\user_product_storage\UserProductStorage;
use app\common\model\user_product_storage_log\UserProductStorageLog;
use think\facade\Db;
@ -46,6 +49,7 @@ class UserProductStorageLogic extends BaseLogic
if($times!=''){
$times=strtotime($times);
}
$user_ship=User::where('id',$uid)->value('user_ship');
foreach ($data as $k=>$v){
$find=UserProductStorage::where('uid',$uid)->where('product_id',$v['product_id'])->find();
if($find){
@ -60,6 +64,19 @@ class UserProductStorageLogic extends BaseLogic
$find->status=0;
}
$find->save();
if(in_array($user_ship,[0,4])){
$cart_info=StoreOrderCartInfo::where(['oid'=>$find['oid'],'uid'=>$uid,'product_id'=>$find['product_id']])->value('cart_info');
if($cart_info){
$price=bcdiv($cart_info['pay_price'],$cart_info['cart_num'],2);
if($price){
$price=bcmul($price,$v['nums'],2);
$rate=bcdiv($price,100,2);
$order_id= StoreOrder::where('id',$cart_info['oid'])->value('order_id');
UserSignLogic::storage($order_id,$rate);
}
}
}
$data_log[$k]['uid']=$uid;
$data_log[$k]['oid']=$find['oid'];
$data_log[$k]['product_id']=$find['product_id'];