💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 团购管理 文件路径:shop/controllers/Seller/Promotion/GroupBuyCtl.php 一、团购列表【方法:index();】 1.套餐过期时间及备注 ``` <pre class="calibre14">``` <span class="token2">if</span> <span class="token1">(</span><span class="token">!</span>$this<span class="token">-</span><span class="token">></span>selfSupportFlag<span class="token1">)</span> <span class="token5">//普通店铺</span> <span class="token1">{</span> $com_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>comboFlag<span class="token1">;</span> <span class="token2">if</span> <span class="token1">(</span>$this<span class="token">-</span><span class="token">></span>comboFlag<span class="token1">)</span><span class="token5">//套餐可用</span> <span class="token1">{</span> <span class="token5">//店铺套餐信息</span> $combo_row <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyQuotaModel<span class="token">-</span><span class="token">></span><span class="token3">getGroupBuyQuotaByShopID</span><span class="token1">(</span>Perm<span class="token1">:</span><span class="token1">:</span>$shopId<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 2.团购类型【全部、线上团、虚拟团】 3.活动状态 ``` <pre class="calibre14">``` $cond_row<span class="token1">[</span><span class="token4">'shop_id'</span><span class="token1">]</span> <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$shopId<span class="token1">;</span> <span class="token5">//团购类型</span> <span class="token2">if</span> <span class="token1">(</span><span class="token3">request_int</span><span class="token1">(</span><span class="token4">'type'</span><span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span> $cond_row<span class="token1">[</span><span class="token4">'groupbuy_type'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">request_int</span><span class="token1">(</span><span class="token4">'type'</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">//活动状态</span> <span class="token2">if</span> <span class="token1">(</span><span class="token3">request_int</span><span class="token1">(</span><span class="token4">'state'</span><span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span> <span class="token5">//groupbuy_state--团购状态 1.审核中 2.正常 3.结束 4.审核失败 5.管理员关闭</span> $cond_row<span class="token1">[</span><span class="token4">'groupbuy_state'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">request_int</span><span class="token1">(</span><span class="token4">'state'</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">//团购活动列表</span> $data <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyBaseModel<span class="token">-</span><span class="token">></span><span class="token3">getGroupBuyGoodsList</span><span class="token1">(</span>$cond_row<span class="token1">,</span> <span class="token3">array</span><span class="token1">(</span><span class="token4">'groupbuy_id'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'DESC'</span><span class="token1">)</span><span class="token1">,</span> $page<span class="token1">,</span> $rows<span class="token1">)</span><span class="token1">;</span> ``` ``` 二、新增(虚拟)团购【方法:add();addVr();】 1.团购活动开始时间:不得小于当前时间,且小于团购套餐结束时间 2.团购活动结束时间:不得小于当前时间,且小于团购套餐结束时间 3.团购商品:选择商品 通过AJAX获得店铺所有商品,并且判断商品是否已经参加过其他团购活动 ``` <pre class="calibre14">``` $<span class="token1">(</span><span class="token4">".btn_show_search_goods"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">'click'</span><span class="token1">,</span> <span class="token2">function</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> $<span class="token1">(</span><span class="token4">'.search-goods-list'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">show</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $<span class="token1">(</span><span class="token4">'.btn_search_goods'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">click</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> <span class="token5">//搜索店铺商品</span> $<span class="token1">(</span><span class="token4">'.btn_search_goods'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">on</span><span class="token1">(</span><span class="token4">'click'</span><span class="token1">,</span> <span class="token2">function</span><span class="token1">(</span><span class="token1">)</span> <span class="token1">{</span> var url <span class="token">=</span> <span class="token4">"index.php?ctl=Seller_Promotion_GroupBuy&met=getShopGoods&typ=e"</span><span class="token1">;</span> var key <span class="token">=</span> $<span class="token1">(</span><span class="token4">"#key"</span><span class="token1">)</span><span class="token1">.</span><span class="token3">val</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> url <span class="token">=</span> key <span class="token">?</span> url <span class="token">+</span> <span class="token4">"&goods_name="</span> <span class="token">+</span> key <span class="token1">:</span> url<span class="token1">;</span> $<span class="token1">(</span><span class="token4">'.search-goods-list-bd'</span><span class="token1">)</span><span class="token1">.</span><span class="token3">load</span><span class="token1">(</span>url<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span><span class="token1">)</span><span class="token1">;</span> ``` ``` 4.提交 新增团购活动提交时进行表单验证:`$('#form').validator({})` 参数:group\_id -> 用于判断当前活动是修改还是添加 ``` <pre class="calibre14">``` $group_info <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyBaseModel<span class="token">-</span><span class="token">></span><span class="token3">getOneByWhere</span><span class="token1">(</span><span class="token1">[</span><span class="token4">'groupbuy_id'</span><span class="token">=</span><span class="token">></span>$group_id<span class="token1">]</span><span class="token1">)</span><span class="token1">;</span> $this<span class="token">-</span><span class="token">></span>groupBuyBaseModel<span class="token">-</span><span class="token">></span>sql<span class="token">-</span><span class="token">></span><span class="token3">startTransactionDb</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token2">if</span><span class="token1">(</span>$group_info<span class="token1">)</span> <span class="token1">{</span> <span class="token5">//编辑活动</span> $field_row<span class="token1">[</span><span class="token4">'groupbuy_state'</span><span class="token1">]</span> <span class="token">=</span> <span class="token6">1</span><span class="token1">;</span> $status_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyBaseModel<span class="token">-</span><span class="token">></span><span class="token3">editGroupBuy</span><span class="token1">(</span>$group_id<span class="token1">,</span> $field_row<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> <span class="token5">//添加活动</span> $status_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyBaseModel<span class="token">-</span><span class="token">></span><span class="token3">addGroupBuy</span><span class="token1">(</span>$field_row<span class="token1">,</span> <span class="token6">true</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> ``` ``` 三、套餐管理【方法:combo();】 1.店铺已有套餐列表 `$data = $this->shopCostModel->listByWhere($cond_row,$order_row,$page, $rows);` 2.提交 (1)购买套餐提交表单验证:`$('#form').validator({})` (2)在店铺的账期结算中扣除相关费用并且在paycenter中添加交易记录 ``` <pre class="calibre15">``` $flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>shopCostModel<span class="token">-</span><span class="token">></span><span class="token3">addCost</span><span class="token1">(</span>$field_row<span class="token1">,</span> <span class="token6">true</span><span class="token1">)</span><span class="token1">;</span> <span class="token5">//记录到店铺费用表</span> $combo_row <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyQuotaModel<span class="token">-</span><span class="token">></span><span class="token3">getGroupBuyQuotaByShopID</span><span class="token1">(</span>Perm<span class="token1">:</span><span class="token1">:</span>$shopId<span class="token1">)</span><span class="token1">;</span><span class="token5">//根据店铺id号查找店铺购买套餐情况</span> <span class="token2">if</span> <span class="token1">(</span>$combo_row<span class="token1">)</span> <span class="token1">{</span> <span class="token5">//1、原套餐已经过期,更新套餐开始时间和结束时间</span> <span class="token2">if</span> <span class="token1">(</span><span class="token3">strtotime</span><span class="token1">(</span>$combo_row<span class="token1">[</span><span class="token4">'combo_endtime'</span><span class="token1">]</span><span class="token1">)</span> <span class="token"><</span> <span class="token3">time</span><span class="token1">(</span><span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span> $field<span class="token1">[</span><span class="token4">'combo_starttime'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">get_date_time</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $field<span class="token1">[</span><span class="token4">'combo_endtime'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">date</span><span class="token1">(</span><span class="token4">'Y-m-d H:i:s'</span><span class="token1">,</span> <span class="token3">strtotime</span><span class="token1">(</span><span class="token4">"+$days days"</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> elseif <span class="token1">(</span><span class="token1">(</span><span class="token3">time</span><span class="token1">(</span><span class="token1">)</span> <span class="token">>=</span> <span class="token3">strtotime</span><span class="token1">(</span>$combo_row<span class="token1">[</span><span class="token4">'combo_starttime'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span> <span class="token">&&</span> <span class="token1">(</span><span class="token3">time</span><span class="token1">(</span><span class="token1">)</span> <span class="token"><=</span> <span class="token3">strtotime</span><span class="token1">(</span>$combo_row<span class="token1">[</span><span class="token4">'combo_endtime'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">)</span> <span class="token1">{</span> <span class="token5">//2、原套餐尚未过期,只需更新结束时间</span> $field<span class="token1">[</span><span class="token4">'combo_endtime'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">date</span><span class="token1">(</span><span class="token4">'Y-m-d H:i:s'</span><span class="token1">,</span> <span class="token3">strtotime</span><span class="token1">(</span><span class="token4">"+$days days"</span><span class="token1">,</span> <span class="token3">strtotime</span><span class="token1">(</span>$combo_row<span class="token1">[</span><span class="token4">'combo_endtime'</span><span class="token1">]</span><span class="token1">)</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> $op_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyQuotaModel<span class="token">-</span><span class="token">></span><span class="token3">renewGroupBuyCombo</span><span class="token1">(</span>$combo_row<span class="token1">[</span><span class="token4">'combo_id'</span><span class="token1">]</span><span class="token1">,</span> $field<span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token2">else</span> <span class="token1">{</span> <span class="token5">//记录不存在,添加套餐</span> $field<span class="token1">[</span><span class="token4">'combo_starttime'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">get_date_time</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> $field<span class="token1">[</span><span class="token4">'combo_endtime'</span><span class="token1">]</span> <span class="token">=</span> <span class="token3">date</span><span class="token1">(</span><span class="token4">'Y-m-d H:i:s'</span><span class="token1">,</span> <span class="token3">strtotime</span><span class="token1">(</span><span class="token4">"+$days days"</span><span class="token1">)</span><span class="token1">)</span><span class="token1">;</span> $field<span class="token1">[</span><span class="token4">'shop_id'</span><span class="token1">]</span> <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$shopId<span class="token1">;</span> $field<span class="token1">[</span><span class="token4">'shop_name'</span><span class="token1">]</span> <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>shopInfo<span class="token1">[</span><span class="token4">'shop_name'</span><span class="token1">]</span><span class="token1">;</span> $field<span class="token1">[</span><span class="token4">'user_id'</span><span class="token1">]</span> <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$userId<span class="token1">;</span> $field<span class="token1">[</span><span class="token4">'user_nickname'</span><span class="token1">]</span> <span class="token">=</span> Perm<span class="token1">:</span><span class="token1">:</span>$row<span class="token1">[</span><span class="token4">'user_account'</span><span class="token1">]</span><span class="token1">;</span> $op_flag <span class="token">=</span> $this<span class="token">-</span><span class="token">></span>groupBuyQuotaModel<span class="token">-</span><span class="token">></span><span class="token3">addGroupBuyCombo</span><span class="token1">(</span>$field<span class="token1">,</span> <span class="token6">true</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token5">//在paycenter中添加交易记录</span> $rs <span class="token">=</span> <span class="token3">get_url_with_encrypt</span><span class="token1">(</span>$key<span class="token1">,</span> <span class="token3">sprintf</span><span class="token1">(</span><span class="token4">'%s?ctl=Api_Pay_Pay&met=addCombo&typ=json'</span><span class="token1">,</span> $url<span class="token1">)</span><span class="token1">,</span> $formvars<span class="token1">)</span><span class="token1">;</span> ``` ```