123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\common\logic;
-
- use app\common\basics\Logic;
- use app\common\model\user\User;
- use app\common\model\AccountLog;
- use app\admin\logic\user\LevelLogic;
-
- class AccountLogLogic extends Logic
- {
-
-
- public static function AccountRecord($user_id,$amount,$change_type,$source_type,$remark ='',$source_id ='',$source_sn='',$extra=''){
- $user = User::findOrEmpty($user_id);
- if($user->isEmpty()){
- return false;
- }
- $type = AccountLog::getChangeType($source_type);
- $left_amount = 0;
- switch ($type){
- case 'money':
- $left_amount = $user->user_money;
- break;
- case 'integral':
- $left_amount = $user->user_integral;
- break;
- case 'growth':
- $left_amount = $user->user_growth;
- break;
- case 'earnings':
- $left_amount = $user->earnings;
- }
- $account_log = new AccountLog();
- $account_log->log_sn = createSn('account_log','log_sn','',4);
- $account_log->user_id = $user_id;
- $account_log->source_type = $source_type;
- $account_log->source_id = $source_id;
- $account_log->source_sn = $source_sn;
- $account_log->change_amount = $amount;
- $account_log->left_amount = $left_amount;
- $account_log->remark = AccountLog::getRemarkDesc($source_type,$source_sn,$remark);
- $account_log->extra = $extra;
- $account_log->change_type = $change_type;
- $account_log->create_time = time();
- $account_log->save();
-
-
- if($type === 'growth' && $change_type == 1){
- LevelLogic::updateUserLevel([$user]);
- }
- return true;
- }
- }
|