From 0bb80ca2d5e7d98a6cf63a930426f65fef34b14b Mon Sep 17 00:00:00 2001 From: wang hou sheng <76928547+wanghousheng@users.noreply.github.com> Date: Sun, 12 May 2024 17:05:45 +0800 Subject: [PATCH] 1 --- app/api/controller/Goods.php | 19 +++++++++++++++++++ app/api/controller/StoreKeeper.php | 8 -------- app/store/controller/Order.php | 8 -------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index 26b4d27b..2a093948 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -15,8 +15,10 @@ namespace app\api\controller; use app\api\model\{Goods as GoodsModel, Store as StoreModel}; use app\api\model\Region; use app\api\service\{Goods as GoodsService, User as UserService}; +use app\common\library\wechat\ShortLink; use app\common\model\GoodsImage as GoodsImageModel; use app\common\model\UploadFile as UploadFileModel; +use app\common\model\wxapp\Setting as WxappSettingModel; use app\common\service\qrcode\Goods as GoodsPoster; use cores\exception\BaseException; use think\db\exception\DbException; @@ -383,5 +385,22 @@ class Goods extends Controller return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]); } + public function shortUrl(): Json + { + $page_url = $this->request->post('page_url'); + if (empty($page_url)) { + return $this->renderError('缺少参数page_url'); + } + $page_title = $this->request->post('page_title'); + if (empty($page_title)) { + return $this->renderError('缺少参数page_title'); + } + $store_id = GoodsModel::$storeId; + $wxConfig = WxappSettingModel::getConfigBasic($store_id); + // 请求api获取短连接 + $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); + $url = $link_obj->shortUrl($page_url, $page_title); + return $this->renderSuccess(['url' => $url]); + } } diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index fbd47bbb..aa68e2d2 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -13,9 +13,7 @@ declare (strict_types=1); namespace app\api\controller; use app\common\enum\RecoveryStatusEnum; -use app\common\library\wechat\ShortLink; use app\common\model\UploadFile; -use app\common\model\wxapp\Setting as WxappSettingModel; use app\store\model\Article as ArticleModel; use app\store\model\article\Category as CategoryModel; use app\store\model\dealer\Order as DealerOrderModel; @@ -195,11 +193,6 @@ class StoreKeeper extends Controller return $this->renderSuccess(compact('list')); } else { $model = new OrderModel; - $store_id = OrderModel::$storeId; - // 小程序配置信息 - $wxConfig = WxappSettingModel::getConfigBasic($store_id); - // 请求api获取短连接 - $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); $list = $model->getNewList($params); if (!empty($list['data'])) { foreach ($list['data'] as $key => $value) { @@ -227,7 +220,6 @@ class StoreKeeper extends Controller $copy_text .= "单价:{$good['goods_price']}\n"; $copy_text .= "数量:{$good['total_num']}\n"; $copy_text .= "总价:{$good['total_price']}\n"; - $copy_text .= "商品链接:" . $link_obj->shortUrl("/pages/goods/detail?goodsId=" . $good['goods_id'], '商品详情'); $copy_text .= "\n"; } if (!empty($value['address'])) { diff --git a/app/store/controller/Order.php b/app/store/controller/Order.php index 4d85ad86..999b7e18 100644 --- a/app/store/controller/Order.php +++ b/app/store/controller/Order.php @@ -12,8 +12,6 @@ declare (strict_types=1); namespace app\store\controller; -use app\common\library\wechat\ShortLink; -use app\common\model\wxapp\Setting as WxappSettingModel; use app\store\model\Order as OrderModel; use think\response\Json; @@ -35,11 +33,6 @@ class Order extends Controller $model = new OrderModel; $result = $model->getList($this->request->param()); $data = $result->items(); - $store_id = OrderModel::$storeId; - // 小程序配置信息 - $wxConfig = WxappSettingModel::getConfigBasic($store_id); - // 请求api获取短连接 - $link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']); if (!empty($data)) { foreach ($data as $key => $value) { $data[$key]['address_match_text'] = '--'; @@ -52,7 +45,6 @@ class Order extends Controller $copy_text .= "单价:{$good['goods_price']}\n"; $copy_text .= "数量:{$good['total_num']}\n"; $copy_text .= "总价:{$good['total_price']}\n"; - $copy_text .= "商品链接:" . $link_obj->shortUrl("pages/goods/detail?goodsId=" . $good['goods_id'], '商品详情'); $copy_text .= "\n"; } if (!empty($value['address'])) {