feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro_aliyun_express;
|
||||
|
||||
use addons\shopro_aliyun_express\library\ExpressConfig;
|
||||
use addons\shopro_aliyun_express\library\ExpressQueryService;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
|
||||
class Config extends Backend
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$data = ExpressConfig::getInstance()->all();
|
||||
$defaults = [
|
||||
'express_enable' => '1',
|
||||
'express_provider' => 'aliyun',
|
||||
'aliyun_appcode' => '',
|
||||
'aliyun_api_url' => '',
|
||||
'aliyun_api_mode' => 'auto',
|
||||
'aliyun_http_method' => 'auto',
|
||||
'expressbird_appcode' => '',
|
||||
'cache_ttl' => '300',
|
||||
];
|
||||
return $this->success('操作成功', null, array_merge($defaults, $data));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$params = $this->request->post('row/a');
|
||||
if (!$params) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$allowed = [
|
||||
'express_enable',
|
||||
'express_provider',
|
||||
'aliyun_appcode',
|
||||
'aliyun_api_url',
|
||||
'aliyun_api_mode',
|
||||
'aliyun_http_method',
|
||||
'expressbird_appcode',
|
||||
'cache_ttl',
|
||||
];
|
||||
|
||||
foreach ($allowed as $name) {
|
||||
if (!array_key_exists($name, $params)) {
|
||||
continue;
|
||||
}
|
||||
$exists = Db::name('shopro_aliyun_express_config')->where('name', $name)->find();
|
||||
if ($exists) {
|
||||
Db::name('shopro_aliyun_express_config')->where('name', $name)->update(['value' => $params[$name]]);
|
||||
} else {
|
||||
Db::name('shopro_aliyun_express_config')->insert(['name' => $name, 'value' => $params[$name]]);
|
||||
}
|
||||
}
|
||||
|
||||
ExpressConfig::reload();
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$waybillNo = trim($this->request->post('waybill_number', ''));
|
||||
$phone = trim($this->request->post('phone', ''));
|
||||
$expressCode = trim($this->request->post('express_code', ''));
|
||||
$provider = trim($this->request->post('express_provider', ''));
|
||||
|
||||
if ($waybillNo === '') {
|
||||
$this->error('请填写快递单号');
|
||||
}
|
||||
|
||||
try {
|
||||
$service = new ExpressQueryService();
|
||||
$normalized = $service->queryTrack($waybillNo, $phone, $expressCode, $provider ?: null, false);
|
||||
if (empty($normalized['success'])) {
|
||||
$raw = !empty($normalized['raw']) ? json_encode($normalized['raw'], JSON_UNESCAPED_UNICODE) : '';
|
||||
$this->error('测试查询失败:未获取到有效轨迹' . ($raw ? ':' . mb_substr($raw, 0, 300) : ''));
|
||||
}
|
||||
$this->success('测试查询成功', null, $normalized);
|
||||
} catch (\think\exception\HttpResponseException $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $e) {
|
||||
$msg = trim($e->getMessage());
|
||||
$this->error('测试查询失败:' . ($msg !== '' ? $msg : get_class($e)));
|
||||
}
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户