diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index da8a86304..28fd3f781 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -44,8 +44,6 @@ class IndexController extends BaseApiController public function index() { - $moeny=$this->request->get('moeny'); - $a=User::where('id',366)->update(['now_money'=>$moeny]); return json([1]); } diff --git a/app/api/validate/LoginAccountValidate.php b/app/api/validate/LoginAccountValidate.php index daef936f5..e9f33c8bf 100644 --- a/app/api/validate/LoginAccountValidate.php +++ b/app/api/validate/LoginAccountValidate.php @@ -13,6 +13,7 @@ use app\common\service\sms\SmsDriver; use app\common\validate\BaseValidate; use app\common\model\user\User; use support\Cache; +use support\exception\BusinessException; use think\Exception; use Webman\Config; /** @@ -92,7 +93,7 @@ class LoginAccountValidate extends BaseValidate //账号安全机制,连续输错后锁定,防止账号密码暴力破解 $userAccountSafeCache = new UserAccountSafeCache(); if (!$userAccountSafeCache->isSafe()) { - return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'; + throw new BusinessException( '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试'); } $where = []; @@ -106,22 +107,22 @@ class LoginAccountValidate extends BaseValidate ->findOrEmpty(); if ($userInfo->isEmpty()) { - return '用户不存在'; + throw new BusinessException( '用户不存在'); } if ($userInfo['is_disable'] === YesNoEnum::YES) { - return '用户已禁用'; + throw new BusinessException( '用户已禁用'); } if (empty($userInfo['password'])) { $userAccountSafeCache->record(); - return '用户不存在'; + throw new BusinessException( '用户不存在'); } $passwordSalt = Config::get('project.unique_identification'); if ($userInfo['password'] !== create_password($password, $passwordSalt)) { $userAccountSafeCache->record(); - return '密码错误'; + throw new BusinessException( '密码错误'); } $userAccountSafeCache->relieve(); @@ -147,10 +148,10 @@ class LoginAccountValidate extends BaseValidate } $code = Cache::get($remark); if(empty($code)){ - return '验证码不存在'; + throw new BusinessException( '验证码不存在'); } if (isset($data['code']) && $code != $data['code']) { - return '验证码错误'; + throw new BusinessException( '验证码错误'); } return true; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 764c6cd9a..7a246093b 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -192,8 +192,7 @@ class PayNotifyLogic extends BaseLogic UserProductStorageLogic::add($order); } // 减去采购款 - $user->purchase_funds = bcsub($user['purchase_funds'], $order['pay_price'], 2); - $user->save(); + $user = User::update(['purchase_funds' => bcsub($user['purchase_funds'], $order['pay_price'], 2)], ['id' => $user['id']]); $capitalFlowDao = new CapitalFlowLogic($user); $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 ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); - if($type==1){ - $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'],'',0); + if ($type == 1) { + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $order['pay_price'], '', 0); $user->now_money = bcadd($user['now_money'], $order['pay_price'], 2); - }else{ - $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money,'',0); + } else { + $capitalFlowDao->userIncome('now_money_refund', 'system_back', $order['id'], $money, '', 0); $user->now_money = bcadd($user['now_money'], $money, 2); } $user->save(); @@ -360,11 +359,11 @@ class PayNotifyLogic extends BaseLogic if ($order['pay_type'] == PayEnum::PURCHASE_FUNDS) { //采购款支付 $user = User::where('id', $order['uid'])->findOrEmpty(); $capitalFlowDao = new CapitalFlowLogic($user); - if($type==1){ - $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'],'',1); + if ($type == 1) { + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); $user->purchase_funds = bcadd($user['purchase_funds'], $order['pay_price'], 2); - }else{ - $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money,'',1); + } else { + $capitalFlowDao->userIncome('purchase_refund', 'system_back', $order['id'], $money, '', 1); $user->purchase_funds = bcadd($user['purchase_funds'], $money, 2); } $user->save(); @@ -671,79 +670,36 @@ class PayNotifyLogic extends BaseLogic // if ($user_ship>0 && $order['pay_type'] != PayEnum::CASH_PAY && $off_activity !=1) { // $order['dealVipAmount']= 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'); - if ($user_ship == 2) { - $village_uid = $order['spread_uid']; - $address = UserAddress::where(['uid' => $order['spread_uid'], 'is_default' => 1])->find(); - if ($address) { - $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; - } - } + + if($order['uid']>0){ + $address = UserAddress::where(['uid' => $order['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['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; - } + $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(); $comm = new CommissionProductLogic(); - try { - 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; + foreach ($info as $k => $v) { + $comm->calculate_product_flow($v, $order, $village_uid, $brigade_uid, $user_ship); } - } else { - try { - $info = StoreOrderCartInfo::where('oid', $order['id'])->field('store_id,product_id,cart_num')->select(); - $comm = new CommissionProductLogic(); - 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; + CommissionnLogic::setStore($order, $village_uid, $brigade_uid, $transaction_id); + } catch (\Throwable $e) { + Log::error('分润报错' . $e->getMessage()); + return false; } + return true; } /** diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 5fb0ede66..c5d807bdf 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -196,20 +196,15 @@ class User extends BaseModel })->field("FROM_UNIXTIME($create_time,'$timeType') as days,count(id) as num")->group('days')->select()->toArray(); } - public static function before_update($data) - { - Log::error('before_update'); - } - public static function after_update($data) - { - Log::error('after_update'); - } - public static function before_write($data) - { - Log::error('before_write'); - } - public static function after_write($data) - { - Log::error('after_write'); - } + // public static function onBeforeUpdate($data) + // { + // var_dump($data->toArray()); + // channelLog($data->toArray()??[], 'user', '更新前'); + // } + // public static function onAfterUpdate($data) + // { + // var_dump($data->toArray()); + + // channelLog($data->toArray()??[], 'user', '更新后'); + // } } diff --git a/app/functions.php b/app/functions.php index 7087f1979..d3275a116 100644 --- a/app/functions.php +++ b/app/functions.php @@ -517,3 +517,9 @@ function onAfterUpdate($data, $type) $log = Log::channel($type); $log->info('更新后:' ,$data); } + +function channelLog($data, $type,$title='更新前') +{ + $log = Log::channel($type); + $log->info($title ,$data); +} \ No newline at end of file diff --git a/config/log.php b/config/log.php index 7db7057d5..38c5ecc21 100644 --- a/config/log.php +++ b/config/log.php @@ -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], + ], + ] + ], + ], ]; diff --git a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php index cb0f55a54..23e33a878 100644 --- a/vendor/topthink/think-orm/src/model/concern/ModelEvent.php +++ b/vendor/topthink/think-orm/src/model/concern/ModelEvent.php @@ -75,7 +75,6 @@ trait ModelEvent } $call = 'on' . Str::studly($event); -d($call); try { if (method_exists(static::class, $call)) { $result = call_user_func([static::class, $call], $this);