wang hou sheng 7 months ago
parent 3d6245d999
commit bb0973b403
  1. 9
      app/api/controller/StoreKeeper.php
  2. 26
      app/common/library/wechat/ShortLink.php
  3. 8
      app/store/controller/Order.php

@ -13,7 +13,9 @@ declare (strict_types=1);
namespace app\api\controller; namespace app\api\controller;
use app\common\enum\RecoveryStatusEnum; use app\common\enum\RecoveryStatusEnum;
use app\common\library\wechat\ShortLink;
use app\common\model\UploadFile; 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 as ArticleModel;
use app\store\model\article\Category as CategoryModel; use app\store\model\article\Category as CategoryModel;
use app\store\model\dealer\Order as DealerOrderModel; use app\store\model\dealer\Order as DealerOrderModel;
@ -193,6 +195,11 @@ class StoreKeeper extends Controller
return $this->renderSuccess(compact('list')); return $this->renderSuccess(compact('list'));
} else { } else {
$model = new OrderModel; $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); $list = $model->getNewList($params);
if (!empty($list['data'])) { if (!empty($list['data'])) {
foreach ($list['data'] as $key => $value) { foreach ($list['data'] as $key => $value) {
@ -220,6 +227,7 @@ class StoreKeeper extends Controller
$copy_text .= "单价:{$good['goods_price']}\n"; $copy_text .= "单价:{$good['goods_price']}\n";
$copy_text .= "数量:{$good['total_num']}\n"; $copy_text .= "数量:{$good['total_num']}\n";
$copy_text .= "总价:{$good['total_price']}\n"; $copy_text .= "总价:{$good['total_price']}\n";
$copy_text .= "商品链接:" . $link_obj->shortUrl("/pages/goods/detail?goodsId=" . $good['goods_id'], '商品详情');
$copy_text .= "\n"; $copy_text .= "\n";
} }
if (!empty($value['address'])) { if (!empty($value['address'])) {
@ -232,6 +240,7 @@ class StoreKeeper extends Controller
} }
$copy_text .= "地址:$address{$value['address']['detail']}\n"; $copy_text .= "地址:$address{$value['address']['detail']}\n";
} }
$list['data'][$key]['copy_text'] = $copy_text; $list['data'][$key]['copy_text'] = $copy_text;
} }
} }

@ -0,0 +1,26 @@
<?php
namespace app\common\library\wechat;
use app\common\library\helper;
class ShortLink extends WxBase
{
public function shortUrl($page_url, $page_title, $is_permanent = false)
{
$accessToken = $this->getAccessToken();
$url = "https://api.weixin.qq.com/wxa/genwxashortlink?access_token=$accessToken";
$data = [
'page_url' => $page_url,
'page_title' => $page_title,
'is_permanent' => $is_permanent,
];
$result = $this->post($url, helper::jsonEncode($data));
$response = $this->jsonDecode($result);
if (!empty($response['link'])) {
return $response['link'];
}
return $response['errmsg'] ?? '';
}
}

@ -12,6 +12,8 @@ declare (strict_types=1);
namespace app\store\controller; 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 app\store\model\Order as OrderModel;
use think\response\Json; use think\response\Json;
@ -33,6 +35,11 @@ class Order extends Controller
$model = new OrderModel; $model = new OrderModel;
$result = $model->getList($this->request->param()); $result = $model->getList($this->request->param());
$data = $result->items(); $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)) { if (!empty($data)) {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$data[$key]['address_match_text'] = '--'; $data[$key]['address_match_text'] = '--';
@ -45,6 +52,7 @@ class Order extends Controller
$copy_text .= "单价:{$good['goods_price']}\n"; $copy_text .= "单价:{$good['goods_price']}\n";
$copy_text .= "数量:{$good['total_num']}\n"; $copy_text .= "数量:{$good['total_num']}\n";
$copy_text .= "总价:{$good['total_price']}\n"; $copy_text .= "总价:{$good['total_price']}\n";
$copy_text .= "商品链接:" . $link_obj->shortUrl("/pages/goods/detail?goodsId=" . $good['goods_id'], '商品详情');
$copy_text .= "\n"; $copy_text .= "\n";
} }
if (!empty($value['address'])) { if (!empty($value['address'])) {

Loading…
Cancel
Save