更新 app/Models/OperatorQue.php
All checks were successful
Deploy main / deploy (push) Successful in 21s
All checks were successful
Deploy main / deploy (push) Successful in 21s
This commit is contained in:
parent
a7b58b0339
commit
8c44c467d0
@ -4,290 +4,81 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* オペレータキューモデル - operator_queテーブル
|
||||
*
|
||||
* バッチ処理結果の通知や作業指示を管理
|
||||
*/
|
||||
class OperatorQue extends Model
|
||||
{
|
||||
/**
|
||||
* テーブル名
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'operator_que';
|
||||
|
||||
/**
|
||||
* プライマリキー
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'que_id';
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* 一括代入可能な属性
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'que_class', // キュークラス
|
||||
'user_id', // ユーザーID
|
||||
'contract_id', // 契約ID
|
||||
'park_id', // 駐輪場ID
|
||||
'que_comment', // キューコメント
|
||||
'que_status', // キューステータス
|
||||
'que_status_comment', // キューステータスコメント
|
||||
'work_instructions', // 作業指示
|
||||
'created_at', // 作成日時
|
||||
'updated_at' // 更新日時
|
||||
'que_class',
|
||||
'user_id',
|
||||
'contract_id',
|
||||
'park_id',
|
||||
'que_comment',
|
||||
'que_status',
|
||||
'que_status_comment',
|
||||
'work_instructions',
|
||||
'operator_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* キャストする属性
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'que_id' => 'integer',
|
||||
'que_class' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'contract_id' => 'integer',
|
||||
'park_id' => 'integer',
|
||||
'que_status' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime'
|
||||
// 定数
|
||||
/** キュー種別 */
|
||||
public const QueClass = [
|
||||
1 => '本人確認(社会人)',
|
||||
2 => '本人確認(学生)',
|
||||
3 => 'タグ発送',
|
||||
4 => '予約告知電話',
|
||||
5 => '定期更新電話',
|
||||
6 => '返金',
|
||||
7 => '再発行リミット超過',
|
||||
8 => '支払い催促',
|
||||
9 => 'シール発行催促',
|
||||
10 => 'シール再発行許可',
|
||||
101 => 'サーバーエラー',
|
||||
102 => 'プリンタエラー',
|
||||
103 => 'スキャナーエラー',
|
||||
104 => 'プリンタ用紙残少警告',
|
||||
];
|
||||
|
||||
/**
|
||||
* キュークラスの定数
|
||||
*/
|
||||
const CLASS_SHJ4C = 4; // SHJ-4C室割当処理
|
||||
const CLASS_SHJ6 = 6; // SHJ-6サーバ死活監視処理
|
||||
const CLASS_SHJ8 = 8; // SHJ-8バッチログ処理
|
||||
const CLASS_SHJ9 = 9; // SHJ-9売上集計処理
|
||||
const CLASS_SHJ10 = 10; // SHJ-10財政年度売上集計処理
|
||||
const CLASS_MAIL_SEND = 11; // メール送信処理
|
||||
/** キューステータス */
|
||||
public const QueStatus = [
|
||||
1 => 'キュー発生',
|
||||
2 => 'キュー作業中',
|
||||
3 => 'キュー作業済',
|
||||
4 => '返金済',
|
||||
];
|
||||
|
||||
/**
|
||||
* キューステータスの定数
|
||||
*/
|
||||
const STATUS_PENDING = 0; // 待機中
|
||||
const STATUS_COMPLETED = 1; // 完了
|
||||
const STATUS_ERROR = 2; // エラー
|
||||
const STATUS_CANCELLED = 3; // キャンセル
|
||||
|
||||
/**
|
||||
* 駐輪場との関連
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function park()
|
||||
public function getQueClassLabel(): string
|
||||
{
|
||||
return $this->belongsTo(Park::class, 'park_id', 'park_id');
|
||||
return self::QueClass[$this->que_class] ?? (string)$this->que_class;
|
||||
}
|
||||
|
||||
public function getQueStatusLabel(): string
|
||||
{
|
||||
return self::QueStatus[$this->que_status] ?? (string)$this->que_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* ユーザーとの関連
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'user_id');
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function park()
|
||||
{
|
||||
return $this->belongsTo(Park::class, 'park_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 契約との関連
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function contract()
|
||||
{
|
||||
return $this->belongsTo(RegularContract::class, 'contract_id', 'contract_id');
|
||||
return $this->belongsTo(Contract::class, 'contract_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* バッチ処理用キューを作成
|
||||
*
|
||||
* @param int $queClass キュークラス
|
||||
* @param string $comment コメント
|
||||
* @param int $status ステータス
|
||||
* @param string|null $workInstructions 作業指示
|
||||
* @param int|null $parkId 駐輪場ID
|
||||
* @return OperatorQue 作成されたキュー
|
||||
*/
|
||||
public static function createBatchQueue(
|
||||
int $queClass,
|
||||
string $comment,
|
||||
int $status = self::STATUS_COMPLETED,
|
||||
?string $workInstructions = null,
|
||||
?int $parkId = null
|
||||
): OperatorQue {
|
||||
return self::create([
|
||||
'que_class' => $queClass,
|
||||
'user_id' => null,
|
||||
'contract_id' => null,
|
||||
'park_id' => $parkId,
|
||||
'que_comment' => $comment,
|
||||
'que_status' => $status,
|
||||
'que_status_comment' => self::getStatusComment($status),
|
||||
'work_instructions' => $workInstructions
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* SHJ-9用キューを作成
|
||||
*
|
||||
* @param string $message メッセージ
|
||||
* @param int $batchLogId バッチログID
|
||||
* @param int $status ステータス
|
||||
* @return OperatorQue 作成されたキュー
|
||||
*/
|
||||
public static function createShjNineQueue(
|
||||
string $message,
|
||||
int $batchLogId,
|
||||
int $status = self::STATUS_COMPLETED
|
||||
): OperatorQue {
|
||||
return self::createBatchQueue(
|
||||
self::CLASS_SHJ9,
|
||||
$message,
|
||||
$status,
|
||||
"SHJ-9売上集計処理 BatchLogID: {$batchLogId}"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定期間のキューを取得
|
||||
*
|
||||
* @param string $startDate 開始日
|
||||
* @param string $endDate 終了日
|
||||
* @param int|null $queClass キュークラス
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getQueuesByPeriod(string $startDate, string $endDate, ?int $queClass = null)
|
||||
public function operator()
|
||||
{
|
||||
$query = self::whereBetween('created_at', [$startDate, $endDate]);
|
||||
|
||||
if ($queClass) {
|
||||
$query->where('que_class', $queClass);
|
||||
return $this->belongsTo(User::class, 'operator_id');
|
||||
}
|
||||
|
||||
return $query->with(['park', 'user', 'contract'])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 未完了のキューを取得
|
||||
*
|
||||
* @param int|null $queClass キュークラス
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function getPendingQueues(?int $queClass = null)
|
||||
{
|
||||
$query = self::where('que_status', self::STATUS_PENDING);
|
||||
|
||||
if ($queClass) {
|
||||
$query->where('que_class', $queClass);
|
||||
}
|
||||
|
||||
return $query->with(['park', 'user', 'contract'])
|
||||
->orderBy('created_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* キューを完了状態に更新
|
||||
*
|
||||
* @param string|null $comment 完了コメント
|
||||
* @return bool 更新結果
|
||||
*/
|
||||
public function markAsCompleted(?string $comment = null): bool
|
||||
{
|
||||
return $this->update([
|
||||
'que_status' => self::STATUS_COMPLETED,
|
||||
'que_status_comment' => $comment ?? self::getStatusComment(self::STATUS_COMPLETED),
|
||||
'updated_at' => now()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* キューをエラー状態に更新
|
||||
*
|
||||
* @param string $errorMessage エラーメッセージ
|
||||
* @return bool 更新結果
|
||||
*/
|
||||
public function markAsError(string $errorMessage): bool
|
||||
{
|
||||
return $this->update([
|
||||
'que_status' => self::STATUS_ERROR,
|
||||
'que_status_comment' => $errorMessage,
|
||||
'updated_at' => now()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* ステータスコメントを取得
|
||||
*
|
||||
* @param int $status ステータス
|
||||
* @return string ステータスコメント
|
||||
*/
|
||||
public static function getStatusComment(int $status): string
|
||||
{
|
||||
switch ($status) {
|
||||
case self::STATUS_PENDING:
|
||||
return '待機中';
|
||||
case self::STATUS_COMPLETED:
|
||||
return '完了';
|
||||
case self::STATUS_ERROR:
|
||||
return 'エラー';
|
||||
case self::STATUS_CANCELLED:
|
||||
return 'キャンセル';
|
||||
default:
|
||||
return '不明';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* キュークラス名を取得
|
||||
*
|
||||
* @param int $queClass キュークラス
|
||||
* @return string クラス名
|
||||
*/
|
||||
public static function getClassName(int $queClass): string
|
||||
{
|
||||
switch ($queClass) {
|
||||
case self::CLASS_SHJ4C:
|
||||
return 'SHJ-4C室割当処理';
|
||||
case self::CLASS_SHJ6:
|
||||
return 'SHJ-6サーバ死活監視処理';
|
||||
case self::CLASS_SHJ8:
|
||||
return 'SHJ-8バッチログ処理';
|
||||
case self::CLASS_SHJ9:
|
||||
return 'SHJ-9売上集計処理';
|
||||
case self::CLASS_SHJ10:
|
||||
return 'SHJ-10財政年度売上集計処理';
|
||||
case self::CLASS_MAIL_SEND:
|
||||
return 'メール送信処理';
|
||||
default:
|
||||
return "クラス{$queClass}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列表現
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return sprintf(
|
||||
'OperatorQue[ID:%d, Class:%s, Status:%s, Date:%s]',
|
||||
$this->que_id,
|
||||
self::getClassName($this->que_class),
|
||||
self::getStatusComment($this->que_status),
|
||||
$this->created_at ? $this->created_at->format('Y-m-d H:i:s') : 'N/A'
|
||||
);
|
||||
}
|
||||
public function getUser() { return $this->user; }
|
||||
public function getPark() { return $this->park; }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user