<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Dao; use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Str; class ModelManageUtil { public static function table($I1hTb, $bJgWQ = 'mysql') { return config('database.connections.' . $bJgWQ . '.prefix') . $I1hTb; } public static function fixDatetime0000($I1hTb, $Q2vn5) { goto bt3ov; GUE6A: $I1hTb = ModelManageUtil::table($I1hTb); goto R8HSp; E77_0: $A0YDi = Carbon::now(); goto GUE6A; bt3ov: if (!is_array($Q2vn5)) { $Q2vn5 = array($Q2vn5); } goto E77_0; R8HSp: foreach ($Q2vn5 as $Nrp0b) { ModelManageUtil::statement("UPDATE {$I1hTb} SET `{$Nrp0b}`='{$A0YDi}' WHERE `{$Nrp0b}`='0000-00-00 00:00:00'"); } goto qbu6C; qbu6C: } public static function hasTable($I1hTb) { return Schema::hasTable($I1hTb); } public static function listTableColumns($I1hTb) { if (!self::hasTable($I1hTb)) { return array(); } return Schema::getColumnListing($I1hTb); } public static function hasTableColumn($I1hTb, $JNXBz) { $aNyiQ = self::listTableColumns($I1hTb); return in_array($JNXBz, $aNyiQ); } public static function listIds($I1hTb, $ArzOE = array(), $c0fAD = 100, $HVUKH = 'id') { $NjVHK = ModelUtil::model($I1hTb)->where($ArzOE)->limit($c0fAD)->get(array($HVUKH)); return ArrayUtil::fetchSpecifiedKeyToArray($NjVHK, $HVUKH); } public static function statement($XV8p2, $bJgWQ = 'mysql') { DB::connection($bJgWQ)->statement($XV8p2); } public static function truncate($I1hTb, $bJgWQ = 'mysql') { $I1hTb = self::table($I1hTb, $bJgWQ); self::statement("TRUNCATE TABLE `{$I1hTb}`", $bJgWQ); } public static function query($XV8p2, $bJgWQ = 'mysql') { goto ZlT4u; ZlT4u: $RgydD = DB::select(DB::raw($XV8p2)); goto VwsvO; fblH0: return $RgydD; goto lYFaE; VwsvO: if (is_array($RgydD)) { foreach ($RgydD as $U9AsU => $yw7NX) { if ($yw7NX instanceof \stdClass) { $RgydD[$U9AsU] = (array) $yw7NX; } } } else { if ($RgydD instanceof \stdClass) { $RgydD = (array) $RgydD; } } goto fblH0; lYFaE: } public static function moveToConn($I1hTb, $bJgWQ, $c0fAD = 100, $HVUKH = 'id') { goto hZ0y_; YFf8y: $NjVHK = ModelUtil::allIn($I1hTb, $HVUKH, $a3gf2); goto q19wt; XxEDA: if (empty($a3gf2)) { return 0; } goto YFf8y; q19wt: if (empty($NjVHK)) { return 0; } goto lMZas; lMZas: try { goto lZiiC; lJgXY: return count($NjVHK); goto pY1sI; lZiiC: DModelUtil::insertAll($bJgWQ, $I1hTb, $NjVHK, false); goto cyMgt; cyMgt: ModelUtil::deleteIn($I1hTb, $a3gf2, $HVUKH); goto lJgXY; pY1sI: } catch (\Exception $vBRkZ) { goto TOGcd; IpyHB: foreach ($NjVHK as $SP0Zs) { try { goto MEuLB; sHDNC: ModelUtil::delete($I1hTb, array($HVUKH => $SP0Zs[$HVUKH])); goto L1MVm; L1MVm: $mKUIu++; goto On8Jo; MEuLB: DModelUtil::insertAll($bJgWQ, $I1hTb, array($SP0Zs), false); goto sHDNC; On8Jo: } catch (\Exception $vBRkZ) { if (Str::contains($vBRkZ->getMessage(), 'Duplicate entry')) { try { goto kRX4y; I0DUk: $mKUIu++; goto n6qAR; YIFod: DModelUtil::insertAll($bJgWQ, $I1hTb, array($SP0Zs), false); goto zId2n; zId2n: ModelUtil::delete($I1hTb, array($HVUKH => $SP0Zs[$HVUKH])); goto I0DUk; kRX4y: DModelUtil::delete($bJgWQ, $I1hTb, array($HVUKH => $SP0Zs[$HVUKH])); goto YIFod; n6qAR: } catch (\Exception $vBRkZ) { } } } } goto hYuZH; M4V36: $mKUIu = 0; goto IpyHB; hYuZH: return $mKUIu; goto mSto1; TOGcd: if (!Str::contains($vBRkZ->getMessage(), 'Duplicate entry')) { return 0; } goto M4V36; mSto1: } goto q6yM4; hZ0y_: $a3gf2 = ModelManageUtil::listIds($I1hTb, array(), $c0fAD, $HVUKH); goto XxEDA; q6yM4: } }