<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>雕木乱</title><link>https://www.zhangkeda.com/</link><description>–   我们都值得被尊重，哪怕是一坨拉稀的屎</description><item><title>uni-app如何将整个页面保存为图片，并且公众号h5中保存图片到相册</title><link>https://www.zhangkeda.com/?id=571</link><description>&lt;p style=&quot;margin-top: 0px; margin-bottom: 1em; font-size: 15px; word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.7em; overflow: auto; color: rgb(51, 51, 51); font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; background-color: rgb(255, 255, 255);&quot;&gt;在 UniApp 中，可以通过 &lt;code style=&quot;padding: 4px 6px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; color: black; border-radius: 1px; white-space: nowrap; background: none rgb(252, 250, 250); border: none; margin: 0px 1px;&quot;&gt;html2canvas&lt;/code&gt; 的替代方案或原生 API 实现将整个页面保存为图片。由于 UniApp 跨平台特性，不同平台（如 H5、小程序）的实现方式不同。以下是具体方法：&lt;/p&gt;&lt;h3 style=&quot;margin: 30px 0px 15px; font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; line-height: 40px; color: rgb(51, 51, 51); text-rendering: optimizelegibility; font-size: 20px; border-bottom: 1px solid rgb(238, 238, 238); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1.&amp;nbsp;&lt;strong&gt;H5 平台&lt;/strong&gt;&lt;/h3&gt;&lt;p style=&quot;margin-top: 1em; margin-bottom: 1em; font-size: 15px; word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.7em; overflow: auto; color: rgb(51, 51, 51); font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; background-color: rgb(255, 255, 255);&quot;&gt;使用 &lt;code style=&quot;padding: 4px 6px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; color: black; border-radius: 1px; white-space: nowrap; background: none rgb(252, 250, 250); border: none; margin: 0px 1px;&quot;&gt;html2canvas&lt;/code&gt; 库捕获 DOM 并生成图片：&lt;/p&gt;&lt;pre class=&quot;prettyprint language-javascript&quot; style=&quot;padding: 0px 15px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; color: rgb(51, 51, 51); border-radius: 0px; margin: 20px -10px; line-height: 22px; word-break: break-all; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(247, 247, 247); border-width: 1px 0px; border-style: none; border-color: initial; border-image: initial; tab-size: 4;&quot;&gt;//&amp;nbsp;安装&amp;nbsp;html2canvas：npm&amp;nbsp;install&amp;nbsp;html2canvasimport&amp;nbsp;html2canvas&amp;nbsp;from&amp;nbsp;&amp;#39;html2canvas&amp;#39;;//&amp;nbsp;方法示例async&amp;nbsp;function&amp;nbsp;capturePage()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;const&amp;nbsp;element&amp;nbsp;=&amp;nbsp;document.getElementById(&amp;#39;capture-area&amp;#39;);&amp;nbsp;//&amp;nbsp;指定要截图的区域
&amp;nbsp;&amp;nbsp;const&amp;nbsp;canvas&amp;nbsp;=&amp;nbsp;await&amp;nbsp;html2canvas(element,&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;useCORS:&amp;nbsp;true,&amp;nbsp;//&amp;nbsp;允许跨域图片
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;scale:&amp;nbsp;2&amp;nbsp;//&amp;nbsp;提高清晰度
&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;//&amp;nbsp;转换为图片并下载
&amp;nbsp;&amp;nbsp;const&amp;nbsp;imgData&amp;nbsp;=&amp;nbsp;canvas.toDataURL(&amp;#39;image/png&amp;#39;);
&amp;nbsp;&amp;nbsp;const&amp;nbsp;link&amp;nbsp;=&amp;nbsp;document.createElement(&amp;#39;a&amp;#39;);
&amp;nbsp;&amp;nbsp;link.href&amp;nbsp;=&amp;nbsp;imgData;
&amp;nbsp;&amp;nbsp;link.download&amp;nbsp;=&amp;nbsp;&amp;#39;page-screenshot.png&amp;#39;;
&amp;nbsp;&amp;nbsp;link.click();}&lt;/pre&gt;&lt;h3 style=&quot;margin: 30px 0px 15px; font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; line-height: 40px; color: rgb(51, 51, 51); text-rendering: optimizelegibility; font-size: 20px; border-bottom: 1px solid rgb(238, 238, 238); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2.&amp;nbsp;&lt;strong&gt;微信小程序平台&lt;/strong&gt;&lt;/h3&gt;&lt;p style=&quot;margin-top: 1em; margin-bottom: 1em; font-size: 15px; word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.7em; overflow: auto; color: rgb(51, 51, 51); font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; background-color: rgb(255, 255, 255);&quot;&gt;使用小程序的 &lt;code style=&quot;padding: 4px 6px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; color: black; border-radius: 1px; white-space: nowrap; background: none rgb(252, 250, 250); border: none; margin: 0px 1px;&quot;&gt;canvas&lt;/code&gt; 组件和 API：&lt;/p&gt;&lt;pre class=&quot;prettyprint language-html&quot; style=&quot;padding: 0px 15px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; color: rgb(51, 51, 51); border-radius: 0px; margin: 20px -10px; line-height: 22px; word-break: break-all; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(247, 247, 247); border-width: 1px 0px; border-style: none; border-color: initial; border-image: initial; tab-size: 4;&quot;&gt;&amp;lt;!--&amp;nbsp;在模板中添加&amp;nbsp;canvas&amp;nbsp;--&amp;gt;&amp;lt;canvas&amp;nbsp;id=&amp;quot;myCanvas&amp;quot;&amp;nbsp;canvas-id=&amp;quot;myCanvas&amp;quot;&amp;nbsp;style=&amp;quot;width:100%;height:100vh;&amp;quot;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/pre&gt;&lt;pre class=&quot;prettyprint language-javascript&quot; style=&quot;padding: 0px 15px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; color: rgb(51, 51, 51); border-radius: 0px; margin: 20px -10px; line-height: 22px; word-break: break-all; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(247, 247, 247); border-width: 1px 0px; border-style: none; border-color: initial; border-image: initial; tab-size: 4;&quot;&gt;//&amp;nbsp;在&amp;nbsp;methods&amp;nbsp;中定义方法methods:&amp;nbsp;{
&amp;nbsp;&amp;nbsp;savePageAsImage()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;query&amp;nbsp;=&amp;nbsp;uni.createSelectorQuery().in(this);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;query.select(&amp;#39;#capture-area&amp;#39;).fields({&amp;nbsp;node:&amp;nbsp;true,&amp;nbsp;size:&amp;nbsp;true&amp;nbsp;}).exec(res&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;node&amp;nbsp;=&amp;nbsp;res[0].node;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建&amp;nbsp;canvas&amp;nbsp;上下文
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const&amp;nbsp;ctx&amp;nbsp;=&amp;nbsp;uni.createCanvasContext(&amp;#39;myCanvas&amp;#39;,&amp;nbsp;this);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ctx.drawImage(node,&amp;nbsp;0,&amp;nbsp;0,&amp;nbsp;300,&amp;nbsp;200);&amp;nbsp;//&amp;nbsp;调整尺寸
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ctx.draw(false,&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;保存到相册
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;uni.canvasToTempFilePath({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;canvasId:&amp;nbsp;&amp;#39;myCanvas&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;success:&amp;nbsp;res&amp;nbsp;=&amp;gt;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;uni.saveImageToPhotosAlbum({
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;filePath:&amp;nbsp;res.tempFilePath,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;success:&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;uni.showToast({&amp;nbsp;title:&amp;nbsp;&amp;#39;保存成功&amp;#39;&amp;nbsp;})
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;h3 style=&quot;margin: 30px 0px 15px; font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; line-height: 40px; color: rgb(51, 51, 51); text-rendering: optimizelegibility; font-size: 20px; border-bottom: 1px solid rgb(238, 238, 238); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;注意事项：&lt;/h3&gt;&lt;ul style=&quot;padding: 0px; margin-bottom: 10px; margin-left: 25px; color: rgb(51, 51, 51); font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;跨平台兼容性&lt;/strong&gt;：需通过条件编译区分平台（&lt;code style=&quot;padding: 4px 6px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; color: black; border-radius: 3px; text-wrap: nowrap; background-color: rgb(252, 250, 250); border: none;&quot;&gt;#ifdef H5&lt;/code&gt;、&lt;code style=&quot;padding: 4px 6px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; color: black; border-radius: 3px; text-wrap: nowrap; background-color: rgb(252, 250, 250); border: none;&quot;&gt;#ifdef MP-WEIXIN&lt;/code&gt;）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;权限问题&lt;/strong&gt;：小程序需用户授权相册权限（&lt;code style=&quot;padding: 4px 6px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; color: black; border-radius: 3px; text-wrap: nowrap; background-color: rgb(252, 250, 250); border: none;&quot;&gt;scope.writePhotosAlbum&lt;/code&gt;）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;性能优化&lt;/strong&gt;：复杂页面可能渲染较慢，建议隐藏非必要元素。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;margin: 30px 0px 15px; font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; line-height: 40px; color: rgb(51, 51, 51); text-rendering: optimizelegibility; font-size: 20px; border-bottom: 1px solid rgb(238, 238, 238); text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;完整示例（H5 + 微信小程序）：&lt;/h3&gt;&lt;pre class=&quot;prettyprint language-javascript&quot; style=&quot;padding: 0px 15px; font-family: Monaco, Menlo, Consolas, &amp;quot;Courier New&amp;quot;, monospace; color: rgb(51, 51, 51); border-radius: 0px; margin: 20px -10px; line-height: 22px; word-break: break-all; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(247, 247, 247); border-width: 1px 0px; border-style: none; border-color: initial; border-image: initial; tab-size: 4;&quot;&gt;export&amp;nbsp;default&amp;nbsp;{
&amp;nbsp;&amp;nbsp;methods:&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;savePage()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;#ifdef&amp;nbsp;H5
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.captureH5Page();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;#endif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;#ifdef&amp;nbsp;MP-WEIXIN
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.captureMiniProgramPage();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;#endif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;captureH5Page()&amp;nbsp;{&amp;nbsp;/*&amp;nbsp;H5&amp;nbsp;实现&amp;nbsp;*/&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;captureMiniProgramPage()&amp;nbsp;{&amp;nbsp;/*&amp;nbsp;小程序实现&amp;nbsp;*/&amp;nbsp;}
&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;p style=&quot;margin-top: 1em; margin-bottom: 1em; font-size: 15px; word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; line-height: 1.7em; overflow: auto; color: rgb(51, 51, 51); font-family: &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Luxi Sans&amp;quot;, &amp;quot;DejaVu Sans&amp;quot;, Tahoma, &amp;quot;Hiragino Sans GB&amp;quot;, STHeiti, sans-serif; background-color: rgb(255, 255, 255);&quot;&gt;通过以上方法，即可在 UniApp 中实现页面保存为图片功能。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot; data-pm-slice=&quot;1 1 [&amp;quot;para&amp;quot;,{&amp;quot;tagName&amp;quot;:&amp;quot;p&amp;quot;,&amp;quot;attributes&amp;quot;:{},&amp;quot;namespaceURI&amp;quot;:&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;}]&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 18px;letter-spacing: 1px;font-weight: bold&quot;&gt;#&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 18px;letter-spacing: 1px;font-weight: bold&quot;&gt;技术来源&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;先说如何把&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot; data-pm-slice=&quot;1 1 [&amp;quot;para&amp;quot;,{&amp;quot;tagName&amp;quot;:&amp;quot;p&amp;quot;,&amp;quot;attributes&amp;quot;:{},&amp;quot;namespaceURI&amp;quot;:&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;}]&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;整个页面变成图片，因为重新去做一个&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;canvas去塞入众多内容不如直接把&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;将整个页面保存为图片&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;用到技术来自文章：《&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;uniapp如何实现将整个页面保存为图片功能&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;》&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;section&gt;&lt;section class=&quot;code-snippet__fix code-snippet__js&quot;&gt;&lt;ul class=&quot;code-snippet__line-index code-snippet__js list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre data-lang=&quot;javascript&quot;&gt;https://bbs.itying.com/topic/690343544a7a41007019982a&lt;/pre&gt;&lt;/section&gt;&lt;/section&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;原理基本也就是把整个图片放入画布转成图片&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;H5平台&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;section class=&quot;code-snippet__fix code-snippet__js&quot;&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;pre data-lang=&quot;javascript&quot;&gt;&lt;code&gt;// 安装 html2canvas：npm install html2canvas&lt;/code&gt;&lt;code&gt;import&amp;nbsp;html2canvas&amp;nbsp;from&amp;nbsp;&amp;#39;html2canvas&amp;#39;;&lt;/code&gt;&lt;code&gt;// 方法示例&lt;/code&gt;&lt;code&gt;async&amp;nbsp;function&amp;nbsp;capturePage() {&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&amp;nbsp;const&amp;nbsp;element =&amp;nbsp;document.getElementById(&amp;#39;capture-area&amp;#39;);&amp;nbsp;// 指定要截图的区域&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;const&amp;nbsp;canvas =&amp;nbsp;await&amp;nbsp;html2canvas(element, {&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;useCORS:&amp;nbsp;true,&amp;nbsp;// 允许跨域图片&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;scale:&amp;nbsp;2&amp;nbsp;// 提高清晰度&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp; });&lt;/code&gt;&lt;code&gt;&lt;br/&gt;&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&amp;nbsp;// 转换为图片并下载&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;const&amp;nbsp;imgData = canvas.toDataURL(&amp;#39;image/png&amp;#39;);&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;const&amp;nbsp;link =&amp;nbsp;document.createElement(&amp;#39;a&amp;#39;);&lt;/code&gt;&lt;code&gt;&amp;nbsp; link.href&amp;nbsp;= imgData;&lt;/code&gt;&lt;code&gt;&amp;nbsp; link.download&amp;nbsp;=&amp;nbsp;&amp;#39;page-screenshot.png&amp;#39;;&lt;/code&gt;&lt;code&gt;&amp;nbsp; link.click();&lt;/code&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/section&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;微信小程序平台&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;section class=&quot;code-snippet__fix code-snippet__js&quot;&gt;&lt;p&gt;&lt;/p&gt;&lt;ul class=&quot;code-snippet__line-index code-snippet__js list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre data-lang=&quot;xml&quot;&gt;&amp;lt;!--&amp;nbsp;在模板中添加&amp;nbsp;canvas&amp;nbsp;--&amp;gt;&amp;lt;canvas&amp;nbsp;id=&amp;quot;myCanvas&amp;quot;&amp;nbsp;canvas-id=&amp;quot;myCanvas&amp;quot;&amp;nbsp;style=&amp;quot;width:100%;height:100vh;&amp;quot;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/pre&gt;&lt;/section&gt;&lt;section class=&quot;code-snippet__fix code-snippet__js&quot;&gt;&lt;ul class=&quot;code-snippet__line-index code-snippet__js list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre data-lang=&quot;javascript&quot;&gt;&lt;code&gt;// 在 methods 中定义方法&lt;/code&gt;&lt;code&gt;methods: {&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;savePageAsImage() {&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;const&amp;nbsp;query = uni.createSelectorQuery().in(this);&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; query.select(&amp;#39;#capture-area&amp;#39;).fields({&amp;nbsp;node:&amp;nbsp;true,&amp;nbsp;size:&amp;nbsp;true&amp;nbsp;}).exec(res&amp;nbsp;=&amp;gt;&amp;nbsp;{&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;const&amp;nbsp;node = res[0].node;&lt;/code&gt;&lt;code&gt;&lt;br/&gt;&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;// 创建 canvas 上下文&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;const&amp;nbsp;ctx = uni.createCanvasContext(&amp;#39;myCanvas&amp;#39;,&amp;nbsp;this);&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ctx.drawImage(node,&amp;nbsp;0,&amp;nbsp;0,&amp;nbsp;300,&amp;nbsp;200);&amp;nbsp;// 调整尺寸&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ctx.draw(false,&amp;nbsp;() =&amp;gt;&amp;nbsp;{&lt;/code&gt;&lt;code&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;// 保存到相册&lt;/span&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uni.canvasToTempFilePath({&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;canvasId:&amp;nbsp;&amp;#39;myCanvas&amp;#39;,&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;success:&amp;nbsp;res&amp;nbsp;=&amp;gt;&amp;nbsp;{&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uni.saveImageToPhotosAlbum({&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;filePath: res.tempFilePath,&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;success:&amp;nbsp;() =&amp;gt;&amp;nbsp;uni.showToast({&amp;nbsp;title:&amp;nbsp;&amp;#39;保存成功&amp;#39;&amp;nbsp;})&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;/code&gt;&lt;code&gt;&amp;nbsp; &amp;nbsp; });&lt;/code&gt;&lt;code&gt;&amp;nbsp; }&lt;/code&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/section&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot; data-pm-slice=&quot;1 1 [&amp;quot;para&amp;quot;,{&amp;quot;tagName&amp;quot;:&amp;quot;p&amp;quot;,&amp;quot;attributes&amp;quot;:{},&amp;quot;namespaceURI&amp;quot;:&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;}]&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 18px;letter-spacing: 1px;font-weight: bold&quot;&gt;#&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot; data-pm-slice=&quot;1 1 [&amp;quot;para&amp;quot;,{&amp;quot;tagName&amp;quot;:&amp;quot;p&amp;quot;,&amp;quot;attributes&amp;quot;:{},&amp;quot;namespaceURI&amp;quot;:&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;}]&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 18px;letter-spacing: 1px;font-weight: bold&quot;&gt;如何保存图片&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot; data-pm-slice=&quot;1 1 [&amp;quot;para&amp;quot;,{&amp;quot;tagName&amp;quot;:&amp;quot;p&amp;quot;,&amp;quot;attributes&amp;quot;:{},&amp;quot;namespaceURI&amp;quot;:&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;}]&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;在uni-app开发H5的环境下是无法使用&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;uni.saveImageToPhotosAlbum；在浏览器中可以直接a标签打开图片进行下载。但是在微信开发工具和公众号H5真机测试是没办法实现的&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;而&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot; data-pm-slice=&quot;1 1 [&amp;quot;para&amp;quot;,{&amp;quot;tagName&amp;quot;:&amp;quot;p&amp;quot;,&amp;quot;attributes&amp;quot;:{},&amp;quot;namespaceURI&amp;quot;:&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;}]&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;canvas转成的画布是&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;Base64，也无法使用&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;uni.previewImage预览；只能通过image标签直接显示 提示用户长按保存&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;section style=&quot;text-align: center&quot;&gt;&lt;/section&gt;&lt;section class=&quot;code-snippet__fix code-snippet__js&quot;&gt;&lt;ul class=&quot;code-snippet__line-index code-snippet__js list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/section&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 18px;letter-spacing: 1px;font-weight: bold&quot;&gt;# 源码下载&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;由于代码很长，打包下载本地运行看看效果（注意需要真机才能长按保存）&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span textstyle=&quot;&quot; style=&quot;font-size: 15px;letter-spacing: 1px&quot;&gt;https://www.123865.com/s/SmZtVv-fnegh&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;转：https://mp.weixin.qq.com/s/mNEuIGzcPL2n4vDQmoeSgg&lt;/p&gt;</description><pubDate>Wed, 08 Apr 2026 16:14:44 +0800</pubDate></item><item><title>抢红包系统设计</title><link>https://www.zhangkeda.com/?id=570</link><description>&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; data-pm-slice=&quot;0 0 []&quot;&gt;&lt;span leaf=&quot;&quot;&gt;实现类似微信红包的抢红包功能，支持拼手气红包、普通红包、高并发秒杀。&lt;/span&gt;&lt;/p&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;系统功能&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;核心功能：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;1. 发红包（拼手气/普通）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;2. 抢红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;3. 红包详情&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;4. 红包记录&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;技术难点：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- 高并发（1万人同时抢）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- 数据一致性（不能超发）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- 金额随机算法&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- 性能优化&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;业务规则&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;红包类型&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1. 拼手气红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 总金额固定（如100元）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 个数固定（如10个）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 每个金额随机&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 最小0.01元&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;2. 普通红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 总金额固定（如100元）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 个数固定（如10个）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 每个金额相等（10元）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;业务约束&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1. 每人只能抢一次&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;2. 红包24小时过期&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;3. 过期金额退回发送者&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;4. 最少2个红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;5. 单个红包最大200元&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;数据库设计&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;-- 红包表&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CREATE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TABLE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;red_packets (&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;id&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;PRIMARY&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;KEY&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;AUTO_INCREMENT,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; user_id&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;发送者&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;type&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TINYINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;1拼手气 2普通&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; total_amount&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DECIMAL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;总金额&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; total_count&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;红包个数&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; remain_amount&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DECIMAL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;剩余金额&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; remain_count&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;剩余个数&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;status&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TINYINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;1进行中 2已抢完 3已过期&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; expired_at&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;过期时间&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; created_at&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INDEX&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;idx_user (user_id),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INDEX&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;idx_status (&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;status&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INDEX&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;idx_expired (expired_at)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;-- 红包明细表&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CREATE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TABLE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;red_packet_details (&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;id&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;PRIMARY&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;KEY&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;AUTO_INCREMENT,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; packet_id&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;红包ID&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; user_id&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;领取者（NULL表示未领取）&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; amount&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DECIMAL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;金额&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; grabbed_at&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;领取时间&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; created_at&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INDEX&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;idx_packet (packet_id),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INDEX&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;idx_user (user_id)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;-- 用户账户表&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CREATE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TABLE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;user_accounts (&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;id&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;PRIMARY&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;KEY&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;AUTO_INCREMENT,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; user_id&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;UNIQUE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; balance&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DECIMAL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;余额&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;version&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;乐观锁版本号&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; updated_at&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;ON&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;UPDATE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;-- 账户流水表&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CREATE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TABLE&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;account_logs (&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;id&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;PRIMARY&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;KEY&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;AUTO_INCREMENT,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; user_id&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;type&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TINYINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;1发红包 2抢红包 3退款&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; amount&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DECIMAL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; balance&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DECIMAL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NOT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;COMMENT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;操作后余额&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; packet_id&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;BIGINT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #56B6C2;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; created_at&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DEFAULT&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;CURRENT_TIMESTAMP&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;INDEX&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;idx_user (user_id)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;表设计要点：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ul style=&quot;box-sizing: border-box; margin-top: 8px; margin-bottom: 8px; cursor: pointer; padding: 0px 0px 0px 25px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 14px;cursor: pointer;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;red_packets&lt;/span&gt;&lt;/code&gt;&lt;span leaf=&quot;&quot;&gt;：红包主表，记录总金额和剩余金额&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 14px;cursor: pointer;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;red_packet_details&lt;/span&gt;&lt;/code&gt;&lt;span leaf=&quot;&quot;&gt;：红包明细，预先生成所有红包&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 14px;cursor: pointer;color: rgb(30, 107, 184);line-height: 1.8em;letter-spacing: 0em;background: none left top / auto no-repeat scroll padding-box border-box rgba(27, 31, 35, 0.05);width: auto;margin: 0px 2px;padding: 2px 4px;border-style: none;border-width: 3px;border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4);border-radius: 4px;overflow-wrap: break-word;word-break: break-all;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;user_accounts.version&lt;/span&gt;&lt;/code&gt;&lt;span leaf=&quot;&quot;&gt;：乐观锁，防止并发扣款问题&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;/ul&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;第一步：发红包&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1.1 红包金额算法&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;App&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Services&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;RedPacketService&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 拼手气红包算法（二倍均值法）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 原理：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 每次抢到的金额 = 随机(0.01, 剩余平均值 * 2)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 例如：100元10个红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 第1个：随机(0.01, 20)，假设抢到15元&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 第2个：随机(0.01, (100-15)/9*2 = 18.89)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* ...&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 最后1个：剩余所有金额&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;generateLuckyAmounts&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(float $totalAmount, int $count)&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;array&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amounts = [];&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $remainAmount = $totalAmount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $remainCount = $count;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;for&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($i =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;; $i &amp;lt; $count -&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;; $i++) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 计算当前可抢的最大金额（剩余平均值的2倍）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $avg = $remainAmount / $remainCount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $max = $avg *&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 随机金额（保留2位小数）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amount = mt_rand(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $max *&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;100&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;) /&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;100&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amount = max(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0.01&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $amount); &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 最少0.01元&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amounts[] = $amount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $remainAmount -= $amount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $remainCount--;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 最后一个红包是剩余所有金额&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amounts[] = round($remainAmount,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$amounts;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 普通红包算法&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;generateNormalAmounts&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(float $totalAmount, int $count)&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;array&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amount = round($totalAmount / $count,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 处理除不尽的情况&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amounts = array_fill(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $count, $amount);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $diff = $totalAmount - ($amount * $count);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($diff &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amounts[&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;] += $diff; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 第一个红包补上差额&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$amounts;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;算法说明：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ul style=&quot;box-sizing: border-box; margin-top: 8px; margin-bottom: 8px; cursor: pointer; padding: 0px 0px 0px 25px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span class=&quot;&quot; link-id=&quot;link-1775610581037-0.02086381982167751&quot;&gt;二倍均值法&lt;/span&gt;保证了金额的随机性和公平性&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;最后一个红包拿剩余所有金额，避免精度问题&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;普通红包平均分配，第一个补差额&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1.2 发红包接口&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;App&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Http&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Controllers&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Http&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Request&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Support&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Facades&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DB&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;RedPacketController&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;extends&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Controller&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;RedPacketService $service;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;__construct&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(RedPacketService $service)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;service = $service;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 发红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;send&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(Request $request)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1. 验证参数&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $request-&amp;gt;validate([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;required|in:1,2&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1拼手气 2普通&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;required|numeric|min:0.02|max:200&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;required|integer|min:2|max:100&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $userId = auth()-&amp;gt;id();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $type = $request-&amp;gt;input(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $totalAmount = $request-&amp;gt;input(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $totalCount = $request-&amp;gt;input(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 2. 检查余额&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $account = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $userId)-&amp;gt;first();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($account-&amp;gt;balance &amp;lt; $totalAmount) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;response()-&amp;gt;json([&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;error&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;余额不足&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;],&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;400&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::beginTransaction();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;try&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 3. 扣除余额（乐观锁）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $affected = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $userId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;version&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $account-&amp;gt;version)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;&amp;gt;=&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $totalAmount)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;balance - {$totalAmount}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;version&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;version + 1&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($affected ===&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;余额不足或并发冲突&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 4. 创建红包&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $packetId = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;insertGetId([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $userId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $type,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $totalAmount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $totalCount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $totalAmount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $totalCount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;expired_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now()-&amp;gt;addHours(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;24&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;created_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 5. 生成红包明细&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $amounts = $type ==&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ?&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;service-&amp;gt;generateLuckyAmounts($totalAmount, $totalCount)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;service-&amp;gt;generateNormalAmounts($totalAmount, $totalCount);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $details = [];&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;foreach&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($amounts&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$amount) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $details[] = [&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packetId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $amount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;created_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ];&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;insert($details);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 6. 记录流水&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;account_logs&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;insert([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $userId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 发红包&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; -$totalAmount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $account-&amp;gt;balance - $totalAmount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packetId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;created_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::commit();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;response()-&amp;gt;json([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packetId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;message&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;发送成功&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$e) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::rollBack();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;response()-&amp;gt;json([&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;error&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $e-&amp;gt;getMessage()],&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;500&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;新手易错点：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ol style=&quot;box-sizing: border-box; margin-top: 8px; margin-bottom: 8px; cursor: pointer; padding: 0px 0px 0px 25px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;❌ 忘记使用事务，导致数据不一致&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;❌ 不使用乐观锁，并发扣款会出问题&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;❌ 金额计算精度问题（使用 DECIMAL 而不是 FLOAT）&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;/ol&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;第二步：抢红包（方案对比）&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2.1 方案一：MySQL 悲观锁（不推荐）&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* 使用 FOR UPDATE 锁定红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;*&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* 缺点：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* - 性能差（串行执行）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* - 锁等待时间长&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* - 不适合高并发&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;grabV1&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(int $packetId, int $userId)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; DB::beginTransaction();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;try&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1. 锁定红包（悲观锁）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $packet = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;lockForUpdate() &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 加锁&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;first();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(!$packet || $packet-&amp;gt;remain_count &amp;lt;=&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;红包已抢完&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 2. 检查是否已抢过&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $exists = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $userId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;exists();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($exists) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;已经抢过了&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 3. 随机获取一个未领取的红包&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $detail = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;whereNull(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;lockForUpdate()&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;first();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 4. 领取红包&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $detail-&amp;gt;id)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $userId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;grabbed_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 5. 更新红包剩余&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;remain_amount - {$detail-&amp;gt;amount}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count - 1&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;IF(remain_count - 1 = 0, 2, status)&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 6. 增加用户余额&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $userId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;balance + {$detail-&amp;gt;amount}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::commit();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$detail-&amp;gt;amount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$e) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::rollBack();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$e;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;性能测试：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ul style=&quot;box-sizing: border-box; margin-top: 8px; margin-bottom: 8px; cursor: pointer; padding: 0px 0px 0px 25px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1000人抢10个红包&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;耗时：约 5-10 秒&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&lt;span class=&quot;&quot; link-id=&quot;link-1775610581037-0.773297794086448&quot;&gt;TPS&lt;/span&gt;：约 100-200&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2.2 方案二：Redis + Lua（推荐）&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* 使用 Redis 原子操作&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;*&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* 优点：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* - 性能高（内存操作）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* - 原子性（Lua 脚本）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* - 适合高并发&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;grabV2&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(int $packetId, int $userId)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1. 检查是否已抢过（Redis Set）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $key =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:grabbed:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(Redis::sismember($key, $userId)) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;已经抢过了&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 2. 使用 Lua 脚本原子操作&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $lua =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;&amp;lt;&amp;lt;LUA&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;-- 检查红包是否存在&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;local packet_key = KEYS[1]&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;local detail_key = KEYS[2]&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;local grabbed_key = KEYS[3]&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;local user_id = ARGV[1]&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;-- 检查是否已抢过&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;if redis.call(&amp;#39;SISMEMBER&amp;#39;, grabbed_key, user_id) == 1 then&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; return {err = &amp;#39;already_grabbed&amp;#39;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;-- 弹出一个红包&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;local detail = redis.call(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;LPOP&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, detail_key)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;not detail then&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;{err =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;empty&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;end&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;-- 标记已抢&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;redis.call(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;SADD&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, grabbed_key, user_id)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;-- 减少剩余数量&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;redis.call(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;HINCRBY&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, packet_key,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;-1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;detail&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;LUA;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $packetKey =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $detailKey =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:details:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $grabbedKey =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:grabbed:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $result = Redis::eval($lua,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetKey, $detailKey, $grabbedKey, $userId);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;isset&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;($result[&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;err&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;])) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;throw&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;($result[&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;err&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;] ==&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;empty&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;?&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;红包已抢完&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;已经抢过了&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $detail = json_decode($result,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 3. 异步写入数据库&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; dispatch(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;UpdateRedPacketJob($packetId, $userId, $detail[&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;], $detail[&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;]));&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$detail[&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;];&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* 初始化 Redis 数据&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;initRedis&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(int $packetId)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $packet = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;find($packetId);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $details = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;get();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 红包信息&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; Redis::hmset(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, [&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;total_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packet-&amp;gt;total_amount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packet-&amp;gt;total_count,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 红包明细（List）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;foreach&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($details&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$detail) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Redis::rpush(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:details:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, json_encode([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $detail-&amp;gt;id,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $detail-&amp;gt;amount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]));&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 设置过期时间（24小时）&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; Redis::expire(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;86400&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; Redis::expire(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;red_packet:details:{$packetId}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;86400&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;性能测试：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;ul style=&quot;box-sizing: border-box; margin-top: 8px; margin-bottom: 8px; cursor: pointer; padding: 0px 0px 0px 25px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot; class=&quot; list-paddingleft-2&quot;&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1000人抢10个红包&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;耗时：约 0.1-0.5 秒&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;li&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin-top: 5px; margin-bottom: 5px; color: rgb(1, 1, 1); line-height: 1.8em; letter-spacing: 0em;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;TPS：约 2000-10000&lt;/span&gt;&lt;/section&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;方案对比：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;section style=&quot;box-sizing: border-box; cursor: pointer; margin: 0px; padding: 0px; overflow-x: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;table&gt;&lt;thead&gt;&lt;tr style=&quot;box-sizing: border-box;cursor: pointer;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;box-sizing: border-box; cursor: pointer; line-height: 1.5em; letter-spacing: 0em; text-align: left; background: none left top / auto no-repeat scroll padding-box border-box rgb(240, 240, 240); height: auto; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px; min-width: 85px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;方案&lt;/span&gt;&lt;/section&gt;&lt;/th&gt;&lt;th style=&quot;box-sizing: border-box; cursor: pointer; line-height: 1.5em; letter-spacing: 0em; text-align: left; background: none left top / auto no-repeat scroll padding-box border-box rgb(240, 240, 240); height: auto; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px; min-width: 85px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;优点&lt;/span&gt;&lt;/section&gt;&lt;/th&gt;&lt;th style=&quot;box-sizing: border-box; cursor: pointer; line-height: 1.5em; letter-spacing: 0em; text-align: left; background: none left top / auto no-repeat scroll padding-box border-box rgb(240, 240, 240); height: auto; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px; min-width: 85px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;缺点&lt;/span&gt;&lt;/section&gt;&lt;/th&gt;&lt;th style=&quot;box-sizing: border-box; cursor: pointer; line-height: 1.5em; letter-spacing: 0em; text-align: left; background: none left top / auto no-repeat scroll padding-box border-box rgb(240, 240, 240); height: auto; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px; min-width: 85px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;适用场景&lt;/span&gt;&lt;/section&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr style=&quot;box-sizing: border-box; cursor: pointer; background-image: none; background-position: left top; background-size: auto; background-repeat: no-repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; width: auto; height: auto;&quot;&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;MySQL 悲观锁&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;实现简单，数据一致性强&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;性能差，不适合高并发&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;小规模（&amp;lt;100人）&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgb(248, 248, 248); width: auto; height: auto;&quot;&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;Redis + Lua&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;性能高，适合高并发&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;实现复杂，需要数据同步&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;td style=&quot;box-sizing: border-box; cursor: pointer; min-width: 85px; border-color: rgba(204, 204, 204, 0.4); border-radius: 0px;&quot;&gt;&lt;section&gt;&lt;span leaf=&quot;&quot;&gt;大规模（&amp;gt;1000人）&lt;/span&gt;&lt;/section&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/section&gt;&lt;/p&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;第三步：异步写入数据库&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;App&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Jobs&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Bus&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Queueable&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Contracts&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Queue&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;ShouldQueue&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Support&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Facades&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DB&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;UpdateRedPacketJob&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;implements&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;ShouldQueue&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Queueable&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;int $packetId;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;int $userId;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;int $detailId;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;float $amount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;__construct&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(int $packetId, int $userId, int $detailId, float $amount)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;packetId = $packetId;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;userId = $userId;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;detailId = $detailId;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;amount = $amount;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;handle&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::beginTransaction();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;try&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1. 更新红包明细&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;detailId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;userId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;grabbed_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 2. 更新红包剩余&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;remain_amount - {$this-&amp;gt;amount}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count - 1&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 3. 增加用户余额&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;userId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;balance + {$this-&amp;gt;amount}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;version&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;version + 1&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 4. 记录流水&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;account_logs&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;insert([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;userId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 抢红包&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;amount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;userId)-&amp;gt;value(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;packetId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;created_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::commit();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$e) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::rollBack();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; \Log::error(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;UpdateRedPacketJob failed&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, [&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;packetId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;userId,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;error&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $e-&amp;gt;getMessage(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;第四步：红包详情&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;/**&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;* 红包详情&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;detail&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(int $packetId)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1. 红包信息&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $packet = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;find($packetId);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 2. 领取记录&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $records = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packet_details as d&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;leftJoin(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;users as u&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;d.user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;=&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;u.id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;d.packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packetId)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;whereNotNull(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;d.user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;select(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;u.nickname&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;d.amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;d.grabbed_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;orderBy(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;d.grabbed_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;get();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 3. 标记最佳手气&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($records-&amp;gt;isNotEmpty()) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $maxAmount = $records-&amp;gt;max(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;foreach&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($records&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$record) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $record-&amp;gt;is_best = ($record-&amp;gt;amount == $maxAmount);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;response()-&amp;gt;json([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packet,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;records&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $records,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;第五步：定时任务（退款）&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;lt;?php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;App&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Console&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Commands&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Console&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Command&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;use&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Illuminate&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Support&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Facades&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;DB&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;RefundExpiredRedPackets&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;extends&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #E6C07B;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Command&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;protected&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$signature =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;redpacket:refund&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;protected&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$description =&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;退款过期红包&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;handle&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 查找过期且未抢完的红包&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $packets = DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;expired_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;&amp;lt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, now())&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;remain_count&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;&amp;gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;get();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;foreach&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($packets&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;as&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$packet) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::beginTransaction();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;try&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 1. 更新红包状态&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;red_packets&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packet-&amp;gt;id)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;]); &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 已过期&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 2. 退款给发送者&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;($packet-&amp;gt;remain_amount &amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packet-&amp;gt;user_id)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;update([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::raw(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;balance + {$packet-&amp;gt;remain_amount}&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 3. 记录流水&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;account_logs&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;insert([&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packet-&amp;gt;user_id,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;type&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #D19A66;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 退款&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;amount&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packet-&amp;gt;remain_amount,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; DB::table(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_accounts&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;where(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;user_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;, $packet-&amp;gt;user_id)-&amp;gt;value(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;balance&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;packet_id&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; $packet-&amp;gt;id,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;created_at&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;=&amp;gt; now(),&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ]);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::commit();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;info(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;红包 {$packet-&amp;gt;id} 退款成功&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;(\&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;Exception&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;$e) {&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DB::rollBack();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;-&amp;gt;error(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;红包 {$packet-&amp;gt;id} 退款失败: &amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;. $e-&amp;gt;getMessage());&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong style=&quot;box-sizing: border-box; cursor: pointer; background: none left top / auto no-repeat scroll padding-box border-box rgba(0, 0, 0, 0); width: auto; height: auto; margin: 0px; padding: 0px; border-style: none; border-width: 3px; border-color: rgba(0, 0, 0, 0.4); border-radius: 0px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;定时任务配置：&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// app/Console/Kernel.php&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;protected&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #C678DD;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;function&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #61AEEE;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;schedule&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;(Schedule $schedule)&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;// 每小时执行一次&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp; $schedule-&amp;gt;command(&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;#39;redpacket:refund&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;)-&amp;gt;hourly();&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;压力测试&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;使用 Apache Bench&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;# 1000个并发请求&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;ab -n 1000 -c 100 -p grab.json -T application/json \&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;http://localhost/api/red-packet/grab&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span style=&quot;box-sizing: border-box;color: #5C6370;font-style: italic;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;# grab.json 内容&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;packet_id&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;: 123,&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;user_id&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;: 456&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 20px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;使用 JMeter&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1. 创建线程组&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 线程数：1000&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- Ramp-Up：10秒&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;2. 添加 HTTP 请求&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 方法：POST&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 路径：/api/red-packet/grab&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- Body：{&lt;/span&gt;&lt;span style=&quot;box-sizing: border-box;color: #98C379;cursor: pointer;line-height: 26px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;&amp;quot;packet_id&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span leaf=&quot;&quot;&gt;: 123}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;3. 添加监听器&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 聚合报告&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 查看结果树&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;性能优化&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;1. Redis 预加载&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 发红包时立即写入 Redis&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 避免首次抢红包时加载&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;2. 限流&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 单用户每秒最多抢3次&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 防止恶意刷接口&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;3. 降级&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- Redis 故障时降级到 MySQL&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 保证可用性&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;4. 监控&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 抢红包成功率&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- 接口响应时间&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;&amp;nbsp; &amp;nbsp;- Redis 命中率&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;hr style=&quot;box-sizing: initial; height: 1px; overflow: visible; cursor: pointer; margin: 10px 0px; padding: 0px; border-style: solid none none; border-right-width: 3px; border-bottom-width: 3px; border-left-width: 3px; border-color: rgb(0, 0, 0) rgba(0, 0, 0, 0.4) rgba(0, 0, 0, 0.4); border-radius: 0px; background: none left top / auto no-repeat scroll padding-box border-box rgb(255, 255, 255); width: auto; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; font-size: 16px; text-wrap: wrap;&quot;/&gt;&lt;h2 style=&quot;box-sizing: border-box; margin: 30px 0px 15px; color: rgba(0, 0, 0, 0.85); font-weight: 500; cursor: pointer; padding: 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;box-sizing: border-box; cursor: pointer; font-size: 22px; color: #000000; line-height: 1.5em; letter-spacing: 0em; font-weight: bold; display: block;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;总结&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;pre style=&quot;box-sizing: border-box; font-size: 16px; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; margin-top: 10px; margin-bottom: 10px; overflow: auto; cursor: pointer; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px; padding: 0px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box;font-family: Consolas, Monaco, Menlo, monospace;font-size: 12px;display: -webkit-box;overflow-x: auto;padding: 15px 16px 16px;color: rgb(171, 178, 191);background: rgb(40, 44, 52);cursor: pointer;border-radius: 5px;&quot;&gt;&lt;span leaf=&quot;&quot;&gt;抢红包核心：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;1. 金额算法：二倍均值法&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;2. 并发控制：Redis + Lua&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;3. 数据一致性：异步写入 + 补偿&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;4. 性能优化：内存操作 + 队列&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;技术栈：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- Redis（高并发）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- Lua（原子操作）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- MySQL（持久化）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- Queue（异步处理）&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;性能指标：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- TPS：10000+&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- 响应时间：&amp;lt; 100ms&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;span leaf=&quot;&quot;&gt;- 成功率：99.9%&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;cursor: pointer;&quot;/&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; cursor: pointer; font-size: 16px; line-height: 1.8em; padding: 8px 0px; font-family: Optima, &amp;quot;Microsoft YaHei&amp;quot;, PingFangSC-regular, serif; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span leaf=&quot;&quot;&gt;抢红包是高并发场景的经典案例！&lt;/span&gt;&lt;/p&gt;&lt;p&gt;转：码上微光&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 08 Apr 2026 09:37:01 +0800</pubDate></item><item><title>thinkphp6.1中分页类调用</title><link>https://www.zhangkeda.com/?id=569</link><description>&lt;pre class=&quot;prism-highlight prism-language-php&quot;&gt;$list&amp;nbsp;=&amp;nbsp;YourModel-&amp;gt;paginate([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;list_rows&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;15
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;simple&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;false,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;type&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;page\Bootstrap&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;var_page&amp;#39;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;page&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;query&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;$this-&amp;gt;request-&amp;gt;get()
]);&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #060A26; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Noto Sans&amp;quot;, Ubuntu, Cantarell, &amp;quot;Helvetica Neue&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;PingFang TC&amp;quot;, &amp;quot;PingFang HK&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, &amp;quot;Microsoft JhengHei&amp;quot;; font-size: 16px; white-space: pre-wrap; background-color: #EBF5FF;&quot;&gt;使用了分页类是extend中的page文件夹下面的Bootstrap.php。并且在provide.php中配置了&amp;#39;think\Paginator&amp;#39; &amp;nbsp; &amp;nbsp;=&amp;gt; \page\Bootstrap::class&lt;/span&gt;&lt;/p&gt;&lt;p&gt;和TP5有区别了：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-php&quot;&gt;$list&amp;nbsp;=&amp;nbsp;YourModel-&amp;gt;paginate($page,&amp;nbsp;$countNum,&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;type&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;page\Bootstrap&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;var_page&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;page&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;simple&amp;#39;=&amp;gt;true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;query&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;$this-&amp;gt;request-&amp;gt;get()
]);&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #060A26; font-family: system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Noto Sans&amp;quot;, Ubuntu, Cantarell, &amp;quot;Helvetica Neue&amp;quot;, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Noto Color Emoji&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;PingFang TC&amp;quot;, &amp;quot;PingFang HK&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, &amp;quot;Microsoft JhengHei&amp;quot;; font-size: 16px; white-space: pre-wrap; background-color: #EBF5FF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 09 Jan 2026 15:52:29 +0800</pubDate></item><item><title>phpstudy提示错误：cURL error 60 配置SSL CA证书 </title><link>https://www.zhangkeda.com/?id=568</link><description>&lt;h3 style=&quot;box-sizing: border-box; outline: 0px; margin: 24px 0px 8px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 20px; color: rgb(79, 79, 79); line-height: 30px; font-synthesis-style: auto; overflow-wrap: break-word; text-wrap: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a href=&quot;https://www.cnblogs.com/qxandxt/p/18338310&quot; id=&quot;cb_post_title_url&quot; title=&quot;phpstudy配置SSL CA证书&quot; rel=&quot;nofollow&quot; style=&quot;box-sizing: border-box; outline: none; margin: 24px 0px 8px; padding: 0px; text-decoration-line: none; cursor: pointer; color: rgb(78, 161, 219); font-synthesis-style: auto; overflow-wrap: break-word;&quot;&gt;phpstudy配置SSL CA证书&lt;/a&gt;&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;本地Windows环境，&amp;nbsp;&lt;span class=&quot;words-blog hl-git-1&quot; data-tit=&quot;phpstudy&quot; data-pretit=&quot;phpstudy&quot; style=&quot;box-sizing: border-box; outline: 0px; margin: 0px 3px 0px 0px; padding: 0px 18px 0px 0px; font-synthesis-style: auto; overflow-wrap: break-word; cursor: pointer; background: url(&amp;quot;../img/gitcode-key.png&amp;quot;) right center / 14px 14px no-repeat transparent; box-shadow: none; color: #4EA1DB !important;&quot;&gt;phpstudy&lt;/span&gt;&amp;nbsp;集成 php7 后，出现错误提示：&lt;br style=&quot;box-sizing: border-box; outline: 0px; font-synthesis-style: auto; overflow-wrap: break-word;&quot;/&gt;cURL error 60: SSL certificate problem: unable to&amp;nbsp;&lt;a href=&quot;https://so.csdn.net/so/search?q=get&amp;spm=1001.2101.3001.7020&quot; target=&quot;_blank&quot; class=&quot;hl hl-1&quot; data-report-click=&quot;{&quot; spm=&quot;&quot;&gt;get&lt;/a&gt;&amp;nbsp;local issuer certificate&lt;br style=&quot;box-sizing: border-box; outline: 0px; font-synthesis-style: auto; overflow-wrap: break-word;&quot;/&gt;查询问题：&lt;span style=&quot;box-sizing: border-box; outline: 0px; font-weight: 700; font-synthesis-style: auto; overflow-wrap: break-word;&quot;&gt;SSL CA证书配置缺失&lt;/span&gt;导致。&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;1、从&lt;span class=&quot;words-blog hl-git-1&quot; data-tit=&quot;CURL&quot; data-pretit=&quot;curl&quot; style=&quot;box-sizing: border-box; outline: 0px; margin: 0px 3px 0px 0px; padding: 0px 18px 0px 0px; font-synthesis-style: auto; overflow-wrap: break-word; cursor: pointer; background: url(&amp;quot;../img/gitcode-key.png&amp;quot;) right center / 14px 14px no-repeat transparent; box-shadow: none; color: #4EA1DB !important;&quot;&gt;CURL&lt;/span&gt;&amp;nbsp;官网下载&lt;a href=&quot;https://so.csdn.net/so/search?q=CA%20%E8%AF%81%E4%B9%A6&amp;spm=1001.2101.3001.7020&quot; target=&quot;_blank&quot; class=&quot;hl hl-1&quot; data-report-click=&quot;{&quot; spm=&quot;&quot;&gt;CA 证书&lt;/a&gt;（cacert.pem）&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;可 选择下载：&lt;a href=&quot;https://links.jianshu.com/go?to=https%3A%2F%2Fcurl.haxx.se%2Fdocs%2Fcaextract.html&quot; title=&quot;https://curl.haxx.se/docs/caextract.html&quot; rel=&quot;nofollow&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; text-decoration-line: none; cursor: pointer; color: rgb(78, 161, 219); font-synthesis-style: auto; overflow-wrap: break-word;&quot;&gt;https://curl.haxx.se/docs/caextract.html&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;或 直接下载：&lt;a href=&quot;https://links.jianshu.com/go?to=https%3A%2F%2Fcurl.haxx.se%2Fca%2Fcacert.pem&quot; title=&quot;https://curl.haxx.se/ca/cacert.pem&quot; rel=&quot;nofollow&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; text-decoration-line: none; cursor: pointer; color: rgb(78, 161, 219); font-synthesis-style: auto; overflow-wrap: break-word;&quot;&gt;https://curl.haxx.se/ca/cacert.pem&lt;/a&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;2、找到 phpstudy 安装路径，对应php版本包&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;例 安装路径下 php包：D:\phpstudy_pro\&lt;span class=&quot;words-blog hl-git-1&quot; data-tit=&quot;Extensions&quot; data-pretit=&quot;extensions&quot; style=&quot;box-sizing: border-box; outline: 0px; margin: 0px 3px 0px 0px; padding: 0px 18px 0px 0px; font-synthesis-style: auto; overflow-wrap: break-word; cursor: pointer; background: url(&amp;quot;../img/gitcode-key.png&amp;quot;) right center / 14px 14px no-repeat transparent; box-shadow: none; color: #4EA1DB !important;&quot;&gt;Extensions&lt;/span&gt;\php\php7.3.4nts&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;将下载的cacert.pem文件，放入 \extras\ssl\&amp;nbsp;&lt;a href=&quot;https://so.csdn.net/so/search?q=%E6%96%87%E4%BB%B6%E5%A4%B9&amp;spm=1001.2101.3001.7020&quot; target=&quot;_blank&quot; class=&quot;hl hl-1&quot; data-report-click=&quot;{&quot; spm=&quot;&quot;&gt;文件夹&lt;/a&gt;下&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;3、修改配置 php.ini 文件&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;启用openssl, curl扩展&lt;/p&gt;&lt;pre data-index=&quot;0&quot; class=&quot;new-version hljs set-code-show&quot; name=&quot;code&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 36px 8px 8px; position: relative; overflow: auto hidden; color: rgb(180, 180, 180); background-color: rgb(40, 44, 52); text-wrap: wrap; overflow-wrap: break-word; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; max-height: unset; border-radius: 5px; font-synthesis-style: auto;&quot;&gt;extension=curl
extension=openssl&lt;/pre&gt;&lt;p style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 16px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); overflow: auto hidden; font-synthesis-style: auto; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif, SimHei, SimSun; text-wrap: wrap; background-color: rgb(255, 255, 255); line-height: 24px !important;&quot;&gt;然后修改两处CA 证书存放位置&lt;/p&gt;&lt;pre data-index=&quot;1&quot; class=&quot;new-version hljs set-code-show&quot; name=&quot;code&quot; style=&quot;box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 36px 8px 8px; position: relative; overflow: auto hidden; color: rgb(180, 180, 180); background-color: rgb(40, 44, 52); text-wrap: wrap; overflow-wrap: break-word; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; max-height: unset; border-radius: 5px; font-synthesis-style: auto;&quot;&gt;curl.cainfo&amp;nbsp;=&amp;nbsp;&amp;quot;D:\phpstudy_pro\Extensions\php\php7.3.4nts\extras\ssl\cacert.pem&amp;quot;
openssl.cafile=&amp;quot;D:\phpstudy_pro\Extensions\php\php7.3.4nts\extras\ssl\cacert.pem&amp;quot;&lt;/pre&gt;</description><pubDate>Fri, 05 Dec 2025 15:20:28 +0800</pubDate></item><item><title>在thinkphp6中使用依赖注入或容器来创建对象</title><link>https://www.zhangkeda.com/?id=567</link><description>&lt;p&gt;很多时候，在自己的控制器中需要调用另一个控制器中的方法，但是没有直接的继承关系，比如两个控制器同时继承了一个common类。如果我们直接new一个控制器中的类，就会提示&lt;/p&gt;&lt;pre data-spm-anchor-id=&quot;5176.28103460.0.i15.2f2e1db8PodMdi&quot; style=&quot;box-sizing: border-box; overflow: auto; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; background-color: rgb(30, 30, 30); border-radius: 6px; color: rgb(221, 221, 221); line-height: 1.45; padding: 16px 8px; letter-spacing: 0.08px;&quot;&gt;Too&amp;nbsp;few&amp;nbsp;arguments&amp;nbsp;to&amp;nbsp;function&amp;nbsp;app\common\controller\WechatApi::__construct(),&amp;nbsp;0&amp;nbsp;passed&lt;/pre&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;当前在 &lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space-collapse: break-spaces;&quot;&gt;Login&lt;/code&gt; 控制器中的方法里这样使用了 &lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space-collapse: break-spaces;&quot;&gt;WechatApi&lt;/code&gt;：&lt;/p&gt;&lt;pre data-spm-anchor-id=&quot;5176.28103460.0.i23.2f2e1db8PodMdi&quot; style=&quot;box-sizing: border-box; overflow: auto; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; background-color: rgb(30, 30, 30); border-radius: 6px; color: rgb(221, 221, 221); line-height: 1.45; padding: 16px 8px; letter-spacing: 0.08px;&quot;&gt;$wxapi&amp;nbsp;=&amp;nbsp;new&amp;nbsp;WechatApi();
$wxapi-&amp;gt;WechatOAuth(&amp;#39;snsapi_base&amp;#39;);&lt;/pre&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;但&lt;/span&gt;&lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space: break-spaces; color: rgb(44, 44, 54); letter-spacing: 0.08px;&quot;&gt;WechatApi&lt;/code&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; 类定义如下：&lt;/span&gt;&lt;/p&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;box-sizing: border-box; overflow: auto; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; background-color: rgb(30, 30, 30); border-radius: 6px; color: rgb(221, 221, 221); line-height: 1.45; padding: 16px 8px; letter-spacing: 0.08px;&quot;&gt;class&amp;nbsp;WechatApi&amp;nbsp;extends&amp;nbsp;Hub{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
public&amp;nbsp;function&amp;nbsp;__construct(App&amp;nbsp;$app)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parent::__construct($app);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
public&amp;nbsp;function&amp;nbsp;WechatOAuth()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}&lt;/pre&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;这里 &lt;/span&gt;&lt;code node=&quot;[object Object]&quot; data-spm-anchor-id=&quot;5176.28103460.0.i31.2f2e1db8PodMdi&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space: break-spaces; color: rgb(44, 44, 54); letter-spacing: 0.08px;&quot;&gt;new WechatApi()&lt;/code&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; 没有传入 &lt;/span&gt;&lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space: break-spaces; color: rgb(44, 44, 54); letter-spacing: 0.08px;&quot;&gt;$app&lt;/code&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; 参数，所以会报错，&lt;/span&gt;或者是Hub中有构造函数被继承了。&lt;/p&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;在 ThinkPHP 6.1 中，&lt;/span&gt;&lt;span data-spm-anchor-id=&quot;5176.28103460.0.i17.2f2e1db8PodMdi&quot; style=&quot;box-sizing: border-box; font-weight: 600; color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;建议使用依赖注入或容器来创建对象&lt;/span&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;，而不是手动 &lt;/span&gt;&lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space: break-spaces; color: rgb(44, 44, 54); letter-spacing: 0.08px;&quot;&gt;new&lt;/code&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;。你可以使用框架提供的容器来自动解析 &lt;/span&gt;&lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space: break-spaces; color: rgb(44, 44, 54); letter-spacing: 0.08px;&quot;&gt;WechatApi&lt;/code&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;，前提是它的依赖能被容器解析。&lt;/span&gt;&lt;/p&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;box-sizing: border-box; overflow: auto; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; background-color: rgb(30, 30, 30); border-radius: 6px; color: rgb(221, 221, 221); line-height: 1.45; padding: 16px 8px; letter-spacing: 0.08px;&quot;&gt;public&amp;nbsp;function&amp;nbsp;checkWechatLogin(){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;使用容器创建&amp;nbsp;WechatApi&amp;nbsp;实例，自动注入&amp;nbsp;App&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$wxapi&amp;nbsp;=&amp;nbsp;Container::getInstance()-&amp;gt;make(WechatApi::class);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$wxapi-&amp;gt;WechatOAuth(&amp;#39;snsapi_base&amp;#39;);
}&lt;/pre&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #2C2C36; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;或者更简洁一点（适用于控制器方法）：&lt;/span&gt;&lt;/p&gt;&lt;pre data-spm-anchor-id=&quot;5176.28103460.0.i41.2f2e1db8PodMdi&quot; style=&quot;box-sizing: border-box; overflow: auto; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13px; margin-top: 0px; margin-bottom: 0px; overflow-wrap: normal; background-color: rgb(30, 30, 30); border-radius: 6px; color: rgb(221, 221, 221); line-height: 1.45; padding: 16px 8px; letter-spacing: 0.08px;&quot;&gt;public&amp;nbsp;function&amp;nbsp;checkWechatLogin(WechatApi&amp;nbsp;$wxapi){&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$wxapi-&amp;gt;WechatOAuth(&amp;#39;snsapi_base&amp;#39;);
}&lt;/pre&gt;&lt;p data-spm-anchor-id=&quot;5176.28103460.0.i21.2f2e1db8PodMdi&quot; style=&quot;white-space: pre-wrap; box-sizing: border-box; margin-bottom: 1em; margin-top: 1em; word-break: break-word; color: rgb(44, 44, 54); font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; background-color: rgb(255, 255, 255);&quot;&gt;&lt;strong&gt;&lt;span style=&quot;font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;这种方式是 &lt;/span&gt;&lt;span style=&quot;box-sizing: border-box; font-weight: 600; font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;依赖注入&lt;/span&gt;&lt;span style=&quot;font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;，由框架自动帮你实例化并传入 &lt;/span&gt;&lt;code node=&quot;[object Object]&quot; style=&quot;box-sizing: border-box; margin: 0px; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; background-color: rgba(175, 184, 193, 0.2); border-radius: 6px; padding: 0.2em 0.4em; white-space: break-spaces; color: rgb(143, 145, 168); letter-spacing: 0.08px;&quot;&gt;App&lt;/code&gt;&lt;span style=&quot;font-family: -apple-system, blinkmacsystemfont, &amp;quot;Helvetica Neue&amp;quot;, helvetica, &amp;quot;segoe ui&amp;quot;, arial, roboto, &amp;quot;PingFang SC&amp;quot;, miui, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft Yahei&amp;quot;, sans-serif, &amp;quot;Source Han Serif&amp;quot;; font-size: 16px; letter-spacing: 0.08px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;。&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;</description><pubDate>Thu, 05 Jun 2025 11:12:44 +0800</pubDate></item><item><title>天地图用服务端去调用接口提示403错误，解决办法</title><link>https://www.zhangkeda.com/?id=566</link><description>&lt;p&gt;天地图用服务端去调用接口提示403错误，这里很有可能就是跨域问题。&lt;/p&gt;&lt;p&gt;可以使用天地图官方的处理跨域的地址去处理：&lt;a href=&quot;https://api.tianditu.gov.cn/apiserver/ajaxproxy?proxyReqUrl=https://api.tianditu.gov.cn/v2/search?postStr=&amp;quot;+postStr+&amp;quot;&amp;type=query&amp;tk=&amp;quot;+tdt_key。&quot; _src=&quot;https://api.tianditu.gov.cn/apiserver/ajaxproxy?proxyReqUrl=https://api.tianditu.gov.cn/v2/search?postStr=&amp;quot;+postStr+&amp;quot;&amp;type=query&amp;tk=&amp;quot;+tdt_key。&quot;&gt;https://api.tianditu.gov.cn/apiserver/ajaxproxy?proxyReqUrl=https://api.tianditu.gov.cn/v2/search?postStr=学校&amp;amp;type=query&amp;amp;tk=秘钥&amp;quot; 。&lt;/a&gt;&lt;/p&gt;&lt;p&gt;如果你直接去访问：&lt;a href=&quot;https://api.tianditu.gov.cn/v2/search?postStr=&amp;quot;+postStr+&amp;quot;&amp;type=query&amp;tk=&amp;quot;+tdt_key就会提示403错误。&quot; _src=&quot;https://api.tianditu.gov.cn/v2/search?postStr=&amp;quot;+postStr+&amp;quot;&amp;type=query&amp;tk=&amp;quot;+tdt_key就会提示403错误。&quot;&gt;&lt;a href=&quot;https://api.tianditu.gov.cn/apiserver/ajaxproxy?proxyReqUrl=https://api.tianditu.gov.cn/v2/search?postStr=%22+postStr+%22&amp;type=query&amp;tk=%22+tdt_key%E3%80%82&quot; _src=&quot;https://api.tianditu.gov.cn/apiserver/ajaxproxy?proxyReqUrl=https://api.tianditu.gov.cn/v2/search?postStr=&amp;quot;+postStr+&amp;quot;&amp;type=query&amp;tk=&amp;quot;+tdt_key。&quot; style=&quot;text-wrap: wrap;&quot;&gt;https://api.tianditu.gov.cn/v2/search?postStr=学校&amp;amp;type=query&amp;amp;tk=秘钥&lt;/a&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 就会提示403错误。&lt;/a&gt;&lt;/p&gt;&lt;p&gt;这里的是调用了天地图的搜索接口。&lt;/p&gt;</description><pubDate>Sun, 27 Apr 2025 15:12:31 +0800</pubDate></item><item><title>在使用do.js进行js管理时遇到的问题</title><link>https://www.zhangkeda.com/?id=565</link><description>&lt;p&gt;&lt;span style=&quot;color: #404040; font-family: DeepSeek-CJK-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Noto Sans&amp;quot;, Ubuntu, Cantarell, &amp;quot;Helvetica Neue&amp;quot;, Oxygen, &amp;quot;Open Sans&amp;quot;, sans-serif; font-size: 16.002px; text-wrap: wrap;&quot;&gt;Do.js 是一个轻量级的 JavaScript 模块加载器和 DOM 就绪事件处理器，它主要用于管理 JavaScript 和 CSS 文件的异步加载、处理模块依赖关系以及执行 DOM 就绪后的回调函数。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;比如我有a.js,在页面中包含a.js时想一起加载其他的js文件，在其他文件加载完后处理js事件。这样就可以用到这个轻量级的模块加载工具do.js。&lt;/p&gt;&lt;p&gt;首先这个do.js是基于jquery实现的，所以在使用的时候必须要有jquery在do.js文件中需要配置jquery的地址：&lt;/p&gt;&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2025/04/202504091744187673722144.png&quot; title=&quot;微信图片_20250409163415.png&quot; alt=&quot;微信图片_20250409163415.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 18px; color: #FF0000;&quot;&gt;&lt;strong&gt;如果你的页面中已经存在了jquery，那么在do.js的文件中核心库这里配置一个空的js文件，如果你不配置则会报错。&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;然后再html中加入&lt;/p&gt;&lt;pre style=&quot;background-color:#2b2b2b;color:#a9b7c6;font-family:&amp;#39;JetBrains Mono&amp;#39;;font-size:10.5pt;&quot;&gt;&amp;lt;script&amp;nbsp;src=&amp;quot;__PUBLIC__/js/do.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;p&gt;在引入&lt;/p&gt;&lt;pre style=&quot;background-color:#2b2b2b;color:#a9b7c6;font-family:&amp;#39;JetBrains Mono&amp;#39;;font-size:10.5pt;&quot;&gt;&amp;lt;script&amp;nbsp;src=&amp;quot;__PUBLIC__/js/a.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/pre&gt;&lt;p&gt;在a.js文件中就可以引入其他的js文件，并且可以有依赖关系：&lt;/p&gt;&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2025/04/202504091744187825405623.png&quot; title=&quot;微信图片_20250409163647.png&quot; alt=&quot;微信图片_20250409163647.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;比如这里我引入了两个js，一个是gcoord.global.prod.js 和 一个天地图的js文件，可以支持远程地址。&lt;/p&gt;&lt;p&gt;然后使用：&lt;/p&gt;&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2025/04/202504151744681468629273.png&quot; title=&quot;微信图片_20250415094309.png&quot; alt=&quot;微信图片_20250415094309.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;这类的gcoordJs表示将&lt;span style=&quot;text-wrap: wrap;&quot;&gt;gcoord.global.prod.js命名成&lt;span style=&quot;text-wrap: wrap;&quot;&gt;gcoordJs模块了。这里表示当两个模块加载成功后，在里面可以执行自己想要的操作，这里比如可以进行天地图的一些接口调用。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;在使用这个js的时候遇到一个bug，必须重点说明一下：&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2025/04/202504151744681581575605.png&quot; title=&quot;微信图片_20250415094607.png&quot; alt=&quot;微信图片_20250415094607.png&quot;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #C00000; font-size: 18px;&quot;&gt;&lt;strong&gt;没有依赖其他的模块，那么里面的requires:[]这个必须去掉，不然无法加载成功，类似下面的情况：&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #C00000; font-size: 18px;&quot;&gt;&lt;strong&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2025/04/202504151744681143875187.png&quot; title=&quot;微信图片_20250415093820.png&quot; alt=&quot;微信图片_20250415093820.png&quot;/&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;font-size: 14px; color: #000000;&quot;&gt;&lt;strong&gt;如果两个js存在依赖关系：&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color:#c00000&quot;&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;&lt;strong&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2025/04/202504151744681243705864.png&quot; title=&quot;微信图片_20250415093955.png&quot; alt=&quot;微信图片_20250415093955.png&quot;/&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;这里表示gcoordJs需要依赖tiandituJS。就是加载gcoordJs的时候会同时加载tiandituJS。&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 18px;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;text-wrap: wrap;&quot;&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #C00000; font-size: 18px;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: wrap; color: #FF0000; font-size: 20px;&quot;&gt;特别注意：在add一个文件后，必须要使用Do(&amp;#39;&amp;#39;)方法去实现，不然没有效果。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #C00000; font-size: 18px;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;比如我现在要实现预加载css文件：&lt;/p&gt;&lt;pre style=&quot;background-color:#2b2b2b;color:#a9b7c6;font-family:&amp;#39;JetBrains Mono&amp;#39;;font-size:10.5pt;&quot;&gt;Do.add(&amp;#39;tdt-css&amp;#39;,&amp;nbsp;{path:&amp;nbsp;&amp;#39;__PUBLIC__/css/tdtcss.css&amp;#39;,&amp;nbsp;type:&amp;nbsp;&amp;#39;css&amp;#39;});&lt;/pre&gt;&lt;p&gt;如果单纯只这样添加一下，页面加载时不会去预加载这个css文件的，必须执行一下：&lt;/p&gt;&lt;pre style=&quot;background-color:#2b2b2b;color:#a9b7c6;font-family:&amp;#39;JetBrains Mono&amp;#39;;font-size:10.5pt;&quot;&gt;Do(&amp;#39;tdt-css&amp;#39;,&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;{

}）&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 09 Apr 2025 16:29:18 +0800</pubDate></item><item><title>composer使用phpstudy的php环境，如果改变php版本如何处理</title><link>https://www.zhangkeda.com/?id=564</link><description>&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;首先安装composer后，先在系统的环境变量中添加php路径，比如之前的路径：C:\zhangsan\work\phpstudy_pro\Extensions\php\php7.3.4nts ，现在要改成：&lt;span style=&quot;text-wrap: wrap;&quot;&gt;C:\zhangsan\work\phpstudy_pro\Extensions\php\php8.0.2.4nts，这样php版本就变成了8.0的了。但是这个时候你去执行composer命令会提示&amp;nbsp;&lt;span style=&quot;color: #2C2C36; font-family: ui-monospace, SFMono-Regular, &amp;quot;SF Mono&amp;quot;, Menlo, Consolas, &amp;quot;Liberation Mono&amp;quot;, monospace; font-size: 13.6px; letter-spacing: 0.08px; white-space: break-spaces; background-color: rgba(175, 184, 193, 0.2);&quot;&gt;&amp;#39;composer&amp;#39; 不是内部或外部命令。&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;这里我们需要将composer两个文件拷贝到：&lt;span style=&quot;text-wrap: wrap;&quot;&gt;C:\zhangsan\work\phpstudy_pro\Extensions\php\php8.0.2文件夹下面去，分别是composer.bat，composer.phar。然后去执行就正常了。&lt;/span&gt;&lt;/p&gt;</description><pubDate>Tue, 11 Mar 2025 09:33:00 +0800</pubDate></item><item><title>ThinkPHP5.1关于条件为[NOT]NULL的写法</title><link>https://www.zhangkeda.com/?id=563</link><description>&lt;p&gt;&lt;img class=&quot;ue-image&quot; src=&quot;https://www.zhangkeda.com/zb_users/upload/2024/12/202412121733993343722285.png&quot; title=&quot;微信图片_20241212164846.png&quot; alt=&quot;微信图片_20241212164846.png&quot;/&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 12 Dec 2024 16:46:31 +0800</pubDate></item><item><title>wangEditor5 在vue3中图片莫名无法显示，丢失的情况</title><link>https://www.zhangkeda.com/?id=562</link><description>&lt;p&gt;&lt;span style=&quot;font-size: 16px; color: #FF0000;&quot;&gt;&lt;strong&gt;问题出现在使用了其他编辑器保存到数据库的数据，或者是采集来的数据在wangEditor中再编辑&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;经过多次测试，发现wangEditor5在vue3下面如果去加载的文章是之前用其他编辑器保存的文章，其他编辑器保存在数据库中的数据，比如使用了&amp;lt;div&amp;gt;&amp;lt;img src=&amp;quot;abc.jpg&amp;quot;/&amp;gt;&amp;lt;div&amp;gt;&lt;/p&gt;&lt;p&gt;载入wangEditor中会自动过滤掉img导致图片无法展示。但是img标签如果在p标签里面不受影响，在其他标签下面可能被过滤。反应给了官方，官方表示不在去处理这个问题了。暂时没有解决方案。&lt;/p&gt;&lt;p&gt;问题的具体描述和体现，可以去wang的官方GitHub提问中查看，我也在那边反馈了此问题：https://github.com/wangeditor-team/wangEditor/issues/5880&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 25 Oct 2024 14:38:25 +0800</pubDate></item></channel></rss>