Subscribe.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\common\models\wechat\SubscribeMessage as SubscribeMessageModel;
  12. class Subscribe 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,$condition=[]){
  22. $count = SubscribeMessageModel::where($condition)->count();
  23. $result = SubscribeMessageModel::where($condition)->page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray();
  24. return [ "count"=>$count, "data"=>$result ];
  25. }
  26. /**
  27. * 详情
  28. * @param $id
  29. * @return array[]
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public static function detail($id){
  35. $row = SubscribeMessageModel::where("id",$id)->find();
  36. if(!empty($row)){
  37. $row["attr"] = json_decode($row["content"],true);
  38. }
  39. return ["data"=>$row??[]];
  40. }
  41. /**
  42. * 保存数据
  43. * @param $data
  44. * @return bool
  45. */
  46. public static function save($data){
  47. $data["content"] = !empty($data["attr"]) ? json_encode($data["attr"],JSON_UNESCAPED_UNICODE) : "";
  48. if(SubscribeMessageModel::where("id",$data["id"])->count()){
  49. SubscribeMessageModel::where("id",$data["id"])->save($data);
  50. }else{
  51. SubscribeMessageModel::create($data);
  52. }
  53. return true;
  54. }
  55. /**
  56. * 删除
  57. * @param $id
  58. * @return bool
  59. */
  60. public static function delete($id){
  61. return SubscribeMessageModel::where("id",$id)->delete();
  62. }
  63. }