Files
cunkebao_v3/Server/application/cunkebao/model/DistributionChannel.php

88 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2025-12-17 16:20:46 +08:00
<?php
namespace app\cunkebao\model;
use app\cunkebao\model\BaseModel;
use think\Model;
/**
* 分销渠道模型
*/
class DistributionChannel extends BaseModel
{
// 设置表名
protected $name = 'distribution_channel';
// 自动写入时间戳
protected $autoWriteTimestamp = true;
protected $createTime = 'createTime';
protected $updateTime = 'updateTime';
protected $deleteTime = 'deleteTime';
protected $defaultSoftDelete = 0;
// 类型转换
protected $type = [
'id' => 'integer',
'companyId' => 'integer',
'totalCustomers' => 'integer',
'todayCustomers' => 'integer',
'totalFriends' => 'integer',
'todayFriends' => 'integer',
'withdrawableAmount' => 'integer',
'createTime' => 'timestamp',
'updateTime' => 'timestamp',
'deleteTime' => 'timestamp',
];
/**
* 生成渠道编码
* 格式QD + 时间戳 + 9位随机字符串
*
* @return string
*/
public static function generateChannelCode()
{
$prefix = 'QD';
$timestamp = time();
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$randomStr = '';
// 生成9位随机字符串
for ($i = 0; $i < 9; $i++) {
$randomStr .= $chars[mt_rand(0, strlen($chars) - 1)];
}
$code = $prefix . $timestamp . $randomStr;
// 检查是否已存在
$exists = self::where('code', $code)->find();
if ($exists) {
// 如果已存在,递归重新生成
return self::generateChannelCode();
}
return $code;
}
/**
* 创建类型manual手动创建
*/
const CREATE_TYPE_MANUAL = 'manual';
/**
* 创建类型auto扫码创建
*/
const CREATE_TYPE_AUTO = 'auto';
/**
* 状态enabled启用
*/
const STATUS_ENABLED = 'enabled';
/**
* 状态disabled禁用
*/
const STATUS_DISABLED = 'disabled';
}