<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Dao; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; class DModelUtil { public static function model($PomZz, $TAWWJ) { goto uZO3n; Q5sZM: $f3czO->setConnection($PomZz); goto fN4nx; fN4nx: return $f3czO; goto veLxz; uZO3n: $f3czO = new DynamicModel(); goto aMs0s; aMs0s: $f3czO->setTable($TAWWJ); goto Q5sZM; veLxz: } public static function get($PomZz, $TAWWJ, $g09Lt, $Oax6w = array('*')) { goto UmgiB; GuyBE: return $f3czO->toArray(); goto PUmYF; UmgiB: if (is_string($g09Lt) || is_numeric($g09Lt)) { $g09Lt = array('id' => $g09Lt); } goto x_zU3; x_zU3: $f3czO = self::model($PomZz, $TAWWJ)->where($g09Lt)->first($Oax6w); goto x2304; x2304: if (empty($f3czO)) { return null; } goto GuyBE; PUmYF: } public static function insert($PomZz, $TAWWJ, $EdQjV) { goto ZokkT; ZokkT: $f3czO = self::model($PomZz, $TAWWJ); goto aaQ98; OnU6h: return $f3czO->toArray(); goto txtUx; aaQ98: foreach ($EdQjV as $kh68j => $tHq0l) { $f3czO->{$kh68j} = $tHq0l; } goto kK8nH; kK8nH: $f3czO->save(); goto OnU6h; txtUx: } public static function insertAll($PomZz, $TAWWJ, $bOI09, $u5iJt = true) { if ($u5iJt) { foreach ($bOI09 as $eQWJY => $EdQjV) { $bOI09[$eQWJY]['created_at'] = date('Y-m-d H:i:s'); $bOI09[$eQWJY]['updated_at'] = date('Y-m-d H:i:s'); } } DB::connection($PomZz)->table($TAWWJ)->insert($bOI09); } public static function delete($PomZz, $TAWWJ, $g09Lt) { if (is_string($g09Lt) || is_numeric($g09Lt)) { $g09Lt = array('id' => $g09Lt); } return self::model($PomZz, $TAWWJ)->where($g09Lt)->delete(); } public static function update($PomZz, $TAWWJ, $g09Lt, $EdQjV) { goto PtKFI; PtKFI: if (empty($g09Lt)) { return null; } goto gh8SH; FjirT: if (empty($EdQjV)) { return null; } goto mm_jz; mm_jz: return self::model($PomZz, $TAWWJ)->where($g09Lt)->update($EdQjV); goto cRGqI; gh8SH: if (is_string($g09Lt) || is_numeric($g09Lt)) { $g09Lt = array('id' => $g09Lt); } goto FjirT; cRGqI: } }