GroupBuyLbActivity.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\api\model\groupbuylb;
  3. use app\common\model\groupbuylb\GroupBuyLbActivity as GroupBuyLbActivityModel;
  4. use app\common\model\groupbuylb\GroupBuyLbActivityAction as GroupBuyLbActivityActionModel;
  5. use app\common\model\groupbuylb\GroupBuyLbGoods as GroupBuyLbGoodsModel;
  6. use think\facade\Log;
  7. /**
  8. * 拼团裂变活动模型
  9. * @package app\store\model\coupon
  10. */
  11. class GroupBuyLbActivity extends GroupBuyLbActivityModel
  12. {
  13. public function getGroupBuyLbPrice($goodsId){
  14. $list = $this->validActivity($goodsId);
  15. $group_price = $list->group_price??null;
  16. if($list){
  17. return ['group_price'=>$group_price,'activity_id'=>$list->id];
  18. }
  19. return null;
  20. }
  21. /**
  22. * 获取列表
  23. * @param $goodsId
  24. * @return mixed
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public static function validActivity($goodsId)
  30. {
  31. // 检索查询条件
  32. $now = date('Y-m-d H:i:s');
  33. $filter[] = ['ac.start_time','<',$now];
  34. $filter[] = ['ac.end_time','>',$now];
  35. $filter[] = ['ac.audit_status','=',1];
  36. $filter[] = ['ac.status','=',1];
  37. $filter[] = ['g.goods_id','=',$goodsId];
  38. // 执行查询
  39. $list = self::field('ac.*,g.group_price')
  40. ->with([])
  41. ->alias('ac')
  42. ->leftJoin('group_buy_lb_goods g','g.group_buy_lb_activity_id = ac.id')
  43. ->where($filter)
  44. ->find();
  45. return $list;
  46. // dd(self::getLastSql());
  47. // dd($list['giftGoods']);
  48. // if (!$list)return null;
  49. // $list = $list->toArray();
  50. // $list['empty_gifts'] = false;//当所有的赠品库存都是0:true
  51. // $giftsGoods = null;
  52. // $count = count($list['giftGoods']);
  53. // foreach ($list['giftGoods'] as $key=>$g){
  54. // if ($g['goods_info']['stock_total'] < 1){
  55. // $count--;
  56. // }else{
  57. // $giftsGoods[] = $g;//库存大于0的才展示这个赠品
  58. // }
  59. // }
  60. // unset($list['giftGoods']);
  61. // if ($count == 0){//
  62. // $list['empty_gifts'] = true;
  63. // }
  64. // $list['gift_goods'] = $giftsGoods;
  65. // $list['remain_secs'] = strtotime($list['end_time']) - time();
  66. return $list;
  67. }
  68. }