Suggest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\users;
  10. use app\admin\model\users\UsersSuggest as UsersSuggestModel;
  11. use app\admin\service\Service;
  12. use app\common\models\users\Users as UsersModel;
  13. use think\facade\Session;
  14. class Suggest extends Service {
  15. /**
  16. * 获取列表数据
  17. * @param $data
  18. * @return array
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\DbException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. */
  23. public static function getList($data){
  24. $condition = [];
  25. $key = $data["key"]??[];
  26. if(isset($key["cat_id"]) && $key["cat_id"] != '-1'){
  27. $filed = $key["cat_id"] == 0 ? "users.username" : "goods.title";
  28. $condition[] = [$filed,"like",'%'.$key["title"].'%'];
  29. }
  30. $count = UsersSuggestModel::withJoin(['users'])->where($condition)->count();
  31. $result = UsersSuggestModel::withJoin(['users'])->where($condition)->page($data["page"]??1,$data["limit"]??10)->order("users_suggest.id","desc")->select()->toArray();
  32. return [ "count"=>$count, "data"=>array_map(function ($res){
  33. $res["username"] = getUserName($res);
  34. return $res;
  35. },$result) ];
  36. }
  37. /**
  38. * 详情
  39. * @param $id
  40. * @return array
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public static function detail($id){
  46. if(!$row=UsersSuggestModel::where("id",$id)->find()){
  47. throw new \Exception("您要查找的内容不存在!");
  48. }
  49. $users = UsersModel::where("id",$row["user_id"])->find();
  50. $row["username"] = getUserName($users);
  51. return [ "data"=>$row ];
  52. }
  53. /**
  54. * 保存数据
  55. * @param $data
  56. * @return bool
  57. * @throws \Exception
  58. */
  59. public static function save($data){
  60. if(empty($data["reply_content"])){
  61. throw new \Exception("请填写回复内容",0);
  62. }
  63. $data["admin_id"] = Session::get("system_user_id");
  64. $data["reply_time"] = time();
  65. $data["status"] = 1;
  66. UsersSuggestModel::where("id",$data["id"])->save($data);
  67. return true;
  68. }
  69. /**
  70. * 删除
  71. * @param $id
  72. * @return bool
  73. */
  74. public static function delete($id){
  75. return UsersSuggestModel::where("id",$id)->delete();
  76. }
  77. }