DC Team 的 Laravel 基底框架、資料庫描述、開發規範、環境佈署、版控規範

TigerManagementService.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Http\Services\Backend\ZooManagement;
  3. use App\Models\ZooManagement\TigerManagement;
  4. class TigerManagementService
  5. {
  6. // 相關私有 model 調用器宣告
  7. private $tigerManagementDb;
  8. public function __construct()
  9. {
  10. // 建構 model 調用器
  11. $this->tigerManagementDb = new TigerManagement();
  12. }
  13. /**
  14. * 取得老虎資訊的列表
  15. * 排序、分頁均未實現
  16. * @return array: 返回老虎列表的陣列
  17. */
  18. public function getTigers()
  19. {
  20. // 取得參數
  21. // 調用資料庫(或者其他業務邏輯)
  22. $tigers = $this->tigerManagementDb->select(['id', 'tigerName'])->get()->toArray();
  23. // 整理返回值並返回
  24. return $tigers;
  25. }
  26. /**
  27. * 取得單一老虎資訊
  28. *
  29. * @param integer $id : 老虎的自增量
  30. *
  31. * @return array: 返回老虎資訊的陣列
  32. */
  33. public function getTigerById($id)
  34. {
  35. // 取得參數
  36. // 調用資料庫(或者其他業務邏輯)
  37. $tigers = $this->tigerManagementDb->select(['id', 'tigerName'])->where('id', $id)->first()->toArray();
  38. // 整理返回值並返回
  39. return $tigers;
  40. }
  41. /**
  42. * 新增老虎
  43. *
  44. * @param string $tigerName : 老虎名字
  45. *
  46. * @return bool: 返回新增的操作結果
  47. */
  48. public function insertTiger($tigerName)
  49. {
  50. // 取得參數
  51. // 調用資料庫(或者其他業務邏輯)
  52. $res = $this->tigerManagementDb
  53. ->insert(['tigerName' => $tigerName]);
  54. // 整理返回值並返回
  55. return $res;
  56. }
  57. /**
  58. * 修改老虎
  59. *
  60. * @param integer $id : 老虎的自增量
  61. * @param string $tigerName : 老虎名字
  62. *
  63. * @return bool: 返回修改的操作結果
  64. */
  65. public function modifyTiger($id, $tigerName)
  66. {
  67. // 取得參數
  68. // 調用資料庫(或者其他業務邏輯)
  69. $res = $this->tigerManagementDb
  70. ->where('id', $id)
  71. ->update(['tigerName' => $tigerName]);
  72. // 整理返回值並返回
  73. return $res;
  74. }
  75. /**
  76. * 刪除老虎
  77. *
  78. * @param integer $id : 老虎的自增量
  79. *
  80. * @return bool: 返回刪除的操作結果
  81. */
  82. public function deleteTigerById($id)
  83. {
  84. // 取得參數
  85. // 調用資料庫(或者其他業務邏輯)
  86. $res = $this->tigerManagementDb
  87. ->where('id', $id)
  88. ->delete();
  89. // 整理返回值並返回
  90. return $res;
  91. }
  92. }