tp拼团&团长加价处理
作者:互联网
模型层代码:
public function getList() { //获取用户id,根据用户id查询此用户所属团长,然后展示团长发布的拼团商品,如果此用户所属的团长没有发布拼团商品则展示为空,如果这个用户没有上级或者上上级团长,则证明此用户为自己注册的,然后展示公司团长的拼团商品 $userId = $this->userId; if(empty($userId)){ return error_code(11067); } //获取当前用户信息 $userInfo = User::where('id', $userId)->find(); if ($userInfo == null){ return error_code(11081); //没有找到此用户 } //如果这个用户所属上级团长user_team_id不为空,则证明有上级团长id,否则获取平台团长platform_team_id,从而查询平台团长所发布的拼团商品 if (!empty($userInfo['user_team_id'])){ //根据当前用户id获取当前用户所属团长user_team_id $team_goods_id = TeamGoods::where('user_id', $userInfo['user_team_id'])->find(); //查看此用户团长有没有发布拼团上品 if (empty($team_goods_id)){ return error_code(15609);//没有找到拼团发起人 } //判断团长添加的拼团活动是否已经结束 if (!empty($team_goods_id['utime'])){ if (time() - $team_goods_id['utime'] > 86400){ return error_code(15600);//活动已结束 } }else{ if (time() - $team_goods_id['etime'] > 86400){ return error_code(15600);//活动已结束 } } $goodsId = explode(',', $team_goods_id['goods_id']); $goodsList = []; foreach ($goodsId as $v){ $data = Goods::where('id', $v)->where('marketable', Goods::MARKETABLE_UP)->find(); //上架 if (!empty($data)){ $goodsList[] = $data; } } }else{ //根据当前用户id获取当前用户所属平台团长platform_team_id $team_goods_id = TeamGoods::where('platform_team_id', $userInfo['platform_team_id'])->find(); //查看此用户团长有没有发布拼团上品 if (empty($team_goods_id)){ return error_code(15609);//没有找到拼团发起人 } //判断团长添加的拼团活动是否已经结束 if (!empty($team_goods_id['utime'])){ if (time() - $team_goods_id['utime'] > 86400){ return error_code(15600); //活动已结束 } }else{ if (time() - $team_goods_id['etime'] > 86400){ return error_code(15600); //活动已结束 } } $goodsId = explode(',', $team_goods_id['goods_id']); $goodsList = []; foreach ($goodsId as $v){ $data = Goods::where('id', $v)->where('marketable', Goods::MARKETABLE_UP)->find(); //上架 if (!empty($data)){ $goodsList[] = $data; } } //根据团长加价商品表shop_team_raise_price看团长有没有对此商品进行加价,如果有拼团商品价格为加价后的拼团价 $teamRaisePrice = TeamRaisePrice::where('team_id', $userInfo['platform_team_id'])->select(); if ($teamRaisePrice){ foreach ($goodsList as $k => $v){ foreach ($teamRaisePrice as $key => $val){ if ($goodsList[$k]['id'] == $teamRaisePrice[$key]['goods_id']) $goodsList[$k]['pintuan_price'] = $goodsList[$k]['pintuan_price'] + $teamRaisePrice[$key]['price']; } } } } foreach ($goodsList as &$value){ $value['image_url'] = _sImage($value['image_id']); } return ['status' => true, 'data' => $goodsList, 'msg' => '查询展示成功']; }
数据表:
标签:goods,tp,goodsList,拼团,加价,team,团长,id 来源: https://www.cnblogs.com/gaoyusui/p/16138452.html