Report.php 2.7 KB

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