new files
This commit is contained in:
35
pro_v3.5.1/crmeb/basic/BaseAi.php
Normal file
35
pro_v3.5.1/crmeb/basic/BaseAi.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\services\AccessTokenServeService;
|
||||
|
||||
abstract class BaseAi extends BaseStorage
|
||||
{
|
||||
/**
|
||||
* access_token
|
||||
* @var null
|
||||
*/
|
||||
protected $accessToken = NULL;
|
||||
|
||||
/**
|
||||
* BaseProduct constructor.
|
||||
* @param string $name
|
||||
* @param AccessTokenServeService $accessTokenServeService
|
||||
* @param string $configFile
|
||||
*/
|
||||
public function __construct(string $name, AccessTokenServeService $accessTokenServeService, string $configFile)
|
||||
{
|
||||
parent::__construct($name, [], $configFile);
|
||||
$this->accessToken = $accessTokenServeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config = [])
|
||||
{
|
||||
}
|
||||
}
|
||||
BIN
pro_v3.5.1/crmeb/basic/BaseAuth.php
Executable file
BIN
pro_v3.5.1/crmeb/basic/BaseAuth.php
Executable file
Binary file not shown.
BIN
pro_v3.5.1/crmeb/basic/BaseController.php
Executable file
BIN
pro_v3.5.1/crmeb/basic/BaseController.php
Executable file
Binary file not shown.
104
pro_v3.5.1/crmeb/basic/BaseDelivery.php
Normal file
104
pro_v3.5.1/crmeb/basic/BaseDelivery.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
|
||||
/**
|
||||
* Class BaseDelivery
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseDelivery extends BaseStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* 回调地址
|
||||
* @var null
|
||||
*/
|
||||
protected $callback_url = null;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config)
|
||||
{
|
||||
$this->callback_url = rtrim(sys_config('site_url'), '/') . '/api/city_delivery/notify';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function addMerchant($data); //注册商户
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function addShop($data); //创建门店
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function updateShop($data); //更新门店
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function addOrder($data); //发布订单
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getOrderPrice($data); //计算订单价格
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getOrderDetail($data); //获取订单详情
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function cancelOrder($data); //取消订单
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getRecharge($data); //获取充值地址
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getBalance($data); //获取余额
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function addTip($data); //支付小费
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getCity($data); //获取城市信息
|
||||
|
||||
}
|
||||
50
pro_v3.5.1/crmeb/basic/BaseErp.php
Normal file
50
pro_v3.5.1/crmeb/basic/BaseErp.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\services\erp\AccessToken;
|
||||
|
||||
|
||||
abstract class BaseErp extends BaseStorage
|
||||
{
|
||||
/**
|
||||
* token句柄
|
||||
* @var AccessToken
|
||||
*/
|
||||
protected $accessToken;
|
||||
|
||||
/**
|
||||
* 驱动类型
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* 配置文件名
|
||||
* @var string
|
||||
*/
|
||||
protected $configFile;
|
||||
|
||||
/**
|
||||
* BaseErp constructor.
|
||||
* @param string $name
|
||||
* @param AccessToken $accessToken
|
||||
* @param string $configFile
|
||||
*/
|
||||
public function __construct(string $name, AccessToken $accessToken, string $configFile)
|
||||
{
|
||||
parent::__construct($name, [], $configFile);
|
||||
$this->accessToken = $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config = [])
|
||||
{
|
||||
// parent::initialize($config);
|
||||
}
|
||||
}
|
||||
76
pro_v3.5.1/crmeb/basic/BaseExpress.php
Normal file
76
pro_v3.5.1/crmeb/basic/BaseExpress.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\services\AccessTokenServeService;
|
||||
use crmeb\services\HttpService;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Config;
|
||||
use crmeb\services\CacheService;
|
||||
|
||||
/**
|
||||
* Class BaseExpress
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseExpress extends BaseStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* access_token
|
||||
* @var null
|
||||
*/
|
||||
protected $accessToken = NULL;
|
||||
|
||||
|
||||
public function __construct(string $name, AccessTokenServeService $accessTokenServeService, string $configFile)
|
||||
{
|
||||
parent::__construct($name, [], $configFile);
|
||||
$this->accessToken = $accessTokenServeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config = [])
|
||||
{
|
||||
// parent::initialize($config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开通服务
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function open();
|
||||
|
||||
/**物流追踪
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function query(string $num, string $com = '');
|
||||
|
||||
/**电子面单
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function dump($data);
|
||||
|
||||
/**快递公司
|
||||
* @return mixed
|
||||
*/
|
||||
//abstract public function express($type, $page, $limit);
|
||||
|
||||
/**面单模板
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function temp(string $com);
|
||||
}
|
||||
77
pro_v3.5.1/crmeb/basic/BaseJobs.php
Normal file
77
pro_v3.5.1/crmeb/basic/BaseJobs.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\queue\Job;
|
||||
|
||||
/**
|
||||
* 消息队列基类
|
||||
* Class BaseJobs
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
class BaseJobs implements JobInterface
|
||||
{
|
||||
/**
|
||||
* 运行消息队列
|
||||
* @param Job $job
|
||||
* @param $data
|
||||
*/
|
||||
public function fire(Job $job, $data): void
|
||||
{
|
||||
try {
|
||||
$action = $data['do'] ?? 'doJob';//任务名
|
||||
$infoData = $data['data'] ?? [];//执行数据
|
||||
$errorCount = $data['errorCount'] ?? 0;//最大错误次数
|
||||
$this->runJob($action, $job, $infoData, $errorCount);
|
||||
} catch (\Throwable $e) {
|
||||
$job->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行队列
|
||||
* @param string $action
|
||||
* @param Job $job
|
||||
* @param array $infoData
|
||||
* @param int $errorCount
|
||||
*/
|
||||
protected function runJob(string $action, Job $job, array $infoData, int $errorCount = 3)
|
||||
{
|
||||
if (!class_exists(get_class($this))) {
|
||||
$job->delete();
|
||||
} else {
|
||||
$action = method_exists($this, $action) ? $action : 'handle';
|
||||
if (!method_exists($this, $action)) {
|
||||
$job->delete();
|
||||
} else {
|
||||
if ($this->{$action}(...$infoData)) {
|
||||
//删除任务
|
||||
$job->delete();
|
||||
} else {
|
||||
if ($job->attempts() >= $errorCount && $errorCount) {
|
||||
//删除任务
|
||||
$job->delete();
|
||||
} else {
|
||||
//从新放入队列
|
||||
$job->release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
219
pro_v3.5.1/crmeb/basic/BaseManager.php
Normal file
219
pro_v3.5.1/crmeb/basic/BaseManager.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use think\facade\Config;
|
||||
use think\helper\Str;
|
||||
use think\Container;
|
||||
|
||||
/**
|
||||
* 驱动基类
|
||||
* Class BaseManager
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseManager
|
||||
{
|
||||
/**
|
||||
* 驱动的命名空间
|
||||
* @var null
|
||||
*/
|
||||
protected string $namespace;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @var null
|
||||
*/
|
||||
protected $configFile = null;
|
||||
|
||||
/**
|
||||
* 配置
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
* 驱动
|
||||
* @var array
|
||||
*/
|
||||
protected $drivers = [];
|
||||
|
||||
/**
|
||||
* 驱动类型
|
||||
* @var null
|
||||
*/
|
||||
protected $name = null;
|
||||
|
||||
/**
|
||||
* BaseManager constructor.
|
||||
* @param string|array|int $name驱动名称
|
||||
* @param array $config 配置
|
||||
*/
|
||||
public function __construct($name = null, array $config = [])
|
||||
{
|
||||
$type = null;
|
||||
if (is_array($name)) {
|
||||
$config = $name;
|
||||
$name = null;
|
||||
}
|
||||
|
||||
if (is_int($name)) {
|
||||
$type = $name;
|
||||
$name = null;
|
||||
}
|
||||
|
||||
if ($name)
|
||||
$this->name = $name;
|
||||
if ($type && is_null($this->name)) {
|
||||
$this->setHandleType((int)$type - 1);
|
||||
}
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取配置文件名
|
||||
* @return $this
|
||||
*/
|
||||
protected function getConfigFile()
|
||||
{
|
||||
if (is_null($this->configFile)) {
|
||||
$this->configFile = strtolower((new \ReflectionClass($this))->getShortName());
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文件句柄
|
||||
* @param int $type
|
||||
*/
|
||||
protected function setHandleType(int $type)
|
||||
{
|
||||
$this->getConfigFile();
|
||||
$stores = array_keys(Config::get($this->configFile . '.stores', []));
|
||||
$name = $stores[$type] ?? null;
|
||||
if (!$name) {
|
||||
throw new \RuntimeException($this->configFile . ' type is not used');
|
||||
}
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认句柄
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function getDefaultDriver();
|
||||
|
||||
/**
|
||||
* 动态调用
|
||||
* @param $method
|
||||
* @param $arguments
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
return $this->driver()->{$method}(...$arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取驱动实例
|
||||
* @param null|string $name
|
||||
* @return mixed
|
||||
*/
|
||||
protected function driver(string $name = null)
|
||||
{
|
||||
$name = $name ?: $this->name;
|
||||
$name = $name ?: $this->getDefaultDriver();
|
||||
|
||||
if (is_null($name)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'Unable to resolve NULL driver for [%s].', static::class
|
||||
));
|
||||
}
|
||||
|
||||
return $this->drivers[$name] = $this->getDriver($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取驱动实例
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getDriver(string $name)
|
||||
{
|
||||
return $this->drivers[$name] ?? $this->createDriver($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取驱动类型
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
protected function resolveType(string $name)
|
||||
{
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建驱动
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
protected function createDriver(string $name)
|
||||
{
|
||||
$type = $this->resolveType($name);
|
||||
|
||||
$method = 'create' . Str::studly($type) . 'Driver';
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method($name);
|
||||
}
|
||||
|
||||
$class = $this->resolveClass($type);
|
||||
$this->name = $type;
|
||||
return $this->invokeClass($class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取驱动类
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected function resolveClass(string $type): string
|
||||
{
|
||||
if ($this->namespace || false !== strpos($type, '\\')) {
|
||||
$class = false !== strpos($type, '\\') ? $type : $this->namespace . Str::studly($type);
|
||||
if (class_exists($class)) {
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("Driver [$type] not supported.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 实例化类
|
||||
* @param $class
|
||||
* @return mixed
|
||||
*/
|
||||
protected function invokeClass($class)
|
||||
{
|
||||
if (!class_exists($class)) {
|
||||
throw new \RuntimeException('class not exists: ' . $class);
|
||||
}
|
||||
$this->getConfigFile();
|
||||
$handle = Container::getInstance()->invokeClass($class, [$this->name, $this->config, $this->configFile]);
|
||||
$this->config = [];
|
||||
return $handle;
|
||||
}
|
||||
|
||||
}
|
||||
152
pro_v3.5.1/crmeb/basic/BaseMessage.php
Normal file
152
pro_v3.5.1/crmeb/basic/BaseMessage.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use think\facade\Config;
|
||||
|
||||
abstract class BaseMessage extends BaseStorage
|
||||
{
|
||||
/**
|
||||
* 模板id
|
||||
* @var array
|
||||
*/
|
||||
protected $templateIds = [];
|
||||
|
||||
/**
|
||||
* openId
|
||||
* @var string
|
||||
*/
|
||||
protected $openId;
|
||||
|
||||
/**
|
||||
* 跳转链接
|
||||
* @var string
|
||||
*/
|
||||
protected $toUrl;
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
* @var string
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config)
|
||||
{
|
||||
$this->templateIds = Config::get($this->configFile . '.stores.' . $this->name . '.template_id', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否记录日志
|
||||
* @return mixed
|
||||
*/
|
||||
public function isLog()
|
||||
{
|
||||
$isLog = Config::get($this->configFile . 'isLog', false);
|
||||
return Config::get($this->configFile . '.stores.' . $this->name . '.isLog', $isLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板id
|
||||
* @return array
|
||||
*/
|
||||
public function getTemplateId()
|
||||
{
|
||||
return $this->templateIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* openid
|
||||
* @param string $openId
|
||||
* @return $this
|
||||
*/
|
||||
public function to(string $openId)
|
||||
{
|
||||
$this->openId = $openId;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转路径
|
||||
* @param string $url
|
||||
* @return $this
|
||||
*/
|
||||
public function url(string $url)
|
||||
{
|
||||
$this->toUrl = $url;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色
|
||||
* @param string $color
|
||||
* @return $this
|
||||
*/
|
||||
public function color(?string $color)
|
||||
{
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取模板code
|
||||
* @param string $templateId
|
||||
* @return null
|
||||
*/
|
||||
protected function getTemplateCode(string $templateId)
|
||||
{
|
||||
return $this->templateIds[$templateId] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复默认值
|
||||
*/
|
||||
protected function clear()
|
||||
{
|
||||
$this->openId = null;
|
||||
$this->toUrl = null;
|
||||
$this->color = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param string $templateId
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function send(string $templateId, array $data = []);
|
||||
|
||||
/**
|
||||
* 添加模板
|
||||
* @param string $shortId
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function add(string $shortId);
|
||||
|
||||
/**
|
||||
* 删除模板
|
||||
* @param string $templateId
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function delete(string $templateId);
|
||||
|
||||
/**
|
||||
* 获取所有模板
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function list();
|
||||
|
||||
}
|
||||
54
pro_v3.5.1/crmeb/basic/BaseModel.php
Normal file
54
pro_v3.5.1/crmeb/basic/BaseModel.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use think\db\Query;
|
||||
use think\Model;
|
||||
use crmeb\topthink\HasManyThrough;
|
||||
|
||||
/**
|
||||
* Class BaseModel
|
||||
* @package crmeb\basic
|
||||
* @mixin ModelTrait
|
||||
* @mixin Query
|
||||
*/
|
||||
class BaseModel extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 重写一对多关联
|
||||
* @param string $model
|
||||
* @param string $through
|
||||
* @param string $foreignKey
|
||||
* @param string $throughKey
|
||||
* @param string $localKey
|
||||
* @param string $throughPk
|
||||
* @return HasManyThrough
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/10/11
|
||||
*/
|
||||
public function hasManyThrough(string $model, string $through, string $foreignKey = '', string $throughKey = '', string $localKey = '', string $throughPk = ''): HasManyThrough
|
||||
{
|
||||
// 记录当前关联信息
|
||||
$model = $this->parseModel($model);
|
||||
$through = $this->parseModel($through);
|
||||
$localKey = $localKey ?: $this->getPk();
|
||||
$foreignKey = $foreignKey ?: $this->getForeignKey($this->name);
|
||||
$throughKey = $throughKey ?: $this->getForeignKey((new $through())->getName());
|
||||
$throughPk = $throughPk ?: (new $through())->getPk();
|
||||
|
||||
return new HasManyThrough($this, $model, $through, $foreignKey, $throughKey, $localKey, $throughPk);
|
||||
}
|
||||
|
||||
}
|
||||
50
pro_v3.5.1/crmeb/basic/BasePay.php
Normal file
50
pro_v3.5.1/crmeb/basic/BasePay.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace crmeb\basic;
|
||||
|
||||
/**
|
||||
* Class BasePay
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BasePay extends BaseStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* 支付参数配置
|
||||
* @var array
|
||||
*/
|
||||
protected $configPay = [];
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
* @param array|null $configPay
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function pay(?array $configPay = []);
|
||||
|
||||
/**
|
||||
* 退款
|
||||
* @param array|null $configPay
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function refund(?array $configPay = []);
|
||||
|
||||
/**
|
||||
* 设置支付参数
|
||||
* @param array $configPay
|
||||
* @return $this
|
||||
*/
|
||||
public function setConfigPay(array $configPay)
|
||||
{
|
||||
$this->configPay = $configPay;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
61
pro_v3.5.1/crmeb/basic/BasePrinter.php
Normal file
61
pro_v3.5.1/crmeb/basic/BasePrinter.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\services\printer\AccessToken;
|
||||
|
||||
/**
|
||||
* Class BasePrinter
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BasePrinter extends BaseStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* token句柄
|
||||
* @var AccessToken
|
||||
*/
|
||||
protected $accessToken;
|
||||
|
||||
/**
|
||||
* 打印内容
|
||||
* @var string
|
||||
*/
|
||||
protected $printerContent;
|
||||
|
||||
/**
|
||||
* BasePrinter constructor.
|
||||
* @param string $name
|
||||
* @param AccessToken $accessToken
|
||||
* @param string $configFile
|
||||
*/
|
||||
public function __construct(string $name, AccessToken $accessToken, string $configFile)
|
||||
{
|
||||
parent::__construct($name, [], $configFile);
|
||||
$this->accessToken = $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始打印
|
||||
* @param array|null $systemConfig
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function startPrinter();
|
||||
|
||||
/**
|
||||
* 设置打印内容
|
||||
* @param array $config
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function setPrinterContent(array $config);
|
||||
|
||||
}
|
||||
61
pro_v3.5.1/crmeb/basic/BaseProduct.php
Normal file
61
pro_v3.5.1/crmeb/basic/BaseProduct.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\services\AccessTokenServeService;
|
||||
|
||||
/**
|
||||
* Class BaseProduct
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseProduct extends BaseStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* access_token
|
||||
* @var null
|
||||
*/
|
||||
protected $accessToken = NULL;
|
||||
|
||||
/**
|
||||
* BaseProduct constructor.
|
||||
* @param string $name
|
||||
* @param AccessTokenServeService $accessTokenServeService
|
||||
* @param string $configFile
|
||||
*/
|
||||
public function __construct(string $name, AccessTokenServeService $accessTokenServeService, string $configFile)
|
||||
{
|
||||
parent::__construct($name, [], $configFile);
|
||||
$this->accessToken = $accessTokenServeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config = [])
|
||||
{
|
||||
// parent::initialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开通服务
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function open();
|
||||
|
||||
/**复制商品
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function goods(string $url);
|
||||
}
|
||||
107
pro_v3.5.1/crmeb/basic/BaseSmss.php
Normal file
107
pro_v3.5.1/crmeb/basic/BaseSmss.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\services\AccessTokenServeService;
|
||||
|
||||
/**
|
||||
* Class BaseSmss
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseSmss extends BaseStorage
|
||||
{
|
||||
|
||||
/**
|
||||
* access_token
|
||||
* @var null
|
||||
*/
|
||||
protected $accessToken = NULL;
|
||||
|
||||
/**
|
||||
* BaseSmss constructor.
|
||||
* @param string $name
|
||||
* @param AccessTokenServeService $accessTokenServeService
|
||||
* @param string $configFile
|
||||
*/
|
||||
public function __construct(string $name, AccessTokenServeService $accessTokenServeService, string $configFile, array $config = [])
|
||||
{
|
||||
$this->accessToken = $accessTokenServeService;
|
||||
$this->name = $name;
|
||||
$this->configFile = $configFile;
|
||||
$this->initialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed|void
|
||||
*/
|
||||
protected function initialize(array $config = [])
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开通服务
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function open();
|
||||
|
||||
/**修改签名
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function modify(string $sign = null, string $phone, string $code);
|
||||
|
||||
/**用户信息
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function info();
|
||||
|
||||
/**发送短信
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function send(string $phone, string $templateId, array $data);
|
||||
|
||||
/**
|
||||
* 短信模板
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function temps(int $page, int $limit, int $type);
|
||||
|
||||
|
||||
/**
|
||||
* 申请模板
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function apply(string $title, string $content, int $type);
|
||||
|
||||
/**
|
||||
* 模板记录
|
||||
* @param int $tempType
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function applys(int $tempType, int $page, int $limit);
|
||||
|
||||
/**发送记录
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function record($record_id);
|
||||
}
|
||||
56
pro_v3.5.1/crmeb/basic/BaseStorage.php
Normal file
56
pro_v3.5.1/crmeb/basic/BaseStorage.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
|
||||
/**
|
||||
* 容器基类
|
||||
* Class BaseStorage
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseStorage
|
||||
{
|
||||
use \crmeb\traits\ErrorTrait;
|
||||
|
||||
/**
|
||||
* 驱动名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* 驱动配置文件名
|
||||
* @var string
|
||||
*/
|
||||
protected $configFile;
|
||||
|
||||
/**
|
||||
* BaseStorage constructor.
|
||||
* @param string $name 驱动名
|
||||
* @param string $configFile 驱动配置名
|
||||
* @param array $config 其他配置
|
||||
*/
|
||||
public function __construct(string $name, array $config = [], string $configFile = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->configFile = $configFile;
|
||||
$this->initialize($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @param array $config
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function initialize(array $config);
|
||||
|
||||
}
|
||||
459
pro_v3.5.1/crmeb/basic/BaseUpload.php
Normal file
459
pro_v3.5.1/crmeb/basic/BaseUpload.php
Normal file
@@ -0,0 +1,459 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace crmeb\basic;
|
||||
|
||||
use crmeb\exceptions\UploadException;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* Class BaseUpload
|
||||
* @package crmeb\basic
|
||||
*/
|
||||
abstract class BaseUpload extends BaseStorage
|
||||
{
|
||||
/**
|
||||
* 缩略图
|
||||
* @var string[]
|
||||
*/
|
||||
protected array $thumb = ['big', 'mid', 'small'];
|
||||
|
||||
/**
|
||||
* 缩略图配置
|
||||
* @var array
|
||||
*/
|
||||
protected array $thumbConfig = [
|
||||
'thumb_big_height' => 700,
|
||||
'thumb_big_width' => 700,
|
||||
'thumb_mid_height' => 400,
|
||||
'thumb_mid_width' => 400,
|
||||
'thumb_small_height' => 100,
|
||||
'thumb_small_width' => 100,
|
||||
];
|
||||
/**
|
||||
* 水印配置
|
||||
* @var array
|
||||
*/
|
||||
protected array $waterConfig = [
|
||||
'image_watermark_status' => 0,
|
||||
'watermark_type' => 1,
|
||||
'watermark_image' => '',
|
||||
'watermark_opacity' => 0,
|
||||
'watermark_position' => 1,
|
||||
'watermark_rotate' => 0,
|
||||
'watermark_text' => '',
|
||||
'watermark_text_angle' => "",
|
||||
'watermark_text_color' => '#000000',
|
||||
'watermark_text_size' => '5',
|
||||
'watermark_text_font' => '',
|
||||
'watermark_x' => 0,
|
||||
'watermark_y' => 0
|
||||
];
|
||||
/**
|
||||
* 图片信息
|
||||
* @var array
|
||||
*/
|
||||
protected $fileInfo;
|
||||
/**
|
||||
* 下载图片信息
|
||||
*/
|
||||
protected $downFileInfo;
|
||||
|
||||
/**
|
||||
* 要生成缩略图、水印的图片地址
|
||||
* @var string
|
||||
*/
|
||||
protected string $filePath;
|
||||
|
||||
/**
|
||||
* 验证配置
|
||||
* @var string
|
||||
*/
|
||||
protected string $validate;
|
||||
|
||||
/**
|
||||
* 保存路径
|
||||
* @var string
|
||||
*/
|
||||
protected string $path = '';
|
||||
|
||||
/**
|
||||
* 是否自动裁剪
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $authThumb = false;
|
||||
|
||||
protected function initialize(array $config)
|
||||
{
|
||||
$this->fileInfo = $this->downFileInfo = new \StdClass();
|
||||
$this->thumbConfig = array_merge($this->thumbConfig, $config['thumb'] ?? []);
|
||||
$this->waterConfig = array_merge($this->waterConfig, $config['water'] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置处理缩略图、水印图片路径
|
||||
* @param string $filePath
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilepath(string $filePath)
|
||||
{
|
||||
$this->filePath = substr($filePath, 0, 1) === '.' ? substr($filePath, 1) : $filePath;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否自动裁剪
|
||||
* @param bool $auth
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuthThumb(bool $auth)
|
||||
{
|
||||
$this->authThumb = $auth;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件路径
|
||||
* @param string $path
|
||||
* @return $this
|
||||
*/
|
||||
public function to(string $path)
|
||||
{
|
||||
$this->path = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件信息
|
||||
* @return array
|
||||
*/
|
||||
public function getFileInfo()
|
||||
{
|
||||
return $this->fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否是图片
|
||||
* @param $filePath
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkImage($filePath)
|
||||
{
|
||||
//获取图像信息
|
||||
$info = @getimagesize($filePath);
|
||||
//检测图像合法性
|
||||
if (false === $info || IMAGETYPE_GIF === $info[2] || empty($info['bits'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证合法上传域名
|
||||
* @param string $url
|
||||
* @return string
|
||||
*/
|
||||
protected function checkUploadUrl(string $url)
|
||||
{
|
||||
if ($url && strstr($url, 'http') === false) {
|
||||
$url = 'http://' . $url;
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统配置
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getConfig()
|
||||
{
|
||||
$config = Config::get($this->configFile . '.stores.' . $this->name, []);
|
||||
if (empty($config)) {
|
||||
$config['filesize'] = Config::get($this->configFile . '.filesize', []);
|
||||
$config['fileExt'] = Config::get($this->configFile . '.fileExt', []);
|
||||
$config['fileMime'] = Config::get($this->configFile . '.fileMime', []);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置验证规则
|
||||
* @param array|null $validate
|
||||
* @return $this
|
||||
*/
|
||||
public function validate(?array $validate = null)
|
||||
{
|
||||
if (is_null($validate)) {
|
||||
$validate = $this->getConfig();
|
||||
}
|
||||
$this->extractValidate($validate);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证目录是否正确
|
||||
* @param string $key
|
||||
* @return false|string
|
||||
*/
|
||||
protected function getUploadPath(string $key)
|
||||
{
|
||||
$path = ($this->path ? $this->path . '/' : '') . $key;
|
||||
if ($path && $path[0] === '/') {
|
||||
$path = substr($path, 1);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取上传验证
|
||||
*/
|
||||
protected function extractValidate(array $validateArray)
|
||||
{
|
||||
$validate = [];
|
||||
foreach ($validateArray as $key => $value) {
|
||||
$validate[] = $key . ':' . (is_array($value) ? implode(',', $value) : $value);
|
||||
}
|
||||
$this->validate = implode('|', $validate);
|
||||
unset($validate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取文件名
|
||||
* @param string $path
|
||||
* @param string $ext
|
||||
* @return string
|
||||
*/
|
||||
protected function saveFileName(string $path = null, string $ext = 'jpg')
|
||||
{
|
||||
mt_srand();
|
||||
return ($path ? substr(md5($path), 0, 5) : '') . date('YmdHis') . rand(0, 9999) . '.' . $ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取文件后缀以及之前部分
|
||||
* @param string $path
|
||||
* @return false|string[]
|
||||
*/
|
||||
protected function getFileName(string $path)
|
||||
{
|
||||
$_empty = ['', ''];
|
||||
if (!$path) return $_empty;
|
||||
if (strpos($path, '?')) {
|
||||
$_tarr = explode('?', $path);
|
||||
$path = trim($_tarr[0]);
|
||||
}
|
||||
$arr = explode('.', $path);
|
||||
if (!is_array($arr) || count($arr) <= 1) return $_empty;
|
||||
$ext_name = trim($arr[count($arr) - 1]);
|
||||
$ext_name = !$ext_name ? 'jpg' : $ext_name;
|
||||
return [explode('.' . $ext_name, $path)[0], $ext_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片地址
|
||||
* @param string $filePath
|
||||
* @param bool $is_parse_url
|
||||
* @return string
|
||||
*/
|
||||
protected function getFilePath(string $filePath = '', bool $is_parse_url = false)
|
||||
{
|
||||
$path = $filePath ? $filePath : $this->filePath;
|
||||
if ($is_parse_url) {
|
||||
$data = parse_url($path);
|
||||
//远程地址处理
|
||||
if (isset($data['host']) && isset($data['path'])) {
|
||||
if (file_exists(app()->getRootPath() . 'public' . $data['path'])) {
|
||||
$path = $data['path'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件是否在本地
|
||||
* @param string $filePath
|
||||
* @return bool
|
||||
*/
|
||||
protected function isLocal(string $filePath)
|
||||
{
|
||||
$isLocal = false;
|
||||
$path = $filePath;
|
||||
$data = parse_url($path);
|
||||
//远程地址处理
|
||||
if (isset($data['host']) && isset($data['path'])) {
|
||||
if (file_exists(app()->getRootPath() . 'public' . $data['path'])) {
|
||||
$isLocal = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $isLocal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件类型和大小
|
||||
* @param string $url
|
||||
* @param bool $isData
|
||||
* @return array
|
||||
*/
|
||||
protected function getFileHeaders(string $url, $isData = true)
|
||||
{
|
||||
stream_context_set_default(['ssl' => ['verify_peer' => false, 'verify_peer_name' => false]]);
|
||||
$header['size'] = 0;
|
||||
$header['type'] = 'image/jpeg';
|
||||
if (!$isData) {
|
||||
return $header;
|
||||
}
|
||||
try {
|
||||
$headerArray = get_headers(str_replace('\\', '/', $url), true);
|
||||
if (!isset($headerArray['Content-Length'])) {
|
||||
$header['size'] = 0;
|
||||
} else {
|
||||
if (is_array($headerArray['Content-Length']) && count($headerArray['Content-Length']) == 2) {
|
||||
$header['size'] = $headerArray['Content-Length'][1];
|
||||
} else {
|
||||
$header['size'] = $headerArray['Content-Length'] ?? 0;
|
||||
}
|
||||
}
|
||||
if (!isset($headerArray['Content-Type'])) {
|
||||
$header['type'] = 'image/jpeg';
|
||||
} else {
|
||||
if (is_array($headerArray['Content-Type']) && count($headerArray['Content-Type']) == 2) {
|
||||
$header['type'] = $headerArray['Content-Type'][1];
|
||||
} else {
|
||||
$header['type'] = $headerArray['Content-Type'] ?? 'image/jpeg';
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上传信息
|
||||
* @return array
|
||||
*/
|
||||
public function getUploadInfo()
|
||||
{
|
||||
if (isset($this->fileInfo->filePath)) {
|
||||
if (strstr($this->fileInfo->filePath, 'http') === false) {
|
||||
$url = request()->domain() . $this->fileInfo->filePath;
|
||||
} else {
|
||||
$url = $this->fileInfo->filePath;
|
||||
}
|
||||
$headers = $this->getFileHeaders($url);
|
||||
return [
|
||||
'name' => $this->fileInfo->fileName,
|
||||
'real_name' => $this->fileInfo->realName ?? '',
|
||||
'size' => $headers['size'] ?? 0,
|
||||
'type' => $headers['type'] ?? 'image/jpeg',
|
||||
'dir' => $this->fileInfo->filePath,
|
||||
'thumb_path' => $this->fileInfo->filePath,
|
||||
'thumb_path_big' => $this->fileInfo->filePathBig ?? '',
|
||||
'thumb_path_mid' => $this->fileInfo->filePathMid ?? '',
|
||||
'thumb_path_small' => $this->fileInfo->filePathSmall ?? '',
|
||||
'thumb_path_water' => $this->fileInfo->filePathWater ?? '',
|
||||
'time' => time(),
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下载信息
|
||||
* @return array
|
||||
*/
|
||||
public function getDownloadInfo()
|
||||
{
|
||||
if (isset($this->downFileInfo->downloadFilePath)) {
|
||||
if (strstr($this->downFileInfo->downloadFilePath, 'http') === false) {
|
||||
$url = request()->domain() . $this->downFileInfo->downloadFilePath;
|
||||
} else {
|
||||
$url = $this->downFileInfo->downloadFilePath;
|
||||
}
|
||||
$headers = $this->getFileHeaders($url);
|
||||
return [
|
||||
'name' => $this->downFileInfo->downloadFileName,
|
||||
'real_name' => $this->downFileInfo->downloadRealName ?? '',
|
||||
'size' => $headers['size'] ?? 0,
|
||||
'type' => $headers['type'] ?? 'image/jpeg',
|
||||
'dir' => $this->downFileInfo->downloadFilePath ?? '',
|
||||
'thumb_path' => $this->downFileInfo->downloadFilePath ?? '',
|
||||
'time' => time(),
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证文件后缀是否为非法文件
|
||||
* @param string $key
|
||||
* @return void
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/10/9
|
||||
*/
|
||||
public function verifyExtension(string $key)
|
||||
{
|
||||
$parseUrl = parse_url($key);
|
||||
$path = $parseUrl['path'] ?? '';
|
||||
$extension = pathinfo($path)['extension'] ?? '';
|
||||
$fileExt = app()->config->get('upload.fileExt');
|
||||
if (!in_array($extension, $fileExt)) {
|
||||
throw new UploadException('文件类型错误,支持:' . implode('、', $fileExt));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function move(string $file = 'file');
|
||||
|
||||
/**
|
||||
* 文件流上传
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function stream(string $fileContent, string $key = null);
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function delete(string $filePath);
|
||||
|
||||
/**
|
||||
* 实例化上传
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function app();
|
||||
|
||||
/**
|
||||
* 获取上传密钥
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function getTempKeys();
|
||||
|
||||
/**
|
||||
* 获取缩略图
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function thumb(string $filePath = '');
|
||||
|
||||
/**
|
||||
* 添加水印
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function water(string $filePath = '');
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user