where('user_id',15)->pluck('store_id')->toArray(); $res = Store::query()->with(['ShoppingCart' => function($query) { $query->with('goods'); }])->whereIn('id',$storeIds) ->get(); foreach ($res as &$k){ $k->subtotal = '99.90'; } return $res; } public function check($goodsId) { return mt_rand(0,6); } public function undo() { $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',198)->pluck('store_id')->toArray(); $res = Store::query()->with(['ShoppingCart' => function($query) { $query->with('goods'); }])->whereIn('id',$storeIds) ->get(); foreach ($res as &$k){ $k->subtotal = '99.90'; foreach ($k->ShoppingCart as &$v){ switch (mt_rand(1,3)) { case 1: $str = '已下架'; break; case 2: $str = '已抢光'; break; case 3: $str = '已打烊'; break; } $v['goods']['invalid_cause'] = $str; } } return $res; } public function countGoods() { return mt_rand(1,100); } public function getTotal() { $randomFloat = rand(100,999)/100; return $randomFloat; } }