100 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			100 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
 | 
						|
namespace app\model;
 | 
						|
 | 
						|
use think\model\relation\HasOne;
 | 
						|
 | 
						|
/**
 | 
						|
 * 积分与佣金日志
 | 
						|
 *
 | 
						|
 * Class AccountDataLog
 | 
						|
 * @package app\model
 | 
						|
 */
 | 
						|
class AccountDataLog extends Base
 | 
						|
{
 | 
						|
    public const TYPE_SCORE      = 'score';//积分
 | 
						|
    public const TYPE_COMMISSION = 'commission';//佣金
 | 
						|
 | 
						|
    public const ACTION_ORDER             = 'order';//订单返佣
 | 
						|
    public const ACTION_ADMIN_RECHARGE    = 'admin_recharge';//后台充值
 | 
						|
    public const ACTION_ADMIN_OPERATION   = 'admin_operation';//后台操作
 | 
						|
    public const ACTION_WITHDRAWAL_RETURN = 'withdrawal_return';//提现-退回
 | 
						|
    public const ACTION_WITHDRAWAL        = 'withdrawal';//提现-扣除
 | 
						|
 | 
						|
    // 积分独有
 | 
						|
    public const ACTION_SHARE_REG         = 'share_reg';//分享注册
 | 
						|
    public const ACTION_SHARE_REG_CHILD   = 'share_reg_child';//分享注册-下级分享时获得积分
 | 
						|
    public const ACTION_SHARE_REG_SERVICE = 'share_reg_service';//分享注册-客户分享时客服获得积分
 | 
						|
 | 
						|
    /**
 | 
						|
     * 记录变更
 | 
						|
     *
 | 
						|
     * @param  int  $accountId
 | 
						|
     * @param  string  $name  日志名称(说明) 如 签到打卡、任务完成等等
 | 
						|
     * @param  string  $num  数量
 | 
						|
     * @param  string  $type  类型 目前仅 TYPE_SCORE TYPE_COMMISSION
 | 
						|
     * @param  string  $action  操作 如打卡=sign 任务=task 订单=order
 | 
						|
     * @param  string  $surplus  剩余积分或佣金
 | 
						|
     * @param  string  $operator  操作人
 | 
						|
     * @param  int  $operatorId  操作人ID
 | 
						|
     * @param  string  $remarks  备注
 | 
						|
     */
 | 
						|
    public static function log(int $accountId, string $name, string $num, string $type, string $action, string $surplus, string $operator = '', int $operatorId = 0, string $remarks = '')
 | 
						|
    {
 | 
						|
        self::create([
 | 
						|
            'account_id'  => $accountId,
 | 
						|
            'name'        => $name,
 | 
						|
            'num'         => $num,
 | 
						|
            'type'        => $type,
 | 
						|
            'action'      => $action,
 | 
						|
            'created_at'  => date('Y-m-d H:i:s'),
 | 
						|
            'surplus'     => $surplus,
 | 
						|
            'operator'    => $operator,
 | 
						|
            'operator_id' => $operatorId,
 | 
						|
            'remarks'     => $remarks,
 | 
						|
        ]);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     *  用户
 | 
						|
     *
 | 
						|
     */
 | 
						|
    public function account(): HasOne
 | 
						|
    {
 | 
						|
        return $this->hasOne(Account::class, 'id', 'account_id');
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 积分操作类型
 | 
						|
     *
 | 
						|
     * @return string[]
 | 
						|
     */
 | 
						|
    public static function scoreAction(): array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            self::ACTION_ORDER             => '订单',
 | 
						|
            self::ACTION_ADMIN_RECHARGE    => '后台充值',
 | 
						|
            self::ACTION_ADMIN_OPERATION   => '后台操作',
 | 
						|
            self::ACTION_SHARE_REG         => '分享注册',
 | 
						|
            self::ACTION_SHARE_REG_CHILD   => '分享注册-下级分享',
 | 
						|
            self::ACTION_SHARE_REG_SERVICE => '分享注册-客服获得积分',
 | 
						|
        ];
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 佣金操作类型
 | 
						|
     *
 | 
						|
     * @return string[]
 | 
						|
     */
 | 
						|
    public static function commissionAction(): array
 | 
						|
    {
 | 
						|
        return [
 | 
						|
            self::ACTION_ORDER             => '订单返佣',
 | 
						|
            self::ACTION_ADMIN_RECHARGE    => '后台充值',
 | 
						|
            self::ACTION_ADMIN_OPERATION   => '后台操作',
 | 
						|
            self::ACTION_WITHDRAWAL_RETURN => '提现退回',
 | 
						|
            self::ACTION_WITHDRAWAL        => '提现扣除',
 | 
						|
        ];
 | 
						|
    }
 | 
						|
}
 |