data) ? $form->data : Json::decode($form->data, true); if ($data['attend_type'] == 1 && $data['num'] != 1) { throw new Exception('手动拼团一次最多只能购买一个商品'); } $basic = \Yii::$app->services->setting->addons->get($form['mall_id'], LuckyGroupEnum::ADDONS_NAME, 'basic'); $is_auto_pintuan = 1; if(isset($basic['is_auto_pintuan'])){ $is_auto_pintuan = $basic['is_auto_pintuan']; } if($is_auto_pintuan==0){ if($data['attend_type'] == 2){ throw new Exception('拼团类型错误'); } } // 合法性验证 if (!isset($data['num']) || (int)$data['num'] < 1) throw new Exception('请设置正确的下单数量'); $sku = GoodsAttr::getOne([['<>', 'status', StatusEnum::DELETE], ['id' => $data['attr_id']]], true, ['goods', 'goods.extra']); if (empty($sku) || empty($sku['goods'])) throw new Exception('找不到产品信息或者产品已删除'); $activity = LuckyGroupActivity::getOne([['id' => $data['activity_id'], 'status' => StatusEnum::ENABLED]]); if (empty($activity)) throw new Exception('拼团活动不存在'); $now = time(); $start_time = strtotime(date('Y-m-d ', time()) . $activity->start_time); $end_time = strtotime(date('Y-m-d ', time()) . $activity->end_time); if ($start_time > $now || $end_time < $now) throw new Exception('拼团活动未到开启时间'); $total_expend_num = bcmul($activity->expend_num, $data['num'], 2); $user_wallet = UserWallet::getOne([['user_id' => $form['user_id']]], false, [], false, 'user_id,score,balance'); $lucky_user = LuckyGroupUser::getGroupUser($form['mall_id'], $form['user_id']); if ($lucky_user->attend_times < $data['num']) throw new Exception('可参团次数不足'); if ($activity->expend_type == LuckyGroupEnum::EXPEND_TYPE_SCORE) {//积分 $score_name = \Yii::$app->services->setting->mall->get($form['mall_id'], 'score.score_name') ?? '积分'; if ($user_wallet->score < $total_expend_num) throw new Exception($score_name.'不足,无法参与拼团'); } else {//余额 if ($user_wallet->balance < $total_expend_num) throw new Exception('余额不足,无法参与拼团'); } $data['total_expend_num'] = $total_expend_num; $data['yu_attend_times'] = $data['num']; $data['expend_type'] = $activity->expend_type; //$form->data = json_encode($data); $form->data = $data; } }