order('weight desc,id asc')->paginate($limit); return $this->success(__('successful'),$list->toArray()); } /** * 详情 * @Apidoc\Query("id", type="int", require=true, desc="ID") */ public function detail(){ try{ $user = \support\Jwt::getUser(); }catch(\Exception $e){ $user = ['id'=>0,'role_id'=>0]; } $appid = input('id'); if(!$appid){ return $this->error(__("Product does not exist")); } /** @var ProductModel $product */ $product = ProductModel::where('id',$appid)->find(); //->cache(true,86400,'product_detail') if(!$product) { return $this->error(__("Product does not exist")); } if($user['id']){ $total_quantity_user = ProductOrderModel::where('product_id',$product->id)->where('user_id',$user['id'])->sum('quantity'); $total_quantity_system = $product->user_quantity ?: 99999999; $max_quantity = $total_quantity_system-$total_quantity_user; $max_quantity= $max_quantity < 0 ? 0: $max_quantity; $product->max_quantity = $max_quantity; $product->total_quantity_user = $total_quantity_user; }else{ $product->total_quantity_user = 0; $product->max_quantity = 0; } return $this->success(__('successful'),$product->toArray()); } }