feat: 初始化雄戈商城服务端代码与Webhook自动部署配置
这个提交包含在:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro_wechat_trade;
|
||||
|
||||
use addons\shopro_wechat_trade\library\WxOrderPathService;
|
||||
use addons\shopro_wechat_trade\library\WxTradeConfig;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
|
||||
class Config extends Backend
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$list = Db::name('shopro_wechat_trade_config')->select();
|
||||
$data = [];
|
||||
foreach ($list as $item) {
|
||||
$data[$item['name']] = $item['value'];
|
||||
}
|
||||
$mini = Db::name('shopro_config')->where('name', 'wxMiniProgram')->value('value');
|
||||
$mini = json_decode($mini, true);
|
||||
$data['mini_program_app_id'] = $mini['app_id'] ?? '';
|
||||
return $this->success('操作成功', null, $data);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$params = $this->request->post('row/a');
|
||||
if (!$params) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
foreach ($params as $name => $value) {
|
||||
Db::name('shopro_wechat_trade_config')->where('name', $name)->update(['value' => $value]);
|
||||
}
|
||||
WxTradeConfig::reload();
|
||||
$this->success('保存成功');
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
try {
|
||||
$pathService = new WxOrderPathService();
|
||||
$managed = $pathService->isTradeManaged();
|
||||
$path = $pathService->getPath();
|
||||
$this->success('检测完成', null, [
|
||||
'is_trade_managed' => $managed,
|
||||
'order_detail_path' => $path,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$this->error('检测失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function initPath()
|
||||
{
|
||||
try {
|
||||
$result = (new WxOrderPathService())->updatePath();
|
||||
$this->success('订单详情路径已配置', null, $result);
|
||||
} catch (\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
if (preg_match('/\((\d{8})\)/', $msg, $m)) {
|
||||
$msg .= ' — ' . WxOrderPathService::explainPathError($m[1]);
|
||||
}
|
||||
$this->error('配置失败:' . $msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro_wechat_trade;
|
||||
|
||||
use addons\shopro_wechat_trade\library\WxShippingService;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
|
||||
class Sync extends Backend
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$page = max(1, intval($this->request->get('page', 1)));
|
||||
$limit = max(1, min(100, intval($this->request->get('limit', 20))));
|
||||
$status = trim($this->request->get('status', ''));
|
||||
|
||||
$query = Db::name('shopro_wechat_trade_sync')->order('id', 'desc');
|
||||
if ($status !== '') {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
$total = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
|
||||
return json(['total' => $total, 'rows' => $list]);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function retry()
|
||||
{
|
||||
$id = intval($this->request->post('id'));
|
||||
$row = Db::name('shopro_wechat_trade_sync')->where('id', $id)->find();
|
||||
if (!$row) {
|
||||
$this->error('记录不存在');
|
||||
}
|
||||
try {
|
||||
$service = new WxShippingService();
|
||||
if ($row['sync_type'] === 'confirm') {
|
||||
$service->syncOrderConfirm($row['order_id']);
|
||||
} else {
|
||||
$service->syncOrderShipping($row['order_id'], $row['order_item_id']);
|
||||
}
|
||||
$this->success('重试成功');
|
||||
} catch (\Exception $e) {
|
||||
$this->error('重试失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<link rel="stylesheet" href="__CDN__/assets/addons/shopro/libs/element/element.css">
|
||||
<div id="wxTradeConfigIndex" v-cloak style="padding:20px;max-width:960px;">
|
||||
<el-form label-width="180px">
|
||||
<el-divider content-position="left">微信交易合规</el-divider>
|
||||
<el-form-item label="功能开关">
|
||||
<el-switch v-model="form.wechat_trade_enable" active-value="1" inactive-value="0"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form-item label="订单详情路径">
|
||||
<el-input v-model="form.order_detail_path" placeholder="pages/order/detail?id=${商品订单号}"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="失败最大重试">
|
||||
<el-input v-model="form.max_retry"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="重试间隔(秒)">
|
||||
<el-input v-model="form.retry_interval"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="小程序AppID">
|
||||
<el-input v-model="form.mini_program_app_id" readonly></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="save">保存</el-button>
|
||||
<el-button @click="check">检测接入状态</el-button>
|
||||
<el-button @click="initPath">初始化订单路径</el-button>
|
||||
</el-form-item>
|
||||
<el-alert v-if="checkResult" :title="checkResult" type="info" show-icon :closable="false" style="margin-top:10px;"></el-alert>
|
||||
</el-form>
|
||||
</div>
|
||||
<script src="__CDN__/assets/addons/shopro/libs/vue.js"></script>
|
||||
<script src="__CDN__/assets/addons/shopro/libs/element/element.js"></script>
|
||||
<script src="__CDN__/assets/js/backend/shopro_wechat_trade/config.js"></script>
|
||||
@@ -0,0 +1,14 @@
|
||||
<div class="panel panel-default panel-intro">
|
||||
<div class="panel-heading">微信发货/确认收货同步日志</div>
|
||||
<div class="panel-body">
|
||||
<div id="toolbar" class="toolbar">
|
||||
<select id="status-filter" class="form-control" style="width:160px;display:inline-block;">
|
||||
<option value="">全部状态</option>
|
||||
<option value="pending">pending</option>
|
||||
<option value="success">success</option>
|
||||
<option value="failed">failed</option>
|
||||
</select>
|
||||
</div>
|
||||
<table id="table" class="table table-striped table-bordered table-hover" width="100%"></table>
|
||||
</div>
|
||||
</div>
|
||||
在新工单中引用
屏蔽一个用户