90 lines
2.9 KiB
PHP
90 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Component\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Dishes extends Model {
|
|
protected $table = 'dishes';
|
|
/**
|
|
* The attributes that aren't mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $guarded = [];
|
|
|
|
public static function getName($data) {
|
|
$dish_name = Dishes::where('code', $data)->where('is_history', 0)->first();
|
|
if ($dish_name) {
|
|
$dish_name = $dish_name['name'];
|
|
} else {
|
|
$dish_name = Dishes::where('code', $data)->where('is_history', 1)->first();
|
|
if ($dish_name) {
|
|
$dish_name = $dish_name['name'];
|
|
} else {
|
|
$dish_name = 'Связанный товар удален';
|
|
}
|
|
}
|
|
if ($dish_name == 'Связанный товар удален') {
|
|
$dish_name = Dishes::where('legacy_code', $data)->where('is_history', 0)->first();
|
|
if ($dish_name) {
|
|
$dish_name = $dish_name['name'];
|
|
} else {
|
|
$dish_name = Dishes::where('legacy_code', $data)->where('is_history', 1)->first();
|
|
if ($dish_name) {
|
|
$dish_name = $dish_name['name'];
|
|
} else {
|
|
$dish_name = 'Связанный товар удален';
|
|
}
|
|
}
|
|
}
|
|
return $dish_name;
|
|
}
|
|
|
|
public static function isReal($data) {
|
|
$dish_isReal = Dishes::where('code', $data)->where('is_history', 0)->first();
|
|
$isReal = 0;
|
|
if ($dish_isReal) {
|
|
$isReal = intval($dish_isReal['real_count']);
|
|
} else {
|
|
$dish_isReal = Dishes::where('code', $data)->where('is_history', 1)->first();
|
|
if ($dish_isReal) {
|
|
$isReal = intval($dish_isReal['real_count']);
|
|
} else {
|
|
$isReal = 0;
|
|
}
|
|
}
|
|
return $isReal;
|
|
}
|
|
|
|
public static function isServing($data) {
|
|
$dish_isServing = Dishes::where('code', $data)->where('is_history', 0)->first();
|
|
$isServing = 0;
|
|
if ($dish_isServing) {
|
|
$isServing = intval($dish_isServing['is_serving']);
|
|
} else {
|
|
$dish_isServing = Dishes::where('code', $data)->where('is_history', 1)->first();
|
|
if ($dish_isServing) {
|
|
$isServing = intval($dish_isServing['is_serving']);
|
|
} else {
|
|
$isServing = 0;
|
|
}
|
|
}
|
|
return $isServing;
|
|
}
|
|
|
|
public static function GetPrinterCode($data) {
|
|
$dish = Dishes::where('legacy_code', $data)->where('is_history', 0)->first();
|
|
if ($dish) {
|
|
$printer_code = $dish['printer_code'];
|
|
} else {
|
|
$dish = Dishes::where('legacy_code', $data)->where('is_history', 1)->first();
|
|
if ($dish) {
|
|
$printer_code = $dish['printer_code'];
|
|
} else {
|
|
$printer_code = 0;
|
|
}
|
|
}
|
|
return $printer_code;
|
|
}
|
|
} |