feat: 修改订单和支付逻辑,增加用户等级判断和积分计算
This commit is contained in:
parent
23bf1ecee8
commit
d6aaceb425
@ -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();
|
||||
|
@ -96,15 +96,15 @@ class PayNotifyLogic extends BaseLogic
|
||||
$capitalFlowDao->userExpense('user_order_balance_pay', 'order', $order['id'], $order['pay_price'], '', 0, $order['store_id']);
|
||||
self::dealProductLog($order);
|
||||
if ($order['shipping_type'] == 3) {
|
||||
// self::descStock($order['id']);
|
||||
// self::descStock($order['id']);
|
||||
}
|
||||
self::afterPay($order);
|
||||
if($order['reservation'] == 1&& in_array($order['shipping_type'],[1,2])){
|
||||
$checkArr =[
|
||||
'cart_id'=>$order['cart_id'],
|
||||
'store_id'=>$order['store_id'],
|
||||
if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
|
||||
$checkArr = [
|
||||
'cart_id' => $order['cart_id'],
|
||||
'store_id' => $order['store_id'],
|
||||
];
|
||||
self::dealGoodsLeft($checkArr,$order['uid'],$order['id']);
|
||||
self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
|
||||
}
|
||||
if ($extra && $extra['store_id']) {
|
||||
$params = [
|
||||
@ -217,12 +217,12 @@ class PayNotifyLogic extends BaseLogic
|
||||
OrderLogic::writeOff($params);
|
||||
}
|
||||
self::dealProductLog($order);
|
||||
if($order['reservation'] == 1&& in_array($order['shipping_type'],[1,2])){
|
||||
$checkArr =[
|
||||
'cart_id'=>$order['cart_id'],
|
||||
'store_id'=>$order['store_id'],
|
||||
if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
|
||||
$checkArr = [
|
||||
'cart_id' => $order['cart_id'],
|
||||
'store_id' => $order['store_id'],
|
||||
];
|
||||
self::dealGoodsLeft($checkArr,$order['uid'],$order['id']);
|
||||
self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
|
||||
}
|
||||
|
||||
// $count = UserSign::where([
|
||||
@ -234,10 +234,10 @@ class PayNotifyLogic extends BaseLogic
|
||||
// if($count){
|
||||
// self::addFlowLog($order);
|
||||
// }
|
||||
//收银台下单直接到账
|
||||
// if($order['shipping_type'] == 3){
|
||||
//收银台下单直接到账
|
||||
// if($order['shipping_type'] == 3){
|
||||
// self::descStock($order['id']);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Redis::send('push-platform-print', ['id' => $order['id']], 60);
|
||||
@ -415,12 +415,12 @@ class PayNotifyLogic extends BaseLogic
|
||||
$capitalFlowDao->userExpense('user_order_pay', 'order', $order['id'], $order->pay_price, '', 1, $order['store_id']);
|
||||
}
|
||||
$order->save();
|
||||
if($order['reservation'] == 1&& in_array($order['shipping_type'],[1,2])){
|
||||
$checkArr =[
|
||||
'cart_id'=>$order['cart_id'],
|
||||
'store_id'=>$order['store_id'],
|
||||
if ($order['reservation'] == 1 && in_array($order['shipping_type'], [1, 2])) {
|
||||
$checkArr = [
|
||||
'cart_id' => $order['cart_id'],
|
||||
'store_id' => $order['store_id'],
|
||||
];
|
||||
self::dealGoodsLeft($checkArr,$order['uid'],$order['id']);
|
||||
self::dealGoodsLeft($checkArr, $order['uid'], $order['id']);
|
||||
}
|
||||
self::afterPay($order, $extra['transaction_id']);
|
||||
// self::addUserSing($order);
|
||||
@ -428,14 +428,13 @@ class PayNotifyLogic extends BaseLogic
|
||||
if ($order['shipping_type'] == 3) {
|
||||
self::descStock($order['id']);
|
||||
//直接加对应兑换券
|
||||
if ($order->uid >0) {
|
||||
$level = User::where('id',$order->uid)->value('user_ship');
|
||||
if ($order->uid > 0) {
|
||||
$level = User::where('id', $order->uid)->value('user_ship');
|
||||
$discount = self::getDiscount($level);
|
||||
$total_vip = bcmul($order['pay_price'], $discount, 2);
|
||||
self::addNewUserSing($order,8,$total_vip,1,1);
|
||||
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);
|
||||
@ -470,10 +469,10 @@ class PayNotifyLogic extends BaseLogic
|
||||
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $orderRe['id'], $purchase_funds, '', 1, $orderRe['store_id']);
|
||||
}
|
||||
//退还 充值得兑换券
|
||||
$level = User::where('id',$order->uid)->value('user_ship');
|
||||
$level = User::where('id', $order->uid)->value('user_ship');
|
||||
$discount = self::getDiscount($level);
|
||||
$total_price = bcmul($orderRe->refund_price, $discount, 2);
|
||||
self::addNewUserSing($orderRe, 3,$total_price); //冻结
|
||||
self::addNewUserSing($orderRe, 3, $total_price); //冻结
|
||||
|
||||
self::addNewUserSing($orderRe, 6, $total_price, 0, 1); //解冻
|
||||
self::descUserSing($orderRe);
|
||||
@ -572,7 +571,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
{
|
||||
// $user_sing = new UserSign();
|
||||
if ($order['uid'] > 0) {
|
||||
$level = User::where('id',$order['uid'])->value('user_ship');
|
||||
$level = User::where('id', $order['uid'])->value('user_ship');
|
||||
$discount = self::getDiscount($level);
|
||||
$user_number = bcmul($order['refund_price'], $discount, 2);
|
||||
// $sing = [
|
||||
@ -689,8 +688,8 @@ class PayNotifyLogic extends BaseLogic
|
||||
}
|
||||
bcscale(2);
|
||||
|
||||
UserSignLogic::dealRechargeFrozen($user,$order,$order['user_ship']);
|
||||
|
||||
UserSignLogic::dealRechargeFrozen($user, $order, $order['user_ship']);
|
||||
|
||||
//更新等级
|
||||
$user->user_ship = $order['user_ship'];
|
||||
|
||||
@ -795,19 +794,27 @@ 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;
|
||||
$user_ship = 0;
|
||||
try{
|
||||
try {
|
||||
Redis::send('order_wetcha_push_send', ['order' => $order]);
|
||||
}catch(\Exception $e){
|
||||
Log::error('订单推送失败:'.$e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
Log::error('订单推送失败:' . $e->getMessage());
|
||||
// 异常处理代码,例如记录日志或发送通知等。
|
||||
}
|
||||
if ($order['uid'] > 0) {
|
||||
// 结算金额 要支付的钱减去冻结得钱去走后面得逻辑 发得兑换券也要去减去
|
||||
//用户下单该用户等级为1得时候才处理冻结金额
|
||||
$user = User::where('id', $order['uid'])->find();
|
||||
$user_ship = $user['user_ship'];
|
||||
|
||||
}
|
||||
//积分写入
|
||||
UserSignLogic::OrderWrite($order);
|
||||
if(in_array($user_ship,[0,4])){
|
||||
UserSignLogic::OrderWrite($order);
|
||||
}
|
||||
if ($off_activity == 1) {
|
||||
//-----活动价结算更改
|
||||
$financeLogic->order = $order;
|
||||
@ -818,19 +825,13 @@ 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) {
|
||||
$vipFrozenAmount = self::dealFrozenPrice($order['id']);
|
||||
//为1的时候要去减活动价
|
||||
$order['pay_price'] = bcsub($order['pay_price'], $vipFrozenAmount, 2);
|
||||
self::dealVipAmount($order, $order['pay_type']);
|
||||
}
|
||||
|
||||
//纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额)
|
||||
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) {
|
||||
@ -1093,21 +1094,20 @@ class PayNotifyLogic extends BaseLogic
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function dealGoodsLeft($cart_id,$uid,$oid)
|
||||
public static function dealGoodsLeft($cart_id, $uid, $oid)
|
||||
{
|
||||
if(is_array($cart_id)){
|
||||
if (is_array($cart_id)) {
|
||||
$cart_id['cart_id'] = $cart_id;
|
||||
}else{
|
||||
$cart_id['cart_id'] = explode(',',$cart_id);
|
||||
} else {
|
||||
$cart_id['cart_id'] = explode(',', $cart_id);
|
||||
}
|
||||
$data = OrderLogic::checkLeft($cart_id,$uid,1);
|
||||
$data = OrderLogic::checkLeft($cart_id, $uid, 1);
|
||||
$format = $data['detail'];
|
||||
foreach ($format as &$value){
|
||||
$value['oid'] =$oid;
|
||||
$value['create_time'] =time();
|
||||
foreach ($format as &$value) {
|
||||
$value['oid'] = $oid;
|
||||
$value['create_time'] = time();
|
||||
}
|
||||
Db::name('store_product_miss')->insertAll($format);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1120,12 +1120,12 @@ class PayNotifyLogic extends BaseLogic
|
||||
public static function getDiscount($level)
|
||||
{
|
||||
switch ($level) {
|
||||
case 0://普通
|
||||
return Config::where('name','ordinary_member')->value('value')??0.1;
|
||||
case 1://vip
|
||||
return Config::where('name','vip_member')->value('value')??0.1;
|
||||
case 4://商户
|
||||
return Config::where('name','merchant')->value('value')??0.1;
|
||||
case 0: //普通
|
||||
return Config::where('name', 'ordinary_member')->value('value') ?? 0.1;
|
||||
case 1: //vip
|
||||
return Config::where('name', 'vip_member')->value('value') ?? 0.1;
|
||||
case 4: //商户
|
||||
return Config::where('name', 'merchant')->value('value') ?? 0.1;
|
||||
default:
|
||||
return 0.1;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user