101 lines
3.3 KiB
PHP
101 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace app\common\service;
|
|
|
|
use app\common\model\account\Logs as AccountLogs;
|
|
use app\common\traits\ServiceTrait;
|
|
use think\Log;
|
|
|
|
class AccountLogService
|
|
{
|
|
use ServiceTrait;
|
|
|
|
/** @var AccountLogs */
|
|
public static $Model = AccountLogs::class;
|
|
|
|
//日志类型 1充值 2消费 3收益 4退款 5提现 6冻结 7解冻 9后台操作
|
|
const TYPE_RECHARGE = 1;
|
|
const TYPE_CONSUME = 2;
|
|
const TYPE_PROFIT = 3;
|
|
const TYPE_REFUND = 4;
|
|
const TYPE_WITHDRAW = 5;
|
|
const TYPE_FREEZE = 6;
|
|
const TYPE_UNFREEZE = 7;
|
|
const TYPE_ADMIN_OPERATE = 9;
|
|
|
|
const TYPE_MAP = [
|
|
self::TYPE_RECHARGE => '充值',
|
|
self::TYPE_CONSUME => '消费',
|
|
self::TYPE_PROFIT => '收益',
|
|
self::TYPE_REFUND => '退款',
|
|
self::TYPE_WITHDRAW => '提现',
|
|
self::TYPE_FREEZE => '冻结',
|
|
self::TYPE_UNFREEZE => '解冻',
|
|
self::TYPE_ADMIN_OPERATE => '后台操作',
|
|
];
|
|
|
|
|
|
//账户类型
|
|
const ACCOUNT_TYPE_AMOUNT = 'amount'; //余额
|
|
const ACCOUNT_TYPE_FREEZE = 'freeze'; //冻结金额
|
|
const ACCOUNT_TYPE_INTEGRAL = 'integral'; //积分
|
|
const ACCOUNT_TYPE_CREDIT_SCORE = 'credit_score'; //信誉分
|
|
|
|
const ACCOUNT_TYPE_MAP = [
|
|
self::ACCOUNT_TYPE_AMOUNT => '余额',
|
|
self::ACCOUNT_TYPE_FREEZE => '冻结金额',
|
|
self::ACCOUNT_TYPE_INTEGRAL => '积分',
|
|
self::ACCOUNT_TYPE_CREDIT_SCORE => '信誉分',
|
|
];
|
|
|
|
//增减去类型
|
|
const INC_EXP_NO = 0; //冻结
|
|
const INC_EXP_INCREASE = 1; //增加
|
|
const INC_EXP_EXPEND = 2; //支出
|
|
|
|
//信誉分类型
|
|
const CREDIT_TYPE_DEMAND_FINISHED = 1; //需求完成奖励
|
|
const CREDIT_TYPE_DEMAND_FAILED = 2; //需求完成失败扣除
|
|
const CREDIT_TYPE_DEMAND_REFUSE = 3; //拒绝接单扣除
|
|
const CREDIT_TYPE_CONTRACT_REFUSE = 4; // 放弃签约扣除
|
|
const CREDIT_TYPE_SYSTEM_RETURN = 5; //系统退回
|
|
const CREDIT_TYPE_ADMIN_OPERATE = 6; //后台操作
|
|
|
|
/**
|
|
* @param $account_type
|
|
* @param $user_id
|
|
* @param $amount
|
|
* @param $log
|
|
* @param $type int 日志类型:1充值 2消费 3收益 4退款 5提现 6冻结 7解冻 9后台操作
|
|
* @param $credit_type int 信誉分日志类型:1=任务完成奖励,2=任务失败扣除,3=拒绝接单扣除,4=放弃签约扣除,5=系统退回,9=后台操作
|
|
* @param $inc_or_exp 1=收入 2支出
|
|
* @param int $refer_id
|
|
* @param int|float $total_amount
|
|
* @param int|float $percent
|
|
* @return mixed
|
|
* @throws \Exception
|
|
*/
|
|
public static function addLog($account_type, $user_id, $amount, $log, int $type, int $credit_type, $inc_or_exp, int $refer_id = 0, int $total_amount = 0, $percent = 0)
|
|
{
|
|
$data = [
|
|
'account_type' => $account_type,
|
|
'user_id' => $user_id,
|
|
'amount' => $amount,
|
|
'log' => $log,
|
|
'type' => $type,
|
|
'credit_type' => $credit_type,
|
|
'refer_id' => $refer_id,
|
|
'total_amount' => $total_amount,
|
|
'percent' => $percent,
|
|
'inc_or_exp' => $inc_or_exp,
|
|
];
|
|
|
|
$res = self::create($data);
|
|
if (!$res) {
|
|
Log::info(__CLASS__ . ' 写入余额日志失败:' . json_encode($data, JSON_UNESCAPED_UNICODE));
|
|
exception('写入余额日志失败');
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
} |