Keywords.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\platform;
  10. use app\admin\service\Service;
  11. use app\common\models\SearchKeywords;
  12. class Keywords extends Service {
  13. /**
  14. * 获取列表
  15. * @param $data
  16. * @return array
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\DbException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. */
  21. public static function getList($data){
  22. return [
  23. "count"=>SearchKeywords::count(),
  24. "data"=>SearchKeywords::page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray()
  25. ];
  26. }
  27. /**
  28. * 获取单条数据
  29. * @param $id
  30. * @return array[]
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\DbException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. */
  35. public static function detail($id){
  36. return [
  37. "data"=>SearchKeywords::where("id",$id)->find() ?? []
  38. ];
  39. }
  40. /**
  41. * 保存数据
  42. * @param $data
  43. * @return SearchKeywords|bool|\think\Model
  44. */
  45. public static function save($data){
  46. if(SearchKeywords::where("id",$data['id'])->count()){
  47. return SearchKeywords::where("id",$data['id'])->save($data);
  48. }else{
  49. return SearchKeywords::create($data);
  50. }
  51. }
  52. /**
  53. * 删除
  54. * @param $id
  55. * @return bool
  56. */
  57. public static function delete($id){
  58. return SearchKeywords::where("id",$id)->delete();
  59. }
  60. /**
  61. * 更新字段值
  62. * @return SearchKeywords
  63. */
  64. public static function setFields(){
  65. $data = self::getFields();
  66. return SearchKeywords::where("id",$data["id"])->update([$data["name"]=>$data["value"]]);
  67. }
  68. }