| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace addons\Bargain\common\logic\order\limit;
- use addons\Bargain\common\enums\BargainEnum;
- use addons\Bargain\common\models\BargainActive;
- use addons\Bargain\common\models\BargainOrder;
- use addons\Bargain\common\models\BargainUserOrder;
- use common\enums\StatusEnum;
- use common\logic\order\OrderFormLogic;
- use common\models\goods\Goods;
- use Exception;
- use yii\helpers\Json;
- class BargainLimit extends BaseLimit
- {
- public function execute(OrderFormLogic $form)
- {
- try {
- } catch (Exception $e) {
- return false;
- }
- }
- /**
- * @desc:
- * @Author: hua
- * @Date: 2022/1/4
- * @Time: 16:46
- * @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);
- $bargain_active = BargainActive::findOne(['id' => $data['active_id'], 'mall_id' => $form->mall_id]);
- if (empty($bargain_active)) throw new \Exception('活动不存在');
- if ($time < $bargain_active['begin_time']) throw new \Exception('活动还没开始');
- if ($time > $bargain_active['end_time']) throw new \Exception('活动已过期');
- if ($bargain_active['type'] == 1) {
- $goods = Goods::getOne([
- ['mall_id' => $form->mall_id],
- ['id' => $bargain_active['goods_id']],
- ['status' => StatusEnum::ENABLED]
- ], true, [], null, 'goods_name');
- if ($bargain_active['stock'] <= 0) throw new \Exception($goods['goods_name'] . '商品已售罄,暂时无法购买哦~');
- }
- }
- }
|