CommentController.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Admin;
  5. use App\Models\DwbsUser;
  6. use App\Models\DwbsWarea;
  7. use App\Models\GoodSku;
  8. use App\Models\OrderDetail;
  9. use App\Models\Order;
  10. use App\Models\Store;
  11. use App\Models\User;
  12. use Illuminate\Http\Request;
  13. use App\Models\Comment;
  14. use App\Models\Region;
  15. use App\Models\Address;
  16. use Illuminate\Support\Facades\Auth;
  17. use Illuminate\Support\Facades\DB;
  18. use Illuminate\Support\Facades\Log;
  19. use Illuminate\Support\Facades\Storage;
  20. class CommentController extends Controller
  21. {
  22. //商品列表
  23. public function list(Request $request){
  24. $page_index=$request->input('page_index');
  25. $page_size=$request->input('page_size');
  26. $num=$page_size*($page_index-1);
  27. $admin_id=Auth::user()->id;
  28. $admin=Admin::where('id',$admin_id)->first();
  29. if($admin && in_array($admin->role_id,[22,24])){//超级管理员
  30. $data=Comment::query();
  31. }else{
  32. $warea_ids=DwbsWarea::where('admin_id',$admin_id)->pluck('id');
  33. $agent_ids=DwbsUser::whereIn('warea_id',$warea_ids)->pluck('id');
  34. $store_ids=Store::whereIn('user_id',$agent_ids)->pluck('id');
  35. $data=Comment::query()->whereIn('store_id',$store_ids);
  36. }
  37. //店铺名称手机号筛选
  38. if($request->has('agent_phone') && !empty($request->input('agent_phone'))){
  39. $store_ids=Store::where('phone','like',"%".$request->input('agent_phone')."%")
  40. ->orWhere('name','like',"%".$request->input('agent_phone')."%")->pluck('id');
  41. $data->whereIn('store_id',$store_ids);
  42. }
  43. //客户信息筛选
  44. if($request->has('user_phone') && !empty($request->input('user_phone'))){
  45. $user_ids=User::where('phone','like',"%".$request->input('user_phone')."%")
  46. ->orWhere('nickname','like',"%".$request->input('user_phone')."%")->pluck('id');
  47. $data->whereIn('user_id',$user_ids);
  48. }
  49. $count=$data->where('is_reply',1)->count();
  50. $list=$data->where('is_reply',1)->with(['user:id,nickname,phone','store:id,name,phone'])
  51. ->orderBy('id','desc')->skip($num)->take($page_size)->get();
  52. return $this->success_list($list,'成功',$count);
  53. }
  54. //
  55. public function detail(Request $request){
  56. $id=$request->input('id');
  57. $comment=Comment::with('reply')->where('id',$id)->first();
  58. return $this->success($comment);
  59. }
  60. //删除
  61. public function destroy(Request $request){
  62. $res=Comment::where('id',$request->input('id'))->delete();
  63. if($res){
  64. return $this->success([]);
  65. }else{
  66. return $this->error();
  67. }
  68. }
  69. }