添加本地生活二维码图片下载功能

This commit is contained in:
wangxiaowei 2024-08-02 00:11:55 +08:00
parent 420565d88c
commit 7f528f2d11
4 changed files with 65 additions and 39 deletions

@ -7,9 +7,9 @@ use app\common\server\ConfigServer;
use app\common\enum\LocalLifeICBCEnum;
use app\admin\logic\shop\LocalStoreLogic;
use app\common\server\JsonServer;
use app\shop\logic\order\InvoiceLogic;
use think\facade\Request;
class LocalStore extends AdminBase
{
public function lists()
@ -47,23 +47,6 @@ class LocalStore extends AdminBase
]);
}
/**
* @notes 删除本地生活
*/
public function del()
{
if ($this->request->isAjax()) {
$id = $this->request->post('id');
try {
if (LocalStoreLogic::del_data($id)) {
return JsonServer::success('操作成功');
}
} catch (\Exception $e) {
return JsonServer::error('操作失败');
}
}
}
/**
* @notes 审核操作
*/
@ -74,10 +57,11 @@ class LocalStore extends AdminBase
if (in_array($post['state'], LocalStoreLogic::$STATE_ENUM)) {
if ($post['state'] == 1) {
$data = LocalStoreLogic::get_data($post['id']);
Request::post('https://dlh.hainings.com/shop/abutment/test', [
$result = Request::post('https://dlh.hainings.com/shop/abutment.abutment/test', [
'empowerPhone' => $data['empowerPhone'],
'crftNo1' => $data['crftNo1']
]);
}
if (LocalStoreLogic::update_state($post['id'], $post['state'])) {
return JsonServer::success('操作成功');
@ -105,4 +89,20 @@ class LocalStore extends AdminBase
}
return JsonServer::success('', $result);
}
public function downloadErCode()
{
if ($this->request->isAjax()) {
$post = $this->request->post();
if ($post['lstore_id'] > 0){
$result = LocalStoreLogic::getPayImage($post['lstore_id']);
if ($result['pay_image']) {
$path = parse_url($result['pay_image'])['path'];
$url = (string)url("index/download/downloadLocalStoreErcodeImage", ['url' => $path], false, true);
return JsonServer::success('', ['url' => $url]);
}
return JsonServer::error('下载失败');
}
}
}
}

@ -17,7 +17,7 @@ class LocalStoreLogic extends Logic
public static function lists()
{
return array(
'lists' => LocalStore::where(['del' => 0])->with('info')->select()->toArray()
'lists' => LocalStore::with('info')->select()->toArray()
);
}
@ -31,19 +31,7 @@ class LocalStoreLogic extends Logic
return LocalStore::where(['lstore_id' => $id])->update(['store_state' => $state]);
}
/**
* @notes 删除本地商家数据
*/
public static function del_data($id) {
return LocalStore::where(['lstore_id' => $id, 'del' => 0])->update([
'del' => 1,
'del_time' => date('Y-m-d H:i:s')
]);
}
/**
* @notes 获取未审核数据
*/
// 获取未审核数据
public static function get_unaudited_data()
{
return LocalStore::where(['store_state' => 0])->count();
@ -100,4 +88,9 @@ class LocalStoreLogic extends Logic
return false;
}
}
public static function getPayImage($lstore_id)
{
return LocalStore::where('lstore_id', $lstore_id)->field('pay_image')->find()->toArray();
}
}

@ -26,9 +26,8 @@
<table id="like-table-lists" lay-filter="like-table-lists"></table>
<script type="text/html" id="localstore-operation">
<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
<script type="text/html" id="table-operation">
<a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="download">下载二维码</a>
</script>
</div>
</div>
@ -49,8 +48,39 @@
, {field: "tips", width: 300, align: "center", title: "交易附言"}
, {field: "notes", width: 300, align: "center", title: "备注"}
, {field: "create_time", width: 300, align: "center", title: "创建时间"}
,{title:"操作", width:200, align:"center", fixed:"right", toolbar:"#table-operation"}
]);
var active = {
download: function(obj) {
like.ajax({
url: "{:url('shop.LocalStore/downloadErCode')}",
data: obj.data,
type: "POST",
success:function(res) {
if(res.code == 1) {
console.log(res.data.url)
// console.log(123)
// const image = new Image()
// image.src = res.data.pay_image;
// image.onload = function () {
// const link = document.createElement('a')
// link.style.display = 'none'
// document.body.appendChild(link)
//
// link.setAttribute('download', 'erCode.jpg')
// link.setAttribute('href', res.data.pay_image)
//
// link.click()
// }
window.location.href = res.data.url;
}
}
});
},
};
like.eventClick(active);
// 导出
form.on('submit(data-export)', function (data) {
var field = data.field;

@ -39,17 +39,20 @@ class Download extends IndexBase
//通过文件缓存的key获取文件储存的路径
$exportCache = new ExportCache($fileKey);
$fileInfo = $exportCache->getFile($fileKey);
if (empty($fileInfo)) {
abort(404, '下载文件不存在');
}
//下载前删除缓存
$exportCache->del($fileKey);
return download($fileInfo['src'] . $fileInfo['name'], $fileInfo['name']);
}
public function downloadLocalStoreErcodeImage()
{
$url = request()->get('url');
$path = public_path() . ltrim($url, '/');
return download($path, basename($url));
}
}