Exemplo n.º 1
0
 public function actionCreate()
 {
     $params = $this->getParams();
     if (empty($params['productIds'])) {
         throw new BadRequestHttpException('missing param productIds');
     }
     if (empty($params['products'])) {
         throw new InvalidParameterException(['productExperice' => \Yii::t('product', 'not_exchange_experience')]);
     }
     $campaign = new Campaign(['scenario' => BaseModel::SCENARIO_CREATE]);
     $accountId = $this->getAccountId();
     $params['accountId'] = $accountId;
     $promotion['type'] = Campaign::TYPE_PROMOTION_CODE;
     if (!empty($params['productIds'])) {
         $promotion['data'] = $params['productIds'];
     }
     if (!empty($params['gift'])) {
         $promotion['gift'] = $params['gift'];
     } else {
         $promotion['gift'] = null;
     }
     $promotion['products'] = $params['products'];
     $promotion['tags'] = empty($params['tags']) ? [] : $params['tags'];
     $promotion['channels'] = empty($params['channels']) ? [] : $params['channels'];
     $params['promotion'] = $promotion;
     $params['participantCount'] = empty($params['participantCount']) ? null : intval($params['participantCount']);
     $params['limitTimes'] = empty($params['limitTimes']) ? null : intval($params['limitTimes']);
     $params['usedCount'] = 0;
     $campaign->load($params, '');
     $campaign->save();
     return $campaign;
 }