public function actionGetFavouriteStory()
 {
     $customer_id = $this->getParam("customer_id");
     $ids = HiStoryFavourite::model()->findByAttributes(array('customer_id' => $customer_id));
     $result = array();
     if (!empty($ids)) {
         $c = new CDbCriteria();
         $c->addInCondition('story_id', json_decode($ids['story_ids']));
         $result = Converter::convertModelToArray(HiStory::model()->with('customer')->findAll($c));
     }
     EchoUtility::echoMsgTF(true, '获取收藏的故事', $result);
 }
 public function actionFavouriteStory()
 {
     $story_id = $this->getParam('story_id');
     $customer_id = $this->getParam('customer_id');
     $ids = HiStoryFavourite::model()->findByAttributes(array('customer_id' => $customer_id));
     $result = array();
     $flag = array();
     if (empty($ids)) {
         $ids = new HiStoryFavourite();
         $ids['customer_id'] = $customer_id;
         $story_ids = array();
         array_push($story_ids, $story_id);
         $ids['story_ids'] = json_encode($story_ids);
         $result = $ids->insert();
         $story = HiStory::model()->findByPk($story_id);
         $story['follow_count'] = (int) $story['follow_count'] + 1;
         $story->update();
         $flag = 1;
     } else {
         $ids_array = json_decode($ids['story_ids']);
         if (in_array($story_id, $ids_array)) {
             foreach ($ids_array as $k => $v) {
                 if ($v == $story_id) {
                     unset($ids_array[$k]);
                 }
             }
             $ids['story_ids'] = json_encode($ids_array);
             $result = $ids->update();
             $story = HiStory::model()->findByPk($story_id);
             $story['follow_count'] = (int) $story['follow_count'] - 1;
             $story->update();
             $flag = 0;
         } else {
             array_push($ids_array, $story_id);
             $ids['story_ids'] = json_encode($ids_array);
             $result = $ids->update();
             $story = HiStory::model()->findByPk($story_id);
             $story['follow_count'] = (int) $story['follow_count'] + 1;
             $story->update();
             $flag = 1;
         }
     }
     EchoUtility::echoMsgTF($result, '喜欢', $flag);
 }