Goods.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. session_start();
  3. if (isset($_SESSION["account"])) {
  4. ?>
  5. <?php require_once('common/header.php'); ?>
  6. <?php require_once('common/sidebar.php'); ?>
  7. <div class="main-content app-content mt-0">
  8. <div class="side-app">
  9. <!--占位-->
  10. <div class="card"> </div>
  11. <!--占位-->
  12. <!-- CONTAINER -->
  13. <div class="main-container container-fluid">
  14. <!--这是获取海报文件-->
  15. <?php
  16. include_once("../untils/conn.php");
  17. mysqli_query($con, "set names utf8");
  18. // 获取poster_url数据
  19. $sql = "SELECT poster_url FROM poster";
  20. $result = mysqli_query($con, $sql);
  21. // 将poster_url存储在一个数组变量中
  22. $poster_urls = array();
  23. while ($row = mysqli_fetch_assoc($result)) {
  24. $poster_urls[] = $row['poster_url'];
  25. }
  26. ?>
  27. <!-- PAGE-HEADER -->
  28. <div class="row row-sm">
  29. <div class="col-lg-12">
  30. <div class="card">
  31. <div class="card-header">
  32. <h3 class="card-title">商品列表</h3></h3>
  33. <a href="#" class="btn btn-info" style="margin-left:20px;" target="_blank" onclick="openShopLink()">号卡店铺</a>
  34. </div>
  35. <div class="card-body">
  36. <div class="table-responsive">
  37. <table class="table table-bordered text-nowrap border-bottom" id="basic-datatable">
  38. <thead>
  39. <tr>
  40. <th class="wd-10p border-bottom-0">商品ID</th>
  41. <th class="wd-10p border-bottom-0">商品主图</th>
  42. <th class="wd-10p border-bottom-0">运营商</th>
  43. <th class="wd-10p border-bottom-0">商品名称</th>
  44. <th class="wd-10p border-bottom-0">介绍</th>
  45. <th class="wd-10p border-bottom-0">商品佣金</th>
  46. <th class="wd-10p border-bottom-0">归属地</th>
  47. <th class="wd-10p border-bottom-0">商品状态</th>
  48. <th class="wd-10p border-bottom-0">商品说明</th>
  49. <th class="wd-10p border-bottom-0">操作</th>
  50. </tr>
  51. </thead>
  52. <tbody id="goods-body">
  53. </tbody>
  54. </table>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- CONTAINER CLOSED -->
  62. </div>
  63. </div>
  64. <!-- MODAL EFFECTS -->
  65. <div class="modal fade" id="modaldemo8">
  66. <div class="modal-dialog modal-dialog-centered text-center" role="document">
  67. <div class="modal-content modal-content-demo">
  68. <div class="modal-header">
  69. <h6 class="modal-title">生成海报</h6>
  70. <button aria-label="Close" class="btn-close" data-bs-dismiss="modal"><span aria-hidden="true">&times;</span></button>
  71. </div>
  72. <div class="modal-body">
  73. <div id="poster-carousel" class="carousel slide" data-bs-ride="carousel">
  74. <div class="carousel-inner">
  75. <?php foreach ($poster_urls as $index => $poster_url) { ?>
  76. <div class="carousel-item <?php if ($index == 0) { echo 'active'; } ?>">
  77. <div class="poster-image-container" style="position: relative;">
  78. <img class="poster-image" src="<?php echo $poster_url; ?>" alt="Poster <?php echo ($index + 1); ?>">
  79. <img class="qr-code-image" src="" alt="QR Code" style="position: absolute; bottom: 20; right: 20; width: 100px; height: 100px;">
  80. </div>
  81. </div>
  82. <?php } ?>
  83. </div>
  84. <a class="carousel-control-prev" href="#poster-carousel" role="button" data-bs-slide="prev">
  85. <span class="carousel-control-prev-icon" aria-hidden="true"></span>
  86. <span class="visually-hidden">上一张</span>
  87. </a>
  88. <a class="carousel-control-next" href="#poster-carousel" role="button" data-bs-slide="next">
  89. <span class="carousel-control-next-icon" aria-hidden="true"></span>
  90. <span class="visually-hidden">下一张</span>
  91. </a>
  92. </div>
  93. </div>
  94. <div class="modal-footer">
  95. <button class="btn btn-primary" onclick="savePoster()">保存本地</button>
  96. <button class="btn btn-light" data-bs-dismiss="modal">取消</button>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <?php
  102. session_start();
  103. include_once("../untils/conn.php");
  104. mysqli_query($con, "set names utf8");
  105. // 获取当前正在登录的账号信息的代理
  106. $proxy_acc = $_SESSION["account"];
  107. // 查询proxy表中的数据
  108. $query = "SELECT proxy_rename_sta FROM proxy WHERE proxy_acc = '$proxy_acc'";
  109. $result = mysqli_query($con, $query);
  110. $row = mysqli_fetch_assoc($result);
  111. if ($row) {
  112. $proxy_rename_sta = $row['proxy_rename_sta'];
  113. ?>
  114. <div class="modal fade" id="modaldemo5" data-bs-backdrop="static" data-bs-keyboard="false">
  115. <div class="modal-dialog modal-dialog-centered text-center" role="document">
  116. <div class="modal-content tx-size-sm">
  117. <div class="modal-body text-center p-4 pb-5">
  118. <i class="icon icon-close fs-70 text-danger lh-1 my-5 d-inline-block"></i>
  119. <h4 class="text-danger">警告: 您的账号未实名!</h4>
  120. <p class="mg-b-20 mg-x-20">平台要求所有代理商必须实名!否则无法使用平台功能!</p>
  121. <a href="profile.php" class="btn btn-primary pd-x-25">去实名</a>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. <!--/div-->
  127. <script src="assets/js/jquery.min.js"></script>
  128. <script>
  129. var puid = ''; // 定义全局变量puid
  130. $.ajax({
  131. url: "controller/public/GetPuid.php",
  132. type: "POST",
  133. dataType: "json",
  134. success: function(res) {
  135. // 获取成功后的代码
  136. puid = res.puid; // 将获取到的puid保存到全局变量中
  137. },
  138. error: function() {
  139. // 获取失败后的代码
  140. alert("获取puid失败");
  141. }
  142. });
  143. $.ajax({
  144. url: "controller/Goods.php",
  145. type: "POST",
  146. dataType: "json",
  147. success: function(data) {
  148. // 获取成功后的代码
  149. var protocol = location.protocol; // 获取当前页面的协议
  150. var hostname = location.hostname; // 获取当前页面的主机名
  151. for (var i = 0; i < data.length; i++) {
  152. var item = data[i];
  153. var state = "";
  154. var button = "";
  155. if (item.state == 0) {
  156. state = "上架中";
  157. button = '<a href="controller/Proxy_upstate.php?id=' + item.id + '&puid=' + puid + '&status=1" class="btn btn-danger">下架</a>';
  158. } else if (item.state == 1) {
  159. state = "已下架";
  160. button = '<a href="controller/Proxy_upstate.php?id=' + item.id + '&puid=' + puid + '&status=0" class="btn btn-primary">上架</a>';
  161. } else {
  162. state = "未知状态";
  163. }
  164. var orderLink = protocol + '//' + hostname + '/shop/links.php?goodsid=' + item.id + '&puid=' + puid;
  165. var orderButton = '<a href="' + orderLink + '" target="_blank" class="btn btn-warning">下单链接</a>';
  166. var html = '<tr>'+
  167. '<td>'+ item.id +'</td>'+
  168. '<td><img style="width:60px;" src="'+ item.zhutu +'"></td>'+
  169. '<td>'+ item.yys +'</td>'+
  170. '<td>'+ item.name +'</td>'+
  171. '<td>'+ item.intro +'</td>'+
  172. '<td>¥'+ item.price +'</td>'+
  173. '<td>'+ item.gsd +'</td>'+
  174. '<td>'+ state +'</td>'+
  175. '<td>'+ item.notes +'</td>'+
  176. '<td>'+ button + orderButton +
  177. '<a class="btn btn-success" data-bs-effect="effect-scale" data-bs-toggle="modal" href="#modaldemo8" onclick="generateQRCode(\'' + orderLink + '\')">生成海报</a></td>'+
  178. '</tr>';
  179. $("#goods-body").append(html);
  180. }
  181. },
  182. error: function() {
  183. // 获取失败后的代码
  184. alert("获取商品信息失败");
  185. }
  186. });
  187. function generateQRCode(orderLink) {
  188. $.ajax({
  189. url: "controller/QRcode.php",
  190. type: "POST",
  191. data: {
  192. orderLink: orderLink
  193. },
  194. dataType: "json", // 指定返回数据的类型为JSON
  195. success: function(data) {
  196. // data.qrCodeBase64 是二维码的base64编码
  197. $(".qr-code-image").attr("src", "data:image/png;base64," + data.qrCodeBase64);
  198. }
  199. });
  200. }
  201. $(document).ready(function() {
  202. <?php
  203. if ($proxy_rename_sta == 0) {
  204. // 未实名认证
  205. echo '$("#modaldemo5").modal("show");';
  206. echo '$("#modaldemo5").modal({backdrop: "static", keyboard: false});';
  207. } elseif ($proxy_rename_sta == 1) {
  208. // 已实名认证
  209. echo '$("#modaldemo5").modal("hide");';
  210. }
  211. ?>
  212. });
  213. function savePoster() {
  214. var canvas = document.createElement('canvas');
  215. var ctx = canvas.getContext('2d');
  216. // 获取当前显示的海报和二维码图像元素
  217. var activeCarouselItem = document.querySelector('.carousel-item.active');
  218. var posterImage = activeCarouselItem.querySelector('.poster-image');
  219. var qrCodeImage = activeCarouselItem.querySelector('.qr-code-image');
  220. // 获取海报图像的实际大小
  221. var posterWidth = posterImage.naturalWidth;
  222. var posterHeight = posterImage.naturalHeight;
  223. // 获取设备像素比
  224. var dpr = window.devicePixelRatio || 1;
  225. // 设置canvas的像素大小以匹配海报的实际大小,并增加像素密度
  226. var canvasWidth = posterWidth * dpr;
  227. var canvasHeight = posterHeight * dpr;
  228. canvas.width = canvasWidth;
  229. canvas.height = canvasHeight;
  230. // 缩放context以适应设备像素比
  231. ctx.scale(dpr, dpr);
  232. // 在canvas上绘制海报
  233. ctx.drawImage(posterImage, 0, 0, canvasWidth, canvasHeight);
  234. // 获取二维码图像的实际大小(不考虑像素密度)
  235. var qrCodeWidth = qrCodeImage.naturalWidth;
  236. var qrCodeHeight = qrCodeImage.naturalHeight;
  237. // 缩小二维码的大小
  238. var qrCodeScale = 0.5; // 调整这个比例以缩小二维码的大小
  239. qrCodeWidth *= qrCodeScale;
  240. qrCodeHeight *= qrCodeScale;
  241. // 计算二维码在canvas上的位置和大小,以适应高像素密度的绘制
  242. var qrCodeX = (posterWidth - qrCodeWidth) * dpr - 30; // 向左偏移20个像素
  243. var qrCodeY = (posterHeight - qrCodeHeight) * dpr - 30; // 向上偏移20个像素
  244. var qrCodeWidthScaled = qrCodeWidth * dpr;
  245. var qrCodeHeightScaled = qrCodeHeight * dpr;
  246. ctx.drawImage(
  247. qrCodeImage,
  248. qrCodeX,
  249. qrCodeY,
  250. qrCodeWidthScaled,
  251. qrCodeHeightScaled
  252. );
  253. // 创建一个新的图像文件并下载它
  254. var link = document.createElement('a');
  255. link.href = canvas.toDataURL('image/png');
  256. link.download = 'liuyueyanyan_powerby_gzking.png';
  257. link.click();
  258. }
  259. </script>
  260. <?php
  261. } else {
  262. // 未找到相关数据
  263. // echo '数据不存在';
  264. }
  265. ?>
  266. <script>
  267. function openShopLink() {
  268. var url = "../shop/index.php?puid=" + puid;
  269. window.open(url, '_blank');
  270. }
  271. </script>
  272. <?php require_once('common/footer.php'); ?>
  273. <?php
  274. } else {
  275. echo "<script>alert('登录过过期,没有权限访问该页面');location.href='login.html';</script>";
  276. }