| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\DepositPresale\common\logic\order\limit;
- use addons\DepositPresale\common\enums\DepositPresaleEnum;
- use addons\DepositPresale\common\models\DepositPresaleActive;
- use addons\DepositPresale\common\models\DepositPresaleOrder;
- use Exception;
- use yii\helpers\Json;
- class DepositPresaleLimit extends BaseLimit
- {
- public function execute($form)
- {
- try {
- } catch (Exception $e) {
- return false;
- }
- }
- /**
- * @desc:购买等级验证
- * @Author: hua
- * @Date: 2021/12/15
- * @Time: 10:17
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $form
- * @throws Exception
- */
- public static function compute($form)
- {
- $user = $form->user;
- $time = time();
- $data = is_array($form->data) ? $form->data : Json::decode($form->data, true);
- $deposit_presale_active = DepositPresaleActive::findOne(['id' => $data['active_id'], 'mall_id' => $form->mall_id]);
- if (empty($deposit_presale_active)) throw new \Exception('活动不存在');
- if ($time < $deposit_presale_active['deposit_start_at']) throw new \Exception('活动还没开始');
- if ($time > $deposit_presale_active['deposit_end_at']) throw new \Exception('活动已过期');
- if (!empty($data['open_group_id'])) {
- //参与别人的团,团员身份
- $user_level_limit = $deposit_presale_active['user_level_limit'];
- if ($user_level_limit != 'all' && !in_array($user['level'], explode(',', $user_level_limit))) {
- throw new \Exception('不是指定的团员等级');
- }
- $open_order = DepositPresaleOrder::findOne(['id' => $data['open_group_id'], 'mall_id' => $form['mall_id']]);
- if ($open_order->deposit_presale_active_id != $data['active_id']) throw new \Exception('该团不合法');
- if ($open_order->order_status != DepositPresaleEnum::JOINING) throw new \Exception('该团无效');
- $effective_time = $deposit_presale_active['effective_time'] * 60;
- if ($time - $open_order['created_at'] > $effective_time) throw new \Exception('定金预售已结束');
- $counts = DepositPresaleOrder::find()->where(['open_group_id' => $data['open_group_id'], 'mall_id' => $form['mall_id'], 'order_status' => DepositPresaleEnum::JOINING])->count();
- $surplus_size = $deposit_presale_active['group_size'] - $counts;
- // if ($deposit_presale_active['is_virtual'] && $counts == $deposit_presale_active['gt_group_size']) throw new \Exception('该团已满员');
- if ($surplus_size <= 0) throw new \Exception('该团已满员');
- $open_order = DepositPresaleOrder::findOne(['open_group_id' => $data['open_group_id'], 'order_status' => [DepositPresaleEnum::NOT_PAY, DepositPresaleEnum::JOINING], 'user_id' => $form->user_id, 'mall_id' => $form['mall_id']]);
- if ($open_order) {
- if ($open_order->order_status == DepositPresaleEnum::NOT_PAY) throw new \Exception('您已参团,还未支付,请到定金预售订单付款');
- if ($open_order->order_status == DepositPresaleEnum::OPEN_GROUP) throw new \Exception('您已参与该定金预售,请耐心等级开团结果');
- }
- } else {
- //自己发起定金预售,团长身份
- $commander_level_limit = $deposit_presale_active['commander_level_limit'];
- if ($commander_level_limit != 'all' && !in_array($user['level'], explode(',', $commander_level_limit))) {
- throw new \Exception('不是指定的团长等级');
- }
- }
- $purchase_limit_num = $form->sku[$deposit_presale_active->goods_id]['purchase_limit_num'];
- $already_buy_count = DepositPresaleOrder::find()
- ->where(
- [
- 'and',
- ['goods_id' => $deposit_presale_active->goods_id],
- ['is_pay' => 1],
- ['user_id' => $user->id]
- ]
- )->count();
- $already_buy_count = $already_buy_count ?: 0;
- if (isset($data['num'])) {
- if (!empty($purchase_limit_num) && ($data['num'] + $already_buy_count) > $purchase_limit_num) throw new \Exception('限购' . $purchase_limit_num);
- if (!empty($deposit_presale_active['minimum_purchase']) && $data['num'] < $deposit_presale_active['minimum_purchase']) throw new \Exception('最低' . $deposit_presale_active['minimum_purchase'] . '件起购');
- }
- $data['deposit_presale_active'] = [
- 'final_payment_start_at' => date('Y-m-d H:i:s', $deposit_presale_active['final_payment_start_at']),
- 'final_payment_end_at' => date('Y-m-d H:i:s', $deposit_presale_active['final_payment_end_at']),
- ];
- $form->data = $data;
- }
- }
|