feat(UserController): 更新用户签到逻辑,修复积分计算错误
This commit is contained in:
parent
3ae5eab678
commit
4b849edc76
@ -233,8 +233,8 @@ class UserController extends BaseApiController
|
||||
$params['page_size'] = $page_size > 0 ? $page_size : 15;
|
||||
$res = UserLogic::dealDetails($params,$this->userId);
|
||||
$integral = User::where('id',$this->userId)->value('integral');
|
||||
$number = 0;//UserSign::where('id',$this->userId)->where('status',0)->sum('number');
|
||||
$GetNumber = 0;//UserSign::where('id',$this->userId)->where('status',1)->sum('number');
|
||||
$number = UserSign::where('id',$this->userId)->where('status',0)->sum('number');
|
||||
$GetNumber = UserSign::where('id',$this->userId)->where('status',1)->sum('number');
|
||||
$res['page_no'] = $params['page_no'];
|
||||
$res['page_size'] = $params['page_size'];
|
||||
$res['extend'] = [
|
||||
|
@ -10,6 +10,7 @@ use app\common\logic\BaseLogic;
|
||||
use app\common\logic\CapitalFlowLogic;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\logic\StoreFinanceFlowLogic;
|
||||
use app\common\logic\UserSignLogic;
|
||||
use app\common\model\Config;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\model\dict\DictType;
|
||||
@ -161,15 +162,15 @@ class OrderLogic extends BaseLogic
|
||||
'activity_price' => self::$activity_price,
|
||||
'activities' => self::$activity_price > 0 ? 1 : 0,
|
||||
'deduction_price' => self::$deduction_price,
|
||||
'is_vip' => 0,
|
||||
'source' => 0,
|
||||
'is_storage' => $params['is_storage'] ?? 0,
|
||||
];
|
||||
$order['default_delivery'] = 0;
|
||||
if ($params['store_id']) {
|
||||
$order['default_delivery'] = SystemStore::where('id', $params['store_id'])->value('is_send');
|
||||
}
|
||||
if ($user && $user['user_ship'] >= 1 && $user['user_ship'] <= 3) {
|
||||
$order['is_vip'] = 1;
|
||||
if (isset($params['source']) && $params['source'] > 0) {
|
||||
$order['source'] = $params['source'];
|
||||
}
|
||||
//处理返回最近的店铺
|
||||
$store['near_store'] = [];
|
||||
@ -514,18 +515,6 @@ class OrderLogic extends BaseLogic
|
||||
$financeFlowLogic->updateStatusUser($v['id'], $v['other_uid'], $v['number'], $v['order_id']);
|
||||
}
|
||||
}
|
||||
if ($order['uid'] && $order['pay_price'] >= 500) {
|
||||
$level = User::where('id', $order['uid'])->value('user_ship');
|
||||
$discount = PayNotifyLogic::getDiscount($level);
|
||||
$user_number = bcmul($order['pay_price'], $discount, 2);
|
||||
User::where('id', $order['uid'])->inc('integral', $user_number)->update();
|
||||
// 核销加冻结礼品券 解冻礼品券
|
||||
self::addUserSing($order, 2, $user_number); //冻结
|
||||
|
||||
self::addUserSing($order, 4, $user_number, 1, 1); //解冻
|
||||
|
||||
UserSign::where(['uid' => $order['uid'], 'order_id' => $order['order_id'], 'title' => 1])->update(['status' => 1]);
|
||||
}
|
||||
if ($order['spread_uid'] > 0) {
|
||||
$spread_find = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 12, 'other_uid' => $order['spread_uid']])->find();
|
||||
if ($spread_find) {
|
||||
@ -535,6 +524,10 @@ class OrderLogic extends BaseLogic
|
||||
$deposit = $financeFlow->where(['order_id' => $order['id'], 'financial_pm' => 1, 'financial_type' => 11])->value('number') ?? 0;
|
||||
$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']==1){
|
||||
UserSignLogic::WriteOff($order);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -544,39 +537,6 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理冻结和解冻 礼品券得记录
|
||||
* @param $order // 订单
|
||||
* @param $category // 分类
|
||||
* @param $number // 金额
|
||||
* @param int $pm //收支 0支出 1获得
|
||||
* @type $type //类型 0冻结 1解冻
|
||||
* @return true
|
||||
*/
|
||||
public static function addUserSing($order, $category, $number, int $pm = 0, $type = 0)
|
||||
{
|
||||
$user_sing = new UserSign();
|
||||
$sing = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
// 'title' => '购买商品获得兑换券',
|
||||
// 'title' => PayNotifyLogic::getTitle($category,$number),
|
||||
'title' => $category,
|
||||
'financial_pm' => $pm,
|
||||
'store_id' => $order['store_id'],
|
||||
'number' => $number,
|
||||
'type' => $type,
|
||||
'status' => 1,
|
||||
];
|
||||
$user_sing->save($sing);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//不走二次分钱的核销
|
||||
public static function lessWriteOff($params): bool
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\admin\logic\user_ship\UserShipLogic;
|
||||
use app\api\logic\order\OrderLogic;
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
@ -667,66 +668,6 @@ class PayNotifyLogic extends BaseLogic
|
||||
return true;
|
||||
}
|
||||
|
||||
//入冻结礼品券
|
||||
public static function addUserSing($order)
|
||||
{
|
||||
$user_sing = new UserSign();
|
||||
if ($order['uid'] > 0 && $order['total_price'] >= 500) {
|
||||
$user_number = bcmul($order['pay_price'], '0.10', 2);
|
||||
$sing = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
'title' => '购买商品获得兑换券',
|
||||
'financial_pm' => 1,
|
||||
'store_id' => $order['store_id'],
|
||||
'number' => $user_number,
|
||||
];
|
||||
$user_sing->save($sing);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function dealRechargeFrozen($order)
|
||||
{
|
||||
$total_vip = bcmul($order['price'], 0.1, 2);
|
||||
$user_sing = new UserSign();
|
||||
//冻结
|
||||
$sing[] = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
// 'title' => '充值获得冻结兑换券',
|
||||
// 'title' => self::getTitle(7,$total_vip),
|
||||
'title' => 7,
|
||||
'financial_pm' => 1,
|
||||
'store_id' => $order['store_id'],
|
||||
// 'type' => 1,
|
||||
'status' => 1,
|
||||
'number' => $total_vip,
|
||||
'back_num' => $total_vip,
|
||||
];
|
||||
//礼品券得
|
||||
$sing[] = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
// 'title' => '充值获得冻结兑换券',
|
||||
// 'title' => self::getTitle(4,$total_vip),
|
||||
'title' => 4,
|
||||
'financial_pm' => 1,
|
||||
'store_id' => $order['store_id'],
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
'number' => $total_vip,
|
||||
'back_num' => $total_vip,
|
||||
];
|
||||
|
||||
$user_sing->saveAll($sing);
|
||||
|
||||
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 充值
|
||||
*/
|
||||
@ -755,11 +696,9 @@ class PayNotifyLogic extends BaseLogic
|
||||
return true;
|
||||
}
|
||||
bcscale(2);
|
||||
// $user->now_money = bcadd($user->now_money, $price, 2);//v.1
|
||||
$check = UserSign::where(['uid' => $order->uid, 'type' => 1])->count();
|
||||
if (empty($check) && $user['user_ship'] == 0) {
|
||||
self::dealRechargeFrozen($order);
|
||||
}
|
||||
|
||||
UserSignLogic::dealRechargeFrozen($user,$order,$order['user_ship']);
|
||||
|
||||
//更新等级
|
||||
$user->user_ship = $order['user_ship'];
|
||||
|
||||
@ -902,6 +841,8 @@ class PayNotifyLogic extends BaseLogic
|
||||
Log::error('订单推送失败:'.$e->getMessage());
|
||||
// 异常处理代码,例如记录日志或发送通知等。
|
||||
}
|
||||
//积分写入
|
||||
UserSignLogic::OrderWrite($order);
|
||||
if ($off_activity == 1) {
|
||||
//-----活动价结算更改
|
||||
$financeLogic->order = $order;
|
||||
@ -910,27 +851,6 @@ class PayNotifyLogic extends BaseLogic
|
||||
$financeLogic->in($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], 0, 0, $order['pay_type']);
|
||||
$financeLogic->out($transaction_id, $order['pay_price'], OrderEnum::SUPPLIER_ORDER_OBTAINS, $order['store_id'], $order['staff_id'], 0, $order['pay_type']);
|
||||
$financeLogic->save();
|
||||
$user_ship = User::where('id', $order['uid'])->value('user_ship'); //会员不加兑换券
|
||||
if (
|
||||
$order['uid'] > 0 && $order['total_price'] >= 500
|
||||
&& $order['pay_type'] != PayEnum::PURCHASE_FUNDS && $user_ship != 1 && $order['shipping_type'] !=3
|
||||
) {
|
||||
$level = User::where('id',$order['uid'])->value('user_ship');
|
||||
$discount = self::getDiscount($level);
|
||||
$user_number = bcmul($order['pay_price'], $discount, 2);
|
||||
$sing = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
// 'title' => '购买商品获得兑换券',
|
||||
// 'title' => self::getTitle(1,$user_number),
|
||||
'title' => 1,
|
||||
'financial_pm' => 1,
|
||||
'store_id' => $order['store_id'],
|
||||
'number' => $user_number,
|
||||
'status' => 0,
|
||||
];
|
||||
$user_sing->save($sing);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ($order['uid'] > 0) {
|
||||
@ -938,23 +858,6 @@ class PayNotifyLogic extends BaseLogic
|
||||
//用户下单该用户等级为1得时候才处理冻结金额
|
||||
$user = User::where('id', $order['uid'])->find();
|
||||
$user_ship = $user['user_ship'];
|
||||
if($order['total_price'] >= 500 && $order['pay_type'] !=PayEnum::PURCHASE_FUNDS && $user_ship !=1
|
||||
&& $order['shipping_type'] !=3){
|
||||
$discount = self::getDiscount($user_ship);
|
||||
$user_number = bcmul($order['pay_price'], $discount, 2);
|
||||
$sing = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
// 'title' => '购买商品获得兑换券',
|
||||
// 'title' => self::getTitle(1,$user_number),
|
||||
'title' => 1,
|
||||
'financial_pm' => 1,
|
||||
'store_id' => $order['store_id'],
|
||||
'number' => $user_number,
|
||||
'status' => 0,
|
||||
];
|
||||
$user_sing->save($sing);
|
||||
}
|
||||
//纯在分销关系的时候要去判断分销出来的用户的采购款的额度 (只有会员按照这个逻辑拆分,其余的还是按照正常的支付金额)
|
||||
if ($user['user_ship'] == 1 && $order['pay_type'] != PayEnum::CASH_PAY) {
|
||||
$vipFrozenAmount = self::dealFrozenPrice($order['id']);
|
||||
|
115
app/common/logic/UserSignLogic.php
Normal file
115
app/common/logic/UserSignLogic.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user_sign\UserSign;
|
||||
use app\common\model\user_sign_log\UserSignLog;
|
||||
|
||||
/**
|
||||
* 会员积分逻辑
|
||||
* Class UserSignLogic
|
||||
*/
|
||||
class UserSignLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 来自充值
|
||||
*/
|
||||
public static function dealRechargeFrozen($user, $order, $user_ship = 0)
|
||||
{
|
||||
$total_vip = bcmul($order['price'], 0.1, 2);
|
||||
$count = UserSign::where('uid', $order->uid)->count();
|
||||
if ($count == 0 && in_array($user_ship, [1, 2, 3, 5, 6, 7, 8])) {
|
||||
$write = self::write($order, $total_vip, 0, 1);
|
||||
self::write_log($write, $total_vip, 0);
|
||||
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
|
||||
} else {
|
||||
$write = self::write($order, $total_vip, 0, 0);
|
||||
self::write_log($write, $total_vip, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 来自订单
|
||||
*/
|
||||
public static function OrderWrite($order)
|
||||
{
|
||||
$total_vip = bcmul($order['price'], 0.1, 2);
|
||||
|
||||
//非收银台订单冻结里礼品卷
|
||||
if ($order['source'] == 0) {
|
||||
$write = self::write($order, $total_vip, 1, 0);
|
||||
} else {
|
||||
$write = self::write($order, $total_vip, 1, 1);
|
||||
self::write_log($write, $total_vip, 1);
|
||||
User::where('id', $order->uid)->inc('integral', $total_vip)->update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 核销
|
||||
*/
|
||||
public static function WriteOff($order){
|
||||
$find=UserSign::where(['order_id'=>$order['order_id'],'status'=>0,'financial_pm'=>1,'order_type'=>1])->find();
|
||||
if($find){
|
||||
$find->status=1;
|
||||
$find->save();
|
||||
User::where('id', $order->uid)->inc('integral', $find['number'])->update();
|
||||
self::write_log($find,$find['number'], 1);
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 储存商品积分结算
|
||||
*/
|
||||
public static function storage($order){
|
||||
$find=UserSign::where(['order_id'=>$order['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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function write($order, $total_vip, $order_type = 0, $status = 0, $title = 4, $pm = 1)
|
||||
{
|
||||
//礼品券得
|
||||
$sing = [
|
||||
'uid' => $order['uid'],
|
||||
'order_id' => $order['order_id'],
|
||||
'title' => $title,
|
||||
'financial_pm' => $pm,
|
||||
'store_id' => $order['store_id'],
|
||||
'status' => $status,
|
||||
'number' => $total_vip,
|
||||
'back_num' => $total_vip,
|
||||
'order_type' => $order_type,
|
||||
|
||||
];
|
||||
return UserSign::create($sing);
|
||||
}
|
||||
public static function write_log($write, $total_vip, $order_type = 0, $title = 4, $pm = 1)
|
||||
{
|
||||
//礼品券日志记录
|
||||
$sing = [
|
||||
'uid' => $write['uid'],
|
||||
'sid' => $write['id'],
|
||||
'order_id' => $write['order_id'],
|
||||
'title' => $title,
|
||||
'financial_pm' => $pm,
|
||||
'order_type' => $order_type,
|
||||
'status' => 1,
|
||||
'number' => $total_vip,
|
||||
];
|
||||
UserSignLog::create($sing);
|
||||
}
|
||||
|
||||
}
|
21
app/common/model/user_sign copy/UserSign.php
Normal file
21
app/common/model/user_sign copy/UserSign.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\user_sign_log;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 积分记录日志
|
||||
* Class UserSign
|
||||
* @package app\common\model\user_sign_log
|
||||
*/
|
||||
class UserSignLog extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'user_sign_log';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
}
|
@ -171,6 +171,7 @@ class StoreOrderController extends BaseAdminController
|
||||
}
|
||||
$params['store_id'] = $this->request->adminInfo['store_id']; //当前登录的店铺id,用于判断是否是当前店铺的订单
|
||||
$params['shipping_type'] =3;
|
||||
$params['source'] =1;
|
||||
$order = OrderLogic::createOrder($cartId, $addressId, $user, $params);
|
||||
if ($order != false) {
|
||||
switch ($pay_type) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user