You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/extend/basic/ModelBasic.php

102 lines
2.5 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace basic;
use think\Db;
use think\Model;
class ModelBasic extends Model
{
private static $errorMsg;
private static $transaction = 0;
private static $DbInstance = [];
const DEFAULT_ERROR_MSG = '操作失败,请稍候再试!';
protected static function getDb($name,$update = false)
{
if(isset(self::$DbInstance[$name]) && $update == false)
return self::$DbInstance[$name];
else
return self::$DbInstance[$name] = Db::name($name);
}
/**
* 设置错误信息
* @param string $errorMsg
* @return bool
*/
protected static function setErrorInfo($errorMsg = self::DEFAULT_ERROR_MSG,$rollback = false)
{
if($rollback) self::rollbackTrans();
self::$errorMsg = $errorMsg;
return false;
}
/**
* 获取错误信息
* @param string $defaultMsg
* @return string
*/
public static function getErrorInfo($defaultMsg = self::DEFAULT_ERROR_MSG)
{
return !empty(self::$errorMsg) ? self::$errorMsg : $defaultMsg;
}
/**
* 开启事务
*/
public static function beginTrans()
{
Db::startTrans();
}
/**
* 提交事务
*/
public static function commitTrans()
{
Db::commit();
}
/**
* 关闭事务
*/
public static function rollbackTrans()
{
Db::rollback();
}
/**
* 根据结果提交滚回事务
* @param $res
*/
public static function checkTrans($res)
{
if($res){
self::commitTrans();
}else{
self::rollbackTrans();
}
}
/**
* 根據模型修改
*/
public static function saveFieldByWhere(array $where, array $data)
{
if (!$where || !$data) return false;
return self::where($where)->update($data);
}
}