Example #1
0
 /**
  * 执行请求
  * @param TXRequest $request
  * @throws TXException
  * @return mixed
  */
 private function call(TXRequest $request)
 {
     $module = $request->getModule() . 'Action';
     $method = $request->getMethod();
     $args = $this->getArgs($module, $method);
     $object = $this->getAction($module, $request);
     if ($object instanceof TXResponse || $object instanceof TXJSONResponse) {
         TXEvent::trigger(afterAction, array($request));
         return $object;
     }
     if ($object instanceof TXAction) {
         $result = call_user_func_array([$object, $method], $args);
         TXEvent::trigger(afterAction, array($request));
         return $result;
     } else {
         throw new TXException(2001, $request->getModule(), 404);
     }
 }
Example #2
0
 /**
  * 构造函数
  * @param string $code
  * @param array $params
  * @param string $html
  */
 public function __construct($code, $params = array(), $html = "500")
 {
     $message = $this->fmt_code($code, $params);
     //        \Biny\Logger::error($message, array('file'=>$this->getFile().":".$this->getLine(), 'trace'=>$this->getTraceAsString()));
     if (class_exists('TXEvent')) {
         TXEvent::trigger(onException, array($code, array($message, $this->getTraceAsString())));
     }
     if (class_exists('TXDatabase')) {
         TXDatabase::rollback();
     }
     try {
         if (RUN_SHELL) {
             echo "<b>Fatal error</b>:  {$message} in <b>{$this->getFile()}</b>:<b>{$this->getLine()}</b>\nStack trace:\n{$this->getTraceAsString()}";
             exit;
         }
         if ($httpCode = TXConfig::getConfig($html, 'http')) {
             header($httpCode);
         }
         if (SYS_DEBUG) {
             echo "<pre>";
             echo "<b>Fatal error</b>:  {$message} in <b>{$this->getFile()}</b>:<b>{$this->getLine()}</b>\nStack trace:\n{$this->getTraceAsString()}";
         } else {
             if (TXApp::$base->request->isShowTpl() || !TXApp::$base->request->isAjax()) {
                 $params = ['CDN_ROOT' => TXConfig::getAppConfig('CDN_ROOT')];
                 echo new TXResponse("error/exception", array('msg' => $this->messages[$html] ?: "系统数据异常:{$html}"), $params);
             } else {
                 $data = array("flag" => false, "error" => $this->messages[$html] ?: "系统数据异常:{$html}");
                 echo new TXJSONResponse($data);
             }
         }
         die;
     } catch (TXException $ex) {
         //防止异常的死循环
         echo "system Error";
         exit;
     }
 }
Example #3
0
 /**
  * 更新数据或者加1
  * @param $inserts
  * @param $sets ['num'=>2]
  * @return bool|int|mysqli_result|string
  */
 public function createOrAdd($inserts, $sets)
 {
     $set = $this->buildCount($sets);
     $fields = $this->buildInsert($inserts);
     $sql = sprintf("INSERT INTO %s %s ON DUPLICATE KEY UPDATE %s", $this->dbTable, $fields, $set);
     TXEvent::trigger(onSql, [$sql]);
     return $this->execute($sql, true);
 }
Example #4
0
 /**
  * @param string $msg
  * @param bool $encode
  * @return TXJSONResponse|TXResponse
  */
 public function error($msg = "数据异常", $encode = true)
 {
     TXEvent::trigger(onError, array($msg));
     if ($this->showTpl && (TXApp::$base->request->isShowTpl() || !TXApp::$base->request->isAjax())) {
         return $this->display('error/msg', ['msg' => $msg]);
     } else {
         $data = array("flag" => false, "error" => $msg);
         return $this->json($data, $encode);
     }
 }
Example #5
0
 /**
  * 查询条件
  * @param $method ['max', 'min', 'sum', 'avg']
  * @param $args
  * @return mixed
  * @throws TXException
  */
 public function __call($method, $args)
 {
     if (in_array($method, $this->methods)) {
         if ($this instanceof TXSingleDAO) {
             $cond = new TXSingleCond($this);
         } else {
             $cond = new TXDoubleCond($this);
         }
         return call_user_func_array([$cond, $method], $args);
     } else {
         if (in_array($method, $this->calcs)) {
             $where = isset($args[1]) && $args[1]->get('where') ? " WHERE " . $args[1]->get('where') : "";
             $sql = sprintf("SELECT %s(`%s`) as `%s` FROM %s%s", $method, $args[0], $method, $this->getTable(), $where);
             TXEvent::trigger(onSql, [$sql]);
             $ret = $this->sql($sql, null, self::FETCH_TYPE_ONE);
             return $ret[$method] ?: 0;
         } else {
             throw new TXException(3009, array($method, get_called_class()));
         }
     }
 }