文件
xionggeshop/application/admin/controller/shopro_wechat_trade/Sync.php

50 行
1.5 KiB
PHP

<?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());
}
}
}