12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\api\model\groupbuylb;
- use app\common\model\groupbuylb\GroupBuyLbActivity as GroupBuyLbActivityModel;
- use app\common\model\groupbuylb\GroupBuyLbActivityAction as GroupBuyLbActivityActionModel;
- use app\common\model\groupbuylb\GroupBuyLbGoods as GroupBuyLbGoodsModel;
- use think\facade\Log;
- /**
- * 拼团裂变活动模型
- * @package app\store\model\coupon
- */
- class GroupBuyLbActivity extends GroupBuyLbActivityModel
- {
-
- public function getGroupBuyLbPrice($goodsId){
- $list = $this->validActivity($goodsId);
- $group_price = $list->group_price??null;
- if($list){
- return ['group_price'=>$group_price,'activity_id'=>$list->id];
- }
- return null;
- }
-
- /**
- * 获取列表
- * @param $goodsId
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function validActivity($goodsId)
- {
- // 检索查询条件
- $now = date('Y-m-d H:i:s');
- $filter[] = ['ac.start_time','<',$now];
- $filter[] = ['ac.end_time','>',$now];
- $filter[] = ['ac.audit_status','=',1];
- $filter[] = ['ac.status','=',1];
- $filter[] = ['g.goods_id','=',$goodsId];
- // 执行查询
- $list = self::field('ac.*,g.group_price')
- ->with([])
- ->alias('ac')
- ->leftJoin('group_buy_lb_goods g','g.group_buy_lb_activity_id = ac.id')
- ->where($filter)
- ->find();
- return $list;
- // dd(self::getLastSql());
- // dd($list['giftGoods']);
- // if (!$list)return null;
- // $list = $list->toArray();
- // $list['empty_gifts'] = false;//当所有的赠品库存都是0:true
- // $giftsGoods = null;
- // $count = count($list['giftGoods']);
- // foreach ($list['giftGoods'] as $key=>$g){
- // if ($g['goods_info']['stock_total'] < 1){
- // $count--;
- // }else{
- // $giftsGoods[] = $g;//库存大于0的才展示这个赠品
- // }
- // }
- // unset($list['giftGoods']);
- // if ($count == 0){//
- // $list['empty_gifts'] = true;
- // }
- // $list['gift_goods'] = $giftsGoods;
- // $list['remain_secs'] = strtotime($list['end_time']) - time();
- return $list;
- }
- }
|