Reply.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\wechat;
  10. use app\admin\service\Service;
  11. use app\admin\model\wechat\WechatKeys as WechatKeysModel;
  12. class Reply 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. $count = WechatKeysModel::withSearch(["keys"],[
  23. 'keys'=>$data['key']["title"]??''
  24. ])->count();
  25. $result = WechatKeysModel::withSearch(["keys"],[
  26. 'keys'=>$data['key']["title"]??''
  27. ])->page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray();
  28. return [ "count"=>$count, "data"=>$result ];
  29. }
  30. /**
  31. * 详情
  32. * @param array $condition
  33. * @return array
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public static function detail($condition=[]){
  39. return [ "data"=>WechatKeysModel::where($condition)->find() ];
  40. }
  41. /**
  42. * 保存数据
  43. * @param $data
  44. * @return bool
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public static function save($data){
  50. if($obj = WechatKeysModel::where(["id"=>$data["id"]])->find()){
  51. $k = WechatKeysModel::where(["keys"=>$data["keys"]])->find();
  52. if($k["id"] != $obj["id"]){
  53. throw new \Exception("关键字已存在!",0);
  54. }
  55. WechatKeysModel::where(["id"=>$data["id"]])->save($data);
  56. }else{
  57. if(WechatKeysModel::where(["keys"=>$data["keys"]])->count()){
  58. throw new \Exception("关键字已存在!",0);
  59. }
  60. WechatKeysModel::save($data);
  61. }
  62. return true;
  63. }
  64. /**
  65. * 保存单条数据
  66. * @param $data
  67. * @return bool
  68. */
  69. public static function saveKeys($data){
  70. if(WechatKeysModel::where(["keys"=>$data["keys"]])->count()){
  71. WechatKeysModel::where(["keys"=>$data["keys"]])->save($data);
  72. }else{
  73. unset($data["id"]);
  74. WechatKeysModel::create($data);
  75. }
  76. return true;
  77. }
  78. /**
  79. * 删除
  80. * @param $id
  81. * @return bool
  82. */
  83. public static function delete($id){
  84. return WechatKeysModel::where("id",$id)->delete();
  85. }
  86. /**
  87. * 更新字段值
  88. * @return bool
  89. */
  90. public static function setFields(){
  91. $data = self::getFields();
  92. WechatKeysModel::where("id",$data["id"])->update([$data["name"]=>$data["value"]]);
  93. return true;
  94. }
  95. }