FittingRoomController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\DB;
  4. use Illuminate\Http\Request;
  5. class FittingRoomController extends Controller
  6. {
  7. // 试衣间装扮列表
  8. public function show(Request $request) {
  9. //
  10. $objUser = unserialize($request->get("account"));
  11. //
  12. $objFittingRoom = \App\Models\FittingRoom::where("account_id", $objUser->id)->with(['attire'])->OrderByDesc("id")->get()->toArray();
  13. // 按照类别进行分类
  14. $result = [
  15. '皮肤' => [
  16. 'cate' => '皮肤',
  17. 'relations' => [],
  18. ],
  19. '套装' => [
  20. 'cate' => '套装',
  21. 'relations' => [],
  22. ],
  23. ];
  24. foreach($objFittingRoom as $v) {
  25. $result[$v['attire']['cate']]['relations'][] = [
  26. 'attire_id' => $v['attire_id'],
  27. 'curr_save' => $v['curr_save'],
  28. 'name' => $v['attire']['name'],
  29. // 'cate' => $v['attire']['cate'],
  30. 'img_1' => \Storage::disk('cosv5')->url($v['attire']['img_1']),
  31. 'img_2' => \Storage::disk('cosv5')->url($v['attire']['img_2']),
  32. ];
  33. }
  34. $result = array_values($result);
  35. return [
  36. 'errno'=> 10000,
  37. "errmsg" => 'ok',
  38. 'data' => $result,
  39. ];
  40. }
  41. // 保存接口
  42. public function save(Request $request) {
  43. //
  44. $objUser = unserialize($request->get("account"));
  45. //
  46. // dd($request->input('attire_ids'));
  47. $ids = $request->input('attire_ids', []);
  48. if(!$ids) {
  49. return [
  50. 'errno'=> 10001,
  51. "errmsg" => '参数错误',
  52. ];
  53. }
  54. //
  55. $arrId = DB::table("fitting_rooms")->where("account_id", $objUser->id)
  56. ->whereIn("attire_id", $ids)
  57. ->pluck("attire_id");
  58. if(count($arrId) < count($ids)) {
  59. return [
  60. 'errno'=> 10002,
  61. "errmsg" => '参数错误',
  62. ];
  63. }
  64. // 先把现在的保存去掉,然后上传的修改为保存
  65. DB::transaction(function () use($ids, $objUser) {
  66. //
  67. DB::table("fitting_rooms")
  68. ->where("account_id", $objUser->id)
  69. ->where("curr_save",1)
  70. ->update(['curr_save'=>0]);
  71. //
  72. DB::table("fitting_rooms")
  73. ->where("account_id", $objUser->id)
  74. ->whereIn("attire_id", $ids)
  75. ->update(['curr_save'=>1]);
  76. });
  77. return [
  78. 'errno'=> 10000,
  79. "errmsg" => 'ok',
  80. ];
  81. }
  82. // 上传接口
  83. public function upload(Request $request) {
  84. //
  85. $objUser = unserialize($request->get("account"));
  86. // 先把现在的保存去掉,然后上传的修改为保存
  87. DB::transaction(function () use($objUser) {
  88. //
  89. DB::table("fitting_rooms")
  90. ->where("account_id", $objUser->id)
  91. ->where("curr_upload",1)
  92. ->update(['curr_upload'=>0]);
  93. //
  94. DB::table("fitting_rooms")
  95. ->where("account_id", $objUser->id)
  96. ->where("curr_save",1)
  97. ->update(['curr_upload'=>1]);
  98. });
  99. // 获取分享的直播间列表
  100. $resources = \App\Models\LiveRoom::where("is_show_share", 1)
  101. ->orderBy("sort","asc")
  102. ->orderBy("id","asc")
  103. ->get(["name","img","room_id"])
  104. ->toArray();
  105. foreach($resources as &$v) {
  106. $v['url'] = "https://live.bilibili.com/h5/{$v['room_id']}";
  107. $v["img"] = \Storage::disk('cosv5')->url($v["img"]);
  108. }
  109. return [
  110. 'errno'=> 10000,
  111. "errmsg" => 'ok',
  112. "data" => $resources,
  113. ];
  114. }
  115. }