1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/02
- */
- namespace crmeb\basic;
- use think\facade\Db;
- use think\Model;
- class BaseModel extends Model
- {
- private static $errorMsg;
- private static $transaction = 0;
- private static $DbInstance = [];
- const DEFAULT_ERROR_MSG = '操作失败,请稍候再试!';
- /**
- * 设置错误信息
- * @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();
- }
- }
- /**
- * 获取ID
- * @param string $key 键名
- * @return mixed
- */
- public static function getkeytoid(string $key)
- {
- // $rs = Db::query(sprintf("call keytoid('%s')",$key));
- // return $rs[0][0]['cus_no'];
- $rs = self::order('uid DESC')->find();
- return $rs['uid']+1;
- }
- }
|