<?php

namespace Business\User;


class FeedBackServiceModel extends \Business\AbstractModel
{


    public function init() {

    }

    public function saveFeedback($param,$memberId){
        $feedbackDescribe = trim($param['feedbackDescribe']);
        $feedbackTelepone = trim($param['feedbackTelepone']);
        $type = (int)$param['type'];
        if(!$feedbackDescribe){
            \Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyFeedbackDescribe);
        }
        if(!$feedbackTelepone){
            \Error\ErrorModel::throwException(\Error\CodeConfigModel::emptyFeedbackDescribe);
        }
        $return = \Our\Common::checkMobilePhone($feedbackTelepone);
        if($return === false){
            \Error\ErrorModel::throwException(\Error\CodeConfigModel::feedbackTelError);
        }
        $imgArr = array();
        for ($i = 0 ; $i < 2 ; $i++){
            $number = str_replace(array(0,1,2),array('A','B','C'),$i);
            $image = $param['image'.$number];
            if($image && $type == 0){
                $time = date('YmdHis_');
                $file_name = $time.\Our\Validate::getNumberString();
                $result = \Our\ImageUtil::uploadBase64Image($image,\Our\ImageConst::feedback,$file_name);
                if($result){
                    $imgArr[] = $file_name;
                }
            }else{
                $imgArr[] = $image;
            }
        }
        $insert = array();
        $insert['feedback_image'] = serialize($imgArr);
        $insert['feedback_describe'] = $feedbackDescribe;
        $insert['feedback_time'] = time();
        $insert['feedback_telepone'] = $feedbackTelepone;
        $insert['member_id'] = $memberId;

        $return = \DAO\FeedBackModel::getInstance()->insert($insert);
        if(!$return){
            \Error\ErrorModel::throwException(\Error\CodeConfigModel::saveFeedbackError);
        }
    }
    private static $_instance = null;

    /**
     * 单例模式获取类实例
     *
     */
    public static function getInstance() {
        if (!(self::$_instance instanceof self)) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }

}
