public function actionDelHistory()
 {
     $createdAt = $this->getParams('createdAt');
     $productId = $this->getParams('productId');
     if (empty($createdAt) || empty($productId)) {
         throw new BadRequestHttpException('missing param createdAt or productId');
     }
     $product = Product::findByPk(new \MongoId($productId));
     if (empty($product)) {
         throw new BadRequestHttpException('invalid productId');
     }
     //check the productId belong to which campaign that it is begining
     $campaignWhere = ['promotion.data' => ['$all' => [$product->_id]], 'isActivated' => true];
     $campaign = Campaign::findOne($campaignWhere);
     if (!empty($campaign)) {
         throw new BadRequestHttpException(Yii::t('product', 'can_not_delete'));
     }
     $usedCount = PromotionCode::countByProductIdAndCreatedAt(new \MongoId($productId), new \MongoDate($createdAt), true);
     if ($usedCount > 0) {
         throw new BadRequestHttpException(Yii::t('product', 'can_not_delete'));
     } else {
         $deleteArgs = ['productId' => $product->_id . '', 'createdAt' => $createdAt, 'type' => 'delete', 'description' => 'Direct: Delete promotionCodes'];
         $jobId = Yii::$app->job->create('backend\\modules\\product\\job\\PromotionCode', $deleteArgs);
     }
     return ['message' => 'OK', 'data' => $jobId];
 }
예제 #2
0
 public function deleteTag($accountId, $name)
 {
     Account::updateAll(['$pull' => ['tags' => ['name' => $name]]], ['_id' => $accountId]);
     Member::updateAll(['$pull' => ['tags' => $name]], ['accountId' => $accountId, 'tags' => $name]);
     Campaign::updateAll(['$pull' => ['tags' => $name]], ['accountId' => $accountId, 'tags' => $name]);
     $data = ['type' => 'tag_deleted', 'account_id' => $accountId, 'name' => $name];
     $this->notifyModules($data);
 }
예제 #3
0
 public function actionDelete($id)
 {
     $idstrList = explode(',', $id);
     $ids = [];
     foreach ($idstrList as $perId) {
         $ids[] = new MongoId($perId);
     }
     $where = ['_id' => ['$in' => $ids]];
     $goodsWhere = ['productId' => ['$in' => $ids]];
     $result = Product::findOne(array_merge($where, ['isBindCode' => true]));
     if (!empty($result)) {
         throw new BadRequestHttpException(Yii::t('product', 'can_not_delete_before_promocode'));
     }
     if (!empty(Campaign::getByProductIds($ids)) || !empty(Goods::findOne($goodsWhere))) {
         throw new BadRequestHttpException(Yii::t('product', 'can_not_delete'));
     }
     if (Product::deleteAll($where) == false) {
         throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
     }
     //delete the product intro
     ProductInfo::deleteAll($where);
     //delete goods and storeGoods
     $this->attachBehavior('ProductBehavior', new ProductBehavior());
     $this->delete($ids);
     Yii::$app->getResponse()->setStatusCode(204);
 }
예제 #4
0
 public static function renameTag($accountId, $name, $newName)
 {
     //add new tag to campaign
     Campaign::updateAll(['$addToSet' => ['tags' => $newName]], ['accountId' => $accountId, 'tags' => $name]);
     //remove old tags from campaign
     Campaign::updateAll(['$pull' => ['tags' => $name]], ['accountId' => $accountId, 'tags' => $name]);
 }
예제 #5
0
 /**
  * @args {"description": "Delay: Campaign expired every minute"}
  */
 public function perform()
 {
     Campaign::expiredByTime(new MongoDate(strtotime('+1 minute')));
 }
예제 #6
0
 public function extraFields()
 {
     return array_merge(parent::extraFields(), ['isAssociated' => function () {
         $campaign = Campaign::getByProductId($this->_id);
         return !empty($campaign);
     }, 'promotionCodeCount' => function () {
         return PromotionCode::countByProductIds([$this->_id]);
     }]);
 }
예제 #7
0
 /**
  * check the status of codes in campaign
  */
 public static function checkCode2CampainStatus($campaignCodeProductId, $member, $exchangeTime, $params)
 {
     if (empty($campaignCodeProductId)) {
         return [];
     }
     $invalid = $over = $vaild = $expired = [];
     $accountId = $member->accountId;
     foreach ($campaignCodeProductId as $code => $productId) {
         $campaigns = Campaign::findAll(['promotion.data' => ['$all' => [$productId]], 'accountId' => $accountId]);
         foreach ($campaigns as $campaign) {
             list($status, $message) = self::getCodeIsVaild($campaign, $exchangeTime);
             switch ($status) {
                 case self::CODE_STATUS_EXPIRED:
                     //campaign is expired
                     $expired[$code] = ['code' => $code, 'score' => 0, 'status' => self::CODE_STATUS_EXPIRED, 'description' => $message];
                     break;
                 case self::CODE_STATUS_INVALID:
                     $expired[$code] = ['code' => $code, 'score' => 0, 'status' => self::CODE_STATUS_INVALID, 'description' => $message];
                     break;
                 case self::CODE_STATUS_VALID:
                     //put the code in cache, we need check the limit times and participate count in the selectcampaign
                     self::setCache($member, $campaign, $code);
                     //get response from campaign
                     $response = self::selectCampaign($campaign, $member, $params, false);
                     if (self::CODE_STATUS_EXCEEDED == $response['status']) {
                         //campaign is over
                         $over[$code] = ['code' => $code, 'score' => 0, 'status' => self::CODE_STATUS_EXCEEDED, 'description' => $response['message']];
                     } else {
                         if (self::CODE_STATUS_VALID == $response['status']) {
                             $score = self::getCampaignScore($campaign);
                             if (isset($vaild[$code])) {
                                 $vaild[$code]['score'] += $score;
                             } else {
                                 $vaild[$code] = ['code' => (string) $code, 'score' => $score, 'status' => self::CODE_STATUS_VALID, 'description' => ''];
                             }
                         } else {
                             //check campain is over or code is can not fit with campaign
                             $invalid[$code] = ['code' => $code, 'score' => 0, 'status' => self::CODE_STATUS_INVALID, 'description' => $response['message']];
                         }
                     }
                     break;
             }
         }
     }
     //check code in vaild,clear other same code in other array
     foreach ($vaild as $code => $value) {
         //check invalid
         unset($invalid[$code]);
         //check expired
         unset($expired[$code]);
         //check over
         unset($over[$code]);
     }
     return array_merge($vaild, $invalid, $expired, $over);
 }
예제 #8
0
 /**
  * get the product info in the campaign
  * if the pageSize = 0,the api will return all products
  */
 public function actionProductInfo()
 {
     $params = $this->getQuery();
     $accountId = $this->getAccountId();
     $pageSize = $page = 0;
     if (!empty($params['pageSize'])) {
         if (empty($params['page'])) {
             throw new BadRequestHttpException('missing param page');
         }
         $pageSize = intval($params['pageSize']);
         $page = intval($params['page']);
     }
     return Campaign::searchProductInfo($accountId, $pageSize, $page);
 }
예제 #9
0
 /**
  * Update the status of campaign for product module.
  */
 public function actionCampaignExpired()
 {
     echo Campaign::expiredByTime(new \MongoDate(strtotime('+1 minute')));
 }