user; $time = time(); $data = is_array($form->data) ? $form->data : Json::decode($form->data, true); $group_buy_active = GroupBuyActive::findOne(['id' => $data['active_id'], 'mall_id' => $form->mall_id]); if (empty($group_buy_active)) throw new \Exception('活动不存在'); if ($time < $group_buy_active['start_at']) throw new \Exception('活动还没开始'); if ($time > $group_buy_active['end_at']) throw new \Exception('活动已过期'); if (!empty($data['open_group_id'])) { //参与别人的团,团员身份 $user_level_limit = $group_buy_active['user_level_limit']; if ($user_level_limit != 'all' && !in_array($user['level'], explode(',', $user_level_limit))) { throw new \Exception('不是指定的团员等级'); } // $res = GroupBuyOrder::findOne([ // 'group_buy_active_id' => $group_buy_active['id'], // 'mall_id' => $form['mall_id'], // 'is_commander' => 0, // 'user_id' => $form['user_id'], // 'order_status' => GroupBuyEnum::GROUP_SUCCESS // ]); // if ($res) throw new \Exception('您已参与过该拼团活动'); $open_order = GroupBuyOrder::findOne(['id' => $data['open_group_id'], 'mall_id' => $form['mall_id']]); if ($open_order->group_buy_active_id != $data['active_id']) throw new \Exception('该团不合法'); if ($open_order->order_status != GroupBuyEnum::JOINING) throw new \Exception('该团无效'); $effective_time = $group_buy_active['effective_time'] * 60; if ($time - $open_order['created_at'] > $effective_time) throw new \Exception('拼团已结束'); $counts = GroupBuyOrder::find()->where(['open_group_id' => $data['open_group_id'], 'mall_id' => $form['mall_id'], 'order_status' => GroupBuyEnum::JOINING])->count(); $surplus_size = $group_buy_active['group_size'] - $counts; // if ($group_buy_active['is_virtual'] && $counts == $group_buy_active['gt_group_size']) throw new \Exception('该团已满员'); if ($surplus_size <= 0) throw new \Exception('该团已满员'); $open_order = GroupBuyOrder::findOne(['open_group_id' => $data['open_group_id'], 'order_status' => [GroupBuyEnum::NOT_PAY, GroupBuyEnum::JOINING], 'user_id' => $form->user_id, 'mall_id' => $form['mall_id']]); if ($open_order){ if($open_order->order_status==GroupBuyEnum::NOT_PAY)throw new \Exception('您已参团,还未支付,请到拼团订单付款'); if($open_order->order_status==GroupBuyEnum::OPEN_GROUP)throw new \Exception('您已参与该拼团,请耐心等级开团结果'); } } else { //自己发起拼团,团长身份 $commander_level_limit = $group_buy_active['commander_level_limit']; if ($commander_level_limit != 'all' && !in_array($user['level'], explode(',', $commander_level_limit))) { throw new \Exception('不是指定的团长等级'); } } if (!empty($group_buy_active['limit_buy_num']) && $data['num'] > $group_buy_active['limit_buy_num']) throw new \Exception('每单限购' . $group_buy_active['limit_buy_num']); } }