GameCategory.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Models;
  3. class GameCategory extends BaseModel
  4. {
  5. protected $table="game_category";
  6. public $timestamps = false;
  7. function getGameCategoryList($list=10)
  8. {
  9. $data = $this->select('id','name','codes','sort','is_show')->orderBy('sort','desc')->paginate($list);
  10. if(!$data){
  11. return -5040000522;//没有数据
  12. }
  13. $data = $data->toArray();
  14. $show = trans ('category.show');
  15. foreach ($data['data'] as $key => $val)
  16. {
  17. $data['data'][$key]['is_show'] = $show[$val['is_show']];
  18. }
  19. return $data;
  20. }
  21. function getCateOne($id){
  22. $data=$this->where('id',$id)->first();
  23. if(!$data){
  24. return -5040000622;
  25. }
  26. return $data->toArray();
  27. }
  28. //更新分类信息
  29. function updateOne($data,$id){
  30. $res=$this->where('id',$id)->update($data);
  31. if(!$res){
  32. return -5040000122;
  33. }
  34. return 1;
  35. }
  36. //检测是否存在
  37. function checkCopyCate($name)
  38. {
  39. $data=$this->where('name',$name)->first();
  40. if(!$data){
  41. return 1;
  42. }
  43. return -5040451122;
  44. }
  45. //检测分类代码是否存在
  46. function checkCopyCateCode($code)
  47. {
  48. $data=$this->where('codes',$code)->first();
  49. if(!$data){
  50. return 1;
  51. }
  52. return -5040451122;
  53. }
  54. function addCate($data)
  55. {
  56. $res=$this->insert($data);
  57. if(!$res){
  58. return -5040001122;
  59. }
  60. }
  61. function getAll()
  62. {
  63. $data = $this->select('id','name')->orderBy('id','asc')->get()->toArray();
  64. if(!$data){
  65. return $data = [ '暂无分类' ]; //没有数据
  66. }
  67. return $data;
  68. }
  69. }