Exemplo n.º 1
0
 public function actionGiftDelete($id)
 {
     $model = GiftModel::model()->findByPk($id);
     /* $codeTable = sprintf(GiftModel::CREATE_CODE_TABLE_NAME, $this->wechatInfo->id);
        GiftCodeModel::model($codeTable)->deleteAll('giftId=:giftId', array(':giftId' => $id));*/
     //删除关键字或者menu action
     switch ($model->type) {
         case GiftModel::TYPE_KEYWORDS:
             KeywordsModel::model()->deleteAll('responseId=:responseId and type=:type', array(':responseId' => $id, ':type' => GiftModel::GIFT_TYPE));
             break;
         case GiftModel::TYPE_MENU:
             $menuactionModel = MenuactionModel::model()->find('responseId=:responseId', array('responseId' => $model->id));
             $menuactionModel->responseId = 0;
             $menuactionModel->save();
             break;
     }
     $model->delete();
     ShowMessage::success('删除成功', Yii::app()->createUrl('market/gift'));
 }
Exemplo n.º 2
0
 private function _getGiftReplay($responseId, $openId)
 {
     $giftInfo = GiftModel::model()->findByPk($responseId);
     if ($giftInfo->startTime > date('Y-m-d H:i:s')) {
         $content = $giftInfo->unstartMsg ? $giftInfo->unstartMsg : "抱歉,还未开始呢";
     } elseif ($giftInfo->endTime < date('Y-m-d H:i:s')) {
         $content = $giftInfo->endMsg ? $giftInfo->endMsg : "抱歉,你来晚了";
     } elseif ($giftInfo->status == 0) {
         $content = $giftInfo->pauseMsg ? $giftInfo->pauseMsg : "抱歉,活动暂时停止";
     } else {
         $codeTableName = GiftModel::model()->getCodeTableName($giftInfo->wechatId);
         $userHasGet = GiftCodeModel::model($codeTableName)->find('giftId=:giftId and openId=:openId', array(':giftId' => $giftInfo->id, ':openId' => $openId));
         if ($userHasGet) {
             $content = $giftInfo->RTemplate ? str_replace('{code}', $userHasGet->code, $giftInfo->RTemplate) : $userHasGet->code;
         } else {
             $codeInfo = GiftCodeModel::model($codeTableName)->find('giftId=:giftId and openId is null', array(':giftId' => $giftInfo->id));
             if ($codeInfo) {
                 //update
                 $codeInfo->openId = $openId;
                 $codeInfo->save();
                 $content = $giftInfo->template ? str_replace('{code}', $codeInfo->code, $giftInfo->template) : $codeInfo->code;
             } else {
                 $content = $giftInfo->codeOverMsg ? $giftInfo->codeOverMsg : "抱歉,领完了";
             }
         }
     }
     $responseObj = new WeChatTextResponse($content);
     return $responseObj;
 }
Exemplo n.º 3
0
 /**
  * 礼包码活动开关
  * @param $id
  */
 public function actionGiftStatus($id)
 {
     $status = Yii::app()->request->getParam('status');
     $model = GiftModel::model()->findByPk($id);
     $model->status = in_array($status, array(0, 1)) ? $status : 0;
     $model->save();
     echo json_encode(array('result' => 0));
 }