getPk(); if (!empty($post[$id])) { $int = self::where($id, $post[$id])->save($post); } else { $int = self::insert($post); } return true; } /** * 获取列表数据 * @param $page * @param $where * @param $pageCount * @param $desc */ public function getList($page, $where = [], $pageCount = 20, $filed = ['*', ""], $desc = '') { $that = $this; if (!empty($filed[1])) { $that = $this->alias($filed[1]); } $that = $that->field($filed[0]) ->when(!empty($where), function ($query) use ($where) { foreach ($where as $k => $v) { if ($v instanceof Closure) { $v($query); } else { if (is_array($v)) { //whereLike if ($v[1] == 'whereLike') { if (!empty($v[0])) $query->whereLike($k, $v[0]); continue; } if ($v[1] == 'whereBetween') { if (!empty($v[0])) $query->whereBetween($k, $v[0]); continue; } $bool = false; eval('$bool = ' . $v[1] . '($v[0]);'); if ($bool) { $query->where($k, $v[0]); } } else { $query->where($k, $v); } } } }); if ($pageCount > 0) { $data = $that->order($desc) ->paginate(['list_rows' => $pageCount, 'page' => $page]) ->toArray(); } else { $odata = $that->order($desc) ->select(); $data['total'] = count($odata); $data['data'] = $data['total'] > 0 ? $odata->toArray() : []; } // echo $this->getLastSql(); return [$data['total'], $data['data']]; } /** * 设置错误信息 * @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(); } } }