GameTmpManagementService.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Http\Services\Backend\DataManagement;
  3. use App\Http\Services\ConstDef\GeneralConst;
  4. use App\Models\Web\GameGpRatio;
  5. use App\Models\Web\Syslog;
  6. class GameTmpManagementService
  7. {
  8. // 相關私有 model 調用器宣告
  9. private $gameManagementDb;
  10. private $syslogManagementDb;
  11. public function __construct()
  12. {
  13. date_default_timezone_set("Asia/Taipei");
  14. // 建構 model 調用器
  15. $this->gameManagementDb = new GameGpRatio();
  16. $this->syslogManagementDb = new Syslog();
  17. }
  18. public function getGames(
  19. &$cnt = 0,
  20. $orderColumn,
  21. $orderDir,
  22. $start,
  23. $length,
  24. $searchValue
  25. )
  26. {
  27. $games = $this->gameManagementDb
  28. ->select([
  29. 'id',
  30. \DB::raw("CONCAT('<a href=\"gameManagement/edit/', id, '\">', IFNULL(ratio_tmp, ''), '</a>', '<hr>', IFNULL(ratio, '')) as ratio"),
  31. \DB::raw("CONCAT(IFNULL(gp_tmp, ''), '<hr>', IFNULL(gp, '')) as gp"),
  32. 'cdate',
  33. 'mdate',
  34. \DB::raw("(select name from users where id=gameGpRatio.oid) as oid"),
  35. ]);
  36. // 過濾搜尋條件
  37. // 取總筆數
  38. $cnt = $games->count();
  39. // 排序
  40. $games = $games
  41. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  42. // 彙整
  43. // 分頁
  44. $games = $games
  45. ->skip($start)->take($length);
  46. // 實際取資料
  47. $games = $games
  48. ->get()
  49. ->toArray();
  50. // 整理返回值並返回
  51. return $games;
  52. }
  53. public function getGameById($id)
  54. {
  55. // 取得參數
  56. // 調用資料庫(或者其他業務邏輯)
  57. $games = $this->gameManagementDb->select([
  58. 'id',
  59. \DB::raw("ratio_tmp as ratio"),
  60. \DB::raw("gp_tmp as gp"),
  61. 'cdate',
  62. 'mdate',
  63. \DB::raw("(select name from users where id=gameGpRatio.oid) as oid"),
  64. ])
  65. ->where('id', $id)
  66. ->first()
  67. ->toArray();
  68. // 整理返回值並返回
  69. return $games;
  70. }
  71. public function insertGame($ratio, $gp, $oid)
  72. {
  73. // 取得參數
  74. $data = [
  75. 'ratio' . '_tmp' => $ratio,
  76. 'gp' . '_tmp' => $gp,
  77. 'cdate' => date('Y-m-d H:i:s'),
  78. 'mdate' => date('Y-m-d H:i:s'),
  79. 'oid' => $oid,
  80. ];
  81. // 調用資料庫(或者其他業務邏輯)
  82. $this->gameManagementDb
  83. ->insert($data);
  84. $id = \DB::getPdo()->lastInsertId();
  85. // syslog
  86. $this->syslogManagementDb
  87. ->insert([
  88. 'type' => GeneralConst::LOG_ADMIN,
  89. 'func' => __FUNCTION__,
  90. 'k' => $oid,
  91. 'memoIn' => json_encode(['data' => $data], JSON_UNESCAPED_UNICODE),
  92. 'memoOut' => json_encode(['id' => $id], JSON_UNESCAPED_UNICODE),
  93. 'cdate' => date("Y-m-d H:i:s"),
  94. ]);
  95. // 整理返回值並返回
  96. return $id;
  97. }
  98. public function modifyGame($id, $ratio, $gp, $oid)
  99. {
  100. // 取得參數
  101. $data = [
  102. 'ratio' . '_tmp' => $ratio,
  103. 'gp' . '_tmp' => $gp,
  104. 'mdate' => date('Y-m-d H:i:s'),
  105. 'oid' => $oid,
  106. ];
  107. // 調用資料庫(或者其他業務邏輯)
  108. $res = $this->gameManagementDb
  109. ->where('id', $id)
  110. ->update($data);
  111. $rc = \DB::select("SELECT ROW_COUNT() AS rc;");
  112. $rc = $rc[0]->rc;
  113. // syslog
  114. $this->syslogManagementDb
  115. ->insert([
  116. 'type' => GeneralConst::LOG_ADMIN,
  117. 'func' => __FUNCTION__,
  118. 'k' => $oid,
  119. 'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
  120. 'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
  121. 'cdate' => date("Y-m-d H:i:s"),
  122. ]);
  123. // 整理返回值並返回
  124. return $res;
  125. }
  126. }