feat: 修改IndexController类中的index方法,移除了更新用户余额的代码;增加了LoginAccountValidate类中的错误抛出异常,优化了PayNotifyLogic类中的代码逻辑,简化了User类中的日志记录方式,更新了log配置文件,修改了ModelEvent类中的代码。
This commit is contained in:
parent
975c5b232f
commit
5fd9781f49
@ -44,8 +44,6 @@ class IndexController extends BaseApiController
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$moeny=$this->request->get('moeny');
|
|
||||||
$a=User::where('id',366)->update(['now_money'=>$moeny]);
|
|
||||||
return json([1]);
|
return json([1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ use app\common\service\sms\SmsDriver;
|
|||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
use support\Cache;
|
use support\Cache;
|
||||||
|
use support\exception\BusinessException;
|
||||||
use think\Exception;
|
use think\Exception;
|
||||||
use Webman\Config;
|
use Webman\Config;
|
||||||
/**
|
/**
|
||||||
@ -92,7 +93,7 @@ class LoginAccountValidate extends BaseValidate
|
|||||||
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
|
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
|
||||||
$userAccountSafeCache = new UserAccountSafeCache();
|
$userAccountSafeCache = new UserAccountSafeCache();
|
||||||
if (!$userAccountSafeCache->isSafe()) {
|
if (!$userAccountSafeCache->isSafe()) {
|
||||||
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
throw new BusinessException( '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试');
|
||||||
}
|
}
|
||||||
|
|
||||||
$where = [];
|
$where = [];
|
||||||
@ -106,22 +107,22 @@ class LoginAccountValidate extends BaseValidate
|
|||||||
->findOrEmpty();
|
->findOrEmpty();
|
||||||
|
|
||||||
if ($userInfo->isEmpty()) {
|
if ($userInfo->isEmpty()) {
|
||||||
return '用户不存在';
|
throw new BusinessException( '用户不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($userInfo['is_disable'] === YesNoEnum::YES) {
|
if ($userInfo['is_disable'] === YesNoEnum::YES) {
|
||||||
return '用户已禁用';
|
throw new BusinessException( '用户已禁用');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($userInfo['password'])) {
|
if (empty($userInfo['password'])) {
|
||||||
$userAccountSafeCache->record();
|
$userAccountSafeCache->record();
|
||||||
return '用户不存在';
|
throw new BusinessException( '用户不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
$passwordSalt = Config::get('project.unique_identification');
|
$passwordSalt = Config::get('project.unique_identification');
|
||||||
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||||
$userAccountSafeCache->record();
|
$userAccountSafeCache->record();
|
||||||
return '密码错误';
|
throw new BusinessException( '密码错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
$userAccountSafeCache->relieve();
|
$userAccountSafeCache->relieve();
|
||||||
@ -147,10 +148,10 @@ class LoginAccountValidate extends BaseValidate
|
|||||||
}
|
}
|
||||||
$code = Cache::get($remark);
|
$code = Cache::get($remark);
|
||||||
if(empty($code)){
|
if(empty($code)){
|
||||||
return '验证码不存在';
|
throw new BusinessException( '验证码不存在');
|
||||||
}
|
}
|
||||||
if (isset($data['code']) && $code != $data['code']) {
|
if (isset($data['code']) && $code != $data['code']) {
|
||||||
return '验证码错误';
|
throw new BusinessException( '验证码错误');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -192,8 +192,7 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
UserProductStorageLogic::add($order);
|
UserProductStorageLogic::add($order);
|
||||||
}
|
}
|
||||||
// 减去采购款
|
// 减去采购款
|
||||||
$user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2);
|
$user = User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]);
|
||||||
$user->save();
|
|
||||||
|
|
||||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||||
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']);
|
$capitalFlowDao->userExpense('user_order_purchase_pay', 'order', $order['id'], $order['pay_price'], '', 18, $order['store_id']);
|
||||||
@ -340,17 +339,17 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
/**
|
/**
|
||||||
* 余额采购款退款
|
* 余额采购款退款
|
||||||
*/
|
*/
|
||||||
public static function balance_purchase_refund($order,$type=1,$money=0)
|
public static function balance_purchase_refund($order, $type = 1, $money = 0)
|
||||||
{
|
{
|
||||||
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
|
if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) {
|
||||||
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
|
if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付
|
||||||
$user = User::where('id', $order['uid'])->findOrEmpty();
|
$user = User::where('id', $order['uid'])->findOrEmpty();
|
||||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||||
if($type==1){
|
if ($type == 1) {
|
||||||
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'],'',0);
|
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0);
|
||||||
$user->now_money = bcadd($user['now_money'], $order['pay_price'], 2);
|
$user->now_money = bcadd($user['now_money'], $order['pay_price'], 2);
|
||||||
}else{
|
} else {
|
||||||
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money,'',0);
|
$capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0);
|
||||||
$user->now_money = bcadd($user['now_money'], $money, 2);
|
$user->now_money = bcadd($user['now_money'], $money, 2);
|
||||||
}
|
}
|
||||||
$user->save();
|
$user->save();
|
||||||
@ -360,11 +359,11 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
|
if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付
|
||||||
$user = User::where('id', $order['uid'])->findOrEmpty();
|
$user = User::where('id', $order['uid'])->findOrEmpty();
|
||||||
$capitalFlowDao = new CapitalFlowLogic($user);
|
$capitalFlowDao = new CapitalFlowLogic($user);
|
||||||
if($type==1){
|
if ($type == 1) {
|
||||||
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'],'',1);
|
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1);
|
||||||
$user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2);
|
$user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2);
|
||||||
}else{
|
} else {
|
||||||
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money,'',1);
|
$capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1);
|
||||||
$user->purchase_funds = bcadd($user['purchase_funds'], $money, 2);
|
$user->purchase_funds = bcadd($user['purchase_funds'], $money, 2);
|
||||||
}
|
}
|
||||||
$user->save();
|
$user->save();
|
||||||
@ -671,79 +670,36 @@ class PayNotifyLogic extends BaseLogic
|
|||||||
// if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) {
|
// if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) {
|
||||||
// $order['dealVipAmount']= self::dealVipAmount($order, $order['pay_type']);
|
// $order['dealVipAmount']= self::dealVipAmount($order, $order['pay_type']);
|
||||||
// }
|
// }
|
||||||
if ($order['spread_uid'] > 0 || $user_ship > 0) {
|
|
||||||
if ($order['spread_uid'] > 0 && $user_ship == 0) {
|
if($order['uid']>0){
|
||||||
$user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
|
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
|
||||||
if ($user_ship == 2) {
|
if ($address) {
|
||||||
$village_uid = $order['spread_uid'];
|
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
|
||||||
$address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
|
if ($arr1) {
|
||||||
if ($address) {
|
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
|
||||||
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
|
|
||||||
if ($arr2) {
|
|
||||||
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($user_ship == 3) {
|
|
||||||
$brigade_uid = $order['spread_uid'];
|
|
||||||
$address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
|
|
||||||
if ($address) {
|
|
||||||
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
|
|
||||||
if ($arr1) {
|
|
||||||
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find();
|
|
||||||
if ($address) {
|
|
||||||
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
|
|
||||||
if ($arr1) {
|
|
||||||
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
|
|
||||||
}
|
|
||||||
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
|
|
||||||
if ($arr2) {
|
|
||||||
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
|
||||||
//查询用户对应的村长和队长
|
if ($arr2) {
|
||||||
$address = UserAddress::where(['uid' => $order['uid'], 'is_default' => 1])->find();
|
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
|
||||||
if ($address) {
|
|
||||||
$arr1 = UserAddress::where(['village' => $address['village'], 'is_default' => 1])->column('uid');
|
|
||||||
if ($arr1) {
|
|
||||||
$village_uid = User::where('id', 'in', $arr1)->where('user_ship', 2)->value('id') ?? 0;
|
|
||||||
}
|
|
||||||
$arr2 = UserAddress::where(['village' => $address['village'], 'brigade' => $address['brigade'], 'is_default' => 1])->column('uid');
|
|
||||||
if ($arr2) {
|
|
||||||
$brigade_uid = User::where('id', 'in', $arr2)->where('user_ship', 3)->value('id') ?? 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ($order['spread_uid'] > 0) {
|
||||||
|
$user_ship = User::where('id', $order['spread_uid'])->value('user_ship');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
|
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
|
||||||
$comm = new CommissionProductLogic();
|
$comm = new CommissionProductLogic();
|
||||||
try {
|
foreach ($info as $k => $v) {
|
||||||
foreach ($info as $k => $v) {
|
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
|
||||||
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
|
|
||||||
}
|
|
||||||
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Log::error('分润报错' . $e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
|
||||||
try {
|
} catch (\Throwable $e) {
|
||||||
$info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select();
|
Log::error('分润报错' . $e->getMessage());
|
||||||
$comm = new CommissionProductLogic();
|
return false;
|
||||||
foreach ($info as $k => $v) {
|
|
||||||
$comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship);
|
|
||||||
}
|
|
||||||
CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
Log::error('分润报错' . $e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,20 +196,15 @@ class User extends BaseModel
|
|||||||
})->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray();
|
})->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function before_update($data)
|
// public static function onBeforeUpdate($data)
|
||||||
{
|
// {
|
||||||
Log::error('before_update');
|
// var_dump($data->toArray());
|
||||||
}
|
// channelLog($data->toArray()??[], 'user', '更新前');
|
||||||
public static function after_update($data)
|
// }
|
||||||
{
|
// public static function onAfterUpdate($data)
|
||||||
Log::error('after_update');
|
// {
|
||||||
}
|
// var_dump($data->toArray());
|
||||||
public static function before_write($data)
|
|
||||||
{
|
// channelLog($data->toArray()??[], 'user', '更新后');
|
||||||
Log::error('before_write');
|
// }
|
||||||
}
|
|
||||||
public static function after_write($data)
|
|
||||||
{
|
|
||||||
Log::error('after_write');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -517,3 +517,9 @@ function onAfterUpdate($data, $type)
|
|||||||
$log = Log::channel($type);
|
$log = Log::channel($type);
|
||||||
$log->info('更新后:' ,$data);
|
$log->info('更新后:' ,$data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function channelLog($data, $type,$title='更新前')
|
||||||
|
{
|
||||||
|
$log = Log::channel($type);
|
||||||
|
$log->info($title ,$data);
|
||||||
|
}
|
@ -117,4 +117,52 @@ return [
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'user' => [
|
||||||
|
// 处理默认通道的handler,可以设置多个
|
||||||
|
'handlers' => [
|
||||||
|
[
|
||||||
|
// handler类的名字
|
||||||
|
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||||
|
// handler类的构造函数参数
|
||||||
|
'constructor' => [
|
||||||
|
runtime_path() . '/user/'.date('Ym').'/.log',
|
||||||
|
2048,
|
||||||
|
Monolog\Logger::DEBUG,
|
||||||
|
true,
|
||||||
|
0755
|
||||||
|
],
|
||||||
|
// 格式相关
|
||||||
|
'formatter' => [
|
||||||
|
// 格式化处理类的名字
|
||||||
|
'class' => Monolog\Formatter\LineFormatter::class,
|
||||||
|
// 格式化处理类的构造函数参数
|
||||||
|
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'system_store' => [
|
||||||
|
// 处理默认通道的handler,可以设置多个
|
||||||
|
'handlers' => [
|
||||||
|
[
|
||||||
|
// handler类的名字
|
||||||
|
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||||
|
// handler类的构造函数参数
|
||||||
|
'constructor' => [
|
||||||
|
runtime_path() . '/system_store/'.date('Ym').'/.log',
|
||||||
|
2048,
|
||||||
|
Monolog\Logger::DEBUG,
|
||||||
|
true,
|
||||||
|
0755
|
||||||
|
],
|
||||||
|
// 格式相关
|
||||||
|
'formatter' => [
|
||||||
|
// 格式化处理类的名字
|
||||||
|
'class' => Monolog\Formatter\LineFormatter::class,
|
||||||
|
// 格式化处理类的构造函数参数
|
||||||
|
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
@ -75,7 +75,6 @@ trait ModelEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
$call = 'on' . Str::studly($event);
|
$call = 'on' . Str::studly($event);
|
||||||
d($call);
|
|
||||||
try {
|
try {
|
||||||
if (method_exists(static::class, $call)) {
|
if (method_exists(static::class, $call)) {
|
||||||
$result = call_user_func([static::class, $call], $this);
|
$result = call_user_func([static::class, $call], $this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user