drag-create-api/app/common/model/Customer/Customer.php

113 lines
2.9 KiB
PHP

<?php
namespace app\common\model\Customer;
use app\common\arw\adjfut\src\Validate;
use app\common\logic\Customer\Customer as LogicCustomer;
use app\common\logic\Customer\Customer as CommonLogicCustomer;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\common\arw\adjfut\src\Excel;
use app\Request;
use app\common\exception\Tool;
use think\facade\Db;
class Customer extends BaseModel
{
use SoftDelete;
// 删除字段
protected $deleteTime = 'customer_delete_time';
// 设置主键名
protected $pk = 'customer_guid';
// 设置废弃字段
protected $disuse = [];
// 设置字段信息
protected $schema = [
'customer_id' => 'int',
'customer_guid' => 'string',
'customer_name' => 'string',
'customer_account' => 'string',
'customer_password' => 'string',
'customer_phone' => 'string',
'customer_email' => 'string',
'customer_sex' => 'string',
'customer_create_time' => 'datetime',
'customer_create_user_guid' => 'string',
'customer_update_time' => 'datetime',
'customer_update_user_guid' => 'string',
'customer_delete_time' => 'datetime',
'customer_delete_user_guid' => 'string',
];
// 设置json类型字段
protected $json = [''];
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'datetime';
// 创建时间
protected $createTime = 'customer_create_time';
// 修改时间
protected $updateTime = 'customer_update_time';
/**
* 新增前
*/
public static function onBeforeInsert(self $model): void
{
$model->customer_password = CommonLogicCustomer::encryptPassword($model->customer_password);
self::checkRepeatData($model);
$model->completeCreateField();
}
/**
* 更新前
*/
public static function onBeforeUpdate(self $model): void
{
$model->customer_password = CommonLogicCustomer::encryptPassword($model->customer_password);
self::checkRepeatData($model);
$model->completeUpdateField();
}
/**
* 删除前
*/
public static function onBeforeDelete(self $model): void
{
$model->completeDeleteField();
}
/**
* 数据查重
*
* @param self $model
* @return void
* @date 2022-03-11
* @example
* @author admin
* @since 1.0.0
*/
private static function checkRepeatData(self $model)
{
Validate::unique(
self::class,
$model->customer_guid,
$model->getData(),
['customer_account' => '账号',],
['customer_account' => "账号已存在!"]
);
}
/**
* 获取客户菜单
*
* @return array
* @date 2023-06-25
* @author xjh
* @since 1.0.0
*/
public static function getCustomerMenu(): array
{
return LogicCustomer::getCustomerMenu();
}
}